Hello!
I realise that this is an old question but I recently tried to tackle the same problem so I thought it would still be nice to share what I've done in case anyone finds it useful and/or has suggestions on how to improve and develop it. Note that this is just a simple construction and does not fully specify the symmetries of the anisotropic stress tensor (these could be added at this stage or maybe later as rules). I also haven't thought about how this will work with perturbations... The following is not a full script and relies on some standard previous definitions such as DefMatterFields[u,du,h]. Any comments are very welcome!
Best wishes,
Sergi
(*define stress-energy tensor*)
DefTensor[T[-b, -c], Md];
DefTensor[Ts[], Md, PrintAs -> "T"];
DefTensor[PiRaw[-b, -c], Md, Symmetric[{-b, -c}],
PrintAs -> "\[CapitalPi]^{raw}"];
DefTensor[PiST[-b, -c], Md, Symmetric[{-b, -c}],
PrintAs -> "\[CapitalPi]"];
IndexSet[PiST[b_, c_], PiRaw[b, c] - (1/4) g[b, c] PiRaw[d, -d]];
(*Options:"Dust", "PerfectFluid", "ImperfectFluid"*)
$FluidModel = "Dust";
(*Set fluid model flags*)
If[$FluidModel === "Dust", ($Density = True;
$Pressure = False;
$AnisotropicStress = False;)];
If[$FluidModel === "PerfectFluid", ($Density = True;
$Pressure = True;
$AnisotropicStress = False;)];
If[$FluidModel === "ImperfectFluid", ($Density = True;
$Pressure = True;
$AnisotropicStress = True;)];
(*Define T_ab*)
IndexSet[
T[b_, c_], (If[$Density, \[Rho][u][] u[b] u[c], 0] +
If[$Pressure, P[u][] (g[b, c] + u[b] u[c]), 0] +
If[$AnisotropicStress, PiST[b, c], 0])];