Exit

xTensor -> xCoba ?

Intro

Loading Packages

First we load the packages that we’ll need

Needs["xAct`xTensor`"];
Needs["xAct`xPert`"];
Needs["xAct`xTras`"];
Needs["xAct`Invar`"];
Needs["xAct`xCoba`"]

We turn off the verbose output and set up nice-looking dummy indices.

$DefInfoQ = False;
$PrePrint = ScreenDollarIndices;

Basic Definitions

We now define our d-dimensional manifold, and our metric. Our available indices will be all from a to t except g.

First we set up our constant dimension.

DefConstantSymbol[Dim,PrintAs->"D"];

Dim = 3;

DefManifold[M, Dim,IndexRange[a,t]];

Next, we define the (abstract) metric.

DefMetric[-1,gg[-a,-b], CD,{";","∇"},CurvatureRelations->True];
$CovDFormat="Prefix";
PrintAs[gg] ^= "g";PrintAs[RiemannCD] ^= "R"; PrintAs[RicciCD] ^= "R"; PrintAs[RicciScalarCD] ^= "R"; PrintAs[WeylCD] ^= "W"; PrintAs[EinsteinCD] ^= "G"; PrintAs[ChristoffelCD] ^= "Γ"; PrintAs[epsilong] ^= "ϵ";

Abstract Computations

Next I do some abstract computations

DefTensor[L2[],M];
L2[] = Module[{a,b},RicciCD[-a,-b]RicciCD[a,b] - (Dim/(4(Dim-1)))RicciScalarCD[]RicciScalarCD[]];

EOML2 = VarL[gg[a,b]][L2[]] // FullSimplification[] //ContractCurvature  // CollectTensors

TrEOML2 = gg[a,b]EOML2 // ContractMetric // FullSimplification[] // CollectTensors

Component Computations

Let us first define a particular metric, like AdS

DefChart[AdS,M,{0,1,2},{tt[],xx[],rr[]},ChartColor->Green,FormatBasis->{"Partials","Differentials"}];

DefScalarFunction[A]

gAdS=CTensor[DiagonalMatrix[{Exp[2A[rr[]]],Exp[2A[rr[]]],1}],{-AdS,-AdS}];

gAdS[-a,-b]

cd=CovDOfMetric[gAdS];

Ricci[cd][-a,-b]

Now, I would like to evaluate the expressions computed before (EOML2 and TrEOML2) in the metric gAdS, without having to rewrite the expressions using Ricci[cd] and such. 
I am hoping of a function that would take EOML2 and gAdS or cd and compute EOML2 evaluated with this metric. Does such a function exist?
Thank you!

Replacing a metric

Jose: We could use a function like this one, in which more tensors can be added (Einstein, Weyl, etc) in the inner With and the list of rules, if needed.

Clear[MetricReplacements]

MetricReplacements[ametric_Symbol->cmetric_CTensor]:=MetricReplacements[ametric->cmetric]=With[{
icmetric=Inv[cmetric],
acd=CovDOfMetric[ametric],
ccd=CovDOfMetric[cmetric],
basis=-cmetric[[2,1]]
},
With[{
ariemann=Riemann[acd],
criemann=RiemannDown[ccd],
aricci=Ricci[acd],
cricci=Ricci[ccd],
aricciscalar=RicciScalar[acd],
cricciscalar=RicciScalar[ccd]
},
{
ametric[a_?UpIndexQ,b_?UpIndexQ]:>icmetric[a,b],
ametric[a_?DownIndexQ,b_?DownIndexQ]:>cmetric[a,b],
acd:>ccd,
ariemann:>criemann,
aricci:>cricci,
aricciscalar:>cricciscalar
}
]
]

ReplaceMetric[expr_,rule:Rule[ametric_,cmetric_]]:=FromBasisExpand@Expand[SeparateMetric[ametric][expr]/.MetricReplacements[rule]]

$LargeComponentSize=5000

ReplaceMetric[TrEOML2,gg->gAdS]

ReplaceMetric[EOML2,gg->gAdS]//Simplify

Head[%]