Tensorium
Loading...
Searching...
No Matches
RiemannTensor.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "../Core/Matrix.hpp"
5#include "../Core/Tensor.hpp"
6#include "../Core/Vector.hpp"
10
11namespace tensorium_RG {
24template <typename T> class RiemannTensor {
25 public:
29
30 static void print_componentwise(const Tensor4D &R, T threshold = 1e-12) {
31 constexpr size_t dim = 4;
32 std::cout << "\nRiemann tensor components (sliced by upper index λ):\n";
33
34 for (size_t lambda = 0; lambda < dim; ++lambda) {
35 std::cout << "R^" << lambda << "_{μνρ} :\n";
36 for (size_t mu = 0; mu < dim; ++mu) {
37 for (size_t nu = 0; nu < dim; ++nu) {
38 std::cout << " ";
39 for (size_t rho = 0; rho < dim; ++rho) {
40 T val = R({lambda, mu, nu, rho});
41 if (std::abs(val) < threshold)
42 val = 0.0;
43 std::cout << std::setw(10) << std::fixed << std::setprecision(6) << val
44 << " ";
45 }
46 std::cout << "\n";
47 }
48 }
49 std::cout << "\n";
50 }
51 }
52
53 static void print(const Tensor4D &R, const std::string &name = "Riemann") {
54 constexpr size_t dim = 4;
55 std::cout << name << " tensor components:\n";
56 for (size_t rho = 0; rho < dim; ++rho)
57 for (size_t sigma = 0; sigma < dim; ++sigma)
58 for (size_t mu = 0; mu < dim; ++mu)
59 for (size_t nu = 0; nu < dim; ++nu) {
60 const T val = R({rho, sigma, mu, nu});
61 if (std::abs(val) > T(1e-12)) {
62 std::cout << name << "[" << rho << "][" << sigma << "][" << mu << "]["
63 << nu << "] = " << val << "\n";
64 }
65 }
66 }
90 static Tensor4D compute(const VectorT &X, T h, const Metric<T> &metric) {
91 constexpr size_t dim = 4;
92 Tensor2D g({dim, dim});
93 metric(X, g);
94 Tensor2D g_inv = tensorium_RG::inv_mat_tensor_local(g);
95
96 std::array<ChristoffelSym<T>, 4> gamma_ph{ChristoffelSym<T>(h), ChristoffelSym<T>(h),
98 std::array<ChristoffelSym<T>, 4> gamma_mh = gamma_ph;
99 std::array<ChristoffelSym<T>, 4> gamma_ph2 = gamma_ph;
100 std::array<ChristoffelSym<T>, 4> gamma_mh2 = gamma_ph;
101
102 for (size_t mu = 0; mu < dim; ++mu) {
103 VectorT Xh = X, Xl = X, Xh2 = X, Xl2 = X;
104 Xh(mu) += h;
105 Xl(mu) -= h;
106 Xh2(mu) += h * 0.5;
107 Xl2(mu) -= h * 0.5;
108
109 Tensor2D gh({dim, dim}), gl({dim, dim});
110 Tensor2D gh2({dim, dim}), gl2({dim, dim});
111
112 metric(Xh, gh);
113 metric(Xl, gl);
114 metric(Xh2, gh2);
115 metric(Xl2, gl2);
116
117 auto inv_gh = tensorium_RG::inv_mat_tensor_local(gh);
118 auto inv_gl = tensorium_RG::inv_mat_tensor_local(gl);
119 auto inv_gh2 = tensorium_RG::inv_mat_tensor_local(gh2);
120 auto inv_gl2 = tensorium_RG::inv_mat_tensor_local(gl2);
121
122 gamma_ph[mu] = compute_christoffel(Xh, h, gh, inv_gh, metric);
123 gamma_mh[mu] = compute_christoffel(Xl, h, gl, inv_gl, metric);
124 gamma_ph2[mu] = compute_christoffel(Xh2, h, gh2, inv_gh2, metric);
125 gamma_mh2[mu] = compute_christoffel(Xl2, h, gl2, inv_gl2, metric);
126 }
127
128 Tensor4D R({dim, dim, dim, dim});
129 R.fill(T(0));
130
131 for (size_t rho = 0; rho < dim; ++rho)
132 for (size_t sigma = 0; sigma < dim; ++sigma)
133 for (size_t mu = 0; mu < dim; ++mu)
134 for (size_t nu = 0; nu < dim; ++nu) {
136 gamma_ph[mu](rho, nu, sigma, 0), gamma_mh[mu](rho, nu, sigma, 0),
137 gamma_ph2[mu](rho, nu, sigma, 0), gamma_mh2[mu](rho, nu, sigma, 0), h);
138
140 gamma_ph[nu](rho, mu, sigma, 0), gamma_mh[nu](rho, mu, sigma, 0),
141 gamma_ph2[nu](rho, mu, sigma, 0), gamma_mh2[nu](rho, mu, sigma, 0), h);
142
143 T sum = dGamma_mu - dGamma_nu;
144
145 for (size_t lambda = 0; lambda < dim; ++lambda) {
146 sum += gamma_ph[mu](rho, mu, lambda, 0) *
147 gamma_ph[nu](lambda, nu, sigma, 0);
148 sum -= gamma_ph[nu](rho, nu, lambda, 0) *
149 gamma_ph[mu](lambda, mu, sigma, 0);
150 }
151
152 R({rho, sigma, mu, nu}) = sum;
153 }
154
155 return R;
156 }
157};
158
159} // namespace tensorium_RG
Numerical differentiation operators using SIMD.
static FrontendPluginRegistry::Add< TensoriumPluginAction > X("tensorium-dispatch", "Handle #pragma tensorium directives")
Register the plugin under the name "tensorium-dispatch".
Multi-dimensional tensor class with fixed rank and SIMD support.
Definition Tensor.hpp:25
void fill(K value)
Fill tensor with a constant value.
Definition Tensor.hpp:125
Stores and computes Christoffel symbols .
Definition ChristoffelSymbol.hpp:40
A callable 4D metric class for general relativity (Minkowski, Schwarzschild, Kerr,...
Definition Metric.hpp:27
Computes the 4D Riemann curvature tensor .
Definition RiemannTensor.hpp:24
static Tensor4D compute(const VectorT &X, T h, const Metric< T > &metric)
Computes the 4D Riemann curvature tensor .
Definition RiemannTensor.hpp:90
static void print_componentwise(const Tensor4D &R, T threshold=1e-12)
Definition RiemannTensor.hpp:30
static void print(const Tensor4D &R, const std::string &name="Riemann")
Definition RiemannTensor.hpp:53
Definition BSSNAtildeTensor.hpp:10
T richardson_derivative(const T &plus_h, const T &minus_h, const T &plus_half_h, const T &minus_half_h, double h)
Richardson extrapolation for scalar values.
Definition Derivate.hpp:502