Skip to main content

deep_causality_physics/em/
quantities.rs

1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6use deep_causality_core::CausalityError;
7use deep_causality_multivector::{CausalMultiVector, Metric};
8
9/// Electric Potential (Volts or J/C).
10#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
11pub struct ElectricPotential(f64);
12
13impl ElectricPotential {
14    pub fn new(val: f64) -> Result<Self, CausalityError> {
15        Ok(Self(val))
16    }
17    pub fn new_unchecked(val: f64) -> Self {
18        Self(val)
19    }
20    pub fn value(&self) -> f64 {
21        self.0
22    }
23}
24impl From<ElectricPotential> for f64 {
25    fn from(val: ElectricPotential) -> Self {
26        val.0
27    }
28}
29
30/// Magnetic Flux (Webers).
31#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
32pub struct MagneticFlux(f64);
33
34impl MagneticFlux {
35    pub fn new(val: f64) -> Result<Self, CausalityError> {
36        Ok(Self(val))
37    }
38    pub fn new_unchecked(val: f64) -> Self {
39        Self(val)
40    }
41    pub fn value(&self) -> f64 {
42        self.0
43    }
44}
45impl From<MagneticFlux> for f64 {
46    fn from(val: MagneticFlux) -> Self {
47        val.0
48    }
49}
50
51/// Wrapper for CausalMultiVector representing a physical field (E, B, etc.).
52/// Implements Default to return a zero vector.
53#[derive(Debug, Clone, PartialEq)]
54pub struct PhysicalField(pub CausalMultiVector<f64>);
55
56impl Default for PhysicalField {
57    fn default() -> Self {
58        // Default to a zero vector in 3D Euclidean space.
59        // Size of 3D Euclidean multivector is 2^3 = 8.
60        Self(CausalMultiVector::new(vec![0.0; 8], Metric::Euclidean(3)).unwrap())
61    }
62}
63
64impl PhysicalField {
65    pub fn new(val: CausalMultiVector<f64>) -> Self {
66        Self(val)
67    }
68    pub fn inner(&self) -> &CausalMultiVector<f64> {
69        &self.0
70    }
71    pub fn into_inner(self) -> CausalMultiVector<f64> {
72        self.0
73    }
74}