app: multi_core_inverter: perf: move the stimulus Gating to outside the CurlStimulus
the region.contains() logic is much more expensive than the time bounds check. this gets an easy 50% perf boost to the ENTIRE simulation
This commit is contained in:
@@ -346,6 +346,17 @@ impl TimeVarying3 for Exp3 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AbstractStimulus> AbstractStimulus for Exp<A> {
|
||||
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<T> {
|
||||
inner: T,
|
||||
@@ -380,6 +391,16 @@ impl<T: TimeVarying3> TimeVarying3 for Gated<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AbstractStimulus> AbstractStimulus for Gated<T> {
|
||||
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<T> {
|
||||
inner: T,
|
||||
@@ -405,6 +426,12 @@ impl<T: TimeVarying3> TimeVarying3 for Shifted<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AbstractStimulus> AbstractStimulus for Shifted<T> {
|
||||
fn at(&self, t_sec: f32, pos: Meters) -> Fields {
|
||||
self.inner.at(t_sec - self.start_at, pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
Reference in New Issue
Block a user