change macro to inlined func
This commit is contained in:
parent
59c8509a98
commit
a9e4a7e0cc
|
@ -37,59 +37,54 @@ pub trait InterpolationOperator: Send + Sync {
|
||||||
fn coarse2fine(coarse: ArrayView1<Float>, fine: ArrayViewMut1<Float>);
|
fn coarse2fine(coarse: ArrayView1<Float>, fine: ArrayViewMut1<Float>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[inline(always)]
|
||||||
macro_rules! diff_op_1d {
|
pub(crate) fn diff_op_1d(
|
||||||
($name: ident, $BLOCK: expr, $DIAG: expr) => {
|
block: ndarray::ArrayView2<Float>,
|
||||||
diff_op_1d!($name, $BLOCK, $DIAG, false);
|
diag: ndarray::ArrayView1<Float>,
|
||||||
};
|
symmetric: bool,
|
||||||
($name: ident, $BLOCK: expr, $DIAG: expr, $symmetric: expr) => {
|
prev: ArrayView1<Float>,
|
||||||
fn $name(prev: ArrayView1<Float>, mut fut: ArrayViewMut1<Float>) {
|
mut fut: ArrayViewMut1<Float>,
|
||||||
assert_eq!(prev.shape(), fut.shape());
|
) {
|
||||||
let nx = prev.shape()[0];
|
assert_eq!(prev.shape(), fut.shape());
|
||||||
assert!(nx >= 2 * $BLOCK.len());
|
let nx = prev.shape()[0];
|
||||||
|
assert!(nx >= 2 * block.len_of(ndarray::Axis(0)));
|
||||||
|
|
||||||
let dx = 1.0 / (nx - 1) as Float;
|
let dx = 1.0 / (nx - 1) as Float;
|
||||||
let idx = 1.0 / dx;
|
let idx = 1.0 / dx;
|
||||||
|
|
||||||
let block = ::ndarray::arr2($BLOCK);
|
let first_elems = prev.slice(::ndarray::s!(..block.len_of(::ndarray::Axis(1))));
|
||||||
let diag = ::ndarray::arr1($DIAG);
|
for (bl, f) in block.outer_iter().zip(&mut fut) {
|
||||||
|
let diff = first_elems.dot(&bl);
|
||||||
|
*f = diff * idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The window needs to be aligned to the diagonal elements,
|
||||||
|
// based on the block size
|
||||||
|
let window_elems_to_skip = block.len_of(::ndarray::Axis(0)) - ((diag.len() - 1) / 2);
|
||||||
|
|
||||||
let first_elems = prev.slice(::ndarray::s!(..block.len_of(::ndarray::Axis(1))));
|
for (window, f) in prev
|
||||||
for (bl, f) in block.outer_iter().zip(&mut fut) {
|
.windows(diag.len())
|
||||||
let diff = first_elems.dot(&bl);
|
.into_iter()
|
||||||
*f = diff * idx;
|
.skip(window_elems_to_skip)
|
||||||
}
|
.zip(fut.iter_mut().skip(block.len_of(::ndarray::Axis(0))))
|
||||||
|
.take(nx - 2 * block.len_of(::ndarray::Axis(0)))
|
||||||
|
{
|
||||||
|
let diff = diag.dot(&window);
|
||||||
|
*f = diff * idx;
|
||||||
|
}
|
||||||
|
|
||||||
// The window needs to be aligned to the diagonal elements,
|
let last_elems = prev.slice(::ndarray::s!(nx - block.len_of(::ndarray::Axis(1))..;-1));
|
||||||
// based on the block size
|
for (bl, f) in block
|
||||||
let window_elems_to_skip =
|
.outer_iter()
|
||||||
block.len_of(::ndarray::Axis(0)) - ((diag.len() - 1) / 2);
|
.zip(&mut fut.slice_mut(::ndarray::s![nx - block.len_of(::ndarray::Axis(0))..;-1]))
|
||||||
|
{
|
||||||
for (window, f) in prev
|
let diff = if symmetric {
|
||||||
.windows(diag.len())
|
bl.dot(&last_elems)
|
||||||
.into_iter()
|
} else {
|
||||||
.skip(window_elems_to_skip)
|
-bl.dot(&last_elems)
|
||||||
.zip(fut.iter_mut().skip(block.len_of(::ndarray::Axis(0))))
|
};
|
||||||
.take(nx - 2 * block.len_of(::ndarray::Axis(0)))
|
*f = diff * idx;
|
||||||
{
|
}
|
||||||
let diff = diag.dot(&window);
|
|
||||||
*f = diff * idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
let last_elems = prev.slice(::ndarray::s!(nx - block.len_of(::ndarray::Axis(1))..;-1));
|
|
||||||
for (bl, f) in block.outer_iter()
|
|
||||||
.zip(&mut fut.slice_mut(s![nx - block.len_of(::ndarray::Axis(0))..;-1]))
|
|
||||||
{
|
|
||||||
let diff = if $symmetric {
|
|
||||||
bl.dot(&last_elems)
|
|
||||||
} else {
|
|
||||||
-bl.dot(&last_elems)
|
|
||||||
};
|
|
||||||
*f = diff * idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod upwind4;
|
mod upwind4;
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
use super::SbpOperator;
|
use super::SbpOperator;
|
||||||
use crate::diff_op_1d;
|
|
||||||
use crate::Float;
|
use crate::Float;
|
||||||
use ndarray::{s, ArrayView1, ArrayViewMut1};
|
use ndarray::{ArrayView1, ArrayViewMut1};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SBP4 {}
|
pub struct SBP4 {}
|
||||||
|
|
||||||
diff_op_1d!(diff_1d, SBP4::BLOCK, SBP4::DIAG);
|
|
||||||
|
|
||||||
impl SBP4 {
|
impl SBP4 {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const HBLOCK: &'static [Float] = &[
|
const HBLOCK: &'static [Float] = &[
|
||||||
|
@ -28,7 +25,13 @@ impl SBP4 {
|
||||||
|
|
||||||
impl SbpOperator for SBP4 {
|
impl SbpOperator for SBP4 {
|
||||||
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
||||||
diff_1d(prev, fut)
|
super::diff_op_1d(
|
||||||
|
ndarray::arr2(Self::BLOCK).view(),
|
||||||
|
ndarray::arr1(Self::DIAG).view(),
|
||||||
|
false,
|
||||||
|
prev,
|
||||||
|
fut,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h() -> &'static [Float] {
|
fn h() -> &'static [Float] {
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
use super::SbpOperator;
|
use super::SbpOperator;
|
||||||
use crate::diff_op_1d;
|
|
||||||
use crate::Float;
|
use crate::Float;
|
||||||
use ndarray::{s, ArrayView1, ArrayViewMut1};
|
use ndarray::{ArrayView1, ArrayViewMut1};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SBP8 {}
|
pub struct SBP8 {}
|
||||||
|
|
||||||
diff_op_1d!(diff_1d, SBP8::BLOCK, SBP8::DIAG);
|
|
||||||
|
|
||||||
impl SBP8 {
|
impl SBP8 {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const HBLOCK: &'static [Float] = &[
|
const HBLOCK: &'static [Float] = &[
|
||||||
|
@ -32,7 +29,13 @@ impl SBP8 {
|
||||||
|
|
||||||
impl SbpOperator for SBP8 {
|
impl SbpOperator for SBP8 {
|
||||||
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
||||||
diff_1d(prev, fut)
|
super::diff_op_1d(
|
||||||
|
ndarray::arr2(Self::BLOCK).view(),
|
||||||
|
ndarray::arr1(Self::DIAG).view(),
|
||||||
|
false,
|
||||||
|
prev,
|
||||||
|
fut,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h() -> &'static [Float] {
|
fn h() -> &'static [Float] {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use super::{SbpOperator, UpwindOperator};
|
use super::{SbpOperator, UpwindOperator};
|
||||||
use crate::diff_op_1d;
|
|
||||||
use crate::Float;
|
use crate::Float;
|
||||||
use ndarray::{s, ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2, Axis};
|
use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2, Axis};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Upwind4 {}
|
pub struct Upwind4 {}
|
||||||
|
@ -12,9 +11,6 @@ type SimdT = packed_simd::f32x8;
|
||||||
#[cfg(not(feature = "f32"))]
|
#[cfg(not(feature = "f32"))]
|
||||||
type SimdT = packed_simd::f64x8;
|
type SimdT = packed_simd::f64x8;
|
||||||
|
|
||||||
diff_op_1d!(diff_1d, Upwind4::BLOCK, Upwind4::DIAG);
|
|
||||||
diff_op_1d!(diss_1d, Upwind4::DISS_BLOCK, Upwind4::DISS_DIAG, true);
|
|
||||||
|
|
||||||
macro_rules! diff_simd_row_7_47 {
|
macro_rules! diff_simd_row_7_47 {
|
||||||
($name: ident, $BLOCK: expr, $DIAG: expr, $symmetric: expr) => {
|
($name: ident, $BLOCK: expr, $DIAG: expr, $symmetric: expr) => {
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
@ -281,7 +277,13 @@ impl Upwind4 {
|
||||||
|
|
||||||
impl SbpOperator for Upwind4 {
|
impl SbpOperator for Upwind4 {
|
||||||
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
||||||
diff_1d(prev, fut)
|
super::diff_op_1d(
|
||||||
|
ndarray::arr2(Self::BLOCK).view(),
|
||||||
|
ndarray::arr1(Self::DIAG).view(),
|
||||||
|
false,
|
||||||
|
prev,
|
||||||
|
fut,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fn diffxi(prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
|
fn diffxi(prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
|
||||||
assert_eq!(prev.shape(), fut.shape());
|
assert_eq!(prev.shape(), fut.shape());
|
||||||
|
@ -399,7 +401,13 @@ fn upwind4_test() {
|
||||||
|
|
||||||
impl UpwindOperator for Upwind4 {
|
impl UpwindOperator for Upwind4 {
|
||||||
fn diss1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
fn diss1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
||||||
diss_1d(prev, fut)
|
super::diff_op_1d(
|
||||||
|
ndarray::arr2(Self::DISS_BLOCK).view(),
|
||||||
|
ndarray::arr1(Self::DISS_DIAG).view(),
|
||||||
|
true,
|
||||||
|
prev,
|
||||||
|
fut,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fn dissxi(prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
|
fn dissxi(prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
|
||||||
assert_eq!(prev.shape(), fut.shape());
|
assert_eq!(prev.shape(), fut.shape());
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
use super::{SbpOperator, UpwindOperator};
|
use super::{SbpOperator, UpwindOperator};
|
||||||
use crate::diff_op_1d;
|
|
||||||
use crate::Float;
|
use crate::Float;
|
||||||
use ndarray::{s, ArrayView1, ArrayViewMut1};
|
use ndarray::{ArrayView1, ArrayViewMut1};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Upwind9 {}
|
pub struct Upwind9 {}
|
||||||
|
|
||||||
diff_op_1d!(diff_1d, Upwind9::BLOCK, Upwind9::DIAG);
|
|
||||||
diff_op_1d!(diss_1d, Upwind9::DISS_BLOCK, Upwind9::DISS_DIAG, true);
|
|
||||||
|
|
||||||
impl Upwind9 {
|
impl Upwind9 {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const HBLOCK: &'static [Float] = &[
|
const HBLOCK: &'static [Float] = &[
|
||||||
|
@ -50,7 +46,13 @@ impl Upwind9 {
|
||||||
|
|
||||||
impl SbpOperator for Upwind9 {
|
impl SbpOperator for Upwind9 {
|
||||||
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
fn diff1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
||||||
diff_1d(prev, fut)
|
super::diff_op_1d(
|
||||||
|
ndarray::arr2(Self::BLOCK).view(),
|
||||||
|
ndarray::arr1(Self::DIAG).view(),
|
||||||
|
false,
|
||||||
|
prev,
|
||||||
|
fut,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h() -> &'static [Float] {
|
fn h() -> &'static [Float] {
|
||||||
|
@ -60,7 +62,13 @@ impl SbpOperator for Upwind9 {
|
||||||
|
|
||||||
impl UpwindOperator for Upwind9 {
|
impl UpwindOperator for Upwind9 {
|
||||||
fn diss1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
fn diss1d(prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
|
||||||
diss_1d(prev, fut)
|
super::diff_op_1d(
|
||||||
|
ndarray::arr2(Self::DISS_BLOCK).view(),
|
||||||
|
ndarray::arr1(Self::DISS_DIAG).view(),
|
||||||
|
true,
|
||||||
|
prev,
|
||||||
|
fut,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue