Skip to content

Commit

Permalink
Make sure derivatives are expanded out fully so that ToCanonical can …
Browse files Browse the repository at this point in the history
…work on them
  • Loading branch information
barrywardell committed Mar 7, 2014
1 parent ed61609 commit d690767
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Tools/CodeGen/xTensorKranc.m
Expand Up @@ -64,20 +64,34 @@
];

(*************************************************************)
(* Add some convenience xTensor wrapper functions *)
(* DefineTensor *)
(*************************************************************)

DefineTensor[t_[inds___], opts___] :=
Block[{$DefInfoQ = False}, DefTensor[t[inds], KrancManifold, opts]];

(*************************************************************)
(* DefineDerivative *)
(*************************************************************)

(* Define a new derivative operator. This is defined in terms of
xTensor's partial derivative operator wrapped in an inert head
to keep track of what the numerical discretisation should be. *)
DefineDerivative[pd_, numderiv_] :=
Block[{$DefInfoQ = False},
InfoMessage[InfoFull, "Defining derivative:", pd];
Module[{nd},
DefInertHead[nd];
NumericalDiscretisation[nd] ^= numderiv;

(* Support both prefix (xTensor) and postfix (Kranc) style derivatives *)
pd[i_][t_] := nd[PDKrancBasis[i][t]];
pd[t_, i_] := nd[PDKrancBasis[i][t]];

(* Distribute the nd wrapper over Plus, e.g. expand
nd[pd[t[0],0] + pd[t[1],1]] out to nd[pd[t[0],0]] + nd[pd[t[1],1]].
This is important for xTensor's canonicalizer to work reliably. *)
e : nd[_Plus] := Distribute[Unevaluated[e]];
]
];

Expand Down

0 comments on commit d690767

Please sign in to comment.