Example over time
Examples so far have shown how to use aurel to automatically calculate relativistic terms for a given coordinate time. In practice you may be interested in seeing how these quantities evolve over time. For this the aurel package has the function over_time to do this, here we demonstrate how this is used.
First we need a big dictionnary containing the spacetime/matter:
import numpy as np
import aurel
from aurel.solutions import LCDM as sol
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as mcolors
# Define grid and finite difference class
param = { 'Nx': 64, 'Ny': 64, 'Nz': 64,
'xmin': 0.0, 'ymin': 0.0, 'zmin': 0.0,
'dx': 20.0, 'dy': 20.0, 'dz': 20.0}
fd = aurel.FiniteDifference(param)
x, y, z = fd.cartesian_coords
# Generate data for Lamnbda-CDM solution
Nt = 20
tarray = np.linspace(1, 10, Nt)
data = {key:[] for key in ['t', 'gammadown3', 'Kdown3', 'rho0']}
for t in tarray:
data['t'] += [t]
data['gammadown3'] += [sol.gammadown3(t, x, y, z)]
data['Kdown3'] += [sol.Kdown3(t, x, y, z)]
data['rho0'] += [sol.rho(t)*np.ones((fd.Nx, fd.Ny, fd.Nz))]
print('Data keys:', list(data.keys()))
4th order finite difference schemes are defined
Data keys: ['t', 'gammadown3', 'Kdown3', 'rho0']
Calculate any quantity from aurel.descriptions.keys()
# Calculate further terms with AurelCore iterated over time
data = aurel.over_time(data, fd, vars=['null_ray_exp_in'],
Lambda=sol.Lambda)
# all aurel kwargs can be passed here
print('Data keys:', list(data.keys()))
# Plot Cosmological horizon over time
Bcolors = cm.Blues(np.linspace(0.3, 1, Nt))
for i in range(Nt):
plt.plot(fd.xarray, data['null_ray_exp_in'][i][:,0,0], color=Bcolors[i])
plt.grid()
plt.ylim(-0.9, 0.9)
plt.xlabel(r'x [Mpc]')
plt.ylabel(r"$|\Theta_{in}|$")
plt.title(r'Cosmological horizon $\Theta_{in} = 0$ growing over time')
# Colorbar
norm = mcolors.Normalize(vmin=min(data['t']), vmax=max(data['t']))
sm = cm.ScalarMappable(cmap=cm.Blues, norm=norm)
sm.set_array([])
cbar = plt.colorbar(sm, ax=plt.gca(), extend='both')
cbar.set_label(r"t [Mpc]")
Processing t = 1.0
Cosmological constant set to AurelCore.Lambda = 1.04e-07
Calculated gammaup3: $\gamma^{ij}$ Spatial metric with spatial indices up
Calculated s_Gamma_udd3: ${}^{(3)}{\Gamma^{k}}_{ij}$ Christoffel symbols of spatial metric with mixed spatial indices
Calculated Ktrace: $K = \gamma^{ij}K_{ij}$ Trace of extrinsic curvature
Calculated null_ray_exp_in: $\Theta_{in}$ List of expansion of null rays radially going in
Now processing remaining time steps sequentially
Done!
Data keys: ['t', 'gammadown3', 'Kdown3', 'rho0', 'null_ray_exp_in']
Calculate your custom quantity over time
# Example of custom function to calculate backreaction
# Custom function must only take one argument, the AurelCore class instance
def backreaction(rel):
""" Example function """
sqrgdet = np.sqrt(rel['gammadet'])
dcube = rel.fd.dx * rel.fd.dy * rel.fd.dz
volume = np.sum(sqrgdet) * dcube
av_theta = np.sum(rel['theta'] * sqrgdet) * dcube / volume
av_theta2 = np.sum((rel['theta']**2) * sqrgdet) * dcube / volume
av_shear2 = np.sum(rel['shear2'] * sqrgdet) * dcube / volume
return (2/3)*(av_theta2 - av_theta**2) - 2*av_shear2
# Custom function are passed as dict with name and function
data = aurel.over_time(data, fd, vars=[{'backreaction': backreaction}],
Lambda=sol.Lambda)
print('Data keys:', list(data.keys()))
# This is homogeneous, so the backreaction should be zero
print('Backreaction values:', data['backreaction'])
Validating variable function 'backreaction'...
✓ Custom function 'backreaction' validated successfully
Processing t = 1.0
Cosmological constant set to AurelCore.Lambda = 1.04e-07
Calculating custom variable 'backreaction'...
Calculated gammadet: $\gamma$ Determinant of spatial metric
Calculated alpha: $\alpha$ Lapse. I assume $\alpha=1$, if not then please define AurelCore.data['alpha'] = ...
Calculated betax: $\beta^{x}$ x component of the shift vector with indices up. I assume $\beta^{x}=0$, if not then please define AurelCore.data['betax'] = ...
Calculated betay: $\beta^{y}$ y component of the shift vector with indices up. I assume $\beta^{y}=0$, if not then please define AurelCore.data['betay'] = ...
Calculated betaz: $\beta^{z}$ z component of the shift vector with indices up. I assume $\beta^{z}=0$, if not then please define AurelCore.data['betaz'] = ...
Calculated betaup3: $\beta^{i}$ Shift vector with spatial indices up
Calculated betadown3: $\beta_{i}$ Shift vector with spatial indices down
Calculated gdown4: $g_{\mu\nu}$ Spacetime metric with spacetime indices down
Calculated gup4: $g^{\mu\nu}$ Spacetime metric with spacetime indices up
Calculated w_lorentz: $W$ Lorentz factor. I assume $W=1$, if not then please define AurelCore.data['w_lorentz'] = ...
Calculated uup0: $u^t$ Lagrangian fluid four velocity with time indice up
Calculated velx: $v^x$ x component of Eulerian fluid three velocity with indice up. I assume $v^x=0$, if not then please define AurelCore.data['velx'] = ...
Calculated vely: $v^y$ y component of Eulerian fluid three velocity with indice up. I assume $v^y=0$, if not then please define AurelCore.data['vely'] = ...
Calculated velz: $v^z$ z component of Eulerian fluid three velocity with indice up. I assume $v^z=0$, if not then please define AurelCore.data['velz'] = ...
Calculated velup3: $v^i$ Eulerian fluid three velocity with spatial indices up.
Calculated uup3: $u^i$ Lagrangian fluid four velocity with spatial indices up
Calculated uup4: $u^\mu$ Lagrangian fluid four velocity with spacetime indices up
Calculated hup4: $h^{\mu\nu}$ Spatial metric orthonomal to fluid flow with spacetime indices up
Calculated udown4: $u_\mu$ Lagrangian fluid four velocity with spacetime indices down
Calculated hdown4: $h_{\mu\nu}$ Spatial metric orthonomal to fluid flow with spacetime indices down
CLEAN-UP: Cleaning up cache after 20 calculations...
CLEAN-UP: data size before cleanup: 188.00 MB
CLEAN-UP: Removing cached value for 'betadown3' used 13 calculations ago (size: 6.00 MB).
CLEAN-UP: Removing cached value for 'gdown4' used 2 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'gup4' used 2 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'hup4' used 2 calculations ago (size: 32.00 MB).
CLEAN-UP: Removed 4 items
CLEAN-UP: data size after cleanup: 86.00 MB
Calculated hmixed4: ${h^{\mu}}_{\nu}$ Spatial metric orthonomal to fluid flow with mixed spacetime indices
WARNING: dtconserved only works for constant press/rho
Calculated conserved_D: $D$ Conserved mass-energy density in Wilson's formalism
Calculated eps: $\epsilon$ Specific internal energy. I assume $\epsilon=0$, if not then please define AurelCore.data['eps'] = ...
Calculated conserved_E: $E$ Conserved internal energy density in Wilson's formalism
Calculated press: $p$ Pressure. I assume $p=0$, if not then please define AurelCore.data['press'] = ...
Calculated enthalpy: $h$ Specific enthalpy of the fluid
Calculated conserved_Sdown4: $S_{\mu}$ Conserved energy flux (or momentum density) in Wilson's formalism with spacetime indices down
Calculated conserved_Sdown3: $S_{i}$ Conserved energy flux (or momentum density) in Wilson's formalism with spatial indices down
Calculated betadown3: $\beta_{i}$ Shift vector with spatial indices down
Calculated gdown4: $g_{\mu\nu}$ Spacetime metric with spacetime indices down
Calculated gup4: $g^{\mu\nu}$ Spacetime metric with spacetime indices up
Calculated conserved_Sup4: $S^{\mu}$ Conserved energy flux (or momentum density) in Wilson's formalism with spacetime indices up
Calculated conserved_Sup3: $S^{i}$ Conserved energy flux (or momentum density) in Wilson's formalism with spatial indices up
Calculated gammaup3: $\gamma^{ij}$ Spatial metric with spatial indices up
Calculated s_Gamma_udd3: ${}^{(3)}{\Gamma^{k}}_{ij}$ Christoffel symbols of spatial metric with mixed spatial indices
Calculated Ktrace: $K = \gamma^{ij}K_{ij}$ Trace of extrinsic curvature
Calculated Kup3: $K^{ij}$ Extrinsic curvature with spatial indices up
Calculated dtgammaup3: $\partial_t \gamma^{ij}$ Coordinate time derivative of spatial metric with spatial indices up
Calculated dtconserved: $\partial_t D, \; \partial_t E, \partial_t S_{i}$ List of coordinate time derivatives of conserved rest mass-energy density, internal energy density and energy flux (or momentum density) with spatial indices down in Wilson's formalism
Calculated udown3: $u_\mu$ Lagrangian fluid four velocity with spatial indices down
CLEAN-UP: Cleaning up cache after 40 calculations...
CLEAN-UP: data size before cleanup: 324.01 MB
CLEAN-UP: Removing cached value for 'betax' used 37 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'betay' used 36 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'betaz' used 35 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'uup0' used 29 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'velx' used 28 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'vely' used 27 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'velz' used 26 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'velup3' used 25 calculations ago (size: 6.00 MB).
CLEAN-UP: Removing cached value for 'uup3' used 24 calculations ago (size: 6.00 MB).
CLEAN-UP: Removing cached value for 'uup4' used 19 calculations ago (size: 8.00 MB).
CLEAN-UP: Removing cached value for 'hdown4' used 20 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'hmixed4' used 19 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'conserved_Sdown4' used 7 calculations ago (size: 8.00 MB).
CLEAN-UP: Removing cached value for 'betadown3' used 7 calculations ago (size: 6.00 MB).
CLEAN-UP: Removing cached value for 'gdown4' used 10 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'gup4' used 9 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'conserved_Sup4' used 8 calculations ago (size: 8.00 MB).
CLEAN-UP: Removing cached value for 'Kup3' used 3 calculations ago (size: 18.00 MB).
CLEAN-UP: Removed 18 items
CLEAN-UP: data size after cleanup: 122.00 MB
Calculated velx: $v^x$ x component of Eulerian fluid three velocity with indice up. I assume $v^x=0$, if not then please define AurelCore.data['velx'] = ...
Calculated vely: $v^y$ y component of Eulerian fluid three velocity with indice up. I assume $v^y=0$, if not then please define AurelCore.data['vely'] = ...
Calculated velz: $v^z$ z component of Eulerian fluid three velocity with indice up. I assume $v^z=0$, if not then please define AurelCore.data['velz'] = ...
Calculated velup3: $v^i$ Eulerian fluid three velocity with spatial indices up.
Calculated uup3: $u^i$ Lagrangian fluid four velocity with spatial indices up
Calculated uup0: $u^t$ Lagrangian fluid four velocity with time indice up
Calculated dtalpha: $\partial_t \alpha$ Coordinate time derivative of the lapse. I assume $\partial_t \alpha=0$, if not then please define AurelCore.data['dtalpha'] = ...
Calculated dtbetax: $\partial_t\beta^{x}$ Coordinate time derivative of the x component of the shift vector with indices up. I assume $\partial_t\beta^{x}=0$, if not then please define AurelCore.data['dtbetax'] = ...
Calculated dtbetay: $\partial_t\beta^{y}$ Coordinate time derivative of the y component of the shift vector with indices up. I assume $\partial_t\beta^{y}=0$, if not then please define AurelCore.data['dtbetay'] = ...
Calculated dtbetaz: $\partial_t\beta^{z}$ Coordinate time derivative of the z component of the shift vector with indices up. I assume $\partial_t\beta^{z}=0$, if not then please define AurelCore.data['dtbetaz'] = ...
Calculated dtbetaup3: $\partial_t\beta^{i}$ Coordinate time derivative of the shift vector with spatial indices up
Calculated st_Gamma_udd4: ${}^{(4)}{\Gamma^{\alpha}}_{\mu\nu}$ Christoffel symbols of spacetime metric with mixed spacetime indices
Calculated st_covd_udown4: $\nabla_{\mu} u_{\nu}$ Spacetime covariant derivative of Lagrangian fluid four velocity with spacetime indices down
Calculated s_covd_udown4: $\mathcal{D}^{\{u\}}_{\mu} u_{\nu}$ Spatial covariant derivative of Lagrangian fluid four velocity with spacetime indices down, with respect to spatial hypersurfaces orthonormal to the fluid flow
Calculated thetadown4: $\Theta_{\mu\nu}$ Fluid expansion tensor with spacetime indices down
Calculated theta: $\Theta$ Fluid expansion scalar
Calculated betadown3: $\beta_{i}$ Shift vector with spatial indices down
Calculated gdown4: $g_{\mu\nu}$ Spacetime metric with spacetime indices down
Calculated gup4: $g^{\mu\nu}$ Spacetime metric with spacetime indices up
Calculated uup4: $u^\mu$ Lagrangian fluid four velocity with spacetime indices up
CLEAN-UP: Cleaning up cache after 60 calculations...
CLEAN-UP: data size before cleanup: 460.01 MB
CLEAN-UP: Removing cached value for 'gammadet' used 39 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'udown4' used 13 calculations ago (size: 8.00 MB).
CLEAN-UP: Removing cached value for 'conserved_D' used 20 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'eps' used 36 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'conserved_E' used 20 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'press' used 22 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'enthalpy' used 34 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'gammaup3' used 9 calculations ago (size: 18.00 MB).
CLEAN-UP: Removing cached value for 'Ktrace' used 24 calculations ago (size: 2.00 MB).
CLEAN-UP: Removing cached value for 'dtgammaup3' used 20 calculations ago (size: 18.00 MB).
CLEAN-UP: Removing cached value for 'velup3' used 16 calculations ago (size: 6.00 MB).
CLEAN-UP: Removing cached value for 'dtbetaup3' used 9 calculations ago (size: 6.00 MB).
CLEAN-UP: Removing cached value for 'st_Gamma_udd4' used 8 calculations ago (size: 128.00 MB).
CLEAN-UP: Removing cached value for 'st_covd_udown4' used 7 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 's_covd_udown4' used 6 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'thetadown4' used 5 calculations ago (size: 32.00 MB).
CLEAN-UP: Removing cached value for 'gdown4' used 2 calculations ago (size: 32.00 MB).
CLEAN-UP: Removed 17 items
CLEAN-UP: data size after cleanup: 134.00 MB
Calculated hup4: $h^{\mu\nu}$ Spatial metric orthonomal to fluid flow with spacetime indices up
Calculated gdown4: $g_{\mu\nu}$ Spacetime metric with spacetime indices down
Calculated udown4: $u_\mu$ Lagrangian fluid four velocity with spacetime indices down
Calculated hdown4: $h_{\mu\nu}$ Spatial metric orthonomal to fluid flow with spacetime indices down
Calculated hmixed4: ${h^{\mu}}_{\nu}$ Spatial metric orthonomal to fluid flow with mixed spacetime indices
Calculated gammadet: $\gamma$ Determinant of spatial metric
Calculated conserved_D: $D$ Conserved mass-energy density in Wilson's formalism
Calculated eps: $\epsilon$ Specific internal energy. I assume $\epsilon=0$, if not then please define AurelCore.data['eps'] = ...
Calculated conserved_E: $E$ Conserved internal energy density in Wilson's formalism
Calculated gammaup3: $\gamma^{ij}$ Spatial metric with spatial indices up
Calculated Kup3: $K^{ij}$ Extrinsic curvature with spatial indices up
Calculated dtgammaup3: $\partial_t \gamma^{ij}$ Coordinate time derivative of spatial metric with spatial indices up
Calculated dtbetaup3: $\partial_t\beta^{i}$ Coordinate time derivative of the shift vector with spatial indices up
Calculated st_Gamma_udd4: ${}^{(4)}{\Gamma^{\alpha}}_{\mu\nu}$ Christoffel symbols of spacetime metric with mixed spacetime indices
Calculated st_covd_udown4: $\nabla_{\mu} u_{\nu}$ Spacetime covariant derivative of Lagrangian fluid four velocity with spacetime indices down
Calculated s_covd_udown4: $\mathcal{D}^{\{u\}}_{\mu} u_{\nu}$ Spatial covariant derivative of Lagrangian fluid four velocity with spacetime indices down, with respect to spatial hypersurfaces orthonormal to the fluid flow
Calculated thetadown4: $\Theta_{\mu\nu}$ Fluid expansion tensor with spacetime indices down
Calculated sheardown4: $\sigma_{\mu\nu}$ Fluid shear tensor with spacetime indices down
Calculated shear2: $\sigma^2$ Magnitude of fluid shear
Calculated and freezed variable 'backreaction' in AurelCore
Now processing remaining time steps sequentially
Done!
Data keys: ['t', 'gammadown3', 'Kdown3', 'rho0', 'null_ray_exp_in', 'backreaction']
Backreaction values: [-3.55271368e-15 -1.62832710e-15 0.00000000e+00 0.00000000e+00
-2.59052039e-16 0.00000000e+00 -8.07271281e-33 -5.55111512e-17
1.85037171e-17 7.40148683e-17 3.70074342e-17 -9.25185854e-18
4.62592927e-17 -1.85037171e-17 -9.25185854e-18 4.16333634e-17
-9.47791116e-34 9.25185854e-18 2.77555756e-17 1.85037171e-17]
Calculate any estimation from aurel.est_functions.keys()
print('Available estimations:', list(aurel.est_functions.keys()))
Available estimations: ['max', 'mean', 'median', 'min', 'sum', 'std', 'var', 'maxabs', 'minabs', 'meanabs', 'medianabs', 'sumabs', 'stdabs', 'varabs', 'OD', 'UD']
# Calculate further terms with AurelCore iterated over time
data = aurel.over_time(data, fd, estimates=['max'],
Lambda=sol.Lambda)
# all aurel kwargs can be passed here
print('Data keys:', list(data.keys()))
Processing t = 1.0
Processing estimation item: max
Now processing remaining time steps sequentially
Done!
Data keys: ['t', 'gammadown3', 'Kdown3', 'rho0', 'null_ray_exp_in', 'backreaction', 'rho0_max', 'null_ray_exp_in_max']
Estimates are only applied to scalar quantities. In the data available only the \(\rho_0\) and \(\Theta_{in}\) are scalar arrays here.
Let us get the max of an other quantity:
# Calculate further terms with AurelCore iterated over time
data = aurel.over_time(data, fd, vars=['Ktrace'], estimates=['max'],
Lambda=sol.Lambda)
# all aurel kwargs can be passed here
print('Data keys:', list(data.keys()))
Processing t = 1.0
Cosmological constant set to AurelCore.Lambda = 1.04e-07
Calculated gammaup3: $\gamma^{ij}$ Spatial metric with spatial indices up
Calculated Ktrace: $K = \gamma^{ij}K_{ij}$ Trace of extrinsic curvature
Processing estimation item: max
Now processing remaining time steps sequentially
Done!
Data keys: ['t', 'gammadown3', 'Kdown3', 'rho0', 'null_ray_exp_in', 'backreaction', 'rho0_max', 'null_ray_exp_in_max', 'Ktrace', 'Ktrace_max']
Calculate your custom estimate over time
# Example of custom function to calculate scalar range
# Custom function must only take one argument, a scalar array
def range(scalar):
""" Example function """
return np.max(scalar) - np.min(scalar)
# Custom function are passed as dict with name and function
data = aurel.over_time(data, fd, estimates=[{'range': range}],
Lambda=sol.Lambda)
print('Data keys:', list(data.keys()))
Validating estimation function 'range'...
✓ Custom function 'range' validated successfully
Processing t = 1.0
Processing estimation item: range
Now processing remaining time steps sequentially
Done!
Data keys: ['t', 'gammadown3', 'Kdown3', 'rho0', 'null_ray_exp_in', 'backreaction', 'rho0_max', 'null_ray_exp_in_max', 'Ktrace', 'Ktrace_max', 'rho0_range', 'null_ray_exp_in_range', 'Ktrace_range']