aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Examples/Wave.m216
-rw-r--r--Examples/wave.par67
-rw-r--r--Tools/CodeGen/CactusBoundary.m10
-rw-r--r--Tools/CodeGen/CalculationFunction.m28
-rw-r--r--Tools/CodeGen/CodeGen.m6
-rw-r--r--Tools/CodeGen/Differencing.m8
-rw-r--r--Tools/CodeGen/Helpers.m6
-rw-r--r--Tools/CodeGen/Interface.m140
-rw-r--r--Tools/CodeGen/Kranc.m95
-rw-r--r--Tools/CodeGen/KrancGroups.m11
-rw-r--r--Tools/CodeGen/KrancThorn.m538
-rw-r--r--Tools/CodeGen/Param.m248
-rw-r--r--Tools/CodeGen/Schedule.m161
-rw-r--r--Tools/CodeGen/TensorTools.m9
-rw-r--r--Tools/CodeGen/Thorn.m41
15 files changed, 997 insertions, 587 deletions
diff --git a/Examples/Wave.m b/Examples/Wave.m
new file mode 100644
index 0000000..0c19475
--- /dev/null
+++ b/Examples/Wave.m
@@ -0,0 +1,216 @@
+
+Get["KrancThorn`"];
+SetEnhancedTimes[False];
+
+(********************************************************)
+(* Derivatives *)
+(********************************************************)
+
+derivatives =
+{
+ PDstandard2nd[i_] -> StandardCenteredDifferenceOperator[1,1,i],
+ PDstandard2nd[i_, i_] -> StandardCenteredDifferenceOperator[2,1,i],
+ PDstandard2nd[i_, j_] -> StandardCenteredDifferenceOperator[1,1,i] StandardCenteredDifferenceOperator[1,1,j],
+
+ PDstandard4th[i_] -> StandardCenteredDifferenceOperator[1,2,i],
+ PDstandard4th[i_, i_] -> StandardCenteredDifferenceOperator[2,2,i],
+ PDstandard4th[i_, j_] -> StandardCenteredDifferenceOperator[1,2,i] StandardCenteredDifferenceOperator[1,2,j],
+
+ PDonesided2nd[1] -> dir[1] (-shift[1]^(2 dir[1]) + 4 shift[1]^dir[1] - 3 )/(2 spacing[1]),
+ PDonesided2nd[2] -> dir[2] (-shift[2]^(2 dir[2]) + 4 shift[2]^dir[2] - 3 )/(2 spacing[2]),
+ PDonesided2nd[3] -> dir[3] (-shift[3]^(2 dir[3]) + 4 shift[3]^dir[3] - 3 )/(2 spacing[3]),
+
+ Diss2nd[] -> - diss Sum[spacing[i]^3 (DPlus[i] DMinus[i])^2, {i, 1, 3}],
+ Diss4th[] -> diss Sum[spacing[i]^5 (DPlus[i] DMinus[i])^3, {i, 1, 3}],
+
+ PDzero[i_] -> DZero[i],
+ PDzero[i_, j_] -> DZero[i] DZero[j],
+
+ PDplus[i_] -> DPlus[i]
+};
+
+Map[DefineTensor, {norm, dir}];
+
+zerodims = {};
+
+PD = PDstandard2nd;
+PDnorm = PDplus;
+
+evolvedGroup = {"evolved", {phi, pi}};
+normGroup = {"norms", {VL2, VDP, EL2}};
+exactGroup = {"exact", {phiExact, piExact}};
+errorGroup = {"errors", {phiError, piError}};
+
+groups = {evolvedGroup, normGroup, exactGroup, errorGroup};
+
+wp = {Name -> periodicity, Default -> 1};
+wa = {Name -> amplitude, Default -> 1};
+
+nNorm = Sqrt[n1^2+n2^2+n3^2];
+nX = n1 x + n2 y + n3 z;
+
+(* Sine wave exact solution *)
+
+exactSineCalc =
+{
+ Name -> "wave_exact_sine",
+ Before -> {"import_exact"},
+ ConditionalOnKeyword -> {"initial_data", "sine"},
+ Schedule -> {"AT INITIAL before import_exact","AT POSTSTEP before calc_errors"},
+ Shorthands -> {piconst},
+ Equations ->
+ {
+ piconst -> N[Pi,20],
+ phiExact -> amplitude Sin[2 piconst / periodicity (nX - nNorm t)],
+ piExact -> -2 piconst / periodicity nNorm amplitude Cos[2 piconst / periodicity (nX - nNorm t)]
+ }
+}
+
+(* Radial profile of exact Gaussian solution *)
+f[x_] := x^3 Exp[-x^2/nSigma^2];
+
+exactGaussianCalc =
+{
+ Name -> "wave_exact_gaussian",
+ Before -> {"import_exact"},
+ ConditionalOnKeyword -> {"initial_data", "gaussian"},
+ Schedule -> {"AT INITIAL before import_exact","AT POSTSTEP before calc_errors"},
+ Shorthands -> {piconst,rEps},
+ Equations ->
+ {
+ rEps -> (r^4+(10^(-6))^4)^(1/4),
+
+ phiExact -> (f[t+t0+r] - f[t+t0-r]) / rEps,
+ piExact -> (D[f[t+t0+r],t] - D[f[t+t0-r],t]) / rEps
+ }
+}
+
+(* Import the exact solution as the initial data *)
+
+importerEquations =
+{
+ phi -> phiExact,
+ pi -> piExact
+};
+
+importerCalc =
+{
+ Name -> "wave_import_exact",
+ Schedule -> {"at INITIAL as import_exact"},
+ Equations -> importerEquations
+}
+
+(* The evolution equations *)
+
+evolveEquations =
+{
+ dot[phi] -> pi,
+ dot[pi] -> PD[phi,li,ui]
+}
+
+evolveCalc =
+{
+ Name -> "wave_evolve",
+ Schedule -> {"in MoL_CalcRHS as evolve"},
+ Where -> Interior,
+ Equations -> evolveEquations
+}
+
+(* Evaluate the errors *)
+
+errorEquations =
+{
+ phiError -> phi - phiExact,
+ piError -> pi - piExact
+}
+
+errorCalc =
+{
+ Name -> "wave_calc_errors",
+ Schedule -> {"at ANALYSIS as calc_errors"},
+ Equations -> errorEquations
+}
+
+(* Evaluate the norms *)
+
+normEquations =
+{
+ VL2squared -> phi^2 + pi^2,
+ VL2 -> Sqrt[VL2squared],
+ VDPsquared -> pi^2 + PDnorm[phi,li] PDnorm[phi,ui],
+ VDP -> Sqrt[VDPsquared],
+ EL2squared -> phiError^2 + piError^2,
+ EL2 -> Sqrt[EL2squared]
+}
+
+normCalc =
+{
+ Name -> "wave_calc_norm",
+ Where -> Interior,
+ Schedule -> {"at ANALYSIS as calc_norm"},
+ Shorthands -> {VL2squared, VDPsquared, EL2squared},
+ Equations -> normEquations
+}
+
+(**************************************************************************************)
+(* Boundary conditions *)
+(**************************************************************************************)
+
+boundaryParam =
+{
+ Name -> "boundary_condition",
+ Default -> "radiative",
+ AllowedValues -> {"none", "radiative"}
+};
+
+boundaryCalc =
+{
+ Name -> "wave_boundary",
+ Schedule -> {"in MoL_RHSBoundaries"},
+ ConditionalOnKeyword -> {"boundary_condition", "radiative"},
+ Where -> Boundary,
+ Shorthands -> {norm[ui], dir[ui]},
+ Equations ->
+ {
+ norm1 -> -x/r,
+ norm2 -> -y/r,
+ norm3 -> -z/r,
+
+ dir[ui] -> Sign[norm[ui]],
+
+ (* \partial_t u = - (u - u_0) / r - \partial_r u
+ for u_0 some background solution. In this case, Minkowski in Cartesian
+ coordinates. *)
+
+ dot[phi] -> -(phi - 0) / r + norm[ui] PDonesided2nd[phi, li],
+ dot[pi] -> -(pi - 0) / r + norm[ui] PDonesided2nd[pi, li]
+ }
+};
+
+(* Construct the thorn *)
+
+calculations = {exactSineCalc, exactGaussianCalc, importerCalc, evolveCalc, errorCalc, normCalc, boundaryCalc};
+
+declaredGroups = Map[groupName, {evolvedGroup, exactGroup, errorGroup,
+ normGroup}];
+
+idParam =
+{
+ Name -> "initial_data",
+ Default -> "gaussian",
+ AllowedValues -> {"gaussian", "sine"}
+};
+
+keywordParameters =
+{
+ idParam,
+ boundaryParam
+};
+
+CreateKrancThornTT[groups, ".", "Wave",
+ Calculations -> calculations,
+ DeclaredGroups -> declaredGroups,
+ PartialDerivatives -> derivatives,
+ ZeroDimensions -> zerodims,
+ KeywordParameters -> keywordParameters,
+ RealParameters -> {wp, wa, {Name -> n1, Default -> 1}, n2, n3, nSigma, r0, t0, x0}]
diff --git a/Examples/wave.par b/Examples/wave.par
new file mode 100644
index 0000000..e28a05c
--- /dev/null
+++ b/Examples/wave.par
@@ -0,0 +1,67 @@
+
+Cactus::cctk_final_time = 1
+Cactus::terminate = "time"
+
+ActiveThorns = "IOUtil Carpet CarpetLib CarpetSlab CoordBase CoordBase SymBase CartGrid3D Slab CarpetIOBasic CarpetIOASCII Wave Time MoL Periodic Boundary GenericFD CarpetReduce LoopControl"
+
+CoordBase::domainsize = minmax
+
+CoordBase::boundary_size_x_lower = 1
+CoordBase::boundary_size_y_lower = 1
+CoordBase::boundary_size_z_lower = 1
+CoordBase::boundary_shiftout_x_lower = 1
+CoordBase::boundary_shiftout_y_lower = 1
+CoordBase::boundary_shiftout_z_lower = 1
+
+CoordBase::boundary_size_x_upper = 1
+CoordBase::boundary_size_y_upper = 1
+CoordBase::boundary_size_z_upper = 1
+CoordBase::boundary_shiftout_x_upper = 0
+CoordBase::boundary_shiftout_y_upper = 0
+CoordBase::boundary_shiftout_z_upper = 0
+
+CartGrid3D::type = "coordbase"
+CartGrid3D::domain = "full"
+CartGrid3D::avoid_origin = "no"
+
+CoordBase::xmin = 0
+CoordBase::ymin = 0
+CoordBase::zmin = 0
+CoordBase::xmax = 1
+CoordBase::ymax = 1
+CoordBase::zmax = 1
+CoordBase::dx = 0.05
+CoordBase::dy = 0.05
+CoordBase::dz = 0.05
+
+driver::ghost_size = 1
+Carpet::domain_from_coordbase = "yes"
+Carpet::poison_new_timelevels = "yes"
+Carpet::check_for_poison = "no"
+Carpet::poison_value = 113
+
+Carpet::max_refinement_levels = 1
+Carpet::prolongation_order_space = 3
+Carpet::prolongation_order_time = 2
+Carpet::init_each_timelevel = no
+Carpet::print_timestats_every = 0
+
+Periodic::periodic = yes
+
+Time::dtfac = 0.5
+
+MethodOfLines::ode_method = "RK4"
+MethodOfLines::MoL_NaN_Check = "no"
+MethodOfLines::initial_data_is_crap = "yes"
+MethodOfLines::MoL_Intermediate_Steps = 4
+MethodOfLines::MoL_Num_Scratch_Levels = 1
+
+IO::out_dir = $parfile
+
+CarpetIOBasic::outInfo_every = 1
+CarpetIOBasic::outInfo_vars = ""
+
+IOASCII::out1D_every = 1
+IOASCII::out1D_vars = "Wave::phi Wave::phiExact"
+Wave::initial_data = "sine"
+Wave::evolved_bound = "none"
diff --git a/Tools/CodeGen/CactusBoundary.m b/Tools/CodeGen/CactusBoundary.m
index 8c8b81a..090151c 100644
--- a/Tools/CodeGen/CactusBoundary.m
+++ b/Tools/CodeGen/CactusBoundary.m
@@ -32,14 +32,8 @@
*)
-BeginPackage["sym`"];
-
-{};
-
-EndPackage[];
-
-BeginPackage["CactusBoundary`", {"CodeGen`", "sym`", "Thorn`",
- "MapLookup`", "KrancGroups`", "Errors`", "Helpers`"}];
+BeginPackage["CactusBoundary`", {"CodeGen`", "Thorn`",
+ "MapLookup`", "KrancGroups`", "Errors`", "Helpers`", "Kranc`"}];
GetInheritedImplementations::usage = "";
GetIncludeFiles::usage = "";
diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m
index 295fd5e..d73adb6 100644
--- a/Tools/CodeGen/CalculationFunction.m
+++ b/Tools/CodeGen/CalculationFunction.m
@@ -18,19 +18,9 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
-BeginPackage["sym`"];
-
-{GridFunctions, Shorthands, Equations, t, DeclarationIncludes,
-LoopPreIncludes, GroupImplementations, PartialDerivatives, NoSimplify,
-Boundary, Interior, InteriorNoSync, Where, AddToStencilWidth,
-Everywhere, normal1, normal2, normal3, INV, SQR, CUB, QAD, dot, pow,
-exp, dx, dy, dz, idx, idy, idz}
-
-EndPackage[];
-
-BeginPackage["CalculationFunction`", {"CodeGen`", "sym`",
+BeginPackage["CalculationFunction`", {"CodeGen`",
"MapLookup`", "KrancGroups`", "Differencing`", "Errors`",
- "Helpers`"}];
+ "Helpers`", "Kranc`"}];
CreateCalculationFunction::usage = "";
VerifyCalculation::usage = "";
@@ -240,7 +230,7 @@ assignVariableFromExpression[dest_, expr_, declare_] :=
Module[{tSym, type, cleanExpr, code},
tSym = Unique[];
type = If[StringMatchQ[ToString[dest], "dir*"], "int", "CCTK_REAL"];
- cleanExpr = ReplacePowers[expr] /. sym`t -> tSym;
+ cleanExpr = ReplacePowers[expr] /. Kranc`t -> tSym;
If[SOURCELANGUAGE == "C",
code = If[declare, type <> " ", ""] <> ToString[dest] <> " = " <>
@@ -338,7 +328,7 @@ CreateCalculationFunction[calc_, debug_, useCSE_, opts:OptionsPattern[]] :=
Module[{gfs, allSymbols, knownSymbols,
shorts, eqs, parameters,
functionName, dsUsed, groups, pddefs, cleancalc, eqLoop, where,
- addToStencilWidth, pDefs},
+ addToStencilWidth, pDefs, haveCondTextuals, condTextuals},
cleancalc = removeUnusedShorthands[calc];
shorts = lookupDefault[cleancalc, Shorthands, {}];
@@ -350,6 +340,7 @@ CreateCalculationFunction[calc_, debug_, useCSE_, opts:OptionsPattern[]] :=
where = lookupDefault[cleancalc, Where, Everywhere];
addToStencilWidth = lookupDefault[cleancalc, AddToStencilWidth, 0];
pDefs = lookup[cleancalc, PreDefinitions];
+ haveCondTextuals = mapContains[cleancalc, ConditionalOnTextuals];
VerifyCalculation[cleancalc];
@@ -389,6 +380,13 @@ CreateCalculationFunction[calc_, debug_, useCSE_, opts:OptionsPattern[]] :=
ThrowError["The following shorthands are already declared as grid functions:",
Intersection[shorts, gfs]]];
+ (* check that the passed in textual condition makes sense *)
+ If[haveCondTextuals,
+ condTextuals = lookup[cleancalc, ConditionalOnTextuals];
+ If[! MatchQ[condTextuals, {_String ...}],
+ ThrowError["ConditionalOnTextuals entry in calculation expected to be of the form {string, ...}, but was ", condTextuals, "Calculation is ", calc]];
+ ];
+
(* Check that there are no unknown symbols in the calculation *)
allSymbols = calculationSymbols[cleancalc];
knownSymbols = Join[lookupDefault[cleancalc, AllowedSymbols, {}], gfs, shorts, parameters,
@@ -415,6 +413,8 @@ CreateCalculationFunction[calc_, debug_, useCSE_, opts:OptionsPattern[]] :=
ConditionalOnParameterTextual["cctk_iteration % " <> functionName <> "_calc_every != " <>
functionName <> "_calc_offset", "return;\n"],
+ If[haveCondTextuals, Map[ConditionalOnParameterTextual["!(" <> # <> ")", "return;\n"] &,condTextuals], {}],
+
CommentedBlock["Include user-supplied include files",
Map[IncludeFile, lookupDefault[cleancalc, DeclarationIncludes, {}]]],
diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m
index e1776ad..13f8ecc 100644
--- a/Tools/CodeGen/CodeGen.m
+++ b/Tools/CodeGen/CodeGen.m
@@ -19,12 +19,8 @@
along with Kranc; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
-BeginPackage["sym`"];
-{INV, SQR, CUB, QAD, exp, pow, fmax, fmin, dx, dy, dz, khalf, kthird, ktwothird, kfourthird, keightthird};
-EndPackage[];
-
-BeginPackage["CodeGen`", {"sym`", "Errors`"}];
+BeginPackage["CodeGen`", {"Errors`", "Kranc`"}];
SOURCELANGUAGE::usage = "global variable == \"C\" or \"Fortran\" determines language
for code generation";
diff --git a/Tools/CodeGen/Differencing.m b/Tools/CodeGen/Differencing.m
index 7c7df2d..ceb332b 100644
--- a/Tools/CodeGen/Differencing.m
+++ b/Tools/CodeGen/Differencing.m
@@ -125,13 +125,7 @@ point. Should be checked by someone competent!
*)
-BeginPackage["sym`"];
-
-{Name, Definitions, shift, spacing, SBPDerivative};
-
-EndPackage[];
-
-BeginPackage["Differencing`", {"CodeGen`", "sym`", "MapLookup`",
+BeginPackage["Differencing`", {"CodeGen`", "Kranc`", "MapLookup`",
"LinearAlgebra`MatrixManipulation`", "Errors`"}];
CreateDifferencingHeader::usage = "";
diff --git a/Tools/CodeGen/Helpers.m b/Tools/CodeGen/Helpers.m
index ecc4dae..563c514 100644
--- a/Tools/CodeGen/Helpers.m
+++ b/Tools/CodeGen/Helpers.m
@@ -18,12 +18,8 @@
along with Kranc; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
-BeginPackage["sym`"];
-{dummy};
-EndPackage[];
-
-BeginPackage["Helpers`", {"sym`"}];
+BeginPackage["Helpers`", {"Kranc`"}];
TensorName::usage = "get the base name of a tensor object, i.e. TensorName[g[la, lb]] -> TensorName";
diff --git a/Tools/CodeGen/Interface.m b/Tools/CodeGen/Interface.m
new file mode 100644
index 0000000..29c198f
--- /dev/null
+++ b/Tools/CodeGen/Interface.m
@@ -0,0 +1,140 @@
+
+(* Copyright 2004 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["Interface`", {"Thorn`", "KrancGroups`", "MapLookup`", "Errors`", "Helpers`", "Kranc`"}];
+
+CreateKrancInterface;
+
+Begin["`Private`"];
+
+(* --------------------------------------------------------------------------
+ Interface and variable definitions
+ -------------------------------------------------------------------------- *)
+
+nonevolvedGroupInterfaceStructure[group_] :=
+{
+ Name -> groupName[group],
+ VariableType -> "CCTK_REAL",
+ Timelevels -> NonevolvedTimelevels[group],
+ GridType -> "GF",
+ Comment -> groupName[group],
+ Visibility -> "public",
+ Tags -> Join[GroupTags[group]],
+ Variables -> groupVariables[group]
+}
+
+evolvedGroupInterfaceStructure[group_, timelevels_] :=
+{
+ Name -> groupName[group],
+ VariableType -> "CCTK_REAL",
+ Timelevels -> timelevels,
+ GridType -> "GF",
+ Comment -> groupName[group],
+ Visibility -> "public",
+ Tags -> GroupTags[group],
+ Variables -> groupVariables[group]
+}
+
+rhsGroupInterfaceStructure[group_, timelevels_] :=
+{
+ Name -> groupName[group],
+ VariableType -> "CCTK_REAL",
+ Timelevels -> timelevels,
+ GridType -> "GF",
+ Comment -> groupName[group],
+ Visibility -> "public",
+ Tags -> GroupTags[group],
+ Variables -> groupVariables[group]
+}
+
+
+Options[CreateKrancInterface] = ThornOptions;
+
+CreateKrancInterface[nonevolvedGroups_, evolvedGroups_, rhsGroups_, groups_,
+ implementation_, inheritedImplementations_,
+ includeFiles_, opts:OptionsPattern[]] :=
+
+ Module[{registerEvolved, (*registerConstrained,*)
+ nonevolvedGroupStructures, evolvedGroupStructures, rhsGroupStructures,
+ groupStructures, interface},
+ VerifyGroupNames[nonevolvedGroups];
+ VerifyGroupNames[evolvedGroups];
+ VerifyGroupNames[rhsGroups];
+ VerifyGroups[groups];
+ VerifyString[implementation];
+ VerifyStringList[inheritedImplementations];
+ VerifyStringList[includeFiles];
+ (* These are the aliased functions that are USED by this thorn from other thorns *)
+ registerEvolved =
+ {
+ Name -> "MoLRegisterEvolved",
+ Type -> "CCTK_INT",
+ ArgString -> "CCTK_INT IN EvolvedIndex, CCTK_INT IN RHSIndex"
+ };
+
+ (*
+ registerConstrained =
+ {
+ Name -> "MoLRegisterConstrained",
+ Type -> "CCTK_INT",
+ ArgString -> "CCTK_INT IN ConstrainedIndex"
+ };
+ *)
+
+ diffCoeff =
+ {
+ Name -> "Diff_coeff",
+ Type -> "SUBROUTINE",
+ ArgString -> "CCTK_POINTER_TO_CONST IN cctkGH, CCTK_INT IN dir, CCTK_INT IN nsize, CCTK_INT OUT ARRAY imin, CCTK_INT OUT ARRAY imax, CCTK_REAL OUT ARRAY q, CCTK_INT IN table_handle"
+ };
+
+
+ (* For each group declared in this thorn, we need an entry in the
+ interface file. Each evolved group needs an associated rhs
+ group, but these are constructed at a higher level and are
+ listed in the nonevolved groups. *)
+ nonevolvedGroupStructures =
+ Map[nonevolvedGroupInterfaceStructure[groupFromName[#, groups]] &,
+ nonevolvedGroups];
+
+ evolvedGroupStructures =
+ Map[evolvedGroupInterfaceStructure[groupFromName[#, groups],
+ OptionValue[EvolutionTimelevels]] &, evolvedGroups];
+
+ rhsGroupStructures =
+ Map[rhsGroupInterfaceStructure[groupFromName[#, groups],
+ OptionValue[EvolutionTimelevels]] &, rhsGroups];
+
+ groupStructures = Join[nonevolvedGroupStructures,
+ evolvedGroupStructures, rhsGroupStructures];
+
+ interface = CreateInterface[implementation, inheritedImplementations,
+ Join[includeFiles, {CactusBoundary`GetIncludeFiles[]},
+ If[OptionValue[UseLoopControl], {"loopcontrol.h"}, {}]],
+ groupStructures,
+ UsesFunctions ->
+ Join[{registerEvolved, (*registerConstrained,*) diffCoeff},
+ CactusBoundary`GetUsedFunctions[]]];
+ Return[interface]];
+
+
+End[];
+
+EndPackage[];
diff --git a/Tools/CodeGen/Kranc.m b/Tools/CodeGen/Kranc.m
new file mode 100644
index 0000000..fd07c53
--- /dev/null
+++ b/Tools/CodeGen/Kranc.m
@@ -0,0 +1,95 @@
+
+(* Copyright 2004 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["Kranc`"];
+
+(* CodeGen.m *)
+
+{INV, SQR, CUB, QAD, exp, pow, fmax, fmin, dx, dy, dz, khalf, kthird, ktwothird, kfourthird, keightthird};
+
+(* Helpers.m *)
+
+dummy;
+
+(* CalculationFunction.m *)
+
+{GridFunctions, Shorthands, Equations, t, DeclarationIncludes,
+LoopPreIncludes, GroupImplementations, PartialDerivatives, NoSimplify,
+Boundary, Interior, InteriorNoSync, Where, AddToStencilWidth,
+Everywhere, normal1, normal2, normal3, INV, SQR, CUB, QAD, dot, pow,
+exp, dx, dy, dz, idx, idy, idz}
+
+{ConditionalOnKeyword, ConditionalOnKeywords, CollectList, Interior,
+InteriorNoSync, Boundary, BoundaryWithGhosts, Where, PreDefinitions,
+AllowedSymbols, Parameters, ConditionalOnTextuals};
+
+(* Differencing.m *)
+
+{Name, Definitions, shift, spacing, SBPDerivative};
+
+(* KrancThorn.m *)
+
+ThornOptions =
+ {Calculations -> {},
+ DeclaredGroups -> {},
+ Implementation -> None,
+ InheritedImplementations -> {},
+ EvolutionTimelevels -> 3,
+ DefaultEvolutionTimelevels -> None,
+ RealParameters -> {},
+ IntParameters -> {},
+ KeywordParameters -> {},
+ InheritedRealParameters -> {},
+ InheritedIntParameters -> {},
+ InheritedKeywordParameters -> {},
+ ExtendedRealParameters -> {},
+ ExtendedIntParameters -> {},
+ ExtendedKeywordParameters -> {},
+ PartialDerivatives -> {},
+ ReflectionSymmetries -> {},
+ ZeroDimensions -> {},
+ UseLoopControl -> False,
+ UseCSE -> False,
+ ProhibitAssignmentToGridFunctionsRead -> False,
+ IncludeFiles -> {}};
+
+(* Thorn.m *)
+
+{AccumulatorBase, ThornImplementation, Name, Type, Extend, Default,
+Comment, Range, Implementation, Group, SchedulePoint, Language,
+SynchronizedGroups, StorageGroups, Timelevels, MaxTimelevels,
+VariableType, GridType,
+Visibility, Variables, Implementations, Value, AllowedValues,
+UsedParameters, Description, ExtendedParameters, NewParameters,
+Directory, Configuration, Interface, Param, Schedule, Sources, Makefile,
+Filename,
+Contents, ThornName, BaseImplementation, EvolvedGFs, PrimitiveGFs,
+Groups, Calculation, GridFunctions, Shorthands, Equations, Parameter,
+Value, UsesFunctions, ArgString, Conditional, Conditionals, D1, D2, D3, D11, D22,
+D33, D21, D31, D32, Textual, TriggerGroups, Include, RHSGroups, Tags,
+Steerable, Never, Always, Recover};
+
+{ExcisionGFs};
+
+(* TensorTools.m *)
+
+{D1, D2, D3, D11, D22, D33, D21, D31, D32, D12, D13, D23, dot, Eps, Zero3}
+
+EndPackage[];
diff --git a/Tools/CodeGen/KrancGroups.m b/Tools/CodeGen/KrancGroups.m
index a4a65eb..05ebdea 100644
--- a/Tools/CodeGen/KrancGroups.m
+++ b/Tools/CodeGen/KrancGroups.m
@@ -24,12 +24,8 @@
(* Manipulate Kranc group structures *)
(****************************************************************************)
-BeginPackage["sym`"];
-{Timelevels}
-EndPackage[];
-
BeginPackage["KrancGroups`",
- {"sym`", "Errors`", "MapLookup`"}];
+ {"Kranc`", "Errors`", "MapLookup`"}];
CreateGroup;
groupsFromGFs::usage = "";
@@ -55,6 +51,7 @@ SetGroupName;
AddGroupExtra;
GroupTimelevels;
allGroupVariables;
+NonevolvedTimelevels;
Begin["`Private`"];
@@ -107,6 +104,10 @@ GroupTimelevels[g_] :=
extras = Drop[g, 2];
lookupDefault[extras, Timelevels, False]];
+NonevolvedTimelevels[group_] :=
+ Module[{tls = GroupTimelevels[group]},
+ If[ tls === False, 1, tls]];
+
groupName[g_] := First[g];
diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m
index cf28179..0f95d10 100644
--- a/Tools/CodeGen/KrancThorn.m
+++ b/Tools/CodeGen/KrancThorn.m
@@ -24,42 +24,10 @@
(* Generate Cactus Thorns from a high-level interface *)
(****************************************************************************)
-BeginPackage["sym`"];
-
-ThornOptions =
- {Calculations -> {},
- DeclaredGroups -> {},
- Implementation -> None,
- InheritedImplementations -> {},
- EvolutionTimelevels -> 3,
- DefaultEvolutionTimelevels -> None,
- RealParameters -> {},
- IntParameters -> {},
- KeywordParameters -> {},
- InheritedRealParameters -> {},
- InheritedIntParameters -> {},
- InheritedKeywordParameters -> {},
- ExtendedRealParameters -> {},
- ExtendedIntParameters -> {},
- ExtendedKeywordParameters -> {},
- PartialDerivatives -> {},
- ReflectionSymmetries -> {},
- ZeroDimensions -> {},
- UseLoopControl -> False,
- UseCSE -> False,
- ProhibitAssignmentToGridFunctionsRead -> False,
- IncludeFiles -> {}};
-
-{ConditionalOnKeyword, ConditionalOnKeywords, CollectList, Interior,
-InteriorNoSync, Boundary, BoundaryWithGhosts, Where, PreDefinitions,
-AllowedSymbols, Parameters};
-
-EndPackage[];
-
-BeginPackage["KrancThorn`", {"CodeGen`", "sym`", "Thorn`",
+BeginPackage["KrancThorn`", {"CodeGen`", "Thorn`",
"MapLookup`", "KrancGroups`", "Differencing`",
"CalculationFunction`", "Errors`", "Helpers`", "CactusBoundary`",
- "TensorTools`"}];
+ "TensorTools`", "Param`", "Schedule`", "Interface`", "Kranc`"}];
CreateKrancThorn::usage = "Construct a Kranc thorn";
CreateKrancThornTT::usage = "Construct a Kranc thorn using TensorTools";
@@ -67,6 +35,10 @@ CreateGroupFromTensor::usage = "";
Begin["`Private`"];
+(* --------------------------------------------------------------------------
+ Utility functions
+ -------------------------------------------------------------------------- *)
+
VerifyGroups[gs_] :=
If[!ListQ[gs],
ThrowError["Not a list of group definitions: ", gs],
@@ -103,6 +75,10 @@ Module[{used, unrecognized},
replaceDots[x_] :=
x /. (dot[y_] :> Symbol[ToString[y] <> "rhs"]);
+(* --------------------------------------------------------------------------
+ Thorn generation (main entry point for non-tensorial thorns)
+ -------------------------------------------------------------------------- *)
+
Options[CreateKrancThorn] = ThornOptions;
CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[]] :=
@@ -136,8 +112,8 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
defaultEvolutionTimelevels = lookupDefault[{opts}, DefaultEvolutionTimelevels, evolutionTimelevels];
realParams = OptionValue[RealParameters];
intParams = OptionValue[IntParameters];
- realParamDefs = makeFullParamDefs[realParams];
- intParamDefs = makeFullParamDefs[intParams];
+ realParamDefs = MakeFullParamDefs[realParams];
+ intParamDefs = MakeFullParamDefs[intParams];
keywordParams = OptionValue[KeywordParameters];
inheritedRealParams = OptionValue[InheritedRealParameters];
inheritedIntParams = OptionValue[InheritedIntParameters];
@@ -149,7 +125,7 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
reflectionSymmetries = OptionValue[ReflectionSymmetries];
useCSE = OptionValue[UseCSE];
- coordGroup = {"grid::coordinates", {sym`x,sym`y,sym`z,sym`r}};
+ coordGroup = {"grid::coordinates", {Kranc`x,Kranc`y,Kranc`z,Kranc`r}};
groups = Join[groupsOrig, {coordGroup}];
includeFiles = Join[includeFiles, {"GenericFD.h", "Symmetry.h", "sbp_calc_coeffs.h"}];
@@ -187,17 +163,17 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
(* Construct the configuration file *)
InfoMessage[Terse, "Creating configuration file"];
- configuration = createKrancConfiguration[opts];
+ configuration = CreateConfiguration[opts];
(* Construct the interface file *)
InfoMessage[Terse, "Creating interface file"];
- interface = createKrancInterface[nonevolvedGroups,
+ interface = CreateKrancInterface[nonevolvedGroups,
evolvedGroups, rhsGroups, groups,
implementation, inheritedImplementations, includeFiles, opts];
(* Construct the param file *)
InfoMessage[Terse, "Creating param file"];
- param = createKrancParam[evolvedGroups, nonevolvedGroups, groups, thornName,
+ param = CreateKrancParam[evolvedGroups, nonevolvedGroups, groups, thornName,
realParamDefs, intParamDefs, keywordParams,
inheritedRealParams, inheritedIntParams, inheritedKeywordParams,
extendedRealParams, extendedIntParams, extendedKeywordParams,
@@ -206,7 +182,7 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
(* Construct the schedule file *)
InfoMessage[Terse, "Creating schedule file"];
- schedule = createKrancScheduleFile[calcs, groups, evolvedGroups,
+ schedule = CreateKrancScheduleFile[calcs, groups, evolvedGroups,
rhsGroups, nonevolvedGroups, thornName,
evolutionTimelevels];
@@ -235,14 +211,16 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
ext = CodeGen`SOURCESUFFIX;
(* Construct a source file for each calculation *)
- allParams = Join[Map[paramName, realParamDefs],
- Map[paramName, intParamDefs],
+ allParams = Join[Map[ParamName, realParamDefs],
+ Map[ParamName, intParamDefs],
Map[unqualifiedName, inheritedRealParams],
Map[unqualifiedName, inheritedIntParams],
Map[unqualifiedName, inheritedKeywordParams]];
InfoMessage[Terse, "Creating calculation source files"];
- calcSources = Map[CreateSetterSourceWrapper[#, allParams, partialDerivs, useCSE, opts] &, calcs];
+ calcSources = Map[CreateSetterSource[
+ {Join[#, {Parameters -> allParams, PartialDerivatives -> partialDerivs}]},
+ False, useCSE, {}, opts] &, calcs];
calcFilenames = Map[lookup[#, Name] <> ext &, calcs];
(* Makefile *)
@@ -268,6 +246,10 @@ CreateKrancThorn[groupsOrig_, parentDirectory_, thornName_, opts:OptionsPattern[
InfoMessage[Terse, "Creating thorn"];
CreateThorn[thornspec]];
+(* --------------------------------------------------------------------------
+ Functions related to calculations
+ -------------------------------------------------------------------------- *)
+
CalculationEvolvedVars[calc_] :=
Module[{eqs, evolved, lhss},
VerifyNewCalculation[calc];
@@ -300,470 +282,6 @@ extractNonevolvedGroups[declaredGroups_, calcs_, groups_] :=
Return[nonevolvedGroups]];
-nonevolvedGroupInterfaceStructure[group_] :=
-{
- Name -> groupName[group],
- VariableType -> "CCTK_REAL",
- Timelevels -> nonevolvedTimelevels[group],
- GridType -> "GF",
- Comment -> groupName[group],
- Visibility -> "public",
- Tags -> Join[GroupTags[group]],
- Variables -> groupVariables[group]
-}
-
-evolvedGroupInterfaceStructure[group_, timelevels_] :=
-{
- Name -> groupName[group],
- VariableType -> "CCTK_REAL",
- Timelevels -> timelevels,
- GridType -> "GF",
- Comment -> groupName[group],
- Visibility -> "public",
- Tags -> GroupTags[group],
- Variables -> groupVariables[group]
-}
-
-rhsGroupInterfaceStructure[group_, timelevels_] :=
-{
- Name -> groupName[group],
- VariableType -> "CCTK_REAL",
- Timelevels -> timelevels,
- GridType -> "GF",
- Comment -> groupName[group],
- Visibility -> "public",
- Tags -> GroupTags[group],
- Variables -> groupVariables[group]
-}
-
-nonevolvedTimelevels[group_] :=
- Module[{tls = GroupTimelevels[group]},
- If[ tls === False, 1, tls]];
-
-createKrancConfiguration[opts:OptionsPattern[]] :=
- Module[{configuration},
- configuration = CreateConfiguration[opts];
- Return[configuration]];
-
-Options[createKrancInterface] = ThornOptions;
-
-createKrancInterface[nonevolvedGroups_, evolvedGroups_, rhsGroups_, groups_,
- implementation_, inheritedImplementations_,
- includeFiles_, opts:OptionsPattern[]] :=
-
- Module[{registerEvolved, (*registerConstrained,*)
- nonevolvedGroupStructures, evolvedGroupStructures, rhsGroupStructures,
- groupStructures, interface},
- VerifyGroupNames[nonevolvedGroups];
- VerifyGroupNames[evolvedGroups];
- VerifyGroupNames[rhsGroups];
- VerifyGroups[groups];
- VerifyString[implementation];
- VerifyStringList[inheritedImplementations];
- VerifyStringList[includeFiles];
- (* These are the aliased functions that are USED by this thorn from other thorns *)
- registerEvolved =
- {
- Name -> "MoLRegisterEvolved",
- Type -> "CCTK_INT",
- ArgString -> "CCTK_INT IN EvolvedIndex, CCTK_INT IN RHSIndex"
- };
-
- (*
- registerConstrained =
- {
- Name -> "MoLRegisterConstrained",
- Type -> "CCTK_INT",
- ArgString -> "CCTK_INT IN ConstrainedIndex"
- };
- *)
-
- diffCoeff =
- {
- Name -> "Diff_coeff",
- Type -> "SUBROUTINE",
- ArgString -> "CCTK_POINTER_TO_CONST IN cctkGH, CCTK_INT IN dir, CCTK_INT IN nsize, CCTK_INT OUT ARRAY imin, CCTK_INT OUT ARRAY imax, CCTK_REAL OUT ARRAY q, CCTK_INT IN table_handle"
- };
-
-
- (* For each group declared in this thorn, we need an entry in the
- interface file. Each evolved group needs an associated rhs
- group, but these are constructed at a higher level and are
- listed in the nonevolved groups. *)
- nonevolvedGroupStructures =
- Map[nonevolvedGroupInterfaceStructure[groupFromName[#, groups]] &,
- nonevolvedGroups];
-
- evolvedGroupStructures =
- Map[evolvedGroupInterfaceStructure[groupFromName[#, groups],
- OptionValue[EvolutionTimelevels]] &, evolvedGroups];
-
- rhsGroupStructures =
- Map[rhsGroupInterfaceStructure[groupFromName[#, groups],
- OptionValue[EvolutionTimelevels]] &, rhsGroups];
-
- groupStructures = Join[nonevolvedGroupStructures,
- evolvedGroupStructures, rhsGroupStructures];
-
- interface = CreateInterface[implementation, inheritedImplementations,
- Join[includeFiles, {CactusBoundary`GetIncludeFiles[]},
- If[OptionValue[UseLoopControl], {"loopcontrol.h"}, {}]],
- groupStructures,
- UsesFunctions ->
- Join[{registerEvolved, (*registerConstrained,*) diffCoeff},
- CactusBoundary`GetUsedFunctions[]]];
- Return[interface]];
-
-VerifyQualifiedName[name_] :=
- If[! StringQ[name] || ! StringMatchQ[name, "*::*"],
- ThrowError["Not a name with an implementation:", name]];
-
-implementationFromQualifiedName[name_] :=
- Module[{colon},
- VerifyQualifiedName[name];
- colon = First[First[StringPosition[name, ":", 1]]];
- StringDrop[name, colon - 1 - StringLength[name]]];
-
-unqualifiedName[name_] :=
- Module[{colon},
- VerifyQualifiedName[name];
- colon = First[First[StringPosition[name, ":", 1]]];
- Return[StringDrop[name, colon + 1]]];
-
-krancParamStruct[definition_, type_, inherited_] :=
- Module[{description, name},
- name = lookup[definition, Name];
- description = lookupDefault[definition, Description, name];
- Join[
- {Name -> name,
- Type -> type,
- Description -> description,
- Default -> lookup[definition, Default],
- Visibility -> "restricted"},
- If[inherited,
- {},
- {AllowedValues -> {{Value -> "*:*", Description -> ""}}}]]];
-
-krancParamStructExtended[definition_, type_] :=
- Module[{allowedValues, description, name},
- name = unqualifiedName[lookup[definition, Name]];
- description = lookupDefault[definition, Description, name];
- allowedValues = lookup[definition, AllowedValues];
- {Name -> name,
- Type -> type,
- Description -> description,
- Default -> "",
- Visibility -> "restricted",
- AllowedValues -> Map[{Value -> #, Description -> ""} &, allowedValues]}];
-
-krancKeywordParamStruct[struct_] :=
-{
- Name -> lookup[struct, Name],
- Type -> "KEYWORD",
- Default -> lookup[struct, Default],
- Description -> lookupDefault[struct, Description, lookup[struct, Name]],
- Visibility -> lookupDefault[struct, Visibility, "private"],
- AllowedValues -> Map[{Value -> #, Description -> #} &, lookup[struct, AllowedValues]]
-};
-
-makeFullParamDefs[params_] :=
- Module[{p},
- p = Map[If[!ListQ[#], {Name -> #, Default -> 0}, #] &, params];
- p];
-
-paramName[paramDef_] :=
- lookup[paramDef, Name];
-
-inheritParameters[imp_, reals_, ints_, keywords_] :=
- Module[{theseReals, theseInts, theseKeywords, theseRealsNoImp, theseIntsNoImp, theseKeywordsNoImp, realStructs, intStructs, keywordStructs},
- theseReals = Select[reals, implementationFromQualifiedName[#] == imp &];
- theseInts = Select[ints, implementationFromQualifiedName[#] == imp &];
- theseKeywords = Select[keywords, implementationFromQualifiedName[#] == imp &];
- theseRealsNoImp = makeFullParamDefs[Map[unqualifiedName, theseReals]];
- theseIntsNoImp = makeFullParamDefs[Map[unqualifiedName, theseInts]];
- theseKeywordsNoImp = makeFullParamDefs[Map[unqualifiedName, theseKeywords]];
- realStructs = Map[krancParamStruct[#, "CCTK_REAL", True] &, theseRealsNoImp];
- intStructs = Map[krancParamStruct[#, "CCTK_INT", True] &, theseIntsNoImp];
- keywordStructs = Map[krancParamStruct[#, "CCTK_KEYWORD", True] &, theseKeywordsNoImp];
- If[(Length[theseReals] + Length[theseInts] + Length[theseKeywords]) > 0,
- Return[{Name -> imp, UsedParameters -> Join[realStructs, intStructs, keywordStructs]}],
- Return[{}]]];
-
-extendParameters[imp_, reals_, ints_, keywords_] :=
- Module[{theseReals, theseInts, theseKeywords, realStructs, intStructs, keywordStructs},
- theseReals = Select[reals, implementationFromQualifiedName[lookup[#, Name]] == imp &];
- theseInts = Select[ints, implementationFromQualifiedName[lookup[#, Name]] == imp &];
- theseKeywords = Select[keywords, implementationFromQualifiedName[lookup[#, Name]] == imp &];
- realStructs = Map[krancParamStructExtended[#, "CCTK_REAL"] &, theseReals];
- intStructs = Map[krancParamStructExtended[#, "CCTK_INT"] &, theseInts];
- keywordStructs = Map[krancParamStructExtended[#, "CCTK_KEYWORD"] &, theseKeywords];
- If[(Length[theseReals] + Length[theseInts] + Length[theseKeywords]) > 0,
- Return[{Name -> imp, ExtendedParameters -> Join[realStructs, intStructs, keywordStructs]}],
- Return[{}]]];
-
-createKrancParam[evolvedGroups_, nonevolvedGroups_, groups_, thornName_,
- reals_, ints_, keywords_,
- inheritedReals_, inheritedInts_, inheritedKeywords_,
- extendedReals_, extendedInts_, extendedKeywords_,
- evolutionTimelevels_, defaultEvolutionTimelevels_,
- calcs_] :=
- Module[{nEvolved, evolvedMoLParam, evolvedGFs,
- (*constrainedMoLParam,*) genericfdStruct, realStructs, intStructs,
- allInherited, allExtended, implementationNames, molImplementation,
- userImplementations, implementations, params, paramspec, param,
- verboseStruct, calcOffsetStructs, calcEveryStructs},
-
- (* reals and ints are symbols containing parameter names. The
- inherited ones have implementation names as well *)
-
- evolvedGFs = variablesFromGroups[evolvedGroups, groups];
-
- nEvolved = Length[variablesFromGroups[evolvedGroups, groups]];
-(* nPrimitive = Length[variablesFromGroups[nonevolvedGroups, groups]];*)
-(* nPrimitive = Length[getConstrainedVariables[evolvedGroups, groups]];*)
-
- evolvedMoLParam =
- {
- Name -> thornName <> "_MaxNumEvolvedVars",
- Type -> "CCTK_INT",
- Default -> nEvolved,
- Description -> "Number of evolved variables used by this thorn",
- Visibility -> "restricted",
- AccumulatorBase -> "MethodofLines::MoL_Num_Evolved_Vars",
- AllowedValues -> {{Value -> ToString[nEvolved] <> ":" <> ToString[nEvolved] ,
- Description -> "Number of evolved variables used by this thorn"}}
- };
-
- (*
- constrainedMoLParam =
- {
- Name -> thornName <> "_MaxNumConstrainedVars",
- Type -> "CCTK_INT",
- Default -> nPrimitive,
- Description -> "Number of constrained variables used by this thorn",
- Visibility -> "restricted",
- AccumulatorBase -> "MethodofLines::MoL_Num_Constrained_Vars",
- AllowedValues -> {{Value -> ToString[nPrimitive] <> ":" <> ToString[nPrimitive] ,
- Description -> "Number of constrained variables used by this thorn"}}
- };
- *)
-
- timelevelsParam =
- {
- Name -> "timelevels",
- Type -> "CCTK_INT",
- Default -> defaultEvolutionTimelevels,
- Description -> "Number of active timelevels",
- Visibility -> "restricted",
- AllowedValues -> {{Value -> ToString[0] <> ":" <> ToString[evolutionTimelevels],
- Description -> ""}}
- };
-
- rhsTimelevelsParam =
- {
- Name -> "rhs_timelevels",
- Type -> "CCTK_INT",
- Default -> 1,
- Description -> "Number of active RHS timelevels",
- Visibility -> "restricted",
- AllowedValues -> {{Value -> ToString[0] <> ":" <> ToString[evolutionTimelevels],
- Description -> ""}}
- };
-
- genericfdStruct =
- {
- Name -> "GenericFD",
- UsedParameters ->
- {{Name -> "stencil_width", Type -> "CCTK_INT"},
- {Name -> "stencil_width_x", Type -> "CCTK_INT"},
- {Name -> "stencil_width_y", Type -> "CCTK_INT"},
- {Name -> "stencil_width_z", Type -> "CCTK_INT"},
- {Name -> "boundary_width", Type -> "CCTK_INT"}}
- };
-
- realStructs = Map[krancParamStruct[#, "CCTK_REAL", False] &, reals];
- verboseStruct = krancParamStruct[{Name -> "verbose", Default -> 0}, "CCTK_INT", False];
- intStructs = Map[krancParamStruct[#, "CCTK_INT", False] &, ints];
- calcEveryStructs = Map[krancParamStruct[{Name -> lookup[#, Name] <> "_calc_every", Default -> 1}, "CCTK_INT", False] &, calcs];
- calcOffsetStructs = Map[krancParamStruct[{Name -> lookup[#, Name] <> "_calc_offset", Default -> 0}, "CCTK_INT", False] &, calcs];
- keywordStructs = Map[krancKeywordParamStruct, keywords];
-
- allInherited = Join[inheritedReals, inheritedInts, inheritedKeywords];
- allExtended = Join[extendedReals, extendedInts, extendedKeywords];
-
- implementationNames = Union[Map[implementationFromQualifiedName, allInherited],
- Map[implementationFromQualifiedName[lookup[#, Name]] &, allExtended]];
-
- molImplementation =
- {
- Name -> "MethodOfLines",
- UsedParameters ->
- {
- {Name -> "MoL_Num_Evolved_Vars", Type -> "CCTK_INT"}
- (* {Name -> "MoL_Num_Constrained_Vars", Type -> "CCTK_INT"} *)
- }
- };
-
- userImplementations = Map[inheritParameters[#, inheritedReals,inheritedInts,inheritedKeywords] &,
- implementationNames];
- userImplementations2 = Map[extendParameters[#, extendedReals,extendedInts,extendedKeywords] &,
- implementationNames];
-
- userImplementations = If[userImplementations=={{}},{},userImplementations];
- userImplementations2 = If[userImplementations2=={{}},{},userImplementations2];
-
- implementations = Join[userImplementations, userImplementations2, {genericfdStruct, molImplementation}];
- params = Join[{verboseStruct}, realStructs, intStructs, keywordStructs, {evolvedMoLParam, (*constrainedMoLParam,*) timelevelsParam, rhsTimelevelsParam},
- calcEveryStructs, calcOffsetStructs,
- CactusBoundary`GetParameters[evolvedGFs, evolvedGroups]];
-
- paramspec = {Implementations -> implementations,
- NewParameters -> params};
-
- param = CreateParam[paramspec];
- Return[param]
- ];
-
-simpleGroupStruct[groupName_, timelevels_] :=
-{
- Group -> groupName,
- Timelevels -> timelevels
-};
-
-evolvedGroupStruct[groupName_, timelevels_, maxtimelevels_] :=
-{
- Group -> groupName,
- Timelevels -> timelevels,
- MaxTimelevels -> "timelevels"
-};
-
-rhsGroupStruct[groupName_, timelevels_, maxtimelevels_] :=
-{
- Group -> groupName,
- Timelevels -> timelevels,
- MaxTimelevels -> "rhs_timelevels"
-};
-
-groupsSetInCalc[calc_, groups_] :=
- Module[{gfs, eqs, lhss, gfsInLHS, lhsGroupNames},
- gfs = allGroupVariables[groups];
- eqs = lookup[calc, Equations];
- lhss = Map[First, eqs];
- gfsInLHS = Union[Cases[lhss, _ ? (MemberQ[gfs,#] &), Infinity]];
-
- lhsGroupNames = containingGroups[gfsInLHS, groups];
- Return[lhsGroupNames]
- ];
-
-(* Each calculation can be scheduled at multiple points, so this
- function returns a LIST of schedule structures for each calculation
- *)
-scheduleCalc[calc_, groups_] :=
- Module[{points, conditional, conditionals, keywordConditional, keywordConditionals, triggered, keyword, value, keywordvaluepairs, groupsToSync},
- conditional = mapContains[calc, ConditionalOnKeyword];
- conditionals = mapContains[calc, ConditionalOnKeywords];
- triggered = mapContains[calc, TriggerGroups];
- If[conditional,
- keywordConditional = lookup[calc, ConditionalOnKeyword];
- If[! MatchQ[keywordConditional, {lhs_String, rhs_String}],
- ThrowError["ConditionalOnKeyword entry in calculation expected to be of the form {parameter, value}, but was ", keywordConditional, "Calculation is ", calc]];
-
- keyword = keywordConditional[[1]];
- value = keywordConditional[[2]];
- ];
- If[conditionals,
- keywordConditionals = lookup[calc, ConditionalOnKeywords];
- If[! MatchQ[keywordConditionals, {{_, _} ...}],
- ThrowError["ConditionalOnKeywords entry in calculation expected to be of the form {{parameter, value}}, but was ", keywordConditionals, "Calculation is ", calc]];
-
- keywordvaluepairs =
- Map[# /. {keyword_, value_} -> {Parameter -> keyword, Value -> value} &,
- keywordConditionals];
- ];
-
- groupsToSync = If[lookupDefault[calc, Where, Everywhere] === Interior ||
- lookupDefault[calc, Where, Everywhere] === Boundary,
- groupsSetInCalc[calc, groups],
- {}];
-
- Map[
- Join[
- {
- Name -> lookup[calc, Name],
- SchedulePoint -> #,
- SynchronizedGroups -> If[StringMatchQ[#, "*MoL_CalcRHS*", IgnoreCase -> True] || StringMatchQ[#, "*MoL_RHSBoundaries*", IgnoreCase -> True],
- {},
- groupsToSync],
- Language -> CodeGen`SOURCELANGUAGE,
- Comment -> lookup[calc, Name]
- },
- If[triggered, {TriggerGroups -> lookup[calc, TriggerGroups]},
- {}],
- If[conditional, {Conditional -> {Parameter -> keyword, Value -> value}},
- {}],
- If[conditionals, {Conditionals -> keywordvaluepairs},
- {}]
- ] &,
- lookup[calc, Schedule]]];
-
-createKrancScheduleFile[calcs_, groups_, evolvedGroups_, rhsGroups_, nonevolvedGroups_, thornName_,
- evolutionTimelevels_] :=
- Module[{scheduledCalcs, scheduledStartup, scheduleMoLRegister, globalStorageGroups, scheduledFunctions, schedule},
-
- scheduledCalcs = Flatten[Map[scheduleCalc[#, groups] &, calcs], 1];
-
- scheduledStartup =
- {
- Name -> thornName <> "_Startup",
- SchedulePoint -> "at STARTUP",
- Language -> "C",
- Options -> "meta",
- Comment -> "create banner"
- };
-
- scheduleMoLRegister =
- {
- Name -> thornName <> "_RegisterVars",
- SchedulePoint -> "in MoL_Register",
- Language -> "C",
- Options -> "meta",
- Comment -> "Register Variables for MoL"
- };
-
- scheduleRegisterSymmetries =
- {
- Name -> thornName <> "_RegisterSymmetries",
- SchedulePoint -> "in SymmetryRegister",
- Language -> "C",
- Options -> "meta",
- Comment -> "register symmetries"
- };
-
- globalStorageGroups = Join[Map[simpleGroupStruct[#, nonevolvedTimelevels[groupFromName[#, groups]]] &, nonevolvedGroups],
- Map[evolvedGroupStruct[#, evolutionTimelevels, evolutionTimelevels] &, evolvedGroups],
- Map[rhsGroupStruct[#, evolutionTimelevels, evolutionTimelevels] &, rhsGroups]];
-
- scheduledFunctions =
- Join[{scheduledStartup, scheduleMoLRegister, scheduleRegisterSymmetries},
- scheduledCalcs, CactusBoundary`GetScheduledFunctions[thornName, evolvedGroups]];
-
- schedule = CreateSchedule[globalStorageGroups,
- CactusBoundary`GetScheduledGroups[thornName], scheduledFunctions];
-
- Return[schedule]];
-
-Options[CreateSetterSourceWrapper] = ThornOptions;
-
-CreateSetterSourceWrapper[calc_, parameters_, derivs_, useCSE_, opts:OptionsPattern[]] :=
- Module[{modCalc},
- modCalc = Join[calc,
- {Parameters -> parameters},
- {PartialDerivatives -> derivs}];
-
- source = CreateSetterSource[{modCalc}, False, useCSE,
- If[OptionValue[UseLoopControl], {"loopcontrol.h"}, {}], opts];
- Return[source]];
-
(* FIXME: This is still not quite right. We only want to have those variables that
we set as constrained, but I don't think this can hurt.*)
@@ -791,7 +309,9 @@ createKrancMoLRegister[evolvedGroupNames_, nonevolvedGroupNames_, groups_, imple
molregister = CreateMoLRegistrationSource[molspec, False];
Return[molregister]];
-(* Tensorial wrapper *)
+(* --------------------------------------------------------------------------
+ Tensors
+ -------------------------------------------------------------------------- *)
CreateKrancThornTT[groups_, parentDirectory_, thornName_, opts___] :=
Module[{calcs, expCalcs, expGroups, options, derivs, expDerivs, reflectionSymmetries, declaredGroups},
diff --git a/Tools/CodeGen/Param.m b/Tools/CodeGen/Param.m
new file mode 100644
index 0000000..7821f40
--- /dev/null
+++ b/Tools/CodeGen/Param.m
@@ -0,0 +1,248 @@
+
+(* Copyright 2004 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["Param`", {"Thorn`", "Errors`", "Helpers`", "MapLookup`", "KrancGroups`", "Kranc`"}];
+
+CreateKrancParam;
+MakeFullParamDefs;
+ParamName;
+
+Begin["`Private`"];
+
+VerifyQualifiedName[name_] :=
+ If[! StringQ[name] || ! StringMatchQ[name, "*::*"],
+ ThrowError["Not a name with an implementation:", name]];
+
+implementationFromQualifiedName[name_] :=
+ Module[{colon},
+ VerifyQualifiedName[name];
+ colon = First[First[StringPosition[name, ":", 1]]];
+ StringDrop[name, colon - 1 - StringLength[name]]];
+
+unqualifiedName[name_] :=
+ Module[{colon},
+ VerifyQualifiedName[name];
+ colon = First[First[StringPosition[name, ":", 1]]];
+ Return[StringDrop[name, colon + 1]]];
+
+krancParamStruct[definition_, type_, inherited_] :=
+ Module[{description, name},
+ name = lookup[definition, Name];
+ description = lookupDefault[definition, Description, name];
+ Join[
+ {Name -> name,
+ Type -> type,
+ Description -> description,
+ Default -> lookup[definition, Default],
+ Visibility -> "restricted"},
+ If[mapContains[definition, Steerable],
+ {Steerable -> lookup[definition, Steerable]},
+ {}],
+ If[inherited,
+ {},
+ {AllowedValues -> {{Value -> "*:*", Description -> ""}}}]]];
+
+krancParamStructExtended[definition_, type_] :=
+ Module[{allowedValues, description, name},
+ name = unqualifiedName[lookup[definition, Name]];
+ description = lookupDefault[definition, Description, name];
+ allowedValues = lookup[definition, AllowedValues];
+ {Name -> name,
+ Type -> type,
+ Description -> description,
+ Default -> "",
+ Visibility -> "restricted",
+ AllowedValues -> Map[{Value -> #, Description -> ""} &, allowedValues]}];
+
+krancKeywordParamStruct[struct_] :=
+{
+ Name -> lookup[struct, Name],
+ Type -> "KEYWORD",
+ Default -> lookup[struct, Default],
+ Description -> lookupDefault[struct, Description, lookup[struct, Name]],
+ Visibility -> lookupDefault[struct, Visibility, "private"],
+ AllowedValues -> Map[{Value -> #, Description -> #} &, lookup[struct, AllowedValues]]
+};
+
+MakeFullParamDefs[params_] :=
+ Module[{p},
+ p = Map[If[!ListQ[#], {Name -> #, Default -> 0}, #] &, params];
+ p];
+
+ParamName[paramDef_] :=
+ lookup[paramDef, Name];
+
+inheritParameters[imp_, reals_, ints_, keywords_] :=
+ Module[{theseReals, theseInts, theseKeywords, theseRealsNoImp, theseIntsNoImp, theseKeywordsNoImp, realStructs, intStructs, keywordStructs},
+ theseReals = Select[reals, implementationFromQualifiedName[#] == imp &];
+ theseInts = Select[ints, implementationFromQualifiedName[#] == imp &];
+ theseKeywords = Select[keywords, implementationFromQualifiedName[#] == imp &];
+ theseRealsNoImp = MakeFullParamDefs[Map[unqualifiedName, theseReals]];
+ theseIntsNoImp = MakeFullParamDefs[Map[unqualifiedName, theseInts]];
+ theseKeywordsNoImp = MakeFullParamDefs[Map[unqualifiedName, theseKeywords]];
+ realStructs = Map[krancParamStruct[#, "CCTK_REAL", True] &, theseRealsNoImp];
+ intStructs = Map[krancParamStruct[#, "CCTK_INT", True] &, theseIntsNoImp];
+ keywordStructs = Map[krancParamStruct[#, "CCTK_KEYWORD", True] &, theseKeywordsNoImp];
+ If[(Length[theseReals] + Length[theseInts] + Length[theseKeywords]) > 0,
+ Return[{Name -> imp, UsedParameters -> Join[realStructs, intStructs, keywordStructs]}],
+ Return[{}]]];
+
+extendParameters[imp_, reals_, ints_, keywords_] :=
+ Module[{theseReals, theseInts, theseKeywords, realStructs, intStructs, keywordStructs},
+ theseReals = Select[reals, implementationFromQualifiedName[lookup[#, Name]] == imp &];
+ theseInts = Select[ints, implementationFromQualifiedName[lookup[#, Name]] == imp &];
+ theseKeywords = Select[keywords, implementationFromQualifiedName[lookup[#, Name]] == imp &];
+ realStructs = Map[krancParamStructExtended[#, "CCTK_REAL"] &, theseReals];
+ intStructs = Map[krancParamStructExtended[#, "CCTK_INT"] &, theseInts];
+ keywordStructs = Map[krancParamStructExtended[#, "CCTK_KEYWORD"] &, theseKeywords];
+ If[(Length[theseReals] + Length[theseInts] + Length[theseKeywords]) > 0,
+ Return[{Name -> imp, ExtendedParameters -> Join[realStructs, intStructs, keywordStructs]}],
+ Return[{}]]];
+
+CreateKrancParam[evolvedGroups_, nonevolvedGroups_, groups_, thornName_,
+ reals_, ints_, keywords_,
+ inheritedReals_, inheritedInts_, inheritedKeywords_,
+ extendedReals_, extendedInts_, extendedKeywords_,
+ evolutionTimelevels_, defaultEvolutionTimelevels_,
+ calcs_] :=
+ Module[{nEvolved, evolvedMoLParam, evolvedGFs,
+ (*constrainedMoLParam,*) genericfdStruct, realStructs, intStructs,
+ allInherited, allExtended, implementationNames, molImplementation,
+ userImplementations, implementations, params, paramspec, param,
+ verboseStruct, calcOffsetStructs, calcEveryStructs},
+
+ (* reals and ints are symbols containing parameter names. The
+ inherited ones have implementation names as well *)
+
+ evolvedGFs = variablesFromGroups[evolvedGroups, groups];
+
+ nEvolved = Length[variablesFromGroups[evolvedGroups, groups]];
+(* nPrimitive = Length[variablesFromGroups[nonevolvedGroups, groups]];*)
+(* nPrimitive = Length[getConstrainedVariables[evolvedGroups, groups]];*)
+
+ evolvedMoLParam =
+ {
+ Name -> thornName <> "_MaxNumEvolvedVars",
+ Type -> "CCTK_INT",
+ Default -> nEvolved,
+ Description -> "Number of evolved variables used by this thorn",
+ Visibility -> "restricted",
+ AccumulatorBase -> "MethodofLines::MoL_Num_Evolved_Vars",
+ AllowedValues -> {{Value -> ToString[nEvolved] <> ":" <> ToString[nEvolved] ,
+ Description -> "Number of evolved variables used by this thorn"}}
+ };
+
+ (*
+ constrainedMoLParam =
+ {
+ Name -> thornName <> "_MaxNumConstrainedVars",
+ Type -> "CCTK_INT",
+ Default -> nPrimitive,
+ Description -> "Number of constrained variables used by this thorn",
+ Visibility -> "restricted",
+ AccumulatorBase -> "MethodofLines::MoL_Num_Constrained_Vars",
+ AllowedValues -> {{Value -> ToString[nPrimitive] <> ":" <> ToString[nPrimitive] ,
+ Description -> "Number of constrained variables used by this thorn"}}
+ };
+ *)
+
+ timelevelsParam =
+ {
+ Name -> "timelevels",
+ Type -> "CCTK_INT",
+ Default -> defaultEvolutionTimelevels,
+ Description -> "Number of active timelevels",
+ Visibility -> "restricted",
+ AllowedValues -> {{Value -> ToString[0] <> ":" <> ToString[evolutionTimelevels],
+ Description -> ""}}
+ };
+
+ rhsTimelevelsParam =
+ {
+ Name -> "rhs_timelevels",
+ Type -> "CCTK_INT",
+ Default -> 1,
+ Description -> "Number of active RHS timelevels",
+ Visibility -> "restricted",
+ AllowedValues -> {{Value -> ToString[0] <> ":" <> ToString[evolutionTimelevels],
+ Description -> ""}}
+ };
+
+ genericfdStruct =
+ {
+ Name -> "GenericFD",
+ UsedParameters ->
+ {{Name -> "stencil_width", Type -> "CCTK_INT"},
+ {Name -> "stencil_width_x", Type -> "CCTK_INT"},
+ {Name -> "stencil_width_y", Type -> "CCTK_INT"},
+ {Name -> "stencil_width_z", Type -> "CCTK_INT"},
+ {Name -> "boundary_width", Type -> "CCTK_INT"}}
+ };
+
+ realStructs = Map[krancParamStruct[#, "CCTK_REAL", False] &, reals];
+ verboseStruct = krancParamStruct[{Name -> "verbose", Default -> 0}, "CCTK_INT", False];
+ intStructs = Map[krancParamStruct[#, "CCTK_INT", False] &, ints];
+ calcEveryStructs = Map[krancParamStruct[{Name -> lookup[#, Name] <> "_calc_every", Default -> 1}, "CCTK_INT", False] &, calcs];
+ calcOffsetStructs = Map[krancParamStruct[{Name -> lookup[#, Name] <> "_calc_offset", Default -> 0}, "CCTK_INT", False] &, calcs];
+ keywordStructs = Map[krancKeywordParamStruct, keywords];
+
+ allInherited = Join[inheritedReals, inheritedInts, inheritedKeywords];
+ allExtended = Join[extendedReals, extendedInts, extendedKeywords];
+
+ implementationNames = Union[Map[implementationFromQualifiedName, allInherited],
+ Map[implementationFromQualifiedName[lookup[#, Name]] &, allExtended]];
+
+ molImplementation =
+ {
+ Name -> "MethodOfLines",
+ UsedParameters ->
+ {
+ {Name -> "MoL_Num_Evolved_Vars", Type -> "CCTK_INT"}
+ (* {Name -> "MoL_Num_Constrained_Vars", Type -> "CCTK_INT"} *)
+ }
+ };
+
+ userImplementations = Map[inheritParameters[#, inheritedReals,inheritedInts,inheritedKeywords] &,
+ implementationNames];
+ userImplementations2 = Map[extendParameters[#, extendedReals,extendedInts,extendedKeywords] &,
+ implementationNames];
+
+ userImplementations = If[userImplementations=={{}},{},userImplementations];
+ userImplementations2 = If[userImplementations2=={{}},{},userImplementations2];
+
+ implementations = Join[userImplementations, userImplementations2, {genericfdStruct, molImplementation}];
+ params = Join[{verboseStruct}, realStructs, intStructs, keywordStructs, {evolvedMoLParam, (*constrainedMoLParam,*) timelevelsParam, rhsTimelevelsParam},
+ calcEveryStructs, calcOffsetStructs,
+ CactusBoundary`GetParameters[evolvedGFs, evolvedGroups]];
+
+ paramspec = {Implementations -> implementations,
+ NewParameters -> params};
+
+(* Print["paramspec = ", paramspec];*)
+
+ param = CreateParam[paramspec];
+ Return[param]
+ ];
+
+
+
+End[];
+
+EndPackage[];
diff --git a/Tools/CodeGen/Schedule.m b/Tools/CodeGen/Schedule.m
new file mode 100644
index 0000000..98105de
--- /dev/null
+++ b/Tools/CodeGen/Schedule.m
@@ -0,0 +1,161 @@
+
+(* Copyright 2004 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["Schedule`", {"Thorn`", "KrancGroups`", "MapLookup`", "Errors`", "Helpers`", "Kranc`"}];
+
+CreateKrancScheduleFile;
+
+Begin["`Private`"];
+
+(* --------------------------------------------------------------------------
+ Scheduling
+ -------------------------------------------------------------------------- *)
+
+simpleGroupStruct[groupName_, timelevels_] :=
+{
+ Group -> groupName,
+ Timelevels -> timelevels
+};
+
+evolvedGroupStruct[groupName_, timelevels_, maxtimelevels_] :=
+{
+ Group -> groupName,
+ Timelevels -> timelevels,
+ MaxTimelevels -> "timelevels"
+};
+
+rhsGroupStruct[groupName_, timelevels_, maxtimelevels_] :=
+{
+ Group -> groupName,
+ Timelevels -> timelevels,
+ MaxTimelevels -> "rhs_timelevels"
+};
+
+groupsSetInCalc[calc_, groups_] :=
+ Module[{gfs, eqs, lhss, gfsInLHS, lhsGroupNames},
+ gfs = allGroupVariables[groups];
+ eqs = lookup[calc, Equations];
+ lhss = Map[First, eqs];
+ gfsInLHS = Union[Cases[lhss, _ ? (MemberQ[gfs,#] &), Infinity]];
+
+ lhsGroupNames = containingGroups[gfsInLHS, groups];
+ Return[lhsGroupNames]
+ ];
+
+(* Each calculation can be scheduled at multiple points, so this
+ function returns a LIST of schedule structures for each calculation
+ *)
+scheduleCalc[calc_, groups_] :=
+ Module[{points, conditional, conditionals, keywordConditional, keywordConditionals, triggered, keyword, value, keywordvaluepairs, groupsToSync},
+ conditional = mapContains[calc, ConditionalOnKeyword];
+ conditionals = mapContains[calc, ConditionalOnKeywords];
+ triggered = mapContains[calc, TriggerGroups];
+ If[conditional,
+ keywordConditional = lookup[calc, ConditionalOnKeyword];
+ If[! MatchQ[keywordConditional, {lhs_String, rhs_String}],
+ ThrowError["ConditionalOnKeyword entry in calculation expected to be of the form {parameter, value}, but was ", keywordConditional, "Calculation is ", calc]];
+
+ keyword = keywordConditional[[1]];
+ value = keywordConditional[[2]];
+ ];
+ If[conditionals,
+ keywordConditionals = lookup[calc, ConditionalOnKeywords];
+ If[! MatchQ[keywordConditionals, {{_, _} ...}],
+ ThrowError["ConditionalOnKeywords entry in calculation expected to be of the form {{parameter, value}}, but was ", keywordConditionals, "Calculation is ", calc]];
+
+ keywordvaluepairs =
+ Map[# /. {keyword_, value_} -> {Parameter -> keyword, Value -> value} &,
+ keywordConditionals];
+ ];
+
+ groupsToSync = If[lookupDefault[calc, Where, Everywhere] === Interior ||
+ lookupDefault[calc, Where, Everywhere] === Boundary,
+ groupsSetInCalc[calc, groups],
+ {}];
+
+ Map[
+ Join[
+ {
+ Name -> lookup[calc, Name],
+ SchedulePoint -> #,
+ SynchronizedGroups -> If[StringMatchQ[#, "*MoL_CalcRHS*", IgnoreCase -> True] || StringMatchQ[#, "*MoL_RHSBoundaries*", IgnoreCase -> True],
+ {},
+ groupsToSync],
+ Language -> CodeGen`SOURCELANGUAGE,
+ Comment -> lookup[calc, Name]
+ },
+ If[triggered, {TriggerGroups -> lookup[calc, TriggerGroups]},
+ {}],
+ If[conditional, {Conditional -> {Parameter -> keyword, Value -> value}},
+ {}],
+ If[conditionals, {Conditionals -> keywordvaluepairs},
+ {}]
+ ] &,
+ lookup[calc, Schedule]]];
+
+CreateKrancScheduleFile[calcs_, groups_, evolvedGroups_, rhsGroups_, nonevolvedGroups_, thornName_,
+ evolutionTimelevels_] :=
+ Module[{scheduledCalcs, scheduledStartup, scheduleMoLRegister, globalStorageGroups, scheduledFunctions, schedule},
+
+ scheduledCalcs = Flatten[Map[scheduleCalc[#, groups] &, calcs], 1];
+
+ scheduledStartup =
+ {
+ Name -> thornName <> "_Startup",
+ SchedulePoint -> "at STARTUP",
+ Language -> "C",
+ Options -> "meta",
+ Comment -> "create banner"
+ };
+
+ scheduleMoLRegister =
+ {
+ Name -> thornName <> "_RegisterVars",
+ SchedulePoint -> "in MoL_Register",
+ Language -> "C",
+ Options -> "meta",
+ Comment -> "Register Variables for MoL"
+ };
+
+ scheduleRegisterSymmetries =
+ {
+ Name -> thornName <> "_RegisterSymmetries",
+ SchedulePoint -> "in SymmetryRegister",
+ Language -> "C",
+ Options -> "meta",
+ Comment -> "register symmetries"
+ };
+
+ globalStorageGroups = Join[Map[simpleGroupStruct[#, NonevolvedTimelevels[groupFromName[#, groups]]] &, nonevolvedGroups],
+ Map[evolvedGroupStruct[#, evolutionTimelevels, evolutionTimelevels] &, evolvedGroups],
+ Map[rhsGroupStruct[#, evolutionTimelevels, evolutionTimelevels] &, rhsGroups]];
+
+ scheduledFunctions =
+ Join[{scheduledStartup, scheduleMoLRegister, scheduleRegisterSymmetries},
+ scheduledCalcs, CactusBoundary`GetScheduledFunctions[thornName, evolvedGroups]];
+
+ schedule = CreateSchedule[globalStorageGroups,
+ CactusBoundary`GetScheduledGroups[thornName], scheduledFunctions];
+
+ Return[schedule]];
+
+End[];
+
+EndPackage[];
diff --git a/Tools/CodeGen/TensorTools.m b/Tools/CodeGen/TensorTools.m
index ec099ea..e05188c 100644
--- a/Tools/CodeGen/TensorTools.m
+++ b/Tools/CodeGen/TensorTools.m
@@ -18,16 +18,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*)
-(* Place these symbols in the sym context *)
-BeginPackage["sym`"];
-{D1, D2, D3, D11, D22, D33, D21, D31, D32, D12, D13, D23, dot, Eps, Zero3}
-EndPackage[];
-
-BeginPackage["TensorTools`", {"Errors`", "MapLookup`"}];
+BeginPackage["TensorTools`", {"Errors`", "MapLookup`", "Kranc`"}];
(* Cause the sym context to be added to the context of anyone loading
this package *)
-$ContextPath = Join[{"sym`"}, $ContextPath];
+(*$ContextPath = Join[{"sym`"}, $ContextPath]; *)
(* Define usage messages for these functions. Mentioning them here
adds them to the TensorTools context *)
diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m
index a412040..c59bae1 100644
--- a/Tools/CodeGen/Thorn.m
+++ b/Tools/CodeGen/Thorn.m
@@ -23,31 +23,7 @@
(* This package provides a set of functions to create the various
parts of a Cactus thorn and assemble them. *)
-BeginPackage["sym`"];
-
-(* These symbols are used in this file. Whenever this package is
- used, the symbols will be added into the sym` context. You will
- need to make sure the sym` context is on your ContextPath to use
- the symbols without the sym` prefix. *)
-
-{AccumulatorBase, ThornImplementation, Name, Type, Extend, Default,
-Comment, Range, Implementation, Group, SchedulePoint, Language,
-SynchronizedGroups, StorageGroups, Timelevels, MaxTimelevels,
-VariableType, GridType,
-Visibility, Variables, Implementations, Value, AllowedValues,
-UsedParameters, Description, ExtendedParameters, NewParameters,
-Directory, Configuration, Interface, Param, Schedule, Sources, Makefile,
-Filename,
-Contents, ThornName, BaseImplementation, EvolvedGFs, PrimitiveGFs,
-Groups, Calculation, GridFunctions, Shorthands, Equations, Parameter,
-Value, UsesFunctions, ArgString, Conditional, Conditionals, D1, D2, D3, D11, D22,
-D33, D21, D31, D32, Textual, TriggerGroups, Include, RHSGroups, Tags};
-
-{ExcisionGFs};
-
-EndPackage[];
-
-BeginPackage["Thorn`", "CodeGen`", "CalculationFunction`", "MapLookup`", "KrancGroups`", "Helpers`"];
+BeginPackage["Thorn`", "CodeGen`", "CalculationFunction`", "MapLookup`", "KrancGroups`", "Helpers`", "Errors`", "Kranc`"];
(* These functions are externally visible, and comprise the public
interface to this package. *)
@@ -69,7 +45,7 @@ CreatePrecompMacros::usage = "";
CreateStartupFile::usage = "";
(* Ensure that we can refer to symbols without the `sym prefix *)
-$ContextPath = Join[{"sym`"}, $ContextPath];
+(*$ContextPath = Join[{"sym`"}, $ContextPath];*)
Begin["`Private`"];
@@ -179,6 +155,14 @@ parameterBlock[spec_] :=
If[mapContains[spec, AccumulatorBase],
{" ACCUMULATOR-BASE=", lookup[spec, AccumulatorBase]},
{}],
+
+ If[mapContains[spec, Steerable],
+ {" STEERABLE=",Switch[lookup[spec, Steerable],
+ Never,"NEVER",
+ Always,"ALWAYS",
+ Recover, "RECOVER",
+ _,ThrowError["Unknown 'Steerable' entry in parameter " <> ToString[lookup[spec, Name]] <> ": " <> ToString[lookup[spec, Steerable]]]]},
+ {}],
"\n",
SuffixedCBlock[
@@ -497,6 +481,8 @@ calculationMacros[] :=
CodeGen representation of a source file that defines a function for
each Calculation. *)
+Options[CreateSetterSource] = ThornOptions;
+
CreateSetterSource[calcs_, debug_, useCSE_, include_,
opts:OptionsPattern[]] :=
Module[{},
@@ -517,7 +503,8 @@ CreateSetterSource[calcs_, debug_, useCSE_, include_,
],
Map[IncludeFile, Join[{"cctk.h", "cctk_Arguments.h", "cctk_Parameters.h",
- (*"precomputations.h",*) "GenericFD.h", "Differencing.h"}, include]],
+ (*"precomputations.h",*) "GenericFD.h", "Differencing.h"}, include,
+ If[OptionValue[UseLoopControl], {"loopcontrol.h"}, {}]]],
calculationMacros[],
(* For each function structure passed, create the function and