Skip to content

Commit

Permalink
Implement projection operators for variables (Ticket #192).
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenrbrandt committed Mar 8, 2016
1 parent b19689e commit c14f445
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Auxiliary/Grammars/kranc2.peg
Expand Up @@ -50,7 +50,11 @@ on_clause = on {uname}
schedule = scheduled[ \t]+{at_or_in}[ \t]{uname}( {on_clause})?
Opast = Opast \[ {tensor} \]
calculation = begin[ \t]+calculation[ \t]+{uname}([ \t]+{schedule}){-end} {eqns} end[ \t]+calculation
variables = begin[ \t]+variables{-end} ( end[ \t]+variables\b{brk}| ({Opast}|{tensor}))*{-end}
x = (x|)
y = (y|)
z = (z|)
projected_var = {name} \[ {x} ,? {y} ,? {z} \]
variables = begin[ \t]+variables{-end} ( end[ \t]+variables\b{brk}| ({projected_var}|{Opast}|{tensor}))*{-end}
parameters = begin[ \t]+parameters{-end} ( end[ \t]+parameters\b{brk}| {parameter})*{-end}
infinity = infinity
parlo = - {infinity}|{expr}
Expand Down
21 changes: 16 additions & 5 deletions Tools/CodeGen/CodeGenCalculation.m
Expand Up @@ -743,6 +743,21 @@ General Utility Functions (could be moved outside this package)
PastTL[x_] :=
If[StringMatchQ[ToString[x],"*Opast"],"1","0"];

gfMakeAssign[gf_] :=
Module[{res="unset",sizes,info},
info = Global`KrancProjectionInfo[gf];
If[info === False,
res=StringJoin[ " assign_from_gf_load("
<> chemoraQuote[localName[gf]] <> ", "
<> NoPast[chemoraQuote[gf]] <> ", "
<> PastTL[gf] <> ");\n"],
sizes=Global`Sizes /. info;
res=StringJoin[ " assign_from_gf_load_"<>StringJoin[sizes]<>"_only("
<> chemoraQuote[localName[gf]] <> ", "
<> NoPast[chemoraQuote[gf]] <> ", "
<> PastTL[gf] <> ");\n"]];
Return[res]];

DefFn[
equationLoop[eqs_, cleancalc_, gfs_, shorts_, incs_, groups_, odeGroups_, pddefs_,
where_, addToStencilWidth_,
Expand Down Expand Up @@ -899,11 +914,7 @@ it is only possible to do this outside all if(){} statements. *)

mapRefAppend[cleancalc,ChemoraContents, "// gfsInRHS:\n"];
mapRefAppend[cleancalc,ChemoraContents,
StringJoin[ " assign_from_gf_load("
<> chemoraQuote[localName[#]] <> ", "
<> NoPast[chemoraQuote[#]] <> ", "
<> PastTL[#] <> ");\n" &
/@ gfsInRHS ]];
StringJoin[gfMakeAssign /@ gfsInRHS]];

Module[{sortedgfds},
sortedgfds = GridFunctionDerivativesInExpression
Expand Down
10 changes: 10 additions & 0 deletions Tools/CodeGen/KrancScript.m
Expand Up @@ -63,6 +63,16 @@
Join[eqns,tmpeqns]
];

Global`KrancProjectionInfo[_] := False;
ZeroLength[x_String] := StringLength[x]===0;
process["projected_var"["name"[nm_], "x"[xv___], "y"[yv___], "z"[zv___]]] :=
Module[{vsizes,var},
vsizes = DeleteCases[{xv,yv,zv},_?ZeroLength];
var = ToExpression[nm];
Global`KrancProjectionInfo[var] = {Global`Sizes->vsizes};
Return[var];
];

process[thorn:"thorn"[content___]] :=
Module[
{calcs = {}, name, parameters = {}, variables = {}, temporaries = {Global`boundx,Global`boundy,Global`boundz}, tensors, kernels,
Expand Down

0 comments on commit c14f445

Please sign in to comment.