Skip to content

Commit

Permalink
Make xTensor ExpandComponents consistent between rule and expression …
Browse files Browse the repository at this point in the history
…versions
  • Loading branch information
barrywardell committed Mar 11, 2014
1 parent a8d85ed commit e035a08
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Tools/CodeGen/xTensorKranc.m
Expand Up @@ -418,15 +418,19 @@

(* FIXME: Figure out a way to avoid duplicating the code above in here *)
ExpandComponents[x_] :=
Module[{expr},
(* Add brackets to scalars if they aren't present *)
expr = x /. {t_?KrancScalarQ[] -> t[], t_?KrancScalarQ -> t[], Sign[t_] :> KrancSign[t]};

(* FIXME: Maybe we should find an alternative to Quiet here *)
Check[Quiet[Validate[expr], Validate::unknown], ThrowError["Invalid tensor expression"]];
Sequence @@ krancForm[
DeleteDuplicates[
Flatten[{ComponentArray[TraceBasisDummy[expr]]}] /. {-t_?xTensorQ[i___] :> t[i], 0 -> Sequence[]}]]
Module[{expr, inds, exprC},
InfoMessage[InfoFull, "Expanding tensor expression: ", x];
If[MemberQ[expr, IfThen, Infinity, Heads -> True],
ThrowError["IfThen is only supported in the right hand side of equations"];
];
expr = x /. {t_?KrancScalarQ[] -> t[], t_?KrancScalarQ -> t[]};
expr = expr /. {Sign -> KrancSign, Abs -> KrancAbs, Switch -> KrancSwitch};
Check[Quiet[Validate[expr], Validate::unknown], ThrowError["Invalid tensor expression", expr]];
inds = IndicesOf[Free, BIndex][expr];
exprC = Flatten[{ComponentArray[TraceBasisDummy[expr], inds]}];
rules = krancForm[DeleteDuplicates[exprC /. {0 -> Sequence[]}]];
InfoMessage[InfoFull, "Expanded to: ", Map[InputForm, rules]];
Sequence @@ rules
];

(*************************************************************)
Expand Down

0 comments on commit e035a08

Please sign in to comment.