Driver: simplify the StimuliAdapter
it was basically dead code.
This commit is contained in:
@@ -414,7 +414,6 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
|
|||||||
let mut driver = Driver::new(SpirvSim::<f32, Mat, WgpuBackend>::new(
|
let mut driver = Driver::new(SpirvSim::<f32, Mat, WgpuBackend>::new(
|
||||||
g.dim.to_index(p.geom.feat_size), p.geom.feat_size
|
g.dim.to_index(p.geom.feat_size), p.geom.feat_size
|
||||||
));
|
));
|
||||||
driver.set_steps_per_stim(1000);
|
|
||||||
if !driver.add_state_file(&*format!("{}/state.bc", prefix), 16000) {
|
if !driver.add_state_file(&*format!("{}/state.bc", prefix), 16000) {
|
||||||
// mu_r=881.33, starting at H=25 to H=75.
|
// mu_r=881.33, starting at H=25 to H=75.
|
||||||
let ferro_mat = mat::Ferroxcube3R1MH::new();
|
let ferro_mat = mat::Ferroxcube3R1MH::new();
|
||||||
|
@@ -143,8 +143,6 @@ fn main() {
|
|||||||
// render a couple CSV files: one very detailed and the other more sparsely detailed
|
// render a couple CSV files: one very detailed and the other more sparsely detailed
|
||||||
driver.add_csv_renderer(&*format!("{}meas.csv", prefix), 200, None);
|
driver.add_csv_renderer(&*format!("{}meas.csv", prefix), 200, None);
|
||||||
driver.add_csv_renderer(&*format!("{}meas-sparse.csv", prefix), 1600, None);
|
driver.add_csv_renderer(&*format!("{}meas-sparse.csv", prefix), 1600, None);
|
||||||
// how frequently to re-evaluate the stimulus (Sample & Hold interpolation between evaluations)
|
|
||||||
driver.set_steps_per_stim(1000);
|
|
||||||
|
|
||||||
driver.step_until(Seconds(duration));
|
driver.step_until(Seconds(duration));
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ use crate::real::Real;
|
|||||||
use crate::render::{self, MultiRenderer, Renderer};
|
use crate::render::{self, MultiRenderer, Renderer};
|
||||||
use crate::sim::AbstractSim;
|
use crate::sim::AbstractSim;
|
||||||
use crate::sim::units::{Frame, Time};
|
use crate::sim::units::{Frame, Time};
|
||||||
use crate::stim::{self, AbstractStimulus};
|
use crate::stim::AbstractStimulus;
|
||||||
|
|
||||||
use log::{info, trace};
|
use log::{info, trace};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -23,13 +23,16 @@ pub struct Driver<S> {
|
|||||||
render_pool: ThreadPool,
|
render_pool: ThreadPool,
|
||||||
render_channel: (SyncSender<()>, Receiver<()>),
|
render_channel: (SyncSender<()>, Receiver<()>),
|
||||||
measurements: Vec<Arc<dyn AbstractMeasurement<S>>>,
|
measurements: Vec<Arc<dyn AbstractMeasurement<S>>>,
|
||||||
stimuli: StimuliAdapter,
|
stimuli: DynStimuli,
|
||||||
/// simulation end time
|
/// simulation end time
|
||||||
sim_end_time: Option<Frame>,
|
sim_end_time: Option<Frame>,
|
||||||
diag: SyncDiagnostics,
|
diag: SyncDiagnostics,
|
||||||
last_diag_time: Instant,
|
last_diag_time: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// generic stimuli collection which monomorphizes everything by boxing it.
|
||||||
|
pub type DynStimuli = Vec<Box<dyn AbstractStimulus>>;
|
||||||
|
|
||||||
impl<S: AbstractSim> Driver<S> {
|
impl<S: AbstractSim> Driver<S> {
|
||||||
pub fn new(mut state: S) -> Self {
|
pub fn new(mut state: S) -> Self {
|
||||||
let diag = SyncDiagnostics::new();
|
let diag = SyncDiagnostics::new();
|
||||||
@@ -45,7 +48,7 @@ impl<S: AbstractSim> Driver<S> {
|
|||||||
Arc::new(meas::Energy::world()),
|
Arc::new(meas::Energy::world()),
|
||||||
Arc::new(meas::Power::world()),
|
Arc::new(meas::Power::world()),
|
||||||
],
|
],
|
||||||
stimuli: StimuliAdapter::new(),
|
stimuli: DynStimuli::new(),
|
||||||
sim_end_time: None,
|
sim_end_time: None,
|
||||||
diag,
|
diag,
|
||||||
last_diag_time: Instant::now(),
|
last_diag_time: Instant::now(),
|
||||||
@@ -59,10 +62,6 @@ impl<S: AbstractSim> Driver<S> {
|
|||||||
pub fn add_measurement<Meas: AbstractMeasurement<S> + 'static>(&mut self, m: Meas) {
|
pub fn add_measurement<Meas: AbstractMeasurement<S> + 'static>(&mut self, m: Meas) {
|
||||||
self.measurements.push(Arc::new(m));
|
self.measurements.push(Arc::new(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_steps_per_stim(&mut self, steps_per_stim: u64) {
|
|
||||||
self.stimuli.frame_interval = steps_per_stim;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: AbstractSim> Driver<S> {
|
impl<S: AbstractSim> Driver<S> {
|
||||||
@@ -161,11 +160,6 @@ impl<S: AbstractSim + Clone + Default + Send + 'static> Driver<S> {
|
|||||||
fn step_at_most(&mut self, at_most: u32) -> u32 {
|
fn step_at_most(&mut self, at_most: u32) -> u32 {
|
||||||
assert!(at_most != 0);
|
assert!(at_most != 0);
|
||||||
let start_step = self.state.step_no();
|
let start_step = self.state.step_no();
|
||||||
if self.stimuli.should_apply(start_step) {
|
|
||||||
self.stimuli.real_time = self.state.time();
|
|
||||||
self.stimuli.time_step = self.state.timestep();
|
|
||||||
trace!("updating stimuli");
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.renderer.any_work_for_frame(start_step) {
|
if self.renderer.any_work_for_frame(start_step) {
|
||||||
self.render();
|
self.render();
|
||||||
@@ -253,54 +247,3 @@ impl<S: AbstractSim> Driver<S> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adapts the stimuli to be applied only every so often, to improve perf
|
|
||||||
struct StimuliAdapter {
|
|
||||||
stim: Vec<Box<dyn AbstractStimulus>>,
|
|
||||||
/// How many frames to go between applications of the stimulus.
|
|
||||||
frame_interval: u64,
|
|
||||||
real_time: f32,
|
|
||||||
time_step: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AbstractStimulus for StimuliAdapter {
|
|
||||||
fn at(&self, t_sec: f32, pos: Meters) -> stim::Fields {
|
|
||||||
self.stim.at(t_sec, pos)
|
|
||||||
// TODO: remove this stuff (here only for testing)
|
|
||||||
/*
|
|
||||||
if true {
|
|
||||||
// interpolation unaware (i.e. let the Sim backend do it)
|
|
||||||
} else if false {
|
|
||||||
// delta-fn "interpolation"
|
|
||||||
self.stim.at(t_sec, pos) * (self.frame_interval as f32)
|
|
||||||
} else if false {
|
|
||||||
// step-fn "interpolation"
|
|
||||||
self.stim.at(self.real_time, pos)
|
|
||||||
} else {
|
|
||||||
// linear interpolation
|
|
||||||
let interp_width = self.frame_interval as f32 * self.time_step;
|
|
||||||
let prev = self.stim.at(self.real_time, pos);
|
|
||||||
let next = self.stim.at(self.real_time + interp_width, pos);
|
|
||||||
let interp = (t_sec - self.real_time) / interp_width;
|
|
||||||
prev * (1.0 - interp) + next * interp
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StimuliAdapter {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
stim: Default::default(),
|
|
||||||
frame_interval: 1,
|
|
||||||
real_time: 0.0,
|
|
||||||
time_step: 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn should_apply(&self, frame: u64) -> bool {
|
|
||||||
(frame % self.frame_interval == 0) && self.stim.len() != 0
|
|
||||||
}
|
|
||||||
fn push(&mut self, s: Box<dyn AbstractStimulus>) {
|
|
||||||
self.stim.push(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user