diff options
author | Ian Hinder <ian.hinder@aei.mpg.de> | 2012-01-23 21:57:48 -0600 |
---|---|---|
committer | Ian Hinder <ian.hinder@aei.mpg.de> | 2012-01-23 22:01:51 -0600 |
commit | c814616cad3845b100fe05160a968ecba4d1677f (patch) | |
tree | b3f63c131b54ecdbef84b9410dec6246dcf8a432 /Tools/CodeGen | |
parent | 6d3c1bdb15d8f976625dbd5b84af92cbb1c162b8 (diff) |
Calculation.m: New file for providing an abstraction over calculations
Eventually, we want all access to calculations to be through this file.
Diffstat (limited to 'Tools/CodeGen')
-rw-r--r-- | Tools/CodeGen/Calculation.m | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Tools/CodeGen/Calculation.m b/Tools/CodeGen/Calculation.m new file mode 100644 index 0000000..14ac440 --- /dev/null +++ b/Tools/CodeGen/Calculation.m @@ -0,0 +1,64 @@ + +(* Copyright 2012 Ian Hinder + + 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["Calculation`", {"Errors`", "Helpers`", "Kranc`", "KrancGroups`", "MapLookup`"}]; + +InputGridFunctions; +OutputGridFunctions; +AllGridFunctions; + +Begin["`Private`"]; + +DefFn[ + GetGridFunctions[calc_List] := + Module[ + {eqs,rhss,lhss,gfs,gfsInRHS,gfsInLHS}, + eqs = GetEquations[calc]; + + rhss = Map[#[[2]] &, eqs]; + lhss = Map[#[[1]] &, eqs]; + + gfs = allGroupVariables[lookup[calc,Groups]]; + + gfsInRHS = Union[Cases[rhss, _ ? (MemberQ[gfs,#] &), Infinity]]; + gfsInLHS = Union[Cases[lhss, _ ? (MemberQ[gfs,#] &), Infinity]]; + + {gfsInLHS, gfsInRHS}]]; + +DefFn[ + InputGridFunctions[calc_List] := + Last[GetGridFunctions[calc]]]; + +DefFn[ + OutputGridFunctions[calc_List] := + First[GetGridFunctions[calc]]]; + +DefFn[ + AllGridFunctions[calc_List] := + Flatten[GetGridFunctions[calc],1]]; + +(* This is from the user's input calculation, not after processing/optimisation *) +DefFn[ + GetEquations[calc_List] := + lookup[calc,Equations]]; + +End[]; + +EndPackage[]; |