rename GenericSim -> AbstractSim
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use coremem::{self, Driver, GenericSim};
|
||||
use coremem::{self, Driver, AbstractSim};
|
||||
use coremem::sim::legacy::SimState;
|
||||
use coremem::sim::spirv::{SpirvSim, WgpuBackend};
|
||||
use coremem::cross::mat::FullyGenericMaterial;
|
||||
@@ -18,7 +18,7 @@ fn measure<F: FnMut()>(name: &str, n_times: u32, mut f: F) -> f32 {
|
||||
avg
|
||||
}
|
||||
|
||||
fn measure_steps<S: GenericSim + Clone + Default + Send + Sync + 'static>(name: &str, steps_per_call: u32, mut d: Driver<S>) {
|
||||
fn measure_steps<S: AbstractSim + Clone + Default + Send + Sync + 'static>(name: &str, steps_per_call: u32, mut d: Driver<S>) {
|
||||
measure(name, 100/steps_per_call, || d.step_multiple(steps_per_call));
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ use crate::mat;
|
||||
use crate::meas::{self, AbstractMeasurement};
|
||||
use crate::real::Real;
|
||||
use crate::render::{self, MultiRenderer, Renderer};
|
||||
use crate::sim::GenericSim;
|
||||
use crate::sim::AbstractSim;
|
||||
use crate::sim::units::{Frame, Time};
|
||||
use crate::stim::AbstractStimulus;
|
||||
use crate::cross::vec::Vec3;
|
||||
@@ -36,7 +36,7 @@ pub struct Driver<S> {
|
||||
sim_end_time: Option<Frame>,
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Driver<S> {
|
||||
impl<S: AbstractSim> Driver<S> {
|
||||
pub fn new(state: S) -> Self {
|
||||
Self {
|
||||
state,
|
||||
@@ -74,7 +74,7 @@ impl<S: GenericSim> Driver<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Driver<S> {
|
||||
impl<S: AbstractSim> Driver<S> {
|
||||
pub fn fill_region<Reg: Region, M: Into<S::Material> + Clone>(&mut self, region: &Reg, mat: M) {
|
||||
self.state.fill_region(region, mat);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ impl<S: GenericSim> Driver<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Driver<S> {
|
||||
impl<S: AbstractSim> Driver<S> {
|
||||
pub fn size(&self) -> Index {
|
||||
self.state.size()
|
||||
}
|
||||
@@ -99,7 +99,7 @@ impl<S: GenericSim> Driver<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim + Send + Sync + 'static> Driver<S> {
|
||||
impl<S: AbstractSim + Send + Sync + 'static> Driver<S> {
|
||||
fn add_renderer<Rend: Renderer<S> + 'static>(
|
||||
&mut self, renderer: Rend, name: &str, step_frequency: u64, frame_limit: Option<u64>
|
||||
) {
|
||||
@@ -122,14 +122,14 @@ impl<S: GenericSim + Send + Sync + 'static> Driver<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim + Send + Sync + Serialize + 'static> Driver<S> {
|
||||
impl<S: AbstractSim + Send + Sync + Serialize + 'static> Driver<S> {
|
||||
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);
|
||||
self.add_renderer(render::SerializerRenderer::new_static(&*fmt_str), &*fmt_str, step_frequency, frame_limit);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim + Send + Sync + Serialize + for<'a> Deserialize<'a> + 'static> Driver<S> {
|
||||
impl<S: AbstractSim + Send + Sync + Serialize + for<'a> Deserialize<'a> + 'static> Driver<S> {
|
||||
/// instruct the driver to periodically save the simulation state to the provided path.
|
||||
/// also attempts to load an existing state file, returning `true` on success.
|
||||
pub fn add_state_file(&mut self, state_file: &str, snapshot_frequency: u64) -> bool {
|
||||
@@ -142,7 +142,7 @@ impl<S: GenericSim + Send + Sync + Serialize + for<'a> Deserialize<'a> + 'static
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim + Clone + Default + Send + Sync + 'static> Driver<S> {
|
||||
impl<S: AbstractSim + Clone + Default + Send + Sync + 'static> Driver<S> {
|
||||
fn render(&mut self) {
|
||||
let prep_start = Instant::now();
|
||||
let their_state = self.state.clone();
|
||||
@@ -253,7 +253,7 @@ impl<S: GenericSim + Clone + Default + Send + Sync + 'static> Driver<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Driver<S> {
|
||||
impl<S: AbstractSim> Driver<S> {
|
||||
pub fn add_classical_boundary<C: Coord>(&mut self, thickness: C)
|
||||
where S::Material: From<mat::IsomorphicConductor<f32>>
|
||||
{
|
||||
|
@@ -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)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use crate::geom::Meters;
|
||||
use crate::real::ToFloat as _;
|
||||
use crate::cross::vec::{Vec2, Vec3};
|
||||
use crate::sim::{GenericSim, Sample, StaticSim};
|
||||
use crate::sim::{AbstractSim, Sample, StaticSim};
|
||||
use crate::meas::{self, AbstractMeasurement};
|
||||
use crossterm::{cursor, QueueableCommand as _};
|
||||
use crossterm::style::{style, Color, PrintStyledContent, Stylize as _};
|
||||
@@ -55,7 +55,7 @@ fn scale_vector(x: Vec2<f32>, typical_mag: f32) -> Vec2<f32> {
|
||||
x.with_mag(new_mag)
|
||||
}
|
||||
|
||||
fn im_size<S: GenericSim>(state: &S, max_w: u32, max_h: u32) -> (u32, u32) {
|
||||
fn im_size<S: AbstractSim>(state: &S, max_w: u32, max_h: u32) -> (u32, u32) {
|
||||
let mut width = max_w;
|
||||
let mut height = width * state.height() / state.width();
|
||||
if height > max_h {
|
||||
@@ -134,7 +134,7 @@ struct RenderSteps<'a, S> {
|
||||
z: u32,
|
||||
}
|
||||
|
||||
impl<'a, S: GenericSim> RenderSteps<'a, S> {
|
||||
impl<'a, S: AbstractSim> RenderSteps<'a, S> {
|
||||
// TODO: this could probably be a single measurement, and we just let collections of
|
||||
// measurements also behave as measurements
|
||||
/// Render using default configuration constants
|
||||
@@ -354,12 +354,12 @@ pub trait Renderer<S>: Send + Sync {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_render_z_slice<S: GenericSim, R: Renderer<S>>(
|
||||
fn default_render_z_slice<S: AbstractSim, R: Renderer<S>>(
|
||||
me: &R, state: &S, z: u32, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig,
|
||||
) {
|
||||
me.render_with_image(state, &RenderSteps::render(state, measurements, z), measurements, config);
|
||||
}
|
||||
fn default_render<S: GenericSim, R: Renderer<S>>(
|
||||
fn default_render<S: AbstractSim, R: Renderer<S>>(
|
||||
me: &R, state: &S, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig
|
||||
) {
|
||||
me.render_z_slice(state, state.depth() / 2, measurements, config);
|
||||
@@ -388,7 +388,7 @@ fn default_render<S: GenericSim, R: Renderer<S>>(
|
||||
#[derive(Default)]
|
||||
pub struct ColorTermRenderer;
|
||||
|
||||
impl<S: GenericSim> Renderer<S> for ColorTermRenderer {
|
||||
impl<S: AbstractSim> Renderer<S> for ColorTermRenderer {
|
||||
fn render(&self, state: &S, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig) {
|
||||
default_render(self, state, measurements, config)
|
||||
}
|
||||
@@ -450,7 +450,7 @@ impl Y4MRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Renderer<S> for Y4MRenderer {
|
||||
impl<S: AbstractSim> Renderer<S> for Y4MRenderer {
|
||||
fn render_z_slice(&self, state: &S, z: u32, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig) {
|
||||
default_render_z_slice(self, state, z, measurements, config)
|
||||
}
|
||||
@@ -542,7 +542,7 @@ impl<S> MultiRenderer<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Renderer<S> for MultiRenderer<S> {
|
||||
impl<S: AbstractSim> Renderer<S> for MultiRenderer<S> {
|
||||
fn render_z_slice(&self, state: &S, z: u32, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig) {
|
||||
default_render_z_slice(self, state, z, measurements, config)
|
||||
}
|
||||
@@ -569,10 +569,10 @@ pub struct SerializedFrame<S=StaticSim> {
|
||||
pub measurements: Vec<meas::Evaluated>,
|
||||
}
|
||||
|
||||
impl<S: GenericSim> SerializedFrame<S> {
|
||||
impl<S: AbstractSim> SerializedFrame<S> {
|
||||
pub fn to_static(self) -> SerializedFrame<StaticSim> {
|
||||
SerializedFrame {
|
||||
state: GenericSim::to_static(&self.state),
|
||||
state: AbstractSim::to_static(&self.state),
|
||||
measurements: self.measurements,
|
||||
}
|
||||
}
|
||||
@@ -607,7 +607,7 @@ impl SerializerRenderer {
|
||||
}
|
||||
|
||||
impl SerializerRenderer {
|
||||
fn serialize<S: GenericSim + Serialize>(&self, state: &S, measurements: Vec<meas::Evaluated>) {
|
||||
fn serialize<S: AbstractSim + Serialize>(&self, state: &S, measurements: Vec<meas::Evaluated>) {
|
||||
let frame = SerializedFrame {
|
||||
state,
|
||||
measurements,
|
||||
@@ -618,13 +618,13 @@ impl SerializerRenderer {
|
||||
bincode::serialize_into(out, &frame).unwrap();
|
||||
}
|
||||
|
||||
pub fn try_load<S: GenericSim + for <'a> Deserialize<'a>>(&self) -> Option<SerializedFrame<S>> {
|
||||
pub fn try_load<S: AbstractSim + for <'a> Deserialize<'a>>(&self) -> Option<SerializedFrame<S>> {
|
||||
let mut reader = BufReader::new(File::open(&*self.fmt_str).ok()?);
|
||||
bincode::deserialize_from(&mut reader).ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim + Serialize> Renderer<S> for SerializerRenderer {
|
||||
impl<S: AbstractSim + Serialize> Renderer<S> for SerializerRenderer {
|
||||
fn render_z_slice(&self, state: &S, z: u32, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig) {
|
||||
default_render_z_slice(self, state, z, measurements, config)
|
||||
}
|
||||
@@ -667,7 +667,7 @@ impl CsvRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: GenericSim> Renderer<S> for CsvRenderer {
|
||||
impl<S: AbstractSim> Renderer<S> for CsvRenderer {
|
||||
fn render_z_slice(&self, state: &S, z: u32, measurements: &[&dyn AbstractMeasurement<S>], config: RenderConfig) {
|
||||
default_render_z_slice(self, state, z, measurements, config)
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ use crate::geom::{Coord, Index, Meters};
|
||||
use crate::cross::real::{R32, Real};
|
||||
use crate::cross::step::SimMeta;
|
||||
use crate::cross::vec::{Vec3, Vec3u};
|
||||
use crate::sim::{CellStateWithM, GenericSim, Sample, StaticSim};
|
||||
use crate::sim::{CellStateWithM, AbstractSim, Sample, StaticSim};
|
||||
use crate::stim::AbstractStimulus;
|
||||
|
||||
use mat::{GenericMaterial, Material, MaterialExt as _};
|
||||
@@ -314,7 +314,7 @@ impl<R: Real, M: Material<R> + Send + Sync> SimState<R, M> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Real, M: Material<R> + Send + Sync> GenericSim for SimState<R, M> {
|
||||
impl<R: Real, M: Material<R> + Send + Sync> AbstractSim for SimState<R, M> {
|
||||
type Material = M;
|
||||
fn meta(&self) -> SimMeta<f32> {
|
||||
let dim = Vec3u::new(
|
||||
@@ -1198,14 +1198,14 @@ mod test {
|
||||
assert_vec3_eq(actual_df_dt, df_dt(tm));
|
||||
}
|
||||
|
||||
fn energy<S: GenericSim>(s: &S) -> f32 {
|
||||
fn energy<S: AbstractSim>(s: &S) -> f32 {
|
||||
0.5 * s.feature_volume() * s.map_sum_enumerated(|_pos: Index, cell| {
|
||||
// println!("{}: {}", _pos, cell.e());
|
||||
cell.e().mag_sq().to_f64()
|
||||
}).to_f32()
|
||||
}
|
||||
|
||||
fn energy_now_and_then<S: GenericSim>(state: &mut S, frames: u32) -> (f32, f32) {
|
||||
fn energy_now_and_then<S: AbstractSim>(state: &mut S, frames: u32) -> (f32, f32) {
|
||||
let energy_0 = energy(state);
|
||||
for _f in 0..frames {
|
||||
// println!("e({}) = {}", _f, energy(state));
|
||||
@@ -1388,7 +1388,7 @@ mod test {
|
||||
}
|
||||
|
||||
/// Returns the energy ratio (Eend / Estart)
|
||||
fn pml_test_full_interior<F, S: GenericSim>(state: &mut S, f: F) -> f32
|
||||
fn pml_test_full_interior<F, S: AbstractSim>(state: &mut S, f: F) -> f32
|
||||
where F: Fn(Index) -> (Vec3<f32>, f32) + Sync // returns (E vector, cycles (like Hz))
|
||||
{
|
||||
let stim = PmlStim {
|
||||
@@ -1412,7 +1412,7 @@ mod test {
|
||||
where
|
||||
R: Region,
|
||||
F: Fn(Index) -> (Vec3<f32>, f32) + Sync,
|
||||
S: GenericSim,
|
||||
S: AbstractSim,
|
||||
{
|
||||
let feat = state.feature_size();
|
||||
pml_test_full_interior(state, |idx| {
|
||||
@@ -1424,7 +1424,7 @@ mod test {
|
||||
})
|
||||
}
|
||||
|
||||
fn pml_test_at<S: GenericSim>(state: &mut S, e: Vec3<f32>, center: Index) -> f32 {
|
||||
fn pml_test_at<S: AbstractSim>(state: &mut S, e: Vec3<f32>, center: Index) -> f32 {
|
||||
pml_test_full_interior(state, |idx| {
|
||||
if idx == center {
|
||||
(e, 1.0)
|
||||
@@ -1434,14 +1434,14 @@ mod test {
|
||||
})
|
||||
}
|
||||
|
||||
fn pml_test<S: GenericSim, R: RangeBounds<f32> + Debug>(state: &mut S, e: Vec3<f32>, en_range: R) {
|
||||
fn pml_test<S: AbstractSim, R: RangeBounds<f32> + Debug>(state: &mut S, e: Vec3<f32>, en_range: R) {
|
||||
let center = Index(state.size().0 / 2);
|
||||
let pml = pml_test_at(state, e, center);
|
||||
// PML should absorb all energy
|
||||
assert!(en_range.contains(&pml), "{} not in {:?}", pml, en_range);
|
||||
}
|
||||
|
||||
fn pml_test_against_baseline<P: GenericSim, B: GenericSim>(pml_state: &mut P, baseline_state: &mut B, e: Vec3<f32>) {
|
||||
fn pml_test_against_baseline<P: AbstractSim, B: AbstractSim>(pml_state: &mut P, baseline_state: &mut B, e: Vec3<f32>) {
|
||||
assert_eq!(pml_state.size(), baseline_state.size());
|
||||
let center = Index(pml_state.size().0 / 2);
|
||||
let en_pml = pml_test_at(pml_state, e, center);
|
||||
@@ -1646,7 +1646,7 @@ mod test {
|
||||
|
||||
// XXX the energies here are even worse than above.
|
||||
// just don't use our PML implementation: it's not great.
|
||||
// fn pml_test_uniform_over_region<R: Region, S: GenericSim>(state: &mut S, reg: R, e: Vec3<f32>, hz: f32) -> f32 {
|
||||
// fn pml_test_uniform_over_region<R: Region, S: AbstractSim>(state: &mut S, reg: R, e: Vec3<f32>, hz: f32) -> f32 {
|
||||
// pml_test_over_region(state, reg, |_idx| {
|
||||
// (e, hz)
|
||||
// })
|
||||
|
@@ -108,7 +108,7 @@ impl<R: Real> CellStateWithM<R> {
|
||||
}
|
||||
|
||||
// TODO: the Send/Sync bounds here could be removed with some refactoring
|
||||
pub trait GenericSim: Send + Sync {
|
||||
pub trait AbstractSim: Send + Sync {
|
||||
type Material;
|
||||
fn meta(&self) -> SimMeta<f32>;
|
||||
fn step_no(&self) -> u64;
|
||||
|
@@ -4,7 +4,7 @@ use log::{info, trace, warn};
|
||||
|
||||
use crate::geom::{Coord, Index, Meters};
|
||||
use crate::real::Real;
|
||||
use crate::sim::{CellStateWithM, GenericSim, Sample, StaticSim};
|
||||
use crate::sim::{CellStateWithM, AbstractSim, Sample, StaticSim};
|
||||
use crate::stim::AbstractStimulus;
|
||||
use crate::cross::vec::Vec3;
|
||||
use coremem_cross::mat::{FullyGenericMaterial, Material};
|
||||
@@ -69,7 +69,7 @@ impl<R: Clone, M: Clone, B: Default> Clone for SpirvSim<R, M, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R, M, B> GenericSim for SpirvSim<R, M, B>
|
||||
impl<R, M, B> AbstractSim for SpirvSim<R, M, B>
|
||||
where
|
||||
R: Real,
|
||||
M: Send + Sync + Material<R>,
|
||||
@@ -267,17 +267,17 @@ mod test {
|
||||
use crate::real::ToFloat as _;
|
||||
use crate::sim::legacy::{self, SimState};
|
||||
use crate::mat::{self, AnisomorphicConductor};
|
||||
fn mean_magnitude_e<S: GenericSim>(sim: &S) -> f32 {
|
||||
fn mean_magnitude_e<S: AbstractSim>(sim: &S) -> f32 {
|
||||
(sim.map_sum_enumerated(|_pos: Index, cell| {
|
||||
cell.e().mag().to_f64()
|
||||
})/((sim.width() * sim.height() * sim.depth()) as f64)).to_f32()
|
||||
}
|
||||
fn mean_magnitude_h<S: GenericSim>(sim: &S) -> f32 {
|
||||
fn mean_magnitude_h<S: AbstractSim>(sim: &S) -> f32 {
|
||||
(sim.map_sum_enumerated(|_pos: Index, cell| {
|
||||
cell.h().mag().to_f64()
|
||||
})/((sim.width() * sim.height() * sim.depth()) as f64)).to_f32()
|
||||
}
|
||||
fn mean_magnitude_m<S: GenericSim>(sim: &S) -> f32 {
|
||||
fn mean_magnitude_m<S: AbstractSim>(sim: &S) -> f32 {
|
||||
(sim.map_sum_enumerated(|_pos: Index, cell| {
|
||||
cell.m().mag().to_f64()
|
||||
})/((sim.width() * sim.height() * sim.depth()) as f64)).to_f32()
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//! Post-processing tools
|
||||
use coremem::meas;
|
||||
use coremem::render::{ColorTermRenderer, Renderer as _, RenderConfig, SerializedFrame};
|
||||
use coremem::sim::{GenericSim, StaticSim};
|
||||
use coremem::sim::{AbstractSim, StaticSim};
|
||||
|
||||
use itertools::Itertools as _;
|
||||
use lru::LruCache;
|
||||
|
Reference in New Issue
Block a user