From 3593ee2f52be86a851758eefff4000c364dbe0c7 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 21 Sep 2020 16:38:52 +0200 Subject: [PATCH] update sparse maxwell benches --- maxwell/benches/bench.rs | 23 ++++++++++++++++------- sbp/src/grid.rs | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/maxwell/benches/bench.rs b/maxwell/benches/bench.rs index 5673be7..551fdff 100644 --- a/maxwell/benches/bench.rs +++ b/maxwell/benches/bench.rs @@ -97,32 +97,41 @@ fn sparse_creation(c: &mut Criterion) { let w = 40; let h = 26; group.bench_function("create_rhs_trad4", |b| { + let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h); b.iter(|| { - let _matrix = maxwell::sparse::rhs_matrix(&SBP4, w, h); + let _matrix = maxwell::sparse::rhs_matrix(&SBP4, &grid); }) }); group.bench_function("create_rhs_upwind4", |b| { + let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h); b.iter(|| { - let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind4, w, h); + let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind4, &grid); }) }); group.bench_function("create_rhs_upwind9", |b| { + let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h); b.iter(|| { - let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind9, w, h); + let _matrix = maxwell::sparse::rhs_matrix(&sbp::operators::Upwind9, &grid); }) }); group.bench_function("create_rhs_upwind_upwind4", |b| { + let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h); b.iter(|| { - let _matrix = - maxwell::sparse::rhs_matrix_with_upwind_dissipation(&sbp::operators::Upwind4, w, h); + let _matrix = maxwell::sparse::rhs_matrix_with_upwind_dissipation( + &sbp::operators::Upwind4, + &grid, + ); }) }); group.bench_function("create_rhs_upwind_upwind9", |b| { + let grid = sbp::grid::Grid::new_linspace(0.0..1.0, w, 0.0..1.0, h); b.iter(|| { - let _matrix = - maxwell::sparse::rhs_matrix_with_upwind_dissipation(&sbp::operators::Upwind9, w, h); + let _matrix = maxwell::sparse::rhs_matrix_with_upwind_dissipation( + &sbp::operators::Upwind9, + &grid, + ); }) }); } diff --git a/sbp/src/grid.rs b/sbp/src/grid.rs index 8711998..fb56ced 100644 --- a/sbp/src/grid.rs +++ b/sbp/src/grid.rs @@ -21,6 +21,18 @@ pub struct Metrics { } impl Grid { + pub fn new_linspace( + x: std::ops::Range, + nx: usize, + y: std::ops::Range, + ny: usize, + ) -> Self { + let dx = (x.end - x.start) / (nx - 1) as Float; + let dy = (y.end - y.start) / (ny - 1) as Float; + let x = Array2::from_shape_fn((ny, nx), |(_j, i)| i as Float * dx + x.start); + let y = Array2::from_shape_fn((ny, nx), |(j, _i)| j as Float * dy + y.start); + Self { x, y } + } pub fn new(x: Array2, y: Array2) -> Result { assert_eq!(x.shape(), y.shape());