sim: port legacy test to spirv: sane_boundary_conditions

This commit is contained in:
2022-08-23 16:56:35 -07:00
parent 5c7ce8437a
commit 4024ee3316
2 changed files with 29 additions and 9 deletions

View File

@@ -1215,6 +1215,7 @@ mod test {
assert_float_eq!(energy_1, energy_0, r2nd <= 1e-9);
}
// PORT-STATUS: done
#[test]
fn sane_boundary_conditions() {
let mut state = SimState::<R64, Static<R64>>::new(Index((21, 21, 21).into()), 1e-6);

View File

@@ -650,20 +650,23 @@ mod test {
}
}
fn smooth_pulse_at(timestep: f32, loc: Index, frames: u32) -> impl Stimulus<R32> {
let wl = (timestep * frames as f32).to_r32();
let quarter_wl = wl * (0.25).to_r32();
ModulatedVectorField::new(
IndexGatedEField { loc },
Sinusoid::from_wavelength(R32::one(), wl).scaled(
Sinusoid::from_wavelength(R32::one(), wl).shifted(quarter_wl).summed(R32::one())
),
)
}
#[test]
fn energy_conservation_over_time() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
Index((2001, 1, 1).into()), 1e-6
);
let wl = (state.timestep() * 100.0).to_r32();
let quarter_wl = wl * (0.25).to_r32();
let stim = ModulatedVectorField::new(
IndexGatedEField { loc: Index::new(1000, 0, 0) },
Sinusoid::from_wavelength(R32::one(), wl).scaled(
Sinusoid::from_wavelength(R32::one(), wl).shifted(quarter_wl).summed(R32::one())
),
);
let stim = smooth_pulse_at(state.timestep(), Index::new(1000, 0, 0), 100);
state.step_multiple(100, &stim);
let energy_0 = Energy::world().data(&state);
@@ -674,6 +677,22 @@ mod test {
// TODO: assert that energy is something reasonable to begin with, and not 0.
}
#[test]
fn sane_boundary_conditions() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
Index((21, 21, 21).into()), 1e-6
);
let stim = smooth_pulse_at(state.timestep(), Index::new(10, 10, 10), 40);
state.step_multiple(40, &stim);
let energy_0 = Energy::world().data(&state);
state.step_multiple(500, &NoopStimulus);
let energy_1 = Energy::world().data(&state);
// Default boundary conditions reflect waves.
assert_float_eq!(energy_1, energy_0, r2nd <= 1e-2);
}
#[test]
fn test_smoke_small() {
do_smoke_small::<$backend>();