diff options
author | Ian Hinder <ian.hinder@aei.mpg.de> | 2013-09-09 11:39:10 +0200 |
---|---|---|
committer | Ian Hinder <ian.hinder@aei.mpg.de> | 2013-09-09 11:39:10 +0200 |
commit | 10e0c6a4513eff6b649ba0f16bbb426384f80888 (patch) | |
tree | e8fbf9836f21b0692104e1049502ad3bc2c98c2f | |
parent | 83edd892b8b7e70f92cafd07713053a247327062 (diff) |
Thorn.m: Move symmetries registration file generation to new CodeGenSymmetries.m
-rw-r--r-- | Tools/CodeGen/CodeGenSymmetries.m | 135 | ||||
-rw-r--r-- | Tools/CodeGen/KrancThorn.m | 2 | ||||
-rw-r--r-- | Tools/CodeGen/Thorn.m | 102 |
3 files changed, 136 insertions, 103 deletions
diff --git a/Tools/CodeGen/CodeGenSymmetries.m b/Tools/CodeGen/CodeGenSymmetries.m new file mode 100644 index 0000000..143fae0 --- /dev/null +++ b/Tools/CodeGen/CodeGenSymmetries.m @@ -0,0 +1,135 @@ + +(* Copyright 2004-2013 Sascha Husa, Ian Hinder, Christiane Lechner + + This file is part of Kranc. + + Kranc is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Kranc is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Kranc; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*) + +BeginPackage[ + "CodeGenSymmetries`", + {"Errors`", "Helpers`", "Kranc`", "CodeGenCactus`", "MapLookup`", "CodeGenKranc`", + "CodeGenC`"}]; + +CreateSymmetriesRegistrationSource::usage = ""; + +Begin["`Private`"]; + +(* ------------------------------------------------------------------------ + Symmetries Registration + ------------------------------------------------------------------------ *) + +(* Symmetries registration spec = {FullName -> "impl::GFname", + Sym -> {symX, symY, symZ}} *) + +SymmetriesBlock[spec_] := + + Module[{i, KrancDim}, + + If[!MatchQ[spec, {FullName -> _String, Sym -> {_,_,_}}], + ThrowError["SymmetriesBlock: Expecting a symmetry registration spec but got ", spec]]; + + KrancDim = 3; + + sym = lookup[spec, Sym]; + + {Table["sym[" <> ToString[i - 1] <> "] = " <> + ToString@sym[[i]] <> ";\n", {i, 1, KrancDim}], + + "SetCartSymVN(cctkGH, sym, \"" <> lookup[spec, FullName] <> "\");\n\n" +} +]; + +(* syms is a list of rules mapping gridfunctions to their symmetry structures *) +calcSymmetry[gf_, syms_] := + Module[{}, + If[mapContains[syms, gf], + Return[lookup[syms,gf]], + (* FIXME: We are defaulting to scalar symmetries if no information is + available. This shouldn't happen, but I am bypassing this check + temporarily. *) + Print["WARNING: defaulting to symmetries of a scalar for "<>ToString[gf]]; + Return[{1,1,1}]]]; + + +(* This function guesses the symmetries based on component names as we + have not been given them *) +calcSymmetry[gf_] := Module[{sym, q, string}, + +sym = {1, 1, 1}; (* default *) + +string = ToString@gf; + +While[IntegerQ[q = ToExpression@StringTake[string, -1]], + +Module[{}, + sym[[q]] = -sym[[q]]; + string = StringDrop[string, -1] + ] +]; +sym +]; + +(* Compatibility function to be called by KrancThorns because it + doesn't understand reflection symmetries *) +CreateSymmetriesRegistrationSource[thornName_, implementationName_, GFs_, debug_] := + CreateSymmetriesRegistrationSource[thornName, implementationName, GFs, False, debug]; + + + +(* Given a symmetries registration structure as defined above, return a + C CodeGen structure of a source file which will register the symmetries. *) +CreateSymmetriesRegistrationSource[thornName_, implementationName_, GFs_, reflectionSymmetries_, debug_] := + Module[{spec, j, lang, tmp}, + + If[debug, + Print["Registering Symmetries for: ", GFs]; + ]; + + lang = CodeGenC`SOURCELANGUAGE; + CodeGenC`SOURCELANGUAGE = "C"; + + spec = Table[{FullName -> implementationName <> "::" <> ToString@GFs[[j]], + Sym -> If[reflectionSymmetries === False, + calcSymmetry[GFs[[j]]], + calcSymmetry[GFs[[j]], Union@reflectionSymmetries]]}, {j, 1, Length@GFs}]; + + tmp = {FileHeader["C"], + + Map[IncludeFile, + {"cctk.h", "cctk_Arguments.h", "cctk_Parameters.h", "Symmetry.h"}], + + DefineCCTKFunction[ thornName <> "_RegisterSymmetries", "void", + If[Length[spec] > 0, + {CommentedBlock["array holding symmetry definitions", + + "CCTK_INT sym[3];\n\n"], + + CommentedBlock["Register symmetries of grid functions", + + Map[SymmetriesBlock, spec]]}, + {}] +] + }; + + CodeGenC`SOURCELANGUAGE = lang; + +tmp +]; + + +End[]; + +EndPackage[]; diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index 5606b50..55b9c28 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -30,7 +30,7 @@ BeginPackage["KrancThorn`", {"CodeGen`", "Thorn`", "CalculationFunction`", "Errors`", "Helpers`", "CactusBoundary`", "KrancTensor`", "Param`", "Schedule`", "Interface`", "Kranc`", "Jacobian`", "ConservationCalculation`", "CaKernel`", "Calculation`", "ParamCheck`", - "OpenCL`", "CodeGenConfiguration`", "CodeGenMakefile`"}]; + "OpenCL`", "CodeGenConfiguration`", "CodeGenMakefile`", "CodeGenSymmetries`"}]; CreateKrancThorn::usage = "Construct a Kranc thorn"; diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m index cf6b1b4..c45883f 100644 --- a/Tools/CodeGen/Thorn.m +++ b/Tools/CodeGen/Thorn.m @@ -31,7 +31,6 @@ BeginPackage["Thorn`", "CodeGen`", "CodeGenC`", "CodeGenCactus`", "CodeGenKranc` interface to this package. *) CreateThorn::usage = "Create a general Cactus thorn from a thorn specification structure"; -CreateSymmetriesRegistrationSource::usage = ""; CreateMoLRegistrationSource::usage = ""; CreateMoLBoundariesSource::usage = ""; CreateMoLExcisionSource::usage = ""; @@ -117,107 +116,6 @@ CreateSetterSource[calcs_, debug_, include_, -(* ------------------------------------------------------------------------ - Symmetries Registration - ------------------------------------------------------------------------ *) - -(* Symmetries registration spec = {FullName -> "impl::GFname", - Sym -> {symX, symY, symZ}} *) - -SymmetriesBlock[spec_] := - - Module[{i, KrancDim}, - - If[!MatchQ[spec, {FullName -> _String, Sym -> {_,_,_}}], - ThrowError["SymmetriesBlock: Expecting a symmetry registration spec but got ", spec]]; - - KrancDim = 3; - - sym = lookup[spec, Sym]; - - {Table["sym[" <> ToString[i - 1] <> "] = " <> - ToString@sym[[i]] <> ";\n", {i, 1, KrancDim}], - - "SetCartSymVN(cctkGH, sym, \"" <> lookup[spec, FullName] <> "\");\n\n" -} -]; - -(* syms is a list of rules mapping gridfunctions to their symmetry structures *) -calcSymmetry[gf_, syms_] := - Module[{}, - If[mapContains[syms, gf], - Return[lookup[syms,gf]], - (* FIXME: We are defaulting to scalar symmetries if no information is - available. This shouldn't happen, but I am bypassing this check - temporarily. *) - Print["WARNING: defaulting to symmetries of a scalar for "<>ToString[gf]]; - Return[{1,1,1}]]]; - - -(* This function guesses the symmetries based on component names as we - have not been given them *) -calcSymmetry[gf_] := Module[{sym, q, string}, - -sym = {1, 1, 1}; (* default *) - -string = ToString@gf; - -While[IntegerQ[q = ToExpression@StringTake[string, -1]], - -Module[{}, - sym[[q]] = -sym[[q]]; - string = StringDrop[string, -1] - ] -]; -sym -]; - -(* Compatibility function to be called by KrancThorns because it - doesn't understand reflection symmetries *) -CreateSymmetriesRegistrationSource[thornName_, implementationName_, GFs_, debug_] := - CreateSymmetriesRegistrationSource[thornName, implementationName, GFs, False, debug]; - - - -(* Given a symmetries registration structure as defined above, return a - C CodeGen structure of a source file which will register the symmetries. *) -CreateSymmetriesRegistrationSource[thornName_, implementationName_, GFs_, reflectionSymmetries_, debug_] := - Module[{spec, j, lang, tmp}, - - If[debug, - Print["Registering Symmetries for: ", GFs]; - ]; - - lang = CodeGenC`SOURCELANGUAGE; - CodeGenC`SOURCELANGUAGE = "C"; - - spec = Table[{FullName -> implementationName <> "::" <> ToString@GFs[[j]], - Sym -> If[reflectionSymmetries === False, - calcSymmetry[GFs[[j]]], - calcSymmetry[GFs[[j]], Union@reflectionSymmetries]]}, {j, 1, Length@GFs}]; - - tmp = {FileHeader["C"], - - Map[IncludeFile, - {"cctk.h", "cctk_Arguments.h", "cctk_Parameters.h", "Symmetry.h"}], - - DefineCCTKFunction[ thornName <> "_RegisterSymmetries", "void", - If[Length[spec] > 0, - {CommentedBlock["array holding symmetry definitions", - - "CCTK_INT sym[3];\n\n"], - - CommentedBlock["Register symmetries of grid functions", - - Map[SymmetriesBlock, spec]]}, - {}] -] - }; - - CodeGenC`SOURCELANGUAGE = lang; - -tmp -]; (* ------------------------------------------------------------------------ |