sim: remove impulse_e methods

This commit is contained in:
2022-07-28 16:17:02 -07:00
parent afc1f874d2
commit 0465e3d7f5
3 changed files with 34 additions and 34 deletions

View File

@@ -372,10 +372,6 @@ impl<R: Real, M: Material<R> + Send + Sync> GenericSim for SimState<R, M> {
SimState::step(self); SimState::step(self);
} }
} }
fn impulse_e_meters(&mut self, pos: Meters, amount: Vec3<f32>) {
*self.get_e_mut(pos) += amount.cast();
}
} }
#[allow(unused)] #[allow(unused)]
@@ -1236,6 +1232,22 @@ mod test {
assert_eq!(state.time(), state.timestep()); assert_eq!(state.time(), state.timestep());
} }
struct ConstStim {
loc: Index,
feature_size: f32,
e: Vec3<f32>,
h: Vec3<f32>,
}
impl AbstractStimulus for ConstStim {
fn at(&self, _t_sec: f32, loc: Meters) -> (Vec3<f32>, Vec3<f32>) {
if loc.to_index(self.feature_size) == self.loc {
(self.e, self.h)
} else {
Default::default()
}
}
}
#[test] #[test]
fn energy_conservation_over_time() { fn energy_conservation_over_time() {
let mut state = SimState::<R64, Static<R64>>::new(Index((2001, 1, 1).into()), 1e-6); let mut state = SimState::<R64, Static<R64>>::new(Index((2001, 1, 1).into()), 1e-6);
@@ -1244,9 +1256,12 @@ mod test {
let sig = angle.sin(); let sig = angle.sin();
let gate = 0.5*(1.0 - angle.cos()); let gate = 0.5*(1.0 - angle.cos());
//println!("{}", g.exp()); //println!("{}", g.exp());
state.impulse_ez(Index((1000, 0, 0).into()), gate*sig); state.step_multiple(1, &ConstStim {
//dyn_state.impulse_by(index((x, 0, 0).into()), 1.5e-9*g.exp()); loc: Index::new(0, 0, 1000),
state.step(); feature_size: 1e-6,
e: Vec3::new_z(gate*sig/state.timestep()),
h: Vec3::zero(),
});
} }
let (energy_0, energy_1) = energy_now_and_then(&mut state, 800); let (energy_0, energy_1) = energy_now_and_then(&mut state, 800);
// This has some sensitivity to courant number. But surprisingly, not much to f32 v.s. f64 // This has some sensitivity to courant number. But surprisingly, not much to f32 v.s. f64
@@ -1260,8 +1275,12 @@ mod test {
let angle = (t as f32)/10.0*f32::two_pi(); let angle = (t as f32)/10.0*f32::two_pi();
let sig = angle.sin(); let sig = angle.sin();
let gate = 1e9 * 0.5*(1.0 - angle.cos()); let gate = 1e9 * 0.5*(1.0 - angle.cos());
state.impulse_ez(Index((10, 10, 10).into()), gate*sig); state.step_multiple(1, &ConstStim {
state.step(); loc: Index::new(10, 10, 10),
feature_size: 1e-6,
e: Vec3::new_z(gate*sig/state.timestep()),
h: Vec3::zero(),
});
} }
let (energy_0, energy_1) = energy_now_and_then(&mut state, 500); let (energy_0, energy_1) = energy_now_and_then(&mut state, 500);
// Default boundary conditions reflect waves. // Default boundary conditions reflect waves.
@@ -1279,8 +1298,12 @@ mod test {
let angle = 2.0*progress*f32::two_pi(); let angle = 2.0*progress*f32::two_pi();
let sig = angle.sin(); let sig = angle.sin();
let gate = (progress*f32::pi()).sin(); let gate = (progress*f32::pi()).sin();
state.impulse_ez(Index((100, 0, 0).into()), gate*sig); state.step_multiple(1, &ConstStim {
state.step(); loc: Index::new(100, 0, 0),
feature_size: 1e-6,
e: Vec3::new_z(gate*sig/state.timestep()),
h: Vec3::zero(),
});
} }
energy_now_and_then(&mut state, 1000) energy_now_and_then(&mut state, 1000)
} }

View File

@@ -126,23 +126,6 @@ pub trait GenericSim: SampleableSim {
self.step_multiple(1, &NoopStimulus); self.step_multiple(1, &NoopStimulus);
} }
fn step_multiple<S: AbstractStimulus>(&mut self, num_steps: u32, s: &S); fn step_multiple<S: AbstractStimulus>(&mut self, num_steps: u32, s: &S);
/// DEPRECATED. Use stimulus instead
fn impulse_e_meters(&mut self, pos: Meters, amount: Vec3<f32>);
fn impulse_e<C: Coord>(&mut self, pos: C, amt: Vec3<f32>) {
self.impulse_e_meters(pos.to_meters(self.feature_size()), amt)
}
fn impulse_ex<C: Coord>(&mut self, c: C, ex: f32) {
self.impulse_e(c, Vec3::new_x(ex));
}
fn impulse_ey<C: Coord>(&mut self, c: C, ey: f32) {
self.impulse_e(c, Vec3::new_y(ey));
}
fn impulse_ez<C: Coord>(&mut self, c: C, ez: f32) {
self.impulse_e(c, Vec3::new_z(ez));
}
} }
/// Conceptually, one cell looks like this (in 2d): /// Conceptually, one cell looks like this (in 2d):

View File

@@ -160,12 +160,6 @@ where
); );
self.step_no += num_steps as u64; self.step_no += num_steps as u64;
} }
fn impulse_e_meters(&mut self, pos: Meters, amount: Vec3<f32>) {
let idx = pos.to_index(self.feature_size());
let flat_idx = self.flat_index(idx).unwrap();
self.e[flat_idx] += amount.cast();
}
} }
impl<R: Real, M: Default, B> SpirvSim<R, M, B> impl<R: Real, M: Default, B> SpirvSim<R, M, B>