Add a dedicated function for metric inverse

This commit is contained in:
numzero 2024-04-28 23:27:27 +03:00
parent 641b13149f
commit 8e943df809

View File

@ -78,6 +78,7 @@ impl Metric for Coil {
mod riemann {
use glm::*;
use glm::ext::pow2;
use num_traits::identities::Zero;
pub struct Decomp2 {
@ -95,6 +96,11 @@ mod riemann {
transpose(&h.ortho) * diagonal(h.diag * h.diag) * h.ortho
}
fn invmetric(&self, pos: Vec2) -> Mat2 {
let h = self.halfmetric(pos);
transpose(&h.ortho) * diagonal(Vec2::from_s(1.0) / pow2(h.diag)) * h.ortho
}
fn dmetric(&self, pos: Vec2) -> Tens2 {
part_deriv(|p| self.metric(p), pos, 1.0e-3)
}
@ -141,7 +147,7 @@ mod riemann {
fn krist(space: &impl Metric, pos: Vec2) -> Tens2 {
// Γ^i_k_l = .5 * g^i^m * (g_m_k,l + g_m_l,k - g_k_l,m)
let g = inverse(&space.metric(pos)); // с верхними индексами
let g = &space.invmetric(pos); // с верхними индексами
let d = space.dmetric(pos);
let mut ret: Tens2 = [Mat2::zero(); 2];
// ret[i][l][k] = sum((m) => .5f * g[m][i] * (d[k][l][m] + d[l][k][m] - d[m][k][l]))