aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Hinder <ian.hinder@aei.mpg.de>2013-09-12 20:29:28 +0200
committerIan Hinder <ian.hinder@aei.mpg.de>2013-09-12 20:29:28 +0200
commitd7612a318433c8e99daa8348570d0866d37d9f57 (patch)
treec8bb922569fc29490eae99b3a437ad77c9286a85
parent66b5a2e4e6f1151cba25a3f39aaca07e4cd1d38e (diff)
CodeGenSymmetries.m: Reformat code
-rw-r--r--Tools/CodeGen/CodeGenSymmetries.m141
1 files changed, 64 insertions, 77 deletions
diff --git a/Tools/CodeGen/CodeGenSymmetries.m b/Tools/CodeGen/CodeGenSymmetries.m
index 5cdad9f..033fdb9 100644
--- a/Tools/CodeGen/CodeGenSymmetries.m
+++ b/Tools/CodeGen/CodeGenSymmetries.m
@@ -21,7 +21,7 @@
BeginPackage[
"CodeGenSymmetries`",
{"Errors`", "Helpers`", "Kranc`", "CodeGenCactus`", "MapLookup`", "CodeGenKranc`",
- "CodeGenC`"}];
+ "CodeGenC`", "CodeGen`"}];
CreateSymmetriesRegistrationSource::usage = "";
@@ -34,94 +34,81 @@ Begin["`Private`"];
(* Symmetries registration spec = {FullName -> "impl::GFname",
Sym -> {symX, symY, symZ}} *)
-symmetriesBlock[spec_] :=
+DefFn[symmetriesBlock[spec_] :=
+ Module[
+ {i, dim},
- Module[{i, KrancDim},
+ If[!MatchQ[spec, {FullName -> _String, Sym -> {_,_,_}}],
+ ThrowError["symmetriesBlock: Expecting a symmetry registration spec but got ", spec]];
- 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"
-}
-];
+ sym = lookup[spec, Sym];
+ dim = Length[sym];
+
+ {Table[{"sym[", i - 1, "] = ", sym[[i]], ";\n"}, {i, 1, dim}],
+ "SetCartSymVN(cctkGH, sym, ", Quote[lookup[spec, FullName]], ");\n\n"}]];
(* syms is a list of rules mapping gridfunctions to their symmetry structures *)
-calcSymmetry[gf_, syms_] :=
- Module[{},
+DefFn[
+ 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}]]];
+ 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
-];
+DefFn[
+ calcSymmetry[gf_] :=
+ Module[
+ {sym = {1,1,1} (* default *), q, string},
+ string = ToString@gf;
+ While[
+ IntegerQ[q = ToExpression@StringTake[string, -1]],
+ sym[[q]] = -sym[[q]];
+ string = StringDrop[string, -1]];
+ sym]];
(* 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
-];
-
+DefFn[
+ 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[];