diff options
author | Barry Wardell <barry.wardell@gmail.com> | 2012-02-09 10:12:48 +0000 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2012-02-09 10:12:48 +0000 |
commit | 64f15729d15b7b23488e870942f2ff5600d2ec28 (patch) | |
tree | 783a97d6b79c1a9c60353a7e4aa89af479cae4b9 /Tools/CodeGen/CodeGenCactus.m | |
parent | c5aecd6c7d1b69e8e79552b900c576eb14b120ec (diff) | |
parent | 72eefa3dd9e1ebdca001de5bc1497f83675b265a (diff) |
Merge remote-tracking branch 'origin/cakernel'
Conflicts:
Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h
Tools/CodeGen/CalculationFunction.m
Tools/CodeGen/CodeGenCactus.m
Tools/CodeGen/Differencing.m
Tools/CodeGen/KrancThorn.m
Tools/CodeGen/Schedule.m
Diffstat (limited to 'Tools/CodeGen/CodeGenCactus.m')
-rw-r--r-- | Tools/CodeGen/CodeGenCactus.m | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/Tools/CodeGen/CodeGenCactus.m b/Tools/CodeGen/CodeGenCactus.m index 7c54541..f49e791 100644 --- a/Tools/CodeGen/CodeGenCactus.m +++ b/Tools/CodeGen/CodeGenCactus.m @@ -65,7 +65,6 @@ GridLoop::usage = "GridLoop[block] returns a block that is looped over for every "grid point. Must have previously set up the grid loop variables (see " <> "InitialiseGridLoopVariables."; ConditionalOnParameterTextual::usage = ""; -DeclareFDVariables::usage = ""; InitialiseFDVariables::usage = ""; ReplacePowers::usage = ""; BoundaryLoop::usage = ""; @@ -75,6 +74,8 @@ NameRoot::usage = ""; PartitionVarList::usage = ""; DataType::usage = "DataType[] returns a string for the grid function data type (e.g. CCTK_REAL)"; SetDataType::usage = "SetDataType[type] sets a string for the grid function data type (e.g. CCTK_REAL)"; +CCLBlock; +CalculationMacros; Begin["`Private`"]; @@ -177,20 +178,6 @@ DefFn[ }]]; DefFn[ - DeclareFDVariables[] := -(* - CommentedBlock["Declare finite differencing variables", - {Map[DeclareVariables[#, "CCTK_REAL"] &, {{"dx", "dy", "dz"}, - {"dxi", "dyi", "dzi"}, - {khalf,kthird,ktwothird,kfourthird,keightthird}, - {"hdxi", "hdyi", "hdzi"}}], - "\n"}, - {Map[DeclareVariables[#, "ptrdiff_t"] &, {{"di", "dj", "dk"}}], - "\n"}]; -*) - CommentedBlock["Declare finite differencing variables", {}]]; - -DefFn[ InitialiseFDSpacingVariablesC[] := { (* DeclareAssignVariable["ptrdiff_t", "di", "CCTK_GFINDEX3D(cctkGH,1,0,0) - CCTK_GFINDEX3D(cctkGH,0,0,0)"], *) @@ -649,7 +636,7 @@ DefFn[ ReplacePowers[expr_, vectorise:Boolean, noSimplify:Boolean : False] := Module[ {rhs}, - rhs = expr /. Power[xx_, -1] -> INV[xx]; + rhs = expr /. Power[xx_, -1] -> INV[xx] /. ToReal[x_] :> x; (* FIXME: this breaks vectorisation *) If[SOURCELANGUAGE == "C", {rhs = rhs //. Power[xx_, 2 ] -> SQR[xx]; rhs = rhs //. Power[xx_, 3 ] -> CUB[xx]; @@ -716,7 +703,7 @@ DefFn[ rhs = rhs //. Power[E, power_] -> exp[power]; rhs = rhs //. Log[x_] -> log[x]; (* rhs = rhs //. Power[x_, n_Integer] -> pown[x,n]; *) - rhs = rhs //. Power[x_, y_] -> pow[x,y]; + rhs = rhs //. Power[x_, power_] -> pow[x,"(CCTK_REAL) "<>ToString[power]]; rhs = rhs //. Sin[x_] -> sin[x]; rhs = rhs //. Cos[x_] -> cos[x]; rhs = rhs //. Tan[x_] -> tan[x]; @@ -753,6 +740,7 @@ DefFn[ rhs = rhs //. Max[xx_, yy__] -> fmax[xx, Max[yy]]; rhs = rhs //. Min[xx_, yy__] -> fmin[xx, Min[yy]]; rhs = rhs //. Abs[x_] -> fabs[x]; + rhs = rhs //. IntAbs[x_] -> abs[x]; If[vectorise === True, rhs = vectoriseExpression[rhs]]; @@ -764,6 +752,28 @@ DefFn[ (* Print[rhs//FullForm];*) rhs]]; +DefFn[ + CCLBlock[type_String, name_String, attrs:{(_String -> CodeGenBlock)...}, + contents:CodeGenBlock,comment_String:""] := + {type, " ", name, + Map[" "<>#[[1]]<>"="<>#[[2]] &, attrs], "\n", + CBlock[contents], + If[comment === "", "", Quote[comment]],"\n"}]; + +CalculationMacros[vectorise_:False] := + CommentedBlock["Define macros used in calculations", + Map[{"#define ", #, "\n"} &, + {"INITVALUE (42)", + "QAD(x) (SQR(SQR(x)))"} ~Join~ + If[vectorise, + {"INV(x) (kdiv(ToReal(1.0),x))", + "SQR(x) (kmul(x,x))", + "CUB(x) (kmul(x,SQR(x)))"}, + {"INV(x) ((1.0) / (x))", + "SQR(x) ((x) * (x))", + "CUB(x) ((x) * (x) * (x))"}] + ]]; + End[]; EndPackage[]; |