diff --git a/crates/coremem/src/sim/legacy/mod.rs b/crates/coremem/src/sim/legacy/mod.rs index 0594faa..e1d98a6 100644 --- a/crates/coremem/src/sim/legacy/mod.rs +++ b/crates/coremem/src/sim/legacy/mod.rs @@ -2,6 +2,7 @@ pub mod mat; 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::{CellStateWithM, GenericSim, MaterialSim, Sample, SampleableSim, StaticSim}; use crate::stim::AbstractStimulus; @@ -343,22 +344,23 @@ impl + Send + Sync> SampleableSim for SimState { } } - fn size(&self) -> Index { - Index(Vec3u::new( + fn meta(&self) -> SimMeta { + let dim = Vec3u::new( self.cells.shape()[2] as _, self.cells.shape()[1] as _, self.cells.shape()[0] as _, - )) - } - fn feature_size(&self) -> f32 { - self.feature_size.to_f32() - } - fn timestep(&self) -> f32 { - self.timestep.to_f32() + ); + let feature_size = self.feature_size.to_f32(); + let inv_feature_size = 1.0/feature_size; + let time_step = self.timestep.to_f32(); + SimMeta { + dim, feature_size, inv_feature_size, time_step + } } fn step_no(&self) -> u64 { self.step_no } + fn to_static(&self) -> StaticSim { unimplemented!() } diff --git a/crates/coremem/src/sim/mod.rs b/crates/coremem/src/sim/mod.rs index 7526eb4..32d1762 100644 --- a/crates/coremem/src/sim/mod.rs +++ b/crates/coremem/src/sim/mod.rs @@ -1,6 +1,7 @@ use crate::geom::{Coord, Cube, Index, InvertedRegion, Meters, Region}; use crate::cross::mat::Vacuum; use crate::cross::real::Real; +use crate::cross::step::SimMeta; use crate::cross::vec::{Vec3, Vec3u}; use crate::stim::{AbstractStimulus, NoopStimulus}; use rayon::prelude::*; @@ -292,9 +293,18 @@ impl<'a> dyn SampleableSim + 'a { // TODO: the Send/Sync bounds here could be removed with some refactoring pub trait SampleableSim: Send + Sync { fn sample(&self, pos: Meters) -> Sample; + fn meta(&self) -> SimMeta; + fn step_no(&self) -> u64; - fn size(&self) -> Index; - fn feature_size(&self) -> f32; + /// Take a "snapshot" of the simulation, dropping all material-specific information. + fn to_static(&self) -> StaticSim; + + fn size(&self) -> Index { + Index(self.meta().dim) + } + fn feature_size(&self) -> f32 { + self.meta().feature_size + } fn feature_volume(&self) -> f32 { let f = self.feature_size(); f*f*f @@ -303,9 +313,9 @@ pub trait SampleableSim: Send + Sync { let s = self.size().to_meters(self.feature_size()); s.x() * s.y() * s.z() } - fn timestep(&self) -> f32; - - fn step_no(&self) -> u64; + fn timestep(&self) -> f32 { + self.meta().time_step + } fn width(&self) -> u32 { self.size().x() @@ -319,7 +329,4 @@ pub trait SampleableSim: Send + Sync { fn time(&self) -> f32 { self.timestep() * self.step_no() as f32 } - - /// Take a "snapshot" of the simulation, dropping all material-specific information. - fn to_static(&self) -> StaticSim; } diff --git a/crates/coremem/src/sim/spirv/mod.rs b/crates/coremem/src/sim/spirv/mod.rs index 56b292f..dbec0ad 100644 --- a/crates/coremem/src/sim/spirv/mod.rs +++ b/crates/coremem/src/sim/spirv/mod.rs @@ -113,18 +113,13 @@ where } } - fn size(&self) -> Index { - Index(self.meta.dim) - } - fn feature_size(&self) -> f32 { - self.meta.feature_size.cast() - } - fn timestep(&self) -> f32 { - self.meta.time_step.cast() + fn meta(&self) -> SimMeta { + self.meta.cast() } fn step_no(&self) -> u64 { self.step_no } + fn to_static(&self) -> StaticSim { let mut mat = Vec::new(); mat.resize(self.e.len(), Default::default());