diff --git a/crates/coremem/src/meas.rs b/crates/coremem/src/meas.rs index 744cc80..12ff4ff 100644 --- a/crates/coremem/src/meas.rs +++ b/crates/coremem/src/meas.rs @@ -5,7 +5,6 @@ use crate::sim::AbstractSim; use serde::{Serialize, Deserialize}; pub trait AbstractMeasurement: Send + Sync { - fn eval(&self, state: &S) -> String; fn key_value(&self, state: &S) -> Vec; } @@ -88,9 +87,6 @@ impl Measurement { } impl AbstractMeasurement for Measurement { - fn eval(&self, _state: &S) -> String { - format!("{}: {}", self.name, self.str_value()) - } fn key_value(&self, _state: &S) -> Vec { vec![self.clone()] } @@ -173,9 +169,6 @@ impl SiScale { pub struct Time; impl AbstractMeasurement for Time { - fn eval(&self, state: &S) -> String { - format!("{} (step {})", SiScale::format_short(state.time(), "s"), state.step_no()) - } fn key_value(&self, state: &S) -> Vec { vec![ Measurement::new_unitless("step", state.step_no()), @@ -188,9 +181,6 @@ impl AbstractMeasurement for Time { pub struct Meta; impl AbstractMeasurement for Meta { - fn eval(&self, state: &S) -> String { - format!("{}x{}x{} feat: {:.1e}m", state.width(), state.height(), state.depth(), state.feature_size()) - } fn key_value(&self, state: &S) -> Vec { vec![ Measurement::new_unitless("dim", state.size().0), @@ -221,12 +211,6 @@ impl Volume { } impl AbstractMeasurement for Volume { - fn eval(&self, state: &S) -> String { - format!("Vol({}): {:.2e} um^3", - self.name, - self.data(state), - ) - } fn key_value(&self, state: &S) -> Vec { vec![ Measurement::new(&format!("Vol({})", self.name), self.data(state), "um^3"), @@ -304,13 +288,6 @@ impl std::iter::Sum for FieldSamples<[FieldSample; 3]> { } impl AbstractMeasurement for Current { - fn eval(&self, state: &S) -> String { - let (mean_current_mag, mean_current_vec) = self.data(state); - format!("I/cell({}): {:.2e} {:.2e}", - self.name, - mean_current_mag, - mean_current_vec) - } fn key_value(&self, state: &S) -> Vec { let (mean_current_mag, mean_current_vec) = self.data(state); vec![ @@ -320,7 +297,7 @@ impl AbstractMeasurement for Current { "A", ), Measurement::new( - &format!("/cell({})", self.name), + &format!("I/cell({})", self.name), mean_current_vec, "A", ), @@ -359,10 +336,6 @@ impl CurrentLoop { } impl AbstractMeasurement for CurrentLoop { - fn eval(&self, state: &S) -> String { - let cross_sectional_current = self.data(state); - format!("I({}): {:.2e}", self.name, cross_sectional_current) - } fn key_value(&self, state: &S) -> Vec { let cross_sectional_current = self.data(state); vec![ @@ -431,15 +404,6 @@ impl MagneticLoop { } impl AbstractMeasurement for MagneticLoop { - fn eval(&self, state: &S) -> String { - let (mean_directed_m, mean_directed_b, mean_directed_h) = self.data(state); - format!( - "M({}): {:.2e}; B({}): {:.2e}; H({}): {:.2e}", - self.name, mean_directed_m, - self.name, mean_directed_b, - self.name, mean_directed_h, - ) - } fn key_value(&self, state: &S) -> Vec { let (mean_directed_m, mean_directed_b, mean_directed_h) = self.data(state); vec![ @@ -476,10 +440,6 @@ impl MagneticFlux { } impl AbstractMeasurement for MagneticFlux { - fn eval(&self, state: &S) -> String { - let mean_mag = self.data(state); - format!("Bavg({}): {:.2e}", self.name, mean_mag) - } fn key_value(&self, state: &S) -> Vec { let mean_mag = self.data(state); vec![ @@ -517,10 +477,6 @@ impl Magnetization { } impl AbstractMeasurement for Magnetization { - fn eval(&self, state: &S) -> String { - let mean_mag = self.data(state); - format!("Mavg({}): {:.2e}", self.name, mean_mag) - } fn key_value(&self, state: &S) -> Vec { let mean_mag = self.data(state); vec![ @@ -540,10 +496,6 @@ fn loc(v: Meters) -> String { pub struct MagnetizationAt(pub Meters); impl AbstractMeasurement for MagnetizationAt { - fn eval(&self, state: &S) -> String { - let m = state.sample(self.0).m(); - format!("M{}: {:.2e}", loc(self.0), m) - } fn key_value(&self, state: &S) -> Vec { let m = state.sample(self.0).m(); vec![ @@ -557,10 +509,6 @@ impl AbstractMeasurement for MagnetizationAt { pub struct MagneticFluxAt(pub Meters); impl AbstractMeasurement for MagneticFluxAt { - fn eval(&self, state: &S) -> String { - let b = state.sample(self.0).b(); - format!("B{}: {:.2e}", loc(self.0), b) - } fn key_value(&self, state: &S) -> Vec { let b = state.sample(self.0).b(); vec![ @@ -576,10 +524,6 @@ impl AbstractMeasurement for MagneticFluxAt { pub struct MagneticStrengthAt(pub Meters); impl AbstractMeasurement for MagneticStrengthAt { - fn eval(&self, state: &S) -> String { - let h = state.sample(self.0).h(); - format!("H{}: {:.2e}", loc(self.0), h) - } fn key_value(&self, state: &S) -> Vec { let h = state.sample(self.0).h(); vec![ @@ -594,10 +538,6 @@ impl AbstractMeasurement for MagneticStrengthAt { pub struct ElectricField(pub Meters); impl AbstractMeasurement for ElectricField { - fn eval(&self, state: &S) -> String { - let e = state.sample(self.0).e(); - format!("E{}: {}", loc(self.0), e) - } fn key_value(&self, state: &S) -> Vec { let e = state.sample(self.0).e(); vec![ @@ -642,10 +582,6 @@ impl Energy { } impl AbstractMeasurement for Energy { - fn eval(&self, state: &S) -> String { - let e = self.data(state); - format!("U({}): {}", self.name, SiScale::format_short(e, "J")) - } fn key_value(&self, state: &S) -> Vec { let e = self.data(state); vec![ @@ -685,10 +621,6 @@ impl Power { } impl AbstractMeasurement for Power { - fn eval(&self, state: &S) -> String { - let power = self.data(state); - format!("P({}): {}", self.name, SiScale::format_short(power, "W")) - } fn key_value(&self, state: &S) -> Vec { let power = self.data(state); vec![ diff --git a/crates/coremem/src/render.rs b/crates/coremem/src/render.rs index 49b9f2a..1cb689e 100644 --- a/crates/coremem/src/render.rs +++ b/crates/coremem/src/render.rs @@ -294,8 +294,8 @@ impl<'a, S: AbstractSim> RenderSteps<'a, S> { self.im = im; } fn render_measurements(&mut self) { - for (meas_no, m) in self.meas.iter().enumerate() { - let meas_string = m.eval(self.sim); + for (meas_no, m) in meas::eval_multiple_kv(self.sim, &self.meas).into_iter().enumerate() { + let meas_string = m.str_value(); for (i, c) in meas_string.chars().enumerate() { let glyph = BASIC_FONTS.get(c) .or_else(|| GREEK_FONTS.get(c)) @@ -425,6 +425,7 @@ impl Renderer for ColorTermRenderer { measurements: &[&dyn AbstractMeasurement], config: RenderConfig, ) { + let measurements = meas::eval_multiple_kv(state, measurements); let (max_w, mut max_h) = crossterm::terminal::size().unwrap(); max_h = max_h.saturating_sub(2 + measurements.len() as u16); let im = RenderSteps::render_configured(state, &[], z, (max_w as _, max_h as _), config); @@ -453,7 +454,7 @@ impl Renderer for ColorTermRenderer { for m in measurements { // Measurements can be slow to compute stdout.flush().unwrap(); - let meas_string = m.eval(state); + let meas_string = m.str_value(); stdout.queue(cursor::MoveDown(1)).unwrap(); stdout.queue(cursor::MoveToColumn(1)).unwrap(); stdout.queue(PrintStyledContent(style(meas_string))).unwrap();