diff --git a/crates/applications/buffer_proto5/src/main.rs b/crates/applications/buffer_proto5/src/main.rs index d8782b8..436ff97 100644 --- a/crates/applications/buffer_proto5/src/main.rs +++ b/crates/applications/buffer_proto5/src/main.rs @@ -22,7 +22,7 @@ use coremem::real::{R32, Real as _}; use coremem::render::CsvRenderer; use coremem::sim::spirv::{SpirvSim, WgpuBackend}; use coremem::sim::units::{Seconds, Time as _}; -use coremem::stim::{CurlVectorField, Exp1, Gated, ModulatedVectorField, Sinusoid, StimExt as _}; +use coremem::stim::{CurlVectorField, Exp, Gated, ModulatedVectorField, Sinusoid, StimExt as _}; use log::{error, info, warn}; use serde::{Deserialize, Serialize}; @@ -456,7 +456,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results { }; let add_drive_exp_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| { - let wave = Exp1::new_at(amp, start, 0.5*duration); + let wave = Exp::new_at(amp, start, 0.5*duration); driver.add_stimulus(ModulatedVectorField::new( CurlVectorField::new(region.clone()), wave, diff --git a/crates/applications/multi_core_inverter/src/main.rs b/crates/applications/multi_core_inverter/src/main.rs index ed4eae8..718039f 100644 --- a/crates/applications/multi_core_inverter/src/main.rs +++ b/crates/applications/multi_core_inverter/src/main.rs @@ -43,7 +43,7 @@ use coremem::meas; use coremem::real::{self, Real as _}; use coremem::sim::spirv::{self, SpirvSim}; use coremem::sim::units::Seconds; -use coremem::stim::{CurlVectorField, Exp, Gated, ModulatedVectorField, Shifted, StimExt as _}; +use coremem::stim::{CurlVectorField, Exp, Gated, ModulatedVectorField, Scaled, Shifted, StimExt as _}; use coremem::Driver; type R = real::R32; @@ -76,7 +76,7 @@ enum ClockState { ReleaseLow, Float, } -type ClockSegment = Shifted>>; +type ClockSegment = Shifted>>; impl ClockState { fn time_stimulus(&self, params: &Params, cycle: u32) diff --git a/crates/coremem/src/stim.rs b/crates/coremem/src/stim.rs index 1c38050..47cdeb7 100644 --- a/crates/coremem/src/stim.rs +++ b/crates/coremem/src/stim.rs @@ -475,50 +475,27 @@ impl TimeVarying for Sinusoid { } } -/// E field with magnitude that decays exponentially over t. +/// E field that decays exponentially over t. #[derive(Clone)] -pub struct Exp { - amp: A, +pub struct Exp { tau: f32, } -pub type Exp1 = Exp; -impl Exp { - pub fn new(amp: A, half_life: f32) -> Self { +impl Exp { + pub fn new(half_life: f32) -> Self { let tau = std::f32::consts::LN_2/half_life; - Self { amp, tau } + Self { tau } } - pub fn new_at(amp: A, start: f32, half_life: f32) -> Shifted> { - Shifted::new( - Gated::new( - Self::new(amp, half_life), - 0.0, - half_life*100.0 - ), - start, - ) + pub fn new_at(amp: f32, start: f32, half_life: f32) -> Shifted>> { + Self::new(half_life).scaled(amp).gated(0.0, half_life*100.0).shifted(start) } } -impl TimeVarying for Exp { +impl TimeVarying for Exp { fn at(&self, t_sec: f32) -> FieldMags { - self.amp.at(t_sec) * (t_sec * -self.tau).exp() - } -} - -impl Stimulus for Exp { - fn at(&self, t_sec: f32, feat_size: f32, loc: Index) -> Fields { - let scale = (t_sec * -self.tau).exp(); - let inner = self.amp.at(t_sec, feat_size, loc); - Fields { - e: inner.e * scale, - h: inner.h * scale, - } - } - fn eval_into(&self, t_sec: f32, feat_size: f32, scale: f32, mut into: OffsetDimSlice<&mut [Fields]>) { - let my_scale = (t_sec * -self.tau).exp(); - self.amp.eval_into(t_sec, feat_size, scale * my_scale, into.as_mut()); + let a = (t_sec * -self.tau).exp(); + FieldMags::new_eh(a, a) } } @@ -616,6 +593,7 @@ impl Stimulus for Shifted { } +#[derive(Clone)] pub struct Scaled(A, B); impl Scaled {