Skip to content

Commit

Permalink
Improve DefineTensor
Browse files Browse the repository at this point in the history
It actually works as it should now. It takes two arguments, the symbol
which will be used in tensor expressions and the symbol which represents
its numerical discretisation.
  • Loading branch information
barrywardell committed Mar 7, 2014
1 parent 8a9443f commit 180b27c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Tools/CodeGen/xTensorKranc.m
Expand Up @@ -22,7 +22,7 @@
];

DefineTensor::usage = "DefineTensor[T[a, b, ...]] defines the tensor T with indices a, b, c, ....";
DefineDerivative::usage = "DefineDerivative[pd] registers a symbol to be used as a derivative operator.";
DefineDerivative::usage = "DefineDerivative[pd, nd] registers a symbol pd to be used as a derivative operator, with numerical discretisation nd.";
SetComponents::usage = "SetComponents[T[a, b, ...], v] defines the components of the tensor T to be the values given in the list v."

CreateGroupFromTensor::usage = "CreateGroupFromTensor[T[a, b, ...]] Creates a variable group from the tensor T";
Expand Down Expand Up @@ -70,10 +70,15 @@
DefineTensor[t_[inds___], opts___] :=
Block[{$DefInfoQ = False}, DefTensor[t[inds], KrancManifold, opts]];

DefineDerivative[pd_] :=
DefineDerivative[pd_, numderiv_] :=
Block[{$DefInfoQ = False},
InfoMessage[InfoFull, "Defining derivative:", pd];
DefCovD[pd[-$KrancIndices[[1]]], Curvature -> False, Torsion -> False]
Module[{nd},
DefInertHead[nd];
NumericalDiscretisation[nd] ^= numderiv;
pd[i_][t_] := nd[PDKrancBasis[i][t]];
pd[t_, i_] := nd[PDKrancBasis[i][t]];
]
];

toBasis[x_] :=
Expand Down Expand Up @@ -106,8 +111,8 @@
SymbolJoin[t, Sequence @@ ToString /@ {i}[[All, 1]]],
t_Symbol?xTensorQ[] :> t,
(* FIXME: Better handling of derivatives *)
(* pd_?CovDQ[i : (_?CIndexQ ..)][t_?xTensorQ] :> SymbolJoin[pd, krancForm[t], i[[1]]] *)
PDKrancBasis[i_][t_] :> Global`PDstandard2nd[krancForm[t], i[[1]]]};
nd_[pd_?CovDQ[i : (_?CIndexQ ..)][t_?xTensorQ[inds__]]] :> NumericalDiscretisation[nd][krancForm[t[inds]], i[[1]]]
};

SetAttributes[ExpandComponents, Listable];
ExpandComponents[lhs_ -> rhs_] :=
Expand Down

0 comments on commit 180b27c

Please sign in to comment.