measurement: remove the eval method

This commit is contained in:
2022-07-31 23:26:53 -07:00
parent d5d8402c3d
commit 0e0945f744
2 changed files with 5 additions and 72 deletions

View File

@@ -5,7 +5,6 @@ use crate::sim::AbstractSim;
use serde::{Serialize, Deserialize};
pub trait AbstractMeasurement<S>: Send + Sync {
fn eval(&self, state: &S) -> String;
fn key_value(&self, state: &S) -> Vec<Measurement>;
}
@@ -88,9 +87,6 @@ impl Measurement {
}
impl<S> AbstractMeasurement<S> for Measurement {
fn eval(&self, _state: &S) -> String {
format!("{}: {}", self.name, self.str_value())
}
fn key_value(&self, _state: &S) -> Vec<Measurement> {
vec![self.clone()]
}
@@ -173,9 +169,6 @@ impl SiScale {
pub struct Time;
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
vec![
Measurement::new_unitless("step", state.step_no()),
@@ -188,9 +181,6 @@ impl<S: AbstractSim> AbstractMeasurement<S> for Time {
pub struct Meta;
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
vec![
Measurement::new_unitless("dim", state.size().0),
@@ -221,12 +211,6 @@ impl Volume {
}
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
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<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let (mean_current_mag, mean_current_vec) = self.data(state);
vec![
@@ -320,7 +297,7 @@ impl<S: AbstractSim> AbstractMeasurement<S> 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<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let cross_sectional_current = self.data(state);
vec![
@@ -431,15 +404,6 @@ impl MagneticLoop {
}
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let (mean_directed_m, mean_directed_b, mean_directed_h) = self.data(state);
vec![
@@ -476,10 +440,6 @@ impl MagneticFlux {
}
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let mean_mag = self.data(state);
vec![
@@ -517,10 +477,6 @@ impl Magnetization {
}
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let mean_mag = self.data(state);
vec![
@@ -540,10 +496,6 @@ fn loc(v: Meters) -> String {
pub struct MagnetizationAt(pub Meters);
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let m = state.sample(self.0).m();
vec![
@@ -557,10 +509,6 @@ impl<S: AbstractSim> AbstractMeasurement<S> for MagnetizationAt {
pub struct MagneticFluxAt(pub Meters);
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let b = state.sample(self.0).b();
vec![
@@ -576,10 +524,6 @@ impl<S: AbstractSim> AbstractMeasurement<S> for MagneticFluxAt {
pub struct MagneticStrengthAt(pub Meters);
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let h = state.sample(self.0).h();
vec![
@@ -594,10 +538,6 @@ impl<S: AbstractSim> AbstractMeasurement<S> for MagneticStrengthAt {
pub struct ElectricField(pub Meters);
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let e = state.sample(self.0).e();
vec![
@@ -642,10 +582,6 @@ impl Energy {
}
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let e = self.data(state);
vec![
@@ -685,10 +621,6 @@ impl Power {
}
impl<S: AbstractSim> AbstractMeasurement<S> 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<Measurement> {
let power = self.data(state);
vec![