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::geom::{Coord, Index, Meters};
|
||||||
use crate::cross::real::{R32, Real};
|
use crate::cross::real::{R32, Real};
|
||||||
|
use crate::cross::step::SimMeta;
|
||||||
use crate::cross::vec::{Vec3, Vec3u};
|
use crate::cross::vec::{Vec3, Vec3u};
|
||||||
use crate::sim::{CellStateWithM, GenericSim, MaterialSim, Sample, SampleableSim, StaticSim};
|
use crate::sim::{CellStateWithM, GenericSim, MaterialSim, Sample, SampleableSim, StaticSim};
|
||||||
use crate::stim::AbstractStimulus;
|
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 {
|
fn meta(&self) -> SimMeta<f32> {
|
||||||
Index(Vec3u::new(
|
let dim = Vec3u::new(
|
||||||
self.cells.shape()[2] as _,
|
self.cells.shape()[2] as _,
|
||||||
self.cells.shape()[1] as _,
|
self.cells.shape()[1] as _,
|
||||||
self.cells.shape()[0] 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 {
|
fn step_no(&self) -> u64 {
|
||||||
self.step_no
|
self.step_no
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_static(&self) -> StaticSim {
|
fn to_static(&self) -> StaticSim {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
use crate::geom::{Coord, Cube, Index, InvertedRegion, Meters, Region};
|
use crate::geom::{Coord, Cube, Index, InvertedRegion, Meters, Region};
|
||||||
use crate::cross::mat::Vacuum;
|
use crate::cross::mat::Vacuum;
|
||||||
use crate::cross::real::Real;
|
use crate::cross::real::Real;
|
||||||
|
use crate::cross::step::SimMeta;
|
||||||
use crate::cross::vec::{Vec3, Vec3u};
|
use crate::cross::vec::{Vec3, Vec3u};
|
||||||
use crate::stim::{AbstractStimulus, NoopStimulus};
|
use crate::stim::{AbstractStimulus, NoopStimulus};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
@@ -292,9 +293,18 @@ impl<'a> dyn SampleableSim + 'a {
|
|||||||
// TODO: the Send/Sync bounds here could be removed with some refactoring
|
// TODO: the Send/Sync bounds here could be removed with some refactoring
|
||||||
pub trait SampleableSim: Send + Sync {
|
pub trait SampleableSim: Send + Sync {
|
||||||
fn sample(&self, pos: Meters) -> Sample;
|
fn sample(&self, pos: Meters) -> Sample;
|
||||||
|
fn meta(&self) -> SimMeta<f32>;
|
||||||
|
fn step_no(&self) -> u64;
|
||||||
|
|
||||||
fn size(&self) -> Index;
|
/// Take a "snapshot" of the simulation, dropping all material-specific information.
|
||||||
fn feature_size(&self) -> f32;
|
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 {
|
fn feature_volume(&self) -> f32 {
|
||||||
let f = self.feature_size();
|
let f = self.feature_size();
|
||||||
f*f*f
|
f*f*f
|
||||||
@@ -303,9 +313,9 @@ pub trait SampleableSim: Send + Sync {
|
|||||||
let s = self.size().to_meters(self.feature_size());
|
let s = self.size().to_meters(self.feature_size());
|
||||||
s.x() * s.y() * s.z()
|
s.x() * s.y() * s.z()
|
||||||
}
|
}
|
||||||
fn timestep(&self) -> f32;
|
fn timestep(&self) -> f32 {
|
||||||
|
self.meta().time_step
|
||||||
fn step_no(&self) -> u64;
|
}
|
||||||
|
|
||||||
fn width(&self) -> u32 {
|
fn width(&self) -> u32 {
|
||||||
self.size().x()
|
self.size().x()
|
||||||
@@ -319,7 +329,4 @@ pub trait SampleableSim: Send + Sync {
|
|||||||
fn time(&self) -> f32 {
|
fn time(&self) -> f32 {
|
||||||
self.timestep() * self.step_no() as 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 {
|
fn meta(&self) -> SimMeta<f32> {
|
||||||
Index(self.meta.dim)
|
self.meta.cast()
|
||||||
}
|
|
||||||
fn feature_size(&self) -> f32 {
|
|
||||||
self.meta.feature_size.cast()
|
|
||||||
}
|
|
||||||
fn timestep(&self) -> f32 {
|
|
||||||
self.meta.time_step.cast()
|
|
||||||
}
|
}
|
||||||
fn step_no(&self) -> u64 {
|
fn step_no(&self) -> u64 {
|
||||||
self.step_no
|
self.step_no
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_static(&self) -> StaticSim {
|
fn to_static(&self) -> StaticSim {
|
||||||
let mut mat = Vec::new();
|
let mut mat = Vec::new();
|
||||||
mat.resize(self.e.len(), Default::default());
|
mat.resize(self.e.len(), Default::default());
|
||||||
|
Reference in New Issue
Block a user