Peano
Loading...
Searching...
No Matches
tensor-algebra.h
Go to the documentation of this file.
1#ifndef APPARENT_HORIZON_FINDER_TENSOR_ALGEBRA_H_
2#define APPARENT_HORIZON_FINDER_TENSOR_ALGEBRA_H_
3
4#include "ahf-data.h"
5
6// Some handful of 3x3 operations needed to compute the expansion Theta.
7// These work on the AHF Vector3 / Tensor3 types.
8// At the moment, we do not use make use of tarch::la::Matrix here.
9// Instead we use the same raw-loop form used by CCZ4Kernels.cpp.
10//
11// Index convention: spatial indices i, j, k, ... run over {0:x, 1:y, 2:z};
12// Tensor3 is indexed as [i][j].
13
14namespace exahype2::ccz4::ahf {
15
19inline double determinant(const Tensor3& m) {
20 return m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
21 - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
22 + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
23}
24
32inline Tensor3 inverse(const Tensor3& m) {
33 const double invDet = 1.0 / determinant(m);
34 Tensor3 result{};
35 result[0][0] = (m[1][1] * m[2][2] - m[1][2] * m[2][1]) * invDet;
36 result[0][1] = -(m[0][1] * m[2][2] - m[0][2] * m[2][1]) * invDet;
37 result[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * invDet;
38 result[1][0] = -(m[1][0] * m[2][2] - m[1][2] * m[2][0]) * invDet;
39 result[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * invDet;
40 result[1][2] = -(m[0][0] * m[1][2] - m[0][2] * m[1][0]) * invDet;
41 result[2][0] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) * invDet;
42 result[2][1] = -(m[0][0] * m[2][1] - m[0][1] * m[2][0]) * invDet;
43 result[2][2] = (m[0][0] * m[1][1] - m[0][1] * m[1][0]) * invDet;
44 return result;
45}
46
47} // namespace exahype2::ccz4::ahf
48
49#endif // APPARENT_HORIZON_FINDER_TENSOR_ALGEBRA_H_
Tensor3 inverse(const Tensor3 &m)
Inverse of a 3x3 matrix via the closed-form adjugate / determinant.
std::array< std::array< double, 3 >, 3 > Tensor3
Definition ahf-data.h:519
double determinant(const Tensor3 &m)
Determinant of a 3x3 matrix (general; used for the metric determinant).