Exit

<<xAct`xTensor`;
<< xAct`xCoba`;
<< xAct`xTras`;

$PrePrint=ScreenDollarIndices;

DefManifold[Md,4,{a,b,c,d,e,l,i,j,k,p,u,v}];
DefMetric[-1,g[-a,-b],CD,{";","∇"},WeightedWithBasis->AIndex];
PrintAs[RiemannCD]^="R";
PrintAs[RicciCD]^="R";
PrintAs[RicciScalarCD]^="R";
PrintAs[ChristoffelCD]^="Γ";
PrintAs[EinsteinCD]^="G";

If you are going to set a value for a tensor, you don’t need to define that tensor. For example here I removed your DefTensor[F[...], ...]:

DefTensor[φ[],Md];
DefTensor[A[-a],Md];
(* Maxwell strength tensor*)
F[-a_,-b_]:=CD[-a][A[-b]]-CD[-b][A[-a]];
F[a_,b_]:=CD[a][A[b]]-CD[b][A[a]];

DefConstantSymbol[α]

Construct the things you want to compute:

LEH=RicciScalarCD[];
Lφ=2CD[-a]@φ[]CD[a]@φ[];
LF=Exp[-α (((φ[]))^2)]*F[a,b]F[-a,-b];

L=LEH+Lφ+LF

Eombg=VarL[g[a,b]][L]//ContractMetric//Simplification

Eomscalar=VarD[φ[],CD][L]//ContractMetric//Simplification

EomMaxell=VarD[A[-a],CD][L]//ContractMetric//Simplification

Chart:

DefChart[Backg,Md,{0,1,2,3},{t[],r[],θ[],ϕ[]}];

DefScalarFunction/@{n ,δ};

The actual background:

gB=DiagonalMatrix[{-n[r[]]Exp[-2δ[r[]]],(1/(n[r[]])),((r[])^2),((r[])^2)((Sin[θ[]])^2)}];

(Metricgb=CTensor[gB,{-Backg,-Backg}])[-a,-b]

InvMetricgb=Inv[Metricgb]

MetricgbCD=CovDOfMetric[Metricgb];

RicciMetricgbCD=Ricci[MetricgbCD]

DefScalarFunction[ϕ0,PrintAs->"(Subscript[ϕ, 0])"];

DefScalarFunction[V];
AAnsatz={V[r[]],0,0,0}
FourPotentialAnsatz=CTensor[AAnsatz,{-Backg}]

The key idea is to defined a set of replacement rules that take you from the general symbolic situation (with g, CD, A, etc.) to your particular case (with Metricgb, MetricgbCD, FourPotentialAnsatz, etc.). You need to add to this list all objects you may want to replace. xCoba will not deduce new objects for you automatically.

rules={
g[a_?DownIndexQ,b_?DownIndexQ]:>Metricgb[a,b],g[a_?UpIndexQ,b_?UpIndexQ]:>InvMetricgb[a,b],
CD[a_?DownIndexQ]:>MetricgbCD[a],
RicciCD[a_?DownIndexQ,b_?DownIndexQ]:>RicciMetricgbCD[a,b],
A[a_?DownIndexQ]:>FourPotentialAnsatz[a],
φ[]:>ϕ0[t[],r[],θ[],ϕ[]]
};

Simplest case:

A[-a]/.rules

This does not work automatically:

A[a]/.rules

You can do this:

SeparateMetric[][A[a]]

%/.rules

Then:

F[-a,-b]/.rules

g[-a,-b]/.rules

g[a,b]/.rules

Convert things into their natural form (to save same rules above):

SeparateMetric[][Eomscalar]

Differentiation may produce Basis objects. We eliminate them with FromBasisExpand:

res1=%/.rules//FromBasisExpand//Expand

Another object:

SeparateMetric[][Eombg]

%/.rules//FromBasisExpand//Simplify

res2=Head[%];

Get a particular component:

res2[{0,-Backg},{0,-Backg}]

And another:

SeparateMetric[][EomMaxell]

%/.rules//FromBasisExpand//Simplify

res3=Head[%]

Get components, up or down:

res3[{1,Backg}]

res3[{1,-Backg}]/.rules