rename CellStateWithM => Fields; parameterize Sample over R

This commit is contained in:
2022-07-29 14:55:12 -07:00
parent 7e452f508f
commit 895c87869b
3 changed files with 21 additions and 24 deletions

View File

@@ -4,7 +4,7 @@ use crate::geom::{Coord, Index, Meters};
use crate::cross::real::{R32, Real};
use crate::cross::step::SimMeta;
use crate::cross::vec::{Vec3, Vec3u};
use crate::sim::{AbstractSim, CellStateWithM, GenericSim, Sample, StaticSim};
use crate::sim::{AbstractSim, Fields, GenericSim, Sample, StaticSim};
use crate::stim::AbstractStimulus;
use mat::{GenericMaterial, Material, MaterialExt as _};
@@ -355,11 +355,7 @@ impl<R: Real, M: Material<R> + Send + Sync> AbstractSim for SimState<R, M> {
let idx = [pos_sim.z() as usize, pos_sim.y() as _, pos_sim.x() as _];
match self.cells.get(idx) {
Some(mat) => Sample {
state: CellStateWithM {
e: self.e[idx].cast(),
h: self.h[idx].cast(),
m: mat.m().cast(),
},
state: Fields::new(self.e[idx], self.h[idx], mat.m()).cast(),
conductivity: mat.conductivity().cast(),
},
None => Default::default(),
@@ -842,13 +838,8 @@ impl<R: Real> CellState<R> {
pub fn h(&self) -> Vec3<R> {
self.h
}
pub fn with_m(&self, m: Vec3<R>) -> CellStateWithM<R> {
CellStateWithM {
e: self.e,
h: self.h,
m,
}
pub fn with_m(&self, m: Vec3<R>) -> Fields<R> {
Fields::new(self.e, self.h, m)
}
}

View File

@@ -81,19 +81,29 @@ pub type GenericSim<R> = SpirvSim<R, FullyGenericMaterial<R>, CpuBackend>;
/// +------------+------------+
///
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct Sample {
state: CellStateWithM<f32>,
conductivity: Vec3<f32>,
pub struct Sample<R=f32> {
state: Fields<R>,
conductivity: Vec3<R>,
}
#[derive(Copy, Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct CellStateWithM<R> {
pub struct Fields<R> {
e: Vec3<R>,
h: Vec3<R>,
m: Vec3<R>,
}
impl<R: Real> CellStateWithM<R> {
impl<R: Real> Fields<R> {
pub fn new(e: Vec3<R>, h: Vec3<R>, m: Vec3<R>) -> Self {
Self { e, h, m }
}
pub fn cast<R2: Real>(&self) -> Fields<R2> {
Fields {
e: self.e.cast(),
h: self.h.cast(),
m: self.m.cast(),
}
}
pub fn e(&self) -> Vec3<R> {
self.e
}

View File

@@ -4,7 +4,7 @@ use log::{info, trace, warn};
use crate::geom::{Coord, Index, Meters};
use crate::real::Real;
use crate::sim::{AbstractSim, CellStateWithM, GenericSim, Sample, StaticSim};
use crate::sim::{AbstractSim, Fields, GenericSim, Sample, StaticSim};
use crate::stim::AbstractStimulus;
use crate::cross::vec::Vec3;
use coremem_cross::mat::{FullyGenericMaterial, Material};
@@ -116,11 +116,7 @@ where
let flat_idx = self.flat_index(pos_sim);
match flat_idx {
Some(idx) => Sample {
state: CellStateWithM {
h: self.h[idx].cast(),
e: self.e[idx].cast(),
m: self.m[idx].cast(),
},
state: Fields::new(self.e[idx], self.h[idx], self.m[idx]).cast(),
conductivity: self.mat[idx].conductivity().cast(),
},
None => Default::default(),