diff --git a/crates/applications/multi_core_inverter/src/main.rs b/crates/applications/multi_core_inverter/src/main.rs index 42c7990..19f1556 100644 --- a/crates/applications/multi_core_inverter/src/main.rs +++ b/crates/applications/multi_core_inverter/src/main.rs @@ -137,30 +137,30 @@ struct Params { clock_decay: f32, // exp decay half-life } -type HoldStim = CurlStimulus>; -type ReleaseStim = CurlStimulus>>>; +type HoldStim = Gated>; +type ReleaseStim = Shifted>>>; fn control_signal_hold(params: Params, region: Torus, cycle: u32, ty: DriveType) -> HoldStim { let area = region.cross_section(); let amp = ty.direction() as f32 * params.input_magnitude / area; - let start = params.clock_phase_duration * cycle as f32; - // simple square wave: - let wave = Gated::new(amp, start, start + params.clock_phase_duration); - CurlStimulus::new( + let base_stim = CurlStimulus::new( region.clone(), - wave.clone(), - ) + amp, + ); + // simple square wave: + let start = params.clock_phase_duration * cycle as f32; + Gated::new(base_stim, start, start + params.clock_phase_duration) } fn control_signal_release(params: Params, region: Torus, cycle: u32, ty: DriveType) -> ReleaseStim { let area = region.cross_section(); let amp = ty.direction() as f32 * params.input_magnitude / area; - let start = params.clock_phase_duration * cycle as f32; - // decaying exponential wave: - let wave = Exp::new_at(amp, start, params.clock_decay); - CurlStimulus::new( + let base_stim = CurlStimulus::new( region.clone(), - wave.clone(), - ) + amp, + ); + // decaying exponential wave: + let start = params.clock_phase_duration * cycle as f32; + Exp::new_at(base_stim, start, params.clock_decay) } @@ -393,7 +393,7 @@ fn main() { assert_eq!(num_cores, 5); let mut driver = driver.with_stimulus(stim); - let prefix = "out/applications/multi_core_inverter/13/"; + let prefix = "out/applications/multi_core_inverter/14/"; let _ = std::fs::create_dir_all(&prefix); driver.add_state_file(&*format!("{}state.bc", prefix), 6400); driver.add_serializer_renderer(&*format!("{}frame-", prefix), 3200, None); diff --git a/crates/coremem/src/stim.rs b/crates/coremem/src/stim.rs index 092c18b..0c402b0 100644 --- a/crates/coremem/src/stim.rs +++ b/crates/coremem/src/stim.rs @@ -346,6 +346,17 @@ impl TimeVarying3 for Exp3 { } } +impl AbstractStimulus for Exp { + fn at(&self, t_sec: f32, pos: Meters) -> Fields { + let scale = (t_sec * -self.tau).exp(); + let inner = self.amp.at(t_sec, pos); + Fields { + e: inner.e * scale, + h: inner.h * scale, + } + } +} + #[derive(Clone)] pub struct Gated { inner: T, @@ -380,6 +391,16 @@ impl TimeVarying3 for Gated { } } +impl AbstractStimulus for Gated { + fn at(&self, t_sec: f32, pos: Meters) -> Fields { + if (self.start..self.end).contains(&t_sec) { + self.inner.at(t_sec, pos) + } else { + Default::default() + } + } +} + #[derive(Clone)] pub struct Shifted { inner: T, @@ -405,6 +426,12 @@ impl TimeVarying3 for Shifted { } } +impl AbstractStimulus for Shifted { + fn at(&self, t_sec: f32, pos: Meters) -> Fields { + self.inner.at(t_sec - self.start_at, pos) + } +} + #[cfg(test)] mod test { use super::*;