diff --git a/crates/coremem/src/driver.rs b/crates/coremem/src/driver.rs index 623ed58..a07f6d2 100644 --- a/crates/coremem/src/driver.rs +++ b/crates/coremem/src/driver.rs @@ -125,7 +125,7 @@ impl Driver { impl Driver { pub fn add_serializer_renderer(&mut self, out_base: &str, step_frequency: u64, frame_limit: Option) { let fmt_str = format!("{out_base}{{step_no}}.bc", out_base=out_base); - self.add_renderer(render::SerializerRenderer::new_static(&*fmt_str), &*fmt_str, step_frequency, frame_limit); + self.add_renderer(render::SerializerRenderer::new_generic(&*fmt_str), &*fmt_str, step_frequency, frame_limit); } } diff --git a/crates/coremem/src/render.rs b/crates/coremem/src/render.rs index 235a125..d9adee8 100644 --- a/crates/coremem/src/render.rs +++ b/crates/coremem/src/render.rs @@ -1,7 +1,7 @@ use crate::geom::Meters; use crate::real::ToFloat as _; use crate::cross::vec::{Vec2, Vec3}; -use crate::sim::{AbstractSim, Sample, StaticSim}; +use crate::sim::{AbstractSim, GenericSim, Sample}; use crate::meas::{self, AbstractMeasurement}; use crossterm::{cursor, QueueableCommand as _}; use crossterm::style::{style, Color, PrintStyledContent, Stylize as _}; @@ -562,7 +562,7 @@ impl Renderer for MultiRenderer { } #[derive(Serialize, Deserialize)] -pub struct SerializedFrame { +pub struct SerializedFrame { pub state: S, /// although not generally necessary to load the sim, saving the measurements is beneficial for /// post-processing. @@ -570,20 +570,20 @@ pub struct SerializedFrame { } impl SerializedFrame { - pub fn to_static(self) -> SerializedFrame { + pub fn to_generic(self) -> SerializedFrame> { SerializedFrame { - state: AbstractSim::to_static(&self.state), + state: AbstractSim::to_generic(&self.state), measurements: self.measurements, } } } /// this serializes the simulation state plus measurements to disk. -/// it can either convert the state to a generic, material-agnostic format (static) +/// it can either convert the state to a generic, material-agnostic format (generic) /// or dump it as-is. pub struct SerializerRenderer { fmt_str: String, - prefer_static: bool, + prefer_generic: bool, } impl SerializerRenderer { @@ -592,16 +592,16 @@ impl SerializerRenderer { pub fn new(fmt_str: &str) -> Self { Self { fmt_str: fmt_str.into(), - prefer_static: false, + prefer_generic: false, } } - /// Same as `new`, but cast to StaticSim before serializing. This yields a file that's easier - /// for post-processing, and may be smaller in size. - pub fn new_static(fmt_str: &str) -> Self { + /// Same as `new`, but cast to GenericSim before serializing. This yields a file that's easier + /// for post-processing. + pub fn new_generic(fmt_str: &str) -> Self { Self { fmt_str: fmt_str.into(), - prefer_static: true, + prefer_generic: true, } } } @@ -629,8 +629,8 @@ impl Renderer for SerializerRenderer { default_render_z_slice(self, state, z, measurements, config) } fn render(&self, state: &S, measurements: &[&dyn AbstractMeasurement], _config: RenderConfig) { - if self.prefer_static { - self.serialize(&state.to_static(), meas::eval_to_vec(state, measurements)); + if self.prefer_generic { + self.serialize(&state.to_generic(), meas::eval_to_vec(state, measurements)); } else { self.serialize(state, meas::eval_to_vec(state, measurements)); } diff --git a/crates/coremem/src/sim/mod.rs b/crates/coremem/src/sim/mod.rs index 14e5473..cb07546 100644 --- a/crates/coremem/src/sim/mod.rs +++ b/crates/coremem/src/sim/mod.rs @@ -110,7 +110,7 @@ impl CellStateWithM { // TODO: the Sync bound here could be removed with some refactoring pub trait AbstractSim: Sync { - type Real; + type Real: Real; type Material; fn meta(&self) -> SimMeta; fn step_no(&self) -> u64; diff --git a/crates/post/src/lib.rs b/crates/post/src/lib.rs index 0005663..77d41a4 100644 --- a/crates/post/src/lib.rs +++ b/crates/post/src/lib.rs @@ -1,7 +1,7 @@ //! Post-processing tools use coremem::meas; use coremem::render::{ColorTermRenderer, Renderer as _, RenderConfig, SerializedFrame}; -use coremem::sim::{AbstractSim, StaticSim}; +use coremem::sim::{AbstractSim, GenericSim}; use itertools::Itertools as _; use lru::LruCache; @@ -9,7 +9,6 @@ use rayon::{ThreadPool, ThreadPoolBuilder}; use std::collections::HashSet; use std::fs::{DirEntry, File, read_dir}; use std::io::BufReader; -use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::sync::mpsc::{self, Receiver, Sender}; @@ -33,25 +32,21 @@ pub type Result = std::result::Result; pub struct Frame { path: PathBuf, - data: SerializedFrame, + data: SerializedFrame>, } impl Frame { pub fn measurements(&self) -> &[meas::Evaluated] { &*self.data.measurements } + pub fn sim(&self) -> &GenericSim { + &self.data.state + } pub fn path(&self) -> &Path { &*self.path } } -impl Deref for Frame { - type Target = StaticSim; - fn deref(&self) -> &Self::Target { - &self.data.state - } -} - #[derive(Default)] pub struct Loader { dir: PathBuf, @@ -252,7 +247,7 @@ impl Viewer { let mut cache = LoaderCache::new(loader, 6, 6); let viewing = cache.load_first(); Self { - z: viewing.depth() / 2, + z: viewing.sim().depth() / 2, viewing, cache, renderer: Default::default(), @@ -262,7 +257,7 @@ impl Viewer { } pub fn navigate(&mut self, time_steps: isize, z_steps: i32) { let new_z = (self.z as i32).saturating_add(z_steps); - let new_z = new_z.max(0).min(self.viewing.depth() as i32 - 1) as u32; + let new_z = new_z.max(0).min(self.viewing.sim().depth() as i32 - 1) as u32; if time_steps == 0 && new_z == self.z && self.render_config == self.last_config { return; } @@ -274,7 +269,7 @@ impl Viewer { } pub fn render(&self) { self.renderer.render_z_slice( - &**self.viewing, + self.viewing.sim(), self.z, &*meas::as_dyn_measurements(self.viewing.measurements()), self.render_config,