sim: fold most accessors behind the meta
method
This commit is contained in:
@@ -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<R: Real, M: Material<R> + Send + Sync> SampleableSim for SimState<R, M> {
|
||||
}
|
||||
}
|
||||
|
||||
fn size(&self) -> Index {
|
||||
Index(Vec3u::new(
|
||||
fn meta(&self) -> SimMeta<f32> {
|
||||
let dim = Vec3u::new(
|
||||
self.cells.shape()[2] as _,
|
||||
self.cells.shape()[1] as _,
|
||||
self.cells.shape()[0] as _,
|
||||
))
|
||||
);
|
||||
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 feature_size(&self) -> f32 {
|
||||
self.feature_size.to_f32()
|
||||
}
|
||||
fn timestep(&self) -> f32 {
|
||||
self.timestep.to_f32()
|
||||
}
|
||||
fn step_no(&self) -> u64 {
|
||||
self.step_no
|
||||
}
|
||||
|
||||
fn to_static(&self) -> StaticSim {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@@ -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<f32>;
|
||||
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;
|
||||
}
|
||||
|
@@ -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<f32> {
|
||||
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());
|
||||
|
Reference in New Issue
Block a user