diff options
author | Barry Wardell <barry.wardell@gmail.com> | 2010-08-11 20:21:20 +0200 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2010-08-11 20:21:20 +0200 |
commit | b6822104efbb225c3e024387a953411a40b973c5 (patch) | |
tree | 3fee82c9c108c7726b0bca76418e5660011f5d4d /Tools/CodeGen/KrancThorn.m | |
parent | 079231c3536bb898e14248fac8ec14dc12ba917b (diff) |
Factor out tensor code into a separate package which can eventually be used as a wrapper around TensorTools and xTensor.
Diffstat (limited to 'Tools/CodeGen/KrancThorn.m')
-rw-r--r-- | Tools/CodeGen/KrancThorn.m | 231 |
1 files changed, 1 insertions, 230 deletions
diff --git a/Tools/CodeGen/KrancThorn.m b/Tools/CodeGen/KrancThorn.m index c290293..f6565f8 100644 --- a/Tools/CodeGen/KrancThorn.m +++ b/Tools/CodeGen/KrancThorn.m @@ -28,12 +28,9 @@ BeginPackage["KrancThorn`", {"CodeGen`", "Thorn`", "MapLookup`", "KrancGroups`", "Differencing`", "CalculationFunction`", "Errors`", "Helpers`", "CactusBoundary`", - "TensorTools`", "Param`", "Schedule`", "Interface`", "Kranc`"}]; + "Param`", "Schedule`", "Interface`", "Kranc`"}]; CreateKrancThorn::usage = "Construct a Kranc thorn"; -CreateKrancThornTT::usage = "Construct a Kranc thorn using TensorTools"; -CreateKrancThornxTensor::usage = "Construct a Kranc thorn using xTensor"; -CreateGroupFromTensor::usage = ""; Begin["`Private`"]; @@ -311,231 +308,5 @@ createKrancMoLRegister[evolvedGroupNames_, nonevolvedGroupNames_, groups_, imple molregister = CreateMoLRegistrationSource[molspec, False]; Return[molregister]]; -(* -------------------------------------------------------------------------- - Tensor Tools - -------------------------------------------------------------------------- *) - -CreateKrancThornTT[groups_, parentDirectory_, thornName_, opts___] := - Module[{calcs, expCalcs, expGroups, options, derivs, expDerivs, reflectionSymmetries, declaredGroups}, - InfoMessage[Terse, "Processing tensorial arguments"]; - calcs = lookup[{opts}, Calculations]; - derivs = lookupDefault[{opts}, PartialDerivatives, {}]; - Map[CheckCalculationTensors, calcs]; - expCalcs = Map[makeCalculationExplicit, calcs]; - - InfoMessage[Info, "Group definitions:", groups]; - - expDerivs = Flatten[Map[MakeExplicit,derivs],1]; - expGroups = Map[makeGroupExplicit, groups]; - options = Join[DeleteCases[{opts}, Calculations -> _], {Calculations -> expCalcs}]; - options = Join[DeleteCases[options, PartialDerivatives -> _], {PartialDerivatives -> expDerivs}]; - - declaredGroups = lookupDefault[{opts}, DeclaredGroups, {}]; - evolutionTimelevels = lookupDefault[{opts}, EvolutionTimelevels, 3]; - defaultEvolutionTimelevels = lookupDefault[{opts}, DefaultEvolutionTimelevels, evolutionTimelevels]; - InfoMessage[Info, "Declared groups: " <> ToString[declaredGroups]]; - InfoMessage[Terse, "Computing reflection symmetries"]; - reflectionSymmetries = computeReflectionSymmetries[declaredGroups, groups]; - InfoMessage[Info, "Reflection symmetries: ", reflectionSymmetries]; - - InfoMessage[Terse, "Creating (component-based) Kranc thorn"]; - CreateKrancThorn[expGroups, parentDirectory, thornName, Apply[Sequence, options], - ReflectionSymmetries -> reflectionSymmetries]]; - -computeReflectionSymmetries[declaredGroups_, groups_] := - Module[{variables, syms}, - variables = variablesFromGroups[declaredGroups, groups]; - syms = Flatten[Map[ReflectionSymmetriesOfTensor, variables], 1]; - syms]; - -makeCalculationExplicit[calc_] := - mapValueMapMultiple[calc, - {Shorthands -> MakeExplicit, - CollectList -> MakeExplicit, - Equations -> MakeExplicit}]; - -makeGroupExplicit[g_] := - Module[{variables, newVariables, newGroup}, - variables = groupVariables[g]; - newVariables = RemoveDuplicates[MakeExplicit[variables]]; - newGroup = SetGroupVariables[g, newVariables]; - newGroup]; - -tensorTypeString[k_, inds_] := - Module[{}, - InfoMessage[InfoFull, "Tensor attributes of " <> ToString[k], TensorAttributes[k]]; - If[HasTensorAttribute[k, TensorManualCartesianParities], - "ManualCartesian", - If[Length[inds] == 0, - "Scalar", - Apply[StringJoin, Map[If[IndexIsUpper[#], "U", "D"] &, inds]]]]]; - -CreateGroupFromTensor[T:Tensor[k_, is__]] := - CreateGroupFromTensor[k, {is}]; - -reflectionParityString[l_] := - Module[{chars}, - If[!ListQ[l] || !Length[l] == 3, - ThrowError["Expecting a list of three parities for TensorManualCartesianParities, must be 1 or -1"]]; - - chars= Map[Switch[#, -1, "-", +1, "+", _, - ThrowError["Expecting a list of three parities for TensorManualCartesianParities, must be 1 or -1"]] &, - l]; - - Apply[StringJoin, chars]]; - -CreateGroupFromTensor[k_, inds_] := - Module[{ttypeString, nInds, tags, group, vars}, - InfoMessage[InfoFull, "Creating group from tensor with kernel " <> ToString[k] <> " and indices " <> ToString[inds]]; - ttypeString = tensorTypeString[k, inds]; - InfoMessage[InfoFull, "Tensor type string: ", ttypeString]; - nInds = Length[inds]; - If[nInds == 2 && GetTensorAttribute[k, Symmetries] == {{2,1},1}, - ttypeString = ttypeString <> "_sym"]; - If[nInds == 3 && GetTensorAttribute[k, Symmetries] == {{1,3,2},1}, - ttypeString = ttypeString <> "_sym"]; - tags = {"tensortypealias" -> ttypeString, "tensorweight" -> GetTensorAttribute[k, TensorWeight]}; - If[HasTensorAttribute[k, TensorSpecial], - tags = Append[tags, "tensorspecial" -> GetTensorAttribute[k, TensorSpecial]]]; - If[HasTensorAttribute[k, TensorManualCartesianParities], - tags = Append[tags, "cartesianreflectionparities" -> - reflectionParityString[GetTensorAttribute[k, TensorManualCartesianParities]]]]; - If[HasTensorAttribute[k, TensorParity], - tags = Append[tags, "tensorparity" -> GetTensorAttribute[k, TensorParity]]]; - vars = If[nInds == 0, {k}, {Apply[Tensor, {k, Apply[Sequence,inds]}]}]; - group = CreateGroup[ToString[k] <> "_group", vars, {Tags -> tags}]; - Return[group]]; - -CreateGroupFromTensor[x_] := - If[IsTensor[x], - CreateGroupFromTensor[x, {}], - ThrowError["CreateGroupFromTensor: Not a tensor", x]]; - -CheckEquationTensors[eq_] := - Module[{}, - CheckTensors[eq]]; - -CheckCalculationTensors[calc_] := - Module[{eqs}, - - If[mapContains[calc, Shorthands], - CheckTensors[lookup[calc, Shorthands]]]; - - eqs = lookup[calc, Equations]; - Map[CheckEquationTensors, eqs]]; - -(* -------------------------------------------------------------------------- - xTensor - -------------------------------------------------------------------------- *) - -CreateKrancThornxTensor[groups_, parentDirectory_, thornName_, opts___] := - Module[{calcs, expCalcs, expGroups, options, derivs, expDerivs, reflectionSymmetries, declaredGroups}, - InfoMessage[Terse, "Processing tensorial arguments"]; - calcs = lookup[{opts}, Calculations]; - derivs = lookupDefault[{opts}, PartialDerivatives, {}]; - Map[CheckCalculationTensors, calcs]; - expCalcs = Map[makeCalculationExplicit, calcs]; - - InfoMessage[Info, "Group definitions:", groups]; - - expDerivs = Flatten[Map[xTensorMakeExplicit,derivs],1]; - expGroups = Map[makeGroupExplicit, groups]; - options = Join[DeleteCases[{opts}, Calculations -> _], {Calculations -> expCalcs}]; - options = Join[DeleteCases[options, PartialDerivatives -> _], {PartialDerivatives -> expDerivs}]; - - declaredGroups = lookupDefault[{opts}, DeclaredGroups, {}]; - evolutionTimelevels = lookupDefault[{opts}, EvolutionTimelevels, 3]; - defaultEvolutionTimelevels = lookupDefault[{opts}, DefaultEvolutionTimelevels, evolutionTimelevels]; - InfoMessage[Info, "Declared groups: " <> ToString[declaredGroups]]; - InfoMessage[Terse, "Computing reflection symmetries"]; - reflectionSymmetries = computeReflectionSymmetries[declaredGroups, groups]; - InfoMessage[Info, "Reflection symmetries: ", reflectionSymmetries]; - - InfoMessage[Terse, "Creating (component-based) Kranc thorn"]; - CreateKrancThorn[expGroups, parentDirectory, thornName, Apply[Sequence, options], - ReflectionSymmetries -> reflectionSymmetries]]; - -computeReflectionSymmetries[declaredGroups_, groups_] := - Module[{variables, syms}, - variables = variablesFromGroups[declaredGroups, groups]; - syms = Flatten[Map[xTensorReflectionSymmetriesOfTensor, variables], 1]; - syms]; - -makeCalculationExplicit[calc_] := - mapValueMapMultiple[calc, - {Shorthands -> xTensorMakeExplicit, - CollectList -> xTensorMakeExplicit, - Equations -> xTensorMakeExplicit}]; - -makeGroupExplicit[g_] := - Module[{variables, newVariables, newGroup}, - variables = groupVariables[g]; - newVariables = RemoveDuplicates[xTensorMakeExplicit[variables]]; - newGroup = SetGroupVariables[g, newVariables]; - newGroup]; - -tensorTypeString[k_, inds_] := - Module[{}, - InfoMessage[InfoFull, "Tensor attributes of " <> ToString[k], TensorAttributes[k]]; - If[HasTensorAttribute[k, TensorManualCartesianParities], - "ManualCartesian", - If[Length[inds] == 0, - "Scalar", - Apply[StringJoin, Map[If[IndexIsUpper[#], "U", "D"] &, inds]]]]]; - -CreateGroupFromTensor[T:Tensor[k_, is__]] := - CreateGroupFromTensor[k, {is}]; - -reflectionParityString[l_] := - Module[{chars}, - If[!ListQ[l] || !Length[l] == 3, - ThrowError["Expecting a list of three parities for TensorManualCartesianParities, must be 1 or -1"]]; - - chars= Map[Switch[#, -1, "-", +1, "+", _, - ThrowError["Expecting a list of three parities for TensorManualCartesianParities, must be 1 or -1"]] &, - l]; - - Apply[StringJoin, chars]]; - -CreateGroupFromTensor[t_Symbol?xTensorQ[inds___]] := - Module[{ttypeString, nInds, tags, group, vars}, - InfoMessage[InfoFull, "Creating group from tensor with kernel " <> ToString[t] <> " and indices " <> ToString[inds]]; - ttypeString = tensorTypeString[k, {inds}]; - InfoMessage[InfoFull, "Tensor type string: ", ttypeString]; - nInds = Length[inds]; - If[nInds == 2 && GetTensorAttribute[k, Symmetries] == {{2,1},1}, - ttypeString = ttypeString <> "_sym"]; - If[nInds == 3 && GetTensorAttribute[k, Symmetries] == {{1,3,2},1}, - ttypeString = ttypeString <> "_sym"]; - tags = {"tensortypealias" -> ttypeString, "tensorweight" -> GetTensorAttribute[k, TensorWeight]}; - If[HasTensorAttribute[k, TensorSpecial], - tags = Append[tags, "tensorspecial" -> GetTensorAttribute[k, TensorSpecial]]]; - If[HasTensorAttribute[k, TensorManualCartesianParities], - tags = Append[tags, "cartesianreflectionparities" -> - reflectionParityString[GetTensorAttribute[k, TensorManualCartesianParities]]]]; - If[HasTensorAttribute[k, TensorParity], - tags = Append[tags, "tensorparity" -> GetTensorAttribute[k, TensorParity]]]; - vars = If[nInds == 0, {k}, {Apply[Tensor, {k, Apply[Sequence,inds]}]}]; - group = CreateGroup[ToString[t] <> "_group", vars, {Tags -> tags}]; - Return[group]]; - -CreateGroupFromTensor[x_] := - If[IsTensor[x], - CreateGroupFromTensor[x, {}], - ThrowError["CreateGroupFromTensor: Not a tensor", x]]; - -CheckEquationTensors[eq_] := - Module[{}, - CheckTensors[eq]]; - -CheckCalculationTensors[calc_] := - Module[{eqs}, - - If[mapContains[calc, Shorthands], - CheckTensors[lookup[calc, Shorthands]]]; - - eqs = lookup[calc, Equations]; - Map[CheckEquationTensors, eqs]]; - End[]; EndPackage[]; |