2020-01-27 20:00:44 +00:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
2020-05-01 22:22:59 +00:00
|
|
|
use maxwell::System;
|
2020-04-14 22:12:54 +00:00
|
|
|
use sbp::operators::{SbpOperator2d, Upwind4, UpwindOperator2d, SBP4};
|
2020-02-27 19:26:43 +00:00
|
|
|
use sbp::Float;
|
2020-01-27 20:00:44 +00:00
|
|
|
|
2020-04-14 22:12:54 +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(0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 22:12:54 +00:00
|
|
|
fn advance_system_upwind<UO: UpwindOperator2d>(universe: &mut System<UO>, n: usize) {
|
2020-01-27 20:00:44 +00:00
|
|
|
for _ in 0..n {
|
|
|
|
universe.advance_upwind(0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:47:40 +00:00
|
|
|
#[cfg(feature = "sparse")]
|
|
|
|
fn advance_system_matrix<SBP: SbpOperator2d>(universe: &mut System<SBP>, n: usize) {
|
|
|
|
for _ in 0..n {
|
|
|
|
universe.advance_sparse(0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 19:03:39 +00:00
|
|
|
#[cfg(feature = "sparse")]
|
|
|
|
fn advance_system_matrix_implicit<SBP: SbpOperator2d>(universe: &mut System<SBP>, n: usize) {
|
|
|
|
for _ in 0..n {
|
|
|
|
universe.advance_implicit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 20:00:44 +00:00
|
|
|
fn performance_benchmark(c: &mut Criterion) {
|
2020-01-27 20:20:34 +00:00
|
|
|
let mut group = c.benchmark_group("MaxwellSystem");
|
2020-01-27 20:00:44 +00:00
|
|
|
group.sample_size(25);
|
|
|
|
|
|
|
|
let w = 40;
|
|
|
|
let h = 26;
|
2020-02-27 19:26:43 +00:00
|
|
|
let x = ndarray::Array2::from_shape_fn((h, w), |(_, i)| i as Float / (w - 1) as Float);
|
|
|
|
let y = ndarray::Array2::from_shape_fn((h, w), |(j, _)| j as Float / (h - 1) as Float);
|
2020-01-27 20:00:44 +00:00
|
|
|
|
2020-04-14 19:59:02 +00:00
|
|
|
let mut universe = System::new(x.clone(), y.clone(), Upwind4);
|
2020-01-27 20:00:44 +00:00
|
|
|
group.bench_function("advance", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
universe.set_gaussian(0.5, 0.5);
|
|
|
|
advance_system(&mut universe, black_box(20))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:59:02 +00:00
|
|
|
let mut universe = System::new(x.clone(), y.clone(), Upwind4);
|
2020-01-27 20:00:44 +00:00
|
|
|
group.bench_function("advance_upwind", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
universe.set_gaussian(0.5, 0.5);
|
|
|
|
advance_system_upwind(&mut universe, black_box(20))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2020-06-15 20:47:40 +00:00
|
|
|
let mut universe = System::new(x.clone(), y.clone(), SBP4);
|
2020-01-27 20:00:44 +00:00
|
|
|
group.bench_function("advance_trad4", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
universe.set_gaussian(0.5, 0.5);
|
|
|
|
advance_system(&mut universe, black_box(20))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2020-06-15 20:47:40 +00:00
|
|
|
#[cfg(feature = "sparse")]
|
|
|
|
{
|
|
|
|
let mut universe = System::new(x.clone(), y.clone(), Upwind4);
|
|
|
|
group.bench_function("advance_upwind4_as_matrix", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
universe.set_gaussian(0.5, 0.5);
|
|
|
|
advance_system_matrix(&mut universe, black_box(20))
|
|
|
|
})
|
|
|
|
});
|
2020-08-31 19:03:39 +00:00
|
|
|
let mut universe = System::new(x.clone(), y.clone(), sbp::operators::Upwind9);
|
|
|
|
group.bench_function("advance_upwind9_as_matrix", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
universe.set_gaussian(0.5, 0.5);
|
|
|
|
advance_system_matrix(&mut universe, black_box(20))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
let mut universe = System::new(x.clone(), y.clone(), Upwind4);
|
|
|
|
group.bench_function("advance_upwind9_as_matrix_implicit", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
universe.set_gaussian(0.5, 0.5);
|
|
|
|
advance_system_matrix_implicit(&mut universe, black_box(20))
|
|
|
|
})
|
|
|
|
});
|
2020-06-15 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
2020-01-27 20:00:44 +00:00
|
|
|
group.finish();
|
|
|
|
}
|
|
|
|
|
2020-08-21 20:53:37 +00:00
|
|
|
#[cfg(feature = "sparse")]
|
|
|
|
fn sparse_creation(c: &mut Criterion) {
|
|
|
|
let mut group = c.benchmark_group("MaxwellSystem");
|
|
|
|
group.sample_size(25);
|
|
|
|
let w = 40;
|
|
|
|
let h = 26;
|
|
|
|
group.bench_function("create_rhs_trad4", |b| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h);
|
2020-08-21 20:53:37 +00:00
|
|
|
b.iter(|| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let _matrix = maxwell::sparse::rhs_matrix(&SBP4, &grid);
|
2020-08-21 20:53:37 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
group.bench_function("create_rhs_upwind4", |b| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h);
|
2020-08-21 20:53:37 +00:00
|
|
|
b.iter(|| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind4, &grid);
|
2020-08-21 20:53:37 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
group.bench_function("create_rhs_upwind9", |b| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h);
|
2020-08-21 20:53:37 +00:00
|
|
|
b.iter(|| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind9, &grid);
|
2020-08-21 20:53:37 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
group.bench_function("create_rhs_upwind_upwind4", |b| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h);
|
2020-08-21 20:53:37 +00:00
|
|
|
b.iter(|| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let _matrix = maxwell::sparse::rhs_matrix_with_upwind_dissipation(
|
|
|
|
&sbp::operators::Upwind4,
|
|
|
|
&grid,
|
|
|
|
);
|
2020-08-21 20:53:37 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
group.bench_function("create_rhs_upwind_upwind9", |b| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h);
|
2020-08-21 20:53:37 +00:00
|
|
|
b.iter(|| {
|
2020-09-21 14:38:52 +00:00
|
|
|
let _matrix = maxwell::sparse::rhs_matrix_with_upwind_dissipation(
|
|
|
|
&sbp::operators::Upwind9,
|
|
|
|
&grid,
|
|
|
|
);
|
2020-08-21 20:53:37 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "sparse")]
|
|
|
|
criterion_group!(sparse_create, sparse_creation);
|
2020-01-27 20:00:44 +00:00
|
|
|
criterion_group!(benches, performance_benchmark);
|
2020-08-21 20:53:37 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "sparse")]
|
|
|
|
criterion_main!(benches, sparse_create);
|
|
|
|
#[cfg(not(feature = "sparse"))]
|
2020-01-27 20:00:44 +00:00
|
|
|
criterion_main!(benches);
|