sim: backfill a test to show that conductors properly reflect EM waves
This commit is contained in:
@@ -595,6 +595,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
/// verify that an EM ray propagates through the vacuum as expected
|
||||
#[test]
|
||||
fn ray_propagation() {
|
||||
let size = Index::new(1, 1, 1536);
|
||||
@@ -620,6 +621,45 @@ mod test {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// reflect an EM ray off a conductor and make sure the result is as expected
|
||||
#[test]
|
||||
fn conductor_reflection() {
|
||||
let size = Index::new(1, 1, 2048);
|
||||
let feat_size = 1e-3;
|
||||
let mut sim = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(size, feat_size);
|
||||
|
||||
inject_ray(512, 512, &mut sim);
|
||||
|
||||
sim.put_material(Index::new(0, 0, 1536), mat::IsomorphicConductor::new(1e9.cast()));
|
||||
|
||||
// 512 cells for the ray to propagate *toward* the conductor,
|
||||
// 512 cells for it to reflect,
|
||||
// 512 cells for it to propagate back from the conductor.
|
||||
// the wave crosses 0.577 cells per step (Courant value), so roughly 2662 steps
|
||||
// for the wave to return home.
|
||||
for t in 0..2662 {
|
||||
sim.step();
|
||||
}
|
||||
|
||||
// now the wave should have returned to the starting point
|
||||
let eh: Vec<_> = (0..size.z()).into_iter().map(|z| {
|
||||
let f = sim.fields_at_index(Index::new(0, 0, z));
|
||||
(f.e().x().cast::<f32>(), f.h().y().cast::<f32>())
|
||||
}).collect();
|
||||
for (z, (e, h)) in eh.iter().enumerate() {
|
||||
let (ray_e, ray_h) = ray(512, 512, &sim, z as u32, 0);
|
||||
// a conductor forces E=0, hence the head of the return E wave is the
|
||||
// negative of the head of the origin E wave.
|
||||
// because of the opposite orientation, this actually negates again the
|
||||
// return E wave evaluates to the same as the origin E wave.
|
||||
// however, the return H wave is only flipped once, because of the
|
||||
// orientation.
|
||||
let (exp_e, exp_h) = (ray_e, -ray_h);
|
||||
assert_float_eq!(*e, exp_e.cast::<f32>(), abs <= 2e-2, "z={} ... {:?}", z, eh);
|
||||
assert_float_eq!(*h, exp_h.cast::<f32>(), abs <= 2e-4, "z={} ... {:?}", z, eh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user