2020-02-25 18:44:13 +00:00
|
|
|
#![cfg(feature = "expensive_tests")]
|
2020-02-24 19:10:59 +00:00
|
|
|
use ndarray::prelude::*;
|
|
|
|
use sbp::euler::*;
|
2020-02-27 19:26:43 +00:00
|
|
|
use sbp::Float;
|
2020-02-24 19:10:59 +00:00
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
fn run_with_size<SBP: sbp::operators::UpwindOperator>(size: usize) -> Float {
|
2020-02-25 18:44:13 +00:00
|
|
|
let nx = size;
|
|
|
|
let ny = size;
|
2020-02-24 19:10:59 +00:00
|
|
|
let x = Array1::linspace(-5.0, 5.0, nx);
|
|
|
|
let y = Array1::linspace(-5.0, 5.0, ny);
|
|
|
|
|
|
|
|
let x = x.broadcast((ny, nx)).unwrap().to_owned();
|
|
|
|
let y = y
|
|
|
|
.reversed_axes()
|
|
|
|
.broadcast((nx, ny))
|
|
|
|
.unwrap()
|
|
|
|
.reversed_axes()
|
|
|
|
.to_owned();
|
|
|
|
|
|
|
|
let vortex_params = VortexParameters {
|
|
|
|
x0: -1.0,
|
|
|
|
y0: 0.0,
|
|
|
|
mach: 0.5,
|
|
|
|
rstar: 0.5,
|
|
|
|
eps: 1.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut sys = System::<SBP>::new(x, y);
|
|
|
|
sys.vortex(0.0, vortex_params);
|
|
|
|
|
2020-02-25 18:44:13 +00:00
|
|
|
let time = 0.2;
|
2020-02-27 19:26:43 +00:00
|
|
|
let dt = 0.2 * Float::min(1.0 / (nx - 1) as Float, 1.0 / (ny - 1) as Float);
|
2020-02-24 19:10:59 +00:00
|
|
|
|
|
|
|
let nsteps = (time / dt) as usize;
|
|
|
|
for _ in 0..nsteps {
|
|
|
|
sys.advance_upwind(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut verifield = Field::new(ny, nx);
|
2020-02-27 19:26:43 +00:00
|
|
|
verifield.vortex(sys.x(), sys.y(), nsteps as Float * dt, vortex_params);
|
2020-02-24 19:10:59 +00:00
|
|
|
|
2020-02-25 18:44:13 +00:00
|
|
|
verifield.h2_err::<SBP>(sys.field())
|
2020-02-24 19:10:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 21:15:28 +00:00
|
|
|
fn convergence<SBP: sbp::operators::UpwindOperator>() {
|
2020-02-27 19:26:43 +00:00
|
|
|
let sizes = [25, 35, 50, 71, 100, 150, 200];
|
|
|
|
let mut prev: Option<(usize, Float)> = None;
|
2020-02-25 18:44:13 +00:00
|
|
|
println!("Size\tError(h2)\tq");
|
2020-02-24 19:10:59 +00:00
|
|
|
for size in &sizes {
|
2020-02-25 18:44:13 +00:00
|
|
|
print!("{:3}x{:3}", size, size);
|
2020-03-30 21:15:28 +00:00
|
|
|
let e = run_with_size::<SBP>(*size);
|
2020-02-25 18:44:13 +00:00
|
|
|
print!("\t{:.10}", e);
|
|
|
|
if let Some(prev) = prev.take() {
|
|
|
|
let m0 = size * size;
|
|
|
|
let e0 = e;
|
|
|
|
|
|
|
|
let (size1, e1) = prev;
|
|
|
|
let m1 = size1 * size1;
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
let q =
|
|
|
|
Float::log10(e0 / e1) / Float::log10((m0 as Float / m1 as Float).powf(1.0 / 2.0));
|
2020-02-25 18:44:13 +00:00
|
|
|
print!("\t{}", q);
|
|
|
|
}
|
|
|
|
println!();
|
|
|
|
prev = Some((*size, e));
|
2020-02-24 19:10:59 +00:00
|
|
|
}
|
2020-03-30 21:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn convergence_upwind4() {
|
|
|
|
convergence::<sbp::operators::Upwind4>();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn convergence_upwind9() {
|
|
|
|
convergence::<sbp::operators::Upwind9>();
|
2020-02-24 19:10:59 +00:00
|
|
|
}
|