Moddy the Tube test
This commit is contained in:
parent
e8551f5d02
commit
0a27fc1f9b
|
|
@ -49,29 +49,36 @@ impl Metric for Tube {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tube_metric_derivs() {
|
||||
struct Approx(Tube);
|
||||
impl Metric for Approx {
|
||||
fn sqrt_at(&self, pos: Vec2) -> Decomp2 { self.0.sqrt_at(pos) }
|
||||
}
|
||||
let testee = Tube {
|
||||
inner_radius: 30.0,
|
||||
outer_radius: 50.0,
|
||||
internal_halflength: 100.0,
|
||||
external_halflength: 300.0,
|
||||
};
|
||||
let approx = Approx(testee);
|
||||
let epsilon = 1.0e-3;
|
||||
let margin = 1.0 / 16.0;
|
||||
let mul = 1.0 + margin;
|
||||
for x in itertools_num::linspace(-mul * testee.outer_radius, mul * testee.outer_radius, 100) {
|
||||
for y in itertools_num::linspace(-mul * testee.external_halflength, mul * testee.external_halflength, 100) {
|
||||
let pos = vec2(x, y);
|
||||
let computed = testee.part_derivs_at(pos);
|
||||
let reference = approx.part_derivs_at(pos);
|
||||
let eq = (0..2).all(|coord| computed[coord].abs_diff_eq(reference[coord], epsilon));
|
||||
assert!(eq, "Bad derivative computation at {pos}:\n explicit: {computed:?}\n numerical: {reference:?}\n");
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use glam::{Vec2, vec2};
|
||||
use crate::riemann::{Decomp2, Metric};
|
||||
use super::Tube;
|
||||
|
||||
#[test]
|
||||
fn test_tube_metric_derivs() {
|
||||
struct Approx(Tube);
|
||||
impl Metric for Approx {
|
||||
fn sqrt_at(&self, pos: Vec2) -> Decomp2 { self.0.sqrt_at(pos) }
|
||||
}
|
||||
let testee = Tube {
|
||||
inner_radius: 30.0,
|
||||
outer_radius: 50.0,
|
||||
internal_halflength: 100.0,
|
||||
external_halflength: 300.0,
|
||||
};
|
||||
let approx = Approx(testee);
|
||||
let epsilon = 1.0e-3;
|
||||
let margin = 1.0 / 16.0;
|
||||
let mul = 1.0 + margin;
|
||||
for x in itertools_num::linspace(-mul * testee.outer_radius, mul * testee.outer_radius, 100) {
|
||||
for y in itertools_num::linspace(-mul * testee.external_halflength, mul * testee.external_halflength, 100) {
|
||||
let pos = vec2(x, y);
|
||||
let computed = testee.part_derivs_at(pos);
|
||||
let reference = approx.part_derivs_at(pos);
|
||||
let eq = (0..2).all(|coord| computed[coord].abs_diff_eq(reference[coord], epsilon));
|
||||
assert!(eq, "Bad derivative computation at {pos}:\n explicit: {computed:?}\n numerical: {reference:?}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user