Tensorium
Loading...
Searching...
No Matches
BSSNChristoffel.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cassert>
6#include <cstddef>
7#include <stdexcept>
8
9namespace tensorium_RG {
26template <typename T> class BSSNChristoffel {
27 public:
36 static void compute(const tensorium::Tensor<T, 2> &gamma_tilde,
37 const tensorium::Tensor<T, 3> &dgamma_tilde,
38 const tensorium::Tensor<T, 2> &gamma_tilde_inv,
39 tensorium::Tensor<T, 3> &Christoffel) {
40
41 if (gamma_tilde.shape() != std::array<size_t, 2>{3, 3})
42 throw std::invalid_argument("gamma_tilde must be 3x3");
43 if (gamma_tilde_inv.shape() != std::array<size_t, 2>{3, 3})
44 throw std::invalid_argument("gamma_tilde_inv must be 3x3");
45 if (dgamma_tilde.shape() != std::array<size_t, 3>{3, 3, 3})
46 throw std::invalid_argument("dgamma_tilde must be 3x3x3");
47
48 Christoffel.resize(3, 3, 3);
49
50 for (size_t k = 0; k < 3; ++k) {
51 for (size_t i = 0; i < 3; ++i) {
52 for (size_t j = 0; j < 3; ++j) {
53 T sum = 0.0;
54 for (size_t l = 0; l < 3; ++l) {
55 T term =
56 dgamma_tilde(i, l, j) + dgamma_tilde(j, l, i) - dgamma_tilde(l, i, j);
57 sum += gamma_tilde_inv(k, l) * term;
58 }
59 Christoffel(k, i, j) = T(0.5) * sum;
60 }
61 }
62 }
63 }
64
65 static void compute3D(const tensorium::Tensor<T, 5> &gamma_tilde, // [NX, NY, NZ, 3, 3]
66 const tensorium::Tensor<T, 6> &dgamma_tilde, // [NX, NY, NZ, 3, 3, 3]
67 const tensorium::Tensor<T, 5> &gamma_tilde_inv, // [NX, NY, NZ, 3, 3]
68 tensorium::Tensor<T, 6> &Christoffel // [NX, NY, NZ, 3, 3, 3] (output)
69 ) {
70 using namespace tensorium;
71
72 const size_t NX = gamma_tilde.dim(0);
73 const size_t NY = gamma_tilde.dim(1);
74 const size_t NZ = gamma_tilde.dim(2);
75
76 Christoffel.resize(NX, NY, NZ, 3, 3, 3);
77
78 for (size_t x = 0; x < NX; ++x) {
79 for (size_t y = 0; y < NY; ++y) {
80 for (size_t z = 0; z < NZ; ++z) {
81 Tensor<T, 2> gtilde(3, 3);
82 Tensor<T, 2> ginv(3, 3);
83 Tensor<T, 3> dg(3, 3, 3);
84 Tensor<T, 3> chr(3, 3, 3);
85
86 for (size_t i = 0; i < 3; ++i)
87 for (size_t j = 0; j < 3; ++j) {
88 gtilde(i, j) = gamma_tilde(x, y, z, i, j);
89 ginv(i, j) = gamma_tilde_inv(x, y, z, i, j);
90 for (size_t k = 0; k < 3; ++k)
91 dg(i, j, k) = dgamma_tilde(x, y, z, i, j, k);
92 }
93
95
96 for (size_t i = 0; i < 3; ++i)
97 for (size_t j = 0; j < 3; ++j)
98 for (size_t k = 0; k < 3; ++k)
99 Christoffel(x, y, z, i, j, k) = chr(i, j, k);
100 }
101 }
102 }
103 }
104};
125template <typename T>
127 size_t j, size_t k, T dx, T dy, T dz,
129
130 dgamma_out.resize(3, 3, 3);
131
132 auto get = [&](int ii, int jj, int kk, int a, int b) -> T {
133 return gamma_field(ii, jj, kk, a, b);
134 };
135
136 auto dim = gamma_field.shape();
137 size_t Nx = dim[0], Ny = dim[1], Nz = dim[2];
138
139 for (size_t a = 0; a < 3; ++a) {
140 for (size_t b = 0; b < 3; ++b) {
141 if (i >= 2 && i + 2 < Nx)
142 dgamma_out(0, a, b) = (-get(i + 2, j, k, a, b) + 8 * get(i + 1, j, k, a, b) -
143 8 * get(i - 1, j, k, a, b) + get(i - 2, j, k, a, b)) /
144 (12 * dx);
145 else if (i > 0 && i + 1 < Nx)
146 dgamma_out(0, a, b) = (get(i + 1, j, k, a, b) - get(i - 1, j, k, a, b)) / (2 * dx);
147 else
148 dgamma_out(0, a, b) = T(0);
149
150 if (j >= 2 && j + 2 < Ny)
151 dgamma_out(1, a, b) = (-get(i, j + 2, k, a, b) + 8 * get(i, j + 1, k, a, b) -
152 8 * get(i, j - 1, k, a, b) + get(i, j - 2, k, a, b)) /
153 (12 * dy);
154 else if (j > 0 && j + 1 < Ny)
155 dgamma_out(1, a, b) = (get(i, j + 1, k, a, b) - get(i, j - 1, k, a, b)) / (2 * dy);
156 else
157 dgamma_out(1, a, b) = T(0);
158
159 if (k >= 2 && k + 2 < Nz)
160 dgamma_out(2, a, b) = (-get(i, j, k + 2, a, b) + 8 * get(i, j, k + 1, a, b) -
161 8 * get(i, j, k - 1, a, b) + get(i, j, k - 2, a, b)) /
162 (12 * dz);
163 else if (k > 0 && k + 1 < Nz)
164 dgamma_out(2, a, b) = (get(i, j, k + 1, a, b) - get(i, j, k - 1, a, b)) / (2 * dz);
165 else
166 dgamma_out(2, a, b) = T(0);
167 }
168 }
169}
170} // namespace tensorium_RG
Multi-dimensional tensor class with fixed rank and SIMD support.
Definition Tensor.hpp:25
void resize(const std::array< size_t, Rank > &dims)
Resize 2D tensor.
Definition Tensor.hpp:70
std::array< size_t, Rank > shape() const
Definition Tensor.hpp:62
Compute the conformal Christoffel symbols .
Definition BSSNChristoffel.hpp:26
static void compute3D(const tensorium::Tensor< T, 5 > &gamma_tilde, const tensorium::Tensor< T, 6 > &dgamma_tilde, const tensorium::Tensor< T, 5 > &gamma_tilde_inv, tensorium::Tensor< T, 6 > &Christoffel)
Definition BSSNChristoffel.hpp:65
static void compute(const tensorium::Tensor< T, 2 > &gamma_tilde, const tensorium::Tensor< T, 3 > &dgamma_tilde, const tensorium::Tensor< T, 2 > &gamma_tilde_inv, tensorium::Tensor< T, 3 > &Christoffel)
Compute the conformal Christoffel symbols .
Definition BSSNChristoffel.hpp:36
Definition BSSNAtildeTensor.hpp:10
void compute_partial_derivatives_3D(const tensorium::Tensor< T, 5 > &gamma_field, size_t i, size_t j, size_t k, T dx, T dy, T dz, tensorium::Tensor< T, 3 > &dgamma_out)
Compute the 3D partial derivatives from a 5D field tensor.
Definition BSSNChristoffel.hpp:126
Definition Derivate.hpp:24