update sparse maxwell benches

This commit is contained in:
Magnus Ulimoen 2020-09-21 16:38:52 +02:00
parent 939eae9af1
commit 3593ee2f52
2 changed files with 28 additions and 7 deletions

View File

@ -97,32 +97,41 @@ fn sparse_creation(c: &mut Criterion) {
let w = 40; let w = 40;
let h = 26; let h = 26;
group.bench_function("create_rhs_trad4", |b| { 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(|| { 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| { 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(|| { 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| { 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(|| { 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| { 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(|| { b.iter(|| {
let _matrix = let _matrix = maxwell::sparse::rhs_matrix_with_upwind_dissipation(
maxwell::sparse::rhs_matrix_with_upwind_dissipation(&sbp::operators::Upwind4, w, h); &sbp::operators::Upwind4,
&grid,
);
}) })
}); });
group.bench_function("create_rhs_upwind_upwind9", |b| { 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(|| { b.iter(|| {
let _matrix = let _matrix = maxwell::sparse::rhs_matrix_with_upwind_dissipation(
maxwell::sparse::rhs_matrix_with_upwind_dissipation(&sbp::operators::Upwind9, w, h); &sbp::operators::Upwind9,
&grid,
);
}) })
}); });
} }

View File

@ -21,6 +21,18 @@ pub struct Metrics {
} }
impl Grid { impl Grid {
pub fn new_linspace(
x: std::ops::Range<Float>,
nx: usize,
y: std::ops::Range<Float>,
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<Float>, y: Array2<Float>) -> Result<Self, ndarray::ShapeError> { pub fn new(x: Array2<Float>, y: Array2<Float>) -> Result<Self, ndarray::ShapeError> {
assert_eq!(x.shape(), y.shape()); assert_eq!(x.shape(), y.shape());