diff --git a/crates/coremem/src/sim/spirv/mod.rs b/crates/coremem/src/sim/spirv/mod.rs index fdc480b..01e65c6 100644 --- a/crates/coremem/src/sim/spirv/mod.rs +++ b/crates/coremem/src/sim/spirv/mod.rs @@ -172,7 +172,8 @@ impl SpirvSim } } - /// XXX for test + /// test helper for when stimuli can't directly be used for one reason or another + #[cfg(test)] pub(crate) fn set_fields_at_index(&mut self, pos: Index, f: Fields) { let idx = self.flat_index(pos).unwrap(); self.e[idx] = f.e(); @@ -352,9 +353,8 @@ mod test { mod $shortname { use super::*; - use crate::geom::{Coord as _, WorldRegion}; - use crate::sim::Cube; - use crate::stim::{DynStimuli, FieldMags, NoopStimulus, RegionGated, RngStimulus}; + use crate::geom::WorldRegion; + use crate::stim::{NoopStimulus, RngStimulus}; use coremem_cross::mat::{AnisomorphicConductor, IsomorphicConductor}; use float_eq::assert_float_eq; use more_asserts::{assert_gt, assert_lt}; @@ -576,21 +576,23 @@ mod test { if idx < 0.0 || idx > 2.0 { return (R32::zero(), R32::zero()); } + let phase = idx.cast::() * R32::pi(); let a = phase.sin(); (amp_e * a, amp_h * a) - }; // inject the wave at t=0 - for i in 0..size.z() { - let (e, h) = wave(i, 0); - sim.set_fields_at_index(Index::new(0, 0, i), Fields::new( + for z in 0..size.z() { + let (e, h) = wave(z, 0); + // due to the staggered nature of stepping (step_e, then step_h), + // populating the initial E *and* H fields through a Stimulus is + // nontrivial. we just explicitly set the fields instead. + sim.set_fields_at_index(Index::new(0, 0, z), Fields::new( Vec3::new(e, R32::zero(), R32::zero()), Vec3::new(R32::zero(), h, R32::zero()), Vec3::default(), )); - } // advance the simulation N steps.