deep_causality_physics/mhd/
wrappers.rs

1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6use crate::mhd::quantities::{
7    AlfvenSpeed, DebyeLength, Diffusivity, LarmorRadius, MagneticPressure,
8};
9use crate::mhd::{grmhd, ideal, plasma, resistive};
10use crate::{Density, Mass, PhysicalField, Speed, Temperature};
11use deep_causality_core::{CausalityError, PropagatingEffect};
12use deep_causality_tensor::CausalTensor;
13use deep_causality_topology::Manifold;
14
15// ============================================================================
16// Ideal MHD Wrappers
17// ============================================================================
18
19pub fn alfven_speed(b: &PhysicalField, rho: &Density, mu0: f64) -> PropagatingEffect<AlfvenSpeed> {
20    match ideal::alfven_speed_kernel(b, rho, mu0) {
21        Ok(v) => PropagatingEffect::pure(v),
22        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
23    }
24}
25
26pub fn magnetic_pressure(b: &PhysicalField, mu0: f64) -> PropagatingEffect<MagneticPressure> {
27    match ideal::magnetic_pressure_kernel(b, mu0) {
28        Ok(p) => PropagatingEffect::pure(p),
29        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
30    }
31}
32
33pub fn ideal_induction(
34    v: &Manifold<f64>,
35    b: &Manifold<f64>,
36) -> PropagatingEffect<CausalTensor<f64>> {
37    match ideal::ideal_induction_kernel(v, b) {
38        Ok(t) => PropagatingEffect::pure(t),
39        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
40    }
41}
42
43// ============================================================================
44// Resistive MHD Wrappers
45// ============================================================================
46
47pub fn resistive_diffusion(
48    b: &Manifold<f64>,
49    eta: Diffusivity,
50) -> PropagatingEffect<CausalTensor<f64>> {
51    match resistive::resistive_diffusion_kernel(b, eta) {
52        Ok(t) => PropagatingEffect::pure(t),
53        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
54    }
55}
56
57pub fn magnetic_reconnection_rate(va: AlfvenSpeed, s: f64) -> PropagatingEffect<Speed> {
58    match resistive::magnetic_reconnection_rate_kernel(va, s) {
59        Ok(v) => PropagatingEffect::pure(v),
60        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
61    }
62}
63
64// ============================================================================
65// GRMHD Wrappers
66// ============================================================================
67
68pub fn relativistic_current(
69    em: &CausalTensor<f64>,
70    metric: &CausalTensor<f64>,
71) -> PropagatingEffect<CausalTensor<f64>> {
72    match grmhd::relativistic_current_kernel(em, metric) {
73        Ok(j) => PropagatingEffect::pure(j),
74        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
75    }
76}
77
78pub fn energy_momentum_tensor_em(
79    em: &CausalTensor<f64>,
80    metric: &CausalTensor<f64>,
81) -> PropagatingEffect<CausalTensor<f64>> {
82    match grmhd::energy_momentum_tensor_em_kernel(em, metric) {
83        Ok(t) => PropagatingEffect::pure(t),
84        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
85    }
86}
87
88// ============================================================================
89// Plasma Wrappers
90// ============================================================================
91
92pub fn debye_length(t: Temperature, n: f64, eps0: f64, e: f64) -> PropagatingEffect<DebyeLength> {
93    match plasma::debye_length_kernel(t, n, eps0, e) {
94        Ok(l) => PropagatingEffect::pure(l),
95        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
96    }
97}
98
99pub fn larmor_radius(
100    m: Mass,
101    v: Speed,
102    q: f64,
103    b: &PhysicalField,
104) -> PropagatingEffect<LarmorRadius> {
105    match plasma::larmor_radius_kernel(m, v, q, b) {
106        Ok(r) => PropagatingEffect::pure(r),
107        Err(e) => PropagatingEffect::from_error(CausalityError::from(e)),
108    }
109}