On Mar 25, 3:48 pm, Barry Wardell <barry.ward...@aei.mpg.de> wrote:
> Hi,
>
> I want to use xCoba to compute the components of symmetric objects which
> are recursively defined in terms of combinations of partial derivatives
> of the metric. As a specific example, I would like to compute the
> components in Schwarzschild of things like the following:
>
A3_{a b c} &=& g_{(a b ,c)}\\
A4_{a b c d} &=& A3_{(a b |\rho} A3_{\tau| c d)} g^{\rho \tau} + A3_{(b
c d , a)} \\
& &+ A3_{(a b |\rho|} g_{c d ),\tau}g^{\rho \tau} + g_{(a b ,|\rho|}
g_{c d) ,\tau} g^{\rho \tau}
Barry
<< xAct`xCoba`
$Info = False;
$CVVerbose = False;
$PrePrint = ScreenDollarIndices;
<< xAct`ShowTime1`
$ShowTimeThreshold = 0.1;
DefManifold[M, 4, IndexRange[a, q]];
DefMetric[-1, metric[-a, -b], CD, {";", "D"}, PrintAs -> "g"];
DefTensor[t[], TangentM]; DefTensor[
r[], TangentM]; DefTensor[\[Theta][], TangentM]; DefTensor[\[Phi][], \
TangentM];
DefChart[B, M, {0, 1, 2, 3}, {t[],
r[], \[Theta][], \[Phi][]}]; DefConstantSymbol[Mass, PrintAs -> "M"];
metricarray = {
{-(1 - (2 Mass )/r[]), 0, 0, 0},
{0, (1 - (2 Mass )/r[])^-1, 0, 0},
{0, 0, r[]^2, 0},
{0, 0, 0, r[]^2 Sin[\[Theta][]]^2}
};
MetricInBasis[metric, -B, metricarray];
MetricCompute[metric, B, All, CVSimplify -> Simplify];
DefTensor[A3[-a, -b, -c], M, Symmetric[{-a, -b, -c}]];
IndexSet[A3[-a_, -b_, -c_],
ToCanonical[ Symmetrize[PD[-c][metric[-a, -b]],
IndexList[-a, -b, -c]]]];
DefTensor[A4[-a, -b, -c, -d], M, Symmetric[{-a, -b, -c, -d}]]
IndexSet[A4[-a_, -b_, -c_, -d_],
ToCanonical[
Symmetrize[ A3[-a, -b, -e] A3[-f, -c, -d] metric[e, f] +
PD[-a][A3[-b, -c, -d]] +
A3[-a, -b, -e] PD[-f][metric[-c, -d]] metric[e, f] +
PD[-e][metric[-a, -b]] metric[e, f] PD[-f][metric[-c, -d]],
IndexList[-a, -b, -c, -d]]]];
ToBasis[B][ToBasis[B][ A4[-a, -b, -c, -d] ]] /. ChristoffelPDB[_, _, _]
-> 0;
ComponentArray[%];
TraceBasisDummy[%];
ToValues[%]
There is no general algorithm to manipulate components which is always
faster than the rest. For example, depending on whether your arrays of
components are sparse or not, it might be better to work with abstract
representations of the tensors (linear combinations of Basis objects)
or looping through dense arrays of components. The amount of symmetry
in your expressions is also highly relevant.
Hence, our goal so far in xCoba has been to provide enough tools to do
any computation, in any way you might find more efficient or clearer,
and only very recently black-box algorithms like MetricCompute have
been added, to perform very specific standard tasks.
Your problem seems general enough so that I don't see a simple trick
to accelerate the computation for general metrics. However, just by
looking at your expression, I would recommend you to do this, more or
less :
- Think first how many derivatives of the metric you will want to
compute. Compute them in a given chart/frame first and simplify the
results as much as possible. For general metrics this simplification
step could take most of the time of the whole computation. Store those
simplified results, to avoid recomputation, as components of tensors
Dg, DDg, DDDg, etc with appropriate symmetries, and all with lower
indices. Use the command RuleToSet.
- Manipulate your expressions with xTensor, and simplify with
ToCanonical. Replace the derivatives PD[g] by Dg and then use ToBasis.
In this way you will avoid ToBasis worrying about whether the
derivatives are compatible with your frame. At this step you still
have dummy b-indices. Be careful if you use non-coordinated frames.
- Select a set of independent components of the tensor An you want to
compute and compute/store only those.
- Then use TraceBasisDummy on those independent components. The
components of D..Dg will be automatically replaced by their values
(because of RuleToSet). Finally use Simplify.
- Something which is not clear to me is whether it is better to use
Symmetrize at the beginning or at the end. You seem to use it at the
beginning, but it actually could be better to do it at the end if your
expressions get too complicated. I'm not sure.
Try these suggestions, and if you still feel unhappy, send an example
to me, as suggested by Alessandro.
Cheers,
Jose.
On Mar 25, 3:48 pm, Barry Wardell <barry.ward...@aei.mpg.de> wrote:
> Hi,
>
> I want to use xCoba to compute the components of symmetric objects which
> are recursively defined in terms of combinations of partial derivatives
> of the metric. As a specific example, I would like to compute the
> components in Schwarzschild of things like the following:
>
I had a look at your code, and I see that the ToBasis step is slow.
This is essentially because you are introducing an irrelevant
derivative in the problem, namely PD, whose influence you are later
forced to remove with the instruction ChristoffelPDB[_, _, _]-> 0.
Note that ChristoffelPDB is, by definition, the Christoffel connecting
the derivatives PDB and PD. If you define your expressions An directly
using PDB instead of PD then you don't need Christoffels, and the
computation is 20 times faster for A4 already.
A second thing is that you use ComponentArray before TraceBasisDummy.
Because the initial expression has dummies, TraceBasisDummy will have
to do the same job as many times as the number of components of the
array produced by ComponentArray. If you swap the use of those two
commands (simply reorder the lines you wrote), then it is considerably
faster.
Finally, I still think that the key to make this type of computation
faster is to precompute all derivatives of the metric and store them
in tensors Dn, and at the same time make the abstract PDB derivatives
of the metric get automatically converted into these tensors. That
means that the An expressions will be linear combinations of
contractions of Dn tensors. If you precompute upper and lower
components of these Dn tensors you also save much work to
TraceBasisDummy. All this, in combination with RuleToSet (to avoid
using ToValues), could make this computation reasonably fast from the
tensorial point of view. Of course, if the expressions you get after
using the form of the metric are large, then the time taken by
Simplify at the very end could be enormous, so that you have to think
of a guided strategy for simplification.
This is a good example of how component computations, though
conceptually straightforward, can become unmanageable if one does not
use little tricks. Let me emphasise again that xCoba aims to provide
the individual tools you need to perform generic computations in the
way you want, but does not try to decide which way is best. That would
be too difficult, I think.
Cheers,
Jose.
> I should also mention that right now I'm just looking at components for
> Schwarzschild. In this case, the tensors are very sparse. For example,
> the metric has only 4 non-zero components out of 16. Even better,
> DDDDMetric has only 5 non-zero independent components out of 4096! I
> guess this means that TraceBasisDummy is wasting a lot of time
> multiplying by zero, so I wonder if a more manual version would give a
> large speed up.
When this is the case you should consider manipulating tensors in the
abstract way. For instance if a contravariant tensor with m indices in
dimension n has m^n components, but only the first one is nonzero and
equal to 7 in the basis B, then it is better to write it as 7
Basis[{1,-B}, a1] ... Basis[{1, -B}, am] instead of manipulating
arrays or lists of rules. How to switch between the different forms is
explained in the second part of the KerrNewmanExamples.nb notebook,
that you can download from the xCoba webpage.
Cheers,
Jose.
Barry