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