diff options
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/CodeGen/CalculationFunction.m | 4 | ||||
-rw-r--r-- | Tools/CodeGen/CodeGen.m | 16 |
2 files changed, 4 insertions, 16 deletions
diff --git a/Tools/CodeGen/CalculationFunction.m b/Tools/CodeGen/CalculationFunction.m index 69b23da..60ff163 100644 --- a/Tools/CodeGen/CalculationFunction.m +++ b/Tools/CodeGen/CalculationFunction.m @@ -426,9 +426,9 @@ CreateCalculationFunction[calcp_, debug_, imp_, opts:OptionsPattern[]] := InfoMessage[InfoFull, "Equations:"]; - (* Wrap parameters with ToReal *) + (* Wrap parameters with ToReal unless they are part of the condition in an IfThen *) parameterRules = Map[(#->ToReal[#])&, parameters]; - eqs = eqs /. parameterRules; + eqs = eqs /. Prepend[parameterRules, IfThen[cond_, x_, y_] :> IfThen[cond, x/.parameterRules, y/.parameterRules]]; Map[printEq, eqs]; diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m index 4afd995..a1f0896 100644 --- a/Tools/CodeGen/CodeGen.m +++ b/Tools/CodeGen/CodeGen.m @@ -774,24 +774,12 @@ BoundaryWithGhostsLoop[block_] := ]} ]]]}; -(* Remove call to ToReal from condtion. This should really instead be - done much earlier. Sometimes Conditional is called with a - conditional that is an expression, sometimes it is a list of - strings, so we need to handle both cases. *) -(* One approach to remove calls to ToReal is to wrap the condition - into a function call, such as e.g. Cond[x], which is then handled by - the vectorisation code in the same way the IfThen[x,y,z] expression - is handled there. *) -removeToRealFunc[condition_] := Replace[condition, {ToReal[x_] -> x}] -removeToRealString[condition_] := If[StringQ[condition], StringReplace[condition, "ToReal(" ~~ x__ ~~ ")" :> x], condition] -removeToReal[condition_] := Map[removeToRealString, removeToRealFunc[condition]] - Conditional[condition_, block_] := - {"if (", removeToReal[condition], ")\n", + {"if (", condition, ")\n", CBlock[block]}; Conditional[condition_, block1_, block2_] := - {"if (", removeToReal[condition], ")\n", + {"if (", condition, ")\n", CBlock[block1], "else\n", CBlock[block2]}; onceInGridLoop[block_] := |