rename GenericSim -> AbstractSim

This commit is contained in:
2022-07-28 22:32:29 -07:00
parent 3104c06d95
commit 4f2345f608
8 changed files with 65 additions and 65 deletions

View File

@@ -1,7 +1,7 @@
use crate::geom::{Meters, Region, Torus, WorldRegion};
use crate::real::{Real as _, ToFloat as _};
use crate::cross::vec::Vec3;
use crate::sim::GenericSim;
use crate::sim::AbstractSim;
use indexmap::IndexMap;
use serde::{Serialize, Deserialize};
@@ -34,7 +34,7 @@ pub fn eval_to_vec<S>(state: &S, meas: &[&dyn AbstractMeasurement<S>]) -> Vec<Ev
#[derive(Clone, Serialize, Deserialize)]
pub struct Time;
impl<S: GenericSim> AbstractMeasurement<S> for Time {
impl<S: AbstractSim> AbstractMeasurement<S> for Time {
fn eval(&self, state: &S) -> String {
format!("{:.3e}s (step {})", state.time(), state.step_no())
}
@@ -49,7 +49,7 @@ impl<S: GenericSim> AbstractMeasurement<S> for Time {
#[derive(Clone, Serialize, Deserialize)]
pub struct Meta;
impl<S: GenericSim> AbstractMeasurement<S> for 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())
}
@@ -106,14 +106,14 @@ impl Volume {
}
}
/// Returns the volume of the region, in units of um^3
fn data<S: GenericSim>(&self, state: &S) -> f32 {
fn data<S: AbstractSim>(&self, state: &S) -> f32 {
let feat_um = state.feature_size() as f64 * 1e6;
(state.volume_of_region(&*self.region) as f64 * feat_um * feat_um * feat_um) as f32
}
}
impl<S: GenericSim> AbstractMeasurement<S> for Volume {
impl<S: AbstractSim> AbstractMeasurement<S> for Volume {
fn eval(&self, state: &S) -> String {
format!("Vol({}): {:.2e} um^3",
self.name,
@@ -140,7 +140,7 @@ impl Current {
region: Box::new(r)
}
}
fn data<S: GenericSim>(&self, state: &S) -> (f32, Vec3<f32>) {
fn data<S: AbstractSim>(&self, state: &S) -> (f32, Vec3<f32>) {
let FieldSample(volume, current_mag, current_vec) = state.map_sum_over_enumerated(&*self.region, |coord: Meters, _cell| {
let current = state.current(coord);
FieldSample(1, current.mag().cast(), current.cast())
@@ -196,7 +196,7 @@ impl std::iter::Sum for FieldSamples<[FieldSample; 3]> {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for Current {
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}",
@@ -227,7 +227,7 @@ impl CurrentLoop {
region: r,
}
}
fn data<S: GenericSim>(&self, state: &S) -> f32 {
fn data<S: AbstractSim>(&self, state: &S) -> f32 {
let FieldSample(volume, directed_current, _current_vec) = state.map_sum_over_enumerated(&self.region, |coord: Meters, _cell| {
let normal = self.region.axis();
let to_coord = *coord - *self.region.center();
@@ -243,7 +243,7 @@ impl CurrentLoop {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for 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)
@@ -271,7 +271,7 @@ impl MagneticLoop {
region: r,
}
}
fn data<S: GenericSim>(&self, state: &S) -> (f32, f32, f32) {
fn data<S: AbstractSim>(&self, state: &S) -> (f32, f32, f32) {
let FieldSamples([
FieldSample(volume, directed_m, _m_vec),
FieldSample(_, directed_b, _b_vec),
@@ -311,7 +311,7 @@ impl MagneticLoop {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for 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!(
@@ -345,7 +345,7 @@ impl MagneticFlux {
region: Box::new(r)
}
}
fn data<S: GenericSim>(&self, state: &S) -> Vec3<f32> {
fn data<S: AbstractSim>(&self, state: &S) -> Vec3<f32> {
let FieldSample(volume, _directed_mag, mag_vec) = state.map_sum_over(&*self.region, |cell| {
let b = cell.b();
let mag = b.mag();
@@ -356,7 +356,7 @@ impl MagneticFlux {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for 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)
@@ -383,7 +383,7 @@ impl Magnetization {
region: Box::new(r)
}
}
fn data<S: GenericSim>(&self, state: &S) -> Vec3<f32> {
fn data<S: AbstractSim>(&self, state: &S) -> Vec3<f32> {
let FieldSample(volume, _directed_mag, mag_vec) = state.map_sum_over(&*self.region, |cell| {
let m = cell.m();
let mag = m.mag();
@@ -394,7 +394,7 @@ impl Magnetization {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for 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)
@@ -415,7 +415,7 @@ fn loc(v: Meters) -> String {
#[derive(Clone, Serialize, Deserialize)]
pub struct MagnetizationAt(pub Meters);
impl<S: GenericSim> AbstractMeasurement<S> for MagnetizationAt {
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)
@@ -432,7 +432,7 @@ impl<S: GenericSim> AbstractMeasurement<S> for MagnetizationAt {
#[derive(Clone, Serialize, Deserialize)]
pub struct MagneticFluxAt(pub Meters);
impl<S: GenericSim> AbstractMeasurement<S> for MagneticFluxAt {
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)
@@ -449,7 +449,7 @@ impl<S: GenericSim> AbstractMeasurement<S> for MagneticFluxAt {
#[derive(Clone, Serialize, Deserialize)]
pub struct MagneticStrengthAt(pub Meters);
impl<S: GenericSim> AbstractMeasurement<S> for MagneticStrengthAt {
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)
@@ -465,7 +465,7 @@ impl<S: GenericSim> AbstractMeasurement<S> for MagneticStrengthAt {
#[derive(Clone, Serialize, Deserialize)]
pub struct ElectricField(pub Meters);
impl<S: GenericSim> AbstractMeasurement<S> for ElectricField {
impl<S: AbstractSim> AbstractMeasurement<S> for ElectricField {
fn eval(&self, state: &S) -> String {
let e = state.sample(self.0).e();
format!("E{}: {:.2e}", loc(self.0), e)
@@ -494,7 +494,7 @@ impl Energy {
region: Box::new(region),
}
}
fn data<S: GenericSim>(&self, state: &S) -> f32 {
fn data<S: AbstractSim>(&self, state: &S) -> f32 {
// Potential energy stored in a E/M field:
// https://en.wikipedia.org/wiki/Magnetic_energy
// https://en.wikipedia.org/wiki/Electric_potential_energy#Energy_stored_in_an_electrostatic_field_distribution
@@ -511,7 +511,7 @@ impl Energy {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for Energy {
impl<S: AbstractSim> AbstractMeasurement<S> for Energy {
fn eval(&self, state: &S) -> String {
let e = self.data(state);
format!("U({}): {:.2e}", self.name, e)
@@ -540,7 +540,7 @@ impl Power {
region: Box::new(region),
}
}
fn data<S: GenericSim>(&self, state: &S) -> f32 {
fn data<S: AbstractSim>(&self, state: &S) -> f32 {
// Power is P = IV = A*J*V = L^2*J.(LE) = L^3 J.E
// where L is feature size.
#[allow(non_snake_case)]
@@ -552,7 +552,7 @@ impl Power {
}
}
impl<S: GenericSim> AbstractMeasurement<S> for Power {
impl<S: AbstractSim> AbstractMeasurement<S> for Power {
fn eval(&self, state: &S) -> String {
let power = self.data(state);
format!("P({}): {:.2e}", self.name, power)