Update convergence test after trait rework

This commit is contained in:
Magnus Ulimoen 2021-03-30 19:09:11 +02:00
parent 5f7d38dd55
commit 8051954c29
1 changed files with 12 additions and 5 deletions

View File

@ -1,9 +1,12 @@
#![cfg(feature = "expensive_tests")] #![cfg(feature = "expensive_tests")]
use euler::*; use euler::*;
use ndarray::prelude::*; use ndarray::prelude::*;
use sbp::Float; use sbp::{
operators::{SbpOperator2d, UpwindOperator2d},
Float,
};
fn run_with_size(size: usize, op: impl sbp::operators::UpwindOperator2d + Copy) -> Float { fn run_with_size(size: usize, op: impl SbpOperator2d + UpwindOperator2d + Copy) -> Float {
let nx = size; let nx = size;
let ny = size; let ny = size;
let x = Array1::linspace(-5.0, 5.0, nx); let x = Array1::linspace(-5.0, 5.0, nx);
@ -48,9 +51,10 @@ fn run_with_size(size: usize, op: impl sbp::operators::UpwindOperator2d + Copy)
verifield.h2_err(sys.field(), &op) verifield.h2_err(sys.field(), &op)
} }
fn convergence(op: impl sbp::operators::UpwindOperator2d + Copy) { fn convergence(op: impl SbpOperator2d + UpwindOperator2d + Copy, expected_q: Float) {
let sizes = [25, 35, 50, 71, 100, 150, 200]; let sizes = [25, 35, 50, 71, 100, 150, 200];
let mut prev: Option<(usize, Float)> = None; let mut prev: Option<(usize, Float)> = None;
let mut q_last = None;
println!("Size\tError(h2)\tq"); println!("Size\tError(h2)\tq");
for size in &sizes { for size in &sizes {
print!("{:3}x{:3}", size, size); print!("{:3}x{:3}", size, size);
@ -66,18 +70,21 @@ fn convergence(op: impl sbp::operators::UpwindOperator2d + Copy) {
let q = let q =
Float::log10(e0 / e1) / Float::log10((m0 as Float / m1 as Float).powf(1.0 / 2.0)); Float::log10(e0 / e1) / Float::log10((m0 as Float / m1 as Float).powf(1.0 / 2.0));
print!("\t{}", q); print!("\t{}", q);
q_last = Some(q);
} }
println!(); println!();
prev = Some((*size, e)); prev = Some((*size, e));
} }
let actual_q = q_last.unwrap();
assert!(actual_q < expected_q);
} }
#[test] #[test]
fn convergence_upwind4() { fn convergence_upwind4() {
convergence(sbp::operators::Upwind4); convergence(sbp::operators::Upwind4, -4.0);
} }
#[test] #[test]
fn convergence_upwind9() { fn convergence_upwind9() {
convergence(sbp::operators::Upwind9); convergence(sbp::operators::Upwind9, -8.5);
} }