rename diffx/diffy

This commit is contained in:
Magnus Ulimoen 2019-12-08 21:00:47 +01:00
parent a0a125b61c
commit 1ff9ffa7ba
3 changed files with 19 additions and 19 deletions

View File

@ -81,15 +81,15 @@ impl System {
// hz = -ey_x + ex_y
let tmp = &mut k[i].0;
SBP::diffx(y.2.view(), tmp.view_mut());
SBP::diffy(y.0.view(), k[i].1.view_mut());
SBP::diffxi(y.2.view(), tmp.view_mut());
SBP::diffeta(y.0.view(), k[i].1.view_mut());
k[i].1.scaled_add(-1.0, tmp);
// ex = hz_y
SBP::diffy(y.1.view(), k[i].0.view_mut());
SBP::diffeta(y.1.view(), k[i].0.view_mut());
// ey = -hz_x
SBP::diffx(y.1.view(), k[i].2.view_mut());
SBP::diffxi(y.1.view(), k[i].2.view_mut());
k[i].2.mapv_inplace(|v| -v);
// Boundary conditions (SAT)

View File

@ -1,8 +1,8 @@
use ndarray::{ArrayView2, ArrayViewMut2};
pub trait SbpOperator {
fn diffx(prev: ArrayView2<f32>, fut: ArrayViewMut2<f32>);
fn diffy(prev: ArrayView2<f32>, fut: ArrayViewMut2<f32>);
fn diffxi(prev: ArrayView2<f32>, fut: ArrayViewMut2<f32>);
fn diffeta(prev: ArrayView2<f32>, fut: ArrayViewMut2<f32>);
fn h() -> &'static [f32];
}

View File

@ -1,7 +1,7 @@
use super::SbpOperator;
use ndarray::{arr1, arr2, s, ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2};
/// Simdtype used in diffy_simd
/// Simdtype used in diffeta_simd
type SimdT = packed_simd::f32x8;
pub struct Upwind4 {}
@ -149,7 +149,7 @@ impl Upwind4 {
}
#[inline(never)]
fn diffy_simd(prev: &[f32], fut: &mut [f32], nx: usize, ny: usize) {
fn diffeta_simd(prev: &[f32], fut: &mut [f32], nx: usize, ny: usize) {
assert!(ny >= 2 * Self::BLOCK.len());
assert!(nx >= SimdT::lanes());
assert!(nx % SimdT::lanes() == 0);
@ -271,7 +271,7 @@ impl Upwind4 {
}
impl SbpOperator for Upwind4 {
fn diffx(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) {
fn diffxi(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) {
assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[1] >= 2 * Self::BLOCK.len());
for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) {
@ -279,19 +279,19 @@ impl SbpOperator for Upwind4 {
}
}
fn diffy(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) {
fn diffeta(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) {
assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[0] >= 2 * Self::BLOCK.len());
let nx = prev.shape()[1];
let ny = prev.shape()[0];
if nx >= SimdT::lanes() && nx % SimdT::lanes() == 0 {
if let (Some(p), Some(f)) = (prev.as_slice(), fut.as_slice_mut()) {
Self::diffy_simd(p, f, nx, ny);
Self::diffeta_simd(p, f, nx, ny);
return;
}
}
// diffy = transpose then use diffx
Self::diffx(prev.reversed_axes(), fut.reversed_axes());
// diffeta = transpose then use diffxi
Self::diffxi(prev.reversed_axes(), fut.reversed_axes());
}
fn h() -> &'static [f32] {
@ -320,7 +320,7 @@ fn upwind4_test() {
let mut res = res.to_owned().insert_axis(ndarray::Axis(0));
let target = target.to_owned().insert_axis(ndarray::Axis(0));
res.fill(0.0);
Upwind4::diffx(source.view(), res.view_mut());
Upwind4::diffxi(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res, &target, epsilon = 1e-2);
}
@ -329,7 +329,7 @@ fn upwind4_test() {
let target = Array2::from_shape_fn((nx, 8), |(i, _)| target[i]);
let mut res = Array2::zeros((nx, 8));
res.fill(0.0);
Upwind4::diffy(source.view(), res.view_mut());
Upwind4::diffeta(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res.to_owned(), &target.to_owned(), epsilon = 1e-2);
}
@ -346,7 +346,7 @@ fn upwind4_test() {
let mut res = res.to_owned().insert_axis(ndarray::Axis(0));
let target = target.to_owned().insert_axis(ndarray::Axis(0));
res.fill(0.0);
Upwind4::diffx(source.view(), res.view_mut());
Upwind4::diffxi(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res, &target, epsilon = 1e-2);
}
@ -355,7 +355,7 @@ fn upwind4_test() {
let target = Array2::from_shape_fn((nx, 8), |(i, _)| target[i]);
let mut res = Array2::zeros((nx, 8));
res.fill(0.0);
Upwind4::diffy(source.view(), res.view_mut());
Upwind4::diffeta(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res.to_owned(), &target.to_owned(), epsilon = 1e-2);
}
@ -373,7 +373,7 @@ fn upwind4_test() {
let mut res = res.to_owned().insert_axis(ndarray::Axis(0));
let target = target.to_owned().insert_axis(ndarray::Axis(0));
res.fill(0.0);
Upwind4::diffx(source.view(), res.view_mut());
Upwind4::diffxi(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res, &target, epsilon = 1e-2);
}
@ -382,7 +382,7 @@ fn upwind4_test() {
let target = Array2::from_shape_fn((nx, 8), |(i, _)| target[i]);
let mut res = Array2::zeros((nx, 8));
res.fill(0.0);
Upwind4::diffy(source.view(), res.view_mut());
Upwind4::diffeta(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res.to_owned(), &target.to_owned(), epsilon = 1e-2);
}
}