Tensorium
Loading...
Searching...
No Matches
RicciTensor.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"
9namespace tensorium_RG {
26template <typename T> class RicciTensor {
27 public:
41 const tensorium::Tensor<T, 2> &g_inv) {
42 constexpr size_t dim = 4;
43 tensorium::Tensor<T, 2> Ricci({dim, dim});
44 Ricci.fill(T(0));
45
46 for (size_t mu = 0; mu < dim; ++mu) {
47 for (size_t nu = 0; nu < dim; ++nu) {
48 for (size_t rho = 0; rho < dim; ++rho) {
49 for (size_t sigma = 0; sigma < dim; ++sigma) {
50 Ricci(mu, nu) += g_inv(rho, sigma) * Riemann(rho, sigma, mu, nu);
51 }
52 }
53 }
54 }
55
56 return Ricci;
57 }
67 static double compute_ricci_scalar(const Tensor2D &Ricci,
68 const tensorium::Tensor<T, 2> &g_inv) {
69 constexpr size_t dim = 4;
70 double R = 0.0;
71 for (size_t mu = 0; mu < dim; ++mu) {
72 for (size_t nu = 0; nu < dim; ++nu) {
73 R += g_inv(mu, nu) * Ricci(mu, nu);
74 }
75 }
76 return R;
77 }
84 static void print_componentwise(const Tensor2D &R, T threshold = 1e-12) {
85 constexpr size_t dim = 4;
86 std::cout << "\nRicci tensor components:\n";
87 for (size_t mu = 0; mu < dim; ++mu) {
88 for (size_t nu = 0; nu < dim; ++nu) {
89 T val = R(mu, nu);
90 if (std::abs(val) < threshold)
91 val = 0.0;
92 std::cout << std::setw(10) << std::fixed << std::setprecision(6) << val << " ";
93 }
94 std::cout << "\n";
95 }
96 }
97
104 static void print(const Tensor2D &R, const std::string &name = "Ricci") {
105 constexpr size_t dim = 4;
106 std::cout << name << " tensor components:\n";
107 for (size_t mu = 0; mu < dim; ++mu)
108 for (size_t nu = 0; nu < dim; ++nu) {
109 const T val = R(mu, nu);
110 if (std::abs(val) > T(1e-12)) {
111 std::cout << name << "[" << mu << "][" << nu << "] = " << val << "\n";
112 }
113 }
114 }
122 static void print(const Tensor2D &R, const tensorium::Tensor<T, 2> &g_inv,
123 const std::string &name = "Ricci") {
124 constexpr size_t dim = 4;
125 std::cout << name << " tensor components:\n";
126 for (size_t mu = 0; mu < dim; ++mu)
127 for (size_t nu = 0; nu < dim; ++nu) {
128 const T val = R(mu, nu);
129 if (std::abs(val) > T(1e-12)) {
130 std::cout << name << "[" << mu << "][" << nu << "] = " << val << "\n";
131 }
132 }
133 }
134
141 static void print_ricci_scalar(const Tensor2D &Ricci, const tensorium::Tensor<T, 2> &g_inv) {
142 constexpr size_t dim = 4;
143 double R = compute_ricci_scalar(Ricci, g_inv);
144 std::cout << "Ricci scalar R = " << R << "\n";
145 }
146};
147} // namespace tensorium_RG
Numerical differentiation operators using SIMD.
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
Computes the Ricci tensor and Ricci scalar from a 4D Riemann tensor.
Definition RicciTensor.hpp:26
static void print(const Tensor2D &R, const std::string &name="Ricci")
Prints only the non-zero components of the Ricci tensor.
Definition RicciTensor.hpp:104
static void print_ricci_scalar(const Tensor2D &Ricci, const tensorium::Tensor< T, 2 > &g_inv)
Computes and prints the Ricci scalar from the tensor and metric.
Definition RicciTensor.hpp:141
static void print(const Tensor2D &R, const tensorium::Tensor< T, 2 > &g_inv, const std::string &name="Ricci")
Prints non-zero components using both Ricci and inverse metric.
Definition RicciTensor.hpp:122
static void print_componentwise(const Tensor2D &R, T threshold=1e-12)
Prints the Ricci tensor components with optional zero threshold.
Definition RicciTensor.hpp:84
static double compute_ricci_scalar(const Tensor2D &Ricci, const tensorium::Tensor< T, 2 > &g_inv)
Computes the Ricci scalar curvature.
Definition RicciTensor.hpp:67
static tensorium::Tensor< T, 2 > contract_to_ricci(const Tensor4D &Riemann, const tensorium::Tensor< T, 2 > &g_inv)
Contracts a 4D Riemann tensor into the 2D Ricci tensor.
Definition RicciTensor.hpp:40
Definition BSSNAtildeTensor.hpp:10