diff options
-rw-r--r-- | Tools/CodeGen/KrancThorn.m | 17 | ||||
-rw-r--r-- | Tools/CodeGen/Thorn.m | 74 |
2 files changed, 66 insertions, 25 deletions
diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index e1cc5c8..49bea9d 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -32,7 +32,8 @@ BeginPackage["sym`"]; ExtendedRealParameters,ExtendedIntParameters,ExtendedKeywordParameters, Parameters, EvolutionTimelevels, - PartialDerivatives, InheritedImplementations, ConditionalOnKeyword, ReflectionSymmetries, ZeroDimensions, CollectList, Interior, Boundary, BoundaryWithGhosts, Where, PreDefinitions, AllowedSymbols, UseLoopControl}; + +PartialDerivatives, InheritedImplementations, ConditionalOnKeyword, ConditionalOnKeywords, ReflectionSymmetries, ZeroDimensions, CollectList, Interior, Boundary, BoundaryWithGhosts, Where, PreDefinitions, AllowedSymbols, UseLoopControl}; EndPackage[]; @@ -662,8 +663,9 @@ groupsSetInCalc[calc_, groups_] := function returns a LIST of schedule structures for each calculation *) scheduleCalc[calc_, groups_] := - Module[{points, conditional, triggered, keyword, value, groupsToSync}, + 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]; @@ -673,6 +675,15 @@ scheduleCalc[calc_, groups_] := 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, @@ -693,6 +704,8 @@ scheduleCalc[calc_, groups_] := If[triggered, {TriggerGroups -> lookup[calc, TriggerGroups]}, {}], If[conditional, {Conditional -> {Parameter -> keyword, Value -> value}}, + {}], + If[conditionals, {Conditionals -> keywordvaluepairs}, {}] ] &, lookup[calc, Schedule]]]; diff --git a/Tools/CodeGen/Thorn.m b/Tools/CodeGen/Thorn.m index de153ec..6a50a02 100644 --- a/Tools/CodeGen/Thorn.m +++ b/Tools/CodeGen/Thorn.m @@ -40,7 +40,7 @@ Directory, Configuration, Interface, Param, Schedule, Sources, Makefile, Filename, Contents, ThornName, BaseImplementation, EvolvedGFs, PrimitiveGFs, Groups, Calculation, GridFunctions, Shorthands, Equations, Parameter, -Value, UsesFunctions, ArgString, Conditional, D1, D2, D3, D11, D22, +Value, UsesFunctions, ArgString, Conditional, Conditionals, D1, D2, D3, D11, D22, D33, D21, D31, D32, Textual, TriggerGroups, Include, RHSGroups, Tags}; {ExcisionGFs}; @@ -335,6 +335,7 @@ CreateInterface[implementation_, inheritedImplementations_, includeFiles_, {Group -> "admbase::metric", Timelevels -> 3, Conditional -> {Parameter -> "", Value -> ""}, + Conditionals -> {{Parameter -> "", Value -> ""}}, Conditional -> {Textual -> "CCTK_EQUALS(name,value)"}} A "conditional" structure looks like this: {Parameter -> "", Value -> ""} @@ -346,7 +347,8 @@ CreateInterface[implementation_, inheritedImplementations_, includeFiles_, (optional) SynchronizedGroups -> {ADM_BSSN_gamma, ...}, (optional) Options -> {"meta", "level", ...}, (optional) StorageGroups -> {Group -> "mygroup", Timelevels -> 1}, - (optional) Conditional -> {Parameter -> "", Value -> ""}} + (optional) Conditional -> {Parameter -> "", Value -> ""}, + (optional) Conditionals -> {{Parameter -> "", Value -> ""}}} scheduled group: @@ -392,29 +394,55 @@ scheduleUnconditionalFunction[spec_] := (* Handle the aspect of scheduling the function conditionally *) scheduleFunction[spec_] := - Module[{condition, parameter, value, u}, + Module[{condition, conditions, parameter, value, u, v, w, x}, u = scheduleUnconditionalFunction[spec]; - If[mapContains[spec, Conditional], + v = If[mapContains[spec, Conditional], - (* Output the conditional structure *) - condition = lookup[spec, Conditional]; - - If[mapContains[condition, Textual], - - ConditionalOnParameterTextual[lookup[condition, Textual], u], - - If[mapContains[condition, Parameter], - - parameter = lookup[condition, Parameter]; - value = lookup[condition, Value]; - ConditionalOnParameter[parameter, value, u], + (* Output the conditional structure *) + condition = lookup[spec, Conditional]; + + If[mapContains[condition, Textual], + + ConditionalOnParameterTextual[lookup[condition, Textual], u], - If[condition != {}, - Throw["Unrecognized conditional structure", condition], - u]]], - u]]; + If[mapContains[condition, Parameter], + + parameter = lookup[condition, Parameter]; + value = lookup[condition, Value]; + ConditionalOnParameter[parameter, value, u], + + If[condition != {}, + Throw["Unrecognized conditional structure", condition], + u]]], + u]; + + w = If[mapContains[spec, Conditionals], + + (* Output the conditionals structure *) + conditions = lookup[spec, Conditionals]; + + Fold[Function[{x, condition}, + + If[mapContains[condition, Textual], + + ConditionalOnParameterTextual[lookup[condition, Textual], x], + + If[mapContains[condition, Parameter], + + parameter = lookup[condition, Parameter]; + value = lookup[condition, Value]; + ConditionalOnParameter[parameter, value, x], + + If[condition != {}, + Throw["Unrecognized conditional structure", condition], + x]], + x]], + v, conditions], + v]; + + w]; (* Schedule a schedule group. Use a slightly dirty trick; given that @@ -1003,9 +1031,9 @@ CreateMoLExcisionSource[spec_] := "! grid parameters\n", - "nx = cctk_lsh(1)\n", - "ny = cctk_lsh(2)\n", - "nz = cctk_lsh(3)\n\n", + "nx = cctk_lsh(1)\n", + "ny = cctk_lsh(2)\n", + "nz = cctk_lsh(3)\n\n", "if (excision .ne. 0) then\n", |