Tensorium
Loading...
Searching...
No Matches
BSSNRicciTildeTensor.hpp
Go to the documentation of this file.
1
6#pragma once
7
10#include "../../Core/Vector.hpp"
11#include "../Metric.hpp"
12#include "BSSNAutoDiff.hpp"
13#include "BSSNChristoffel.hpp"
15#include "BSSNChiContext.hpp"
16#include "BSSNDerivatives.hpp"
17
18namespace tensorium_RG {
36template <typename T> class RicciTildeTensor {
37 public:
48 compute_laplacian_term(const tensorium::Vector<T> &X, T dx, T dy, T dz, const Metric<T> &metric,
49 const tensorium::Tensor<T, 2> &gamma_tilde_inv) {
50 using namespace tensorium;
51
52 Tensor<T, 2> result({3, 3});
53
54 for (size_t i = 0; i < 3; ++i) {
55 for (size_t j = 0; j < 3; ++j) {
56
57 auto tensor_func = [&](const Vector<T> &Xs, Tensor<T, 2> &out_tensor) {
58 T a;
59 Vector<T> b(3);
60 Tensor<T, 2> g_phys({3, 3});
61 metric.BSSN(Xs, a, b, g_phys);
62 T chi = compute_conformal_factor(metric, g_phys);
63 Tensor<T, 2> gtilde = compute_conformal_metric(metric, g_phys, chi);
64 out_tensor(i, j) = gtilde(i, j);
65 };
66
67 Tensor<T, 4> d2_full({1, 1, 3, 3});
69
70 Tensor<T, 2> d2gamma({3, 3});
71 for (int k = 0; k < 3; ++k)
72 for (int l = 0; l < 3; ++l)
73 d2gamma(k, l) = d2_full(0, 0, k, l);
74
75 T laplace = 0.0;
76 for (int k = 0; k < 3; ++k)
77 for (int l = 0; l < 3; ++l)
78 laplace += gamma_tilde_inv(k, l) * d2gamma(k, l);
79
80 result(i, j) = -0.5 * laplace;
81 }
82 }
83
84 for (size_t i = 0; i < 3; ++i) {
85 for (size_t j = i + 1; j < 3; ++j) {
86 T avg = 0.5 * (result(i, j) + result(j, i));
87 result(i, j) = result(j, i) = avg;
88 }
89 }
90
91 return result;
92 }
93
105 const tensorium::Vector<T> &tilde_Gamma,
107 using namespace tensorium;
108
109 Tensor<T, 2> dGamma({3, 3});
110 for (int k = 0; k < 3; ++k) {
111 auto scalar_func = [&](const Vector<T> &Xs) -> T { return tilde_Gamma(k); };
113 for (int j = 0; j < 3; ++j) {
114 dGamma(j, k) = grad_k(j);
115 }
116 }
117
118 Tensor<T, 2> R2({3, 3});
119 for (int i = 0; i < 3; ++i) {
120 for (int j = 0; j < 3; ++j) {
121 T sum = 0;
122 for (int k = 0; k < 3; ++k) {
123 sum += tilde_gamma_contract(k, i) * dGamma(j, k) +
125 }
126 R2(i, j) = static_cast<T>(0.5) * sum;
127 }
128 }
129
130 return R2;
131 }
132
146 const tensorium::Tensor<T, 3> &christoffel_tilde,
147 const tensorium::Tensor<T, 2> &gamma_tilde) {
148 using namespace tensorium;
149 Tensor<T, 2> R3({3, 3});
150
151 for (size_t i = 0; i < 3; ++i) {
152 for (size_t j = 0; j < 3; ++j) {
153 T sum_ij = 0;
154 for (size_t k = 0; k < 3; ++k) {
155 T G_ijk = 0, G_jik = 0;
156 for (size_t m = 0; m < 3; ++m) {
157 G_ijk += gamma_tilde(i, m) * christoffel_tilde(m, j, k);
158 G_jik += gamma_tilde(j, m) * christoffel_tilde(m, i, k);
159 }
160 sum_ij += tilde_Gamma(k) * (G_ijk + G_jik);
161 }
162 R3(i, j) = T(0.5) * sum_ij;
163 }
164 }
165
166 return R3;
167 }
168
181 const tensorium::Tensor<T, 3> &christoffel_tilde) {
182 using namespace tensorium;
183 Tensor<T, 2> R4({3, 3});
184
185 for (size_t i = 0; i < 3; ++i) {
186 for (size_t j = 0; j < 3; ++j) {
187 T sum = 0;
188 for (size_t ell = 0; ell < 3; ++ell) {
189 for (size_t m = 0; m < 3; ++m) {
190 T term1 = 0;
191 for (size_t k = 0; k < 3; ++k) {
192 term1 += christoffel_tilde(k, ell, i) * christoffel_tilde(j, k, m);
193 }
194 for (size_t k = 0; k < 3; ++k) {
195 term1 += christoffel_tilde(k, ell, j) * christoffel_tilde(i, k, m);
196 }
197 T term2 = 0;
198 for (size_t k = 0; k < 3; ++k) {
199 term2 += christoffel_tilde(k, i, m) * christoffel_tilde(j, k, ell);
200 }
201 sum += gamma_tilde_inv(ell, m) * (term1 + term2);
202 }
203 }
204 R4(i, j) = sum;
205 }
206 }
207 return R4;
208 }
223 const ChiContext<T> &chi_context, const tensorium::Tensor<T, 2> &gamma_tilde_inv,
224 const tensorium::Vector<T> &tilde_Gamma, const tensorium::Tensor<T, 3> &christoffel_tilde,
225 const tensorium::Tensor<T, 2> &gamma_tilde) {
226 using namespace tensorium;
227 const auto& X = chi_context.X;
228 const T dx = chi_context.dx;
229 const T dy = chi_context.dy;
230 const T dz = chi_context.dz;
231 const auto& metric = chi_context.metric;
232 auto R1 = compute_laplacian_term(X, dx, dy, dz, metric, gamma_tilde_inv);
233 auto R2 = compute_dGamma_term(X, dx, dy, dz, tilde_Gamma, gamma_tilde);
234 auto R3 = compute_GammaGamma_term(tilde_Gamma, christoffel_tilde, gamma_tilde);
235 auto R4 = compute_GammaProduct_term(gamma_tilde_inv, christoffel_tilde);
237 for (size_t i = 0; i < 3; ++i) {
238 for (size_t j = 0; j < 3; ++j) {
239 Ricci(i, j) = R1(i, j) + R2(i, j) + R3(i, j) + R4(i, j);
240 }
241 }
242
243 return Ricci;
244 }
245};
246
247} // namespace tensorium_RG
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
A callable 4D metric class for general relativity (Minkowski, Schwarzschild, Kerr,...
Definition Metric.hpp:27
void BSSN(const tensorium::Vector< T > &X, T &alpha, tensorium::Vector< T > &beta, tensorium::Tensor< T, 2 > &gamma) const
Extract BSSN 3+1 variables (lapse, shift, and spatial metric)
Definition Metric.hpp:83
Provides methods to compute the conformal Ricci tensor in the BSSN formulation.
Definition BSSNRicciTildeTensor.hpp:36
static tensorium::Tensor< T, 2 > compute_dGamma_term(const tensorium::Vector< T > &X, T dx, T dy, T dz, const tensorium::Vector< T > &tilde_Gamma, const tensorium::Tensor< T, 2 > &tilde_gamma_contract)
Compute .
Definition BSSNRicciTildeTensor.hpp:104
static tensorium::Tensor< T, 2 > compute_Ricci_Tilde_tensor(const ChiContext< T > &chi_context, const tensorium::Tensor< T, 2 > &gamma_tilde_inv, const tensorium::Vector< T > &tilde_Gamma, const tensorium::Tensor< T, 3 > &christoffel_tilde, const tensorium::Tensor< T, 2 > &gamma_tilde)
Combine all four contributions to compute the conformal Ricci tensor:
Definition BSSNRicciTildeTensor.hpp:222
static tensorium::Tensor< T, 2 > compute_GammaProduct_term(const tensorium::Tensor< T, 2 > &gamma_tilde_inv, const tensorium::Tensor< T, 3 > &christoffel_tilde)
Compute the quadratic Christoffel term:
Definition BSSNRicciTildeTensor.hpp:180
static tensorium::Tensor< T, 2 > compute_laplacian_term(const tensorium::Vector< T > &X, T dx, T dy, T dz, const Metric< T > &metric, const tensorium::Tensor< T, 2 > &gamma_tilde_inv)
Compute using scalar autodiff.
Definition BSSNRicciTildeTensor.hpp:48
static tensorium::Tensor< T, 2 > compute_GammaGamma_term(const tensorium::Vector< T > &tilde_Gamma, const tensorium::Tensor< T, 3 > &christoffel_tilde, const tensorium::Tensor< T, 2 > &gamma_tilde)
Compute the nonlinear contracted term:
Definition BSSNRicciTildeTensor.hpp:145
Definition BSSNAtildeTensor.hpp:10
tensorium::Vector< T > partial_scalar(const tensorium::Vector< T > &X, T dx, T dy, T dz, ScalarFunc &&func)
Definition BSSNDerivatives.hpp:119
Definition Derivate.hpp:24
Definition BSSNChiContext.hpp:10