SummationByParts/euler/benches/bench.rs

93 lines
2.7 KiB
Rust
Raw Normal View History

2020-01-27 20:00:44 +00:00
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2020-05-04 18:03:46 +00:00
use euler::System;
use sbp::operators::{SbpOperator2d, Upwind4, UpwindOperator2d, SBP4};
2020-04-19 18:45:06 +00:00
use sbp::Float;
2020-01-27 20:00:44 +00:00
fn advance_system<SBP: SbpOperator2d>(universe: &mut System<SBP>, n: usize) {
2020-01-27 20:00:44 +00:00
for _ in 0..n {
universe.advance(1.0 / 40.0 * 0.2);
}
}
2021-01-25 22:58:50 +00:00
fn advance_system_upwind<UO: SbpOperator2d + UpwindOperator2d>(
universe: &mut System<UO>,
n: usize,
) {
2020-01-27 20:00:44 +00:00
for _ in 0..n {
universe.advance_upwind(1.0 / 40.0 * 0.2);
}
}
2021-01-25 22:58:50 +00:00
fn advance_embedded<UO: SbpOperator2d + UpwindOperator2d>(
universe: &mut System<UO>,
embedded: bool,
) {
2020-04-19 18:45:06 +00:00
let dt = 0.2 / std::cmp::max(universe.nx(), universe.ny()) as Float;
let t = 1.0;
if embedded {
let mut dt = dt;
universe.advance_adaptive(t, &mut dt, 1e-2);
} else {
for _ in 0..(t / dt).round() as isize {
universe.advance_upwind(dt);
}
}
}
2020-01-27 20:00:44 +00:00
fn performance_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("EulerSystem");
group.sample_size(25);
let w = 40;
let h = 26;
let x = ndarray::Array1::linspace(-10.0, 10.0, w);
let x = x.broadcast((h, w)).unwrap();
let y = ndarray::Array1::linspace(-10.0, 10.0, h);
let y = y.broadcast((w, h)).unwrap().reversed_axes();
2020-04-14 19:59:02 +00:00
let mut universe = System::new(x.into_owned(), y.into_owned(), Upwind4);
2020-01-27 20:00:44 +00:00
group.bench_function("advance", |b| {
b.iter(|| {
2020-01-28 18:31:14 +00:00
universe.init_with_vortex(0.0, 0.0);
2020-01-27 20:00:44 +00:00
advance_system(&mut universe, black_box(20))
})
});
2020-04-14 19:59:02 +00:00
let mut universe = System::new(x.into_owned(), y.into_owned(), Upwind4);
2020-01-27 20:00:44 +00:00
group.bench_function("advance_upwind", |b| {
b.iter(|| {
2020-01-28 18:31:14 +00:00
universe.init_with_vortex(0.0, 0.0);
2020-01-27 20:00:44 +00:00
advance_system_upwind(&mut universe, black_box(20))
})
});
2020-04-14 19:59:02 +00:00
let mut universe = System::new(x.into_owned(), y.into_owned(), SBP4);
2020-01-27 20:00:44 +00:00
group.bench_function("advance_trad4", |b| {
b.iter(|| {
2020-01-28 18:31:14 +00:00
universe.init_with_vortex(0.0, 0.0);
2020-01-27 20:00:44 +00:00
advance_system(&mut universe, black_box(20))
})
});
2020-04-19 18:45:06 +00:00
group.finish();
2020-01-27 20:00:44 +00:00
2020-04-19 18:45:06 +00:00
let mut group = c.benchmark_group("adaptive integration");
group.sample_size(10);
let mut universe = System::new(x.into_owned(), y.into_owned(), Upwind4);
group.bench_function("static dt", |b| {
b.iter(|| {
universe.init_with_vortex(0.0, 0.0);
advance_embedded(&mut universe, false);
})
});
group.bench_function("adaptive dt", |b| {
b.iter(|| {
universe.init_with_vortex(0.0, 0.0);
advance_embedded(&mut universe, true);
})
});
2020-01-27 20:00:44 +00:00
group.finish();
}
criterion_group!(benches, performance_benchmark);
criterion_main!(benches);