change sbp operators for dimensionality

This commit is contained in:
Magnus Ulimoen
2020-04-15 00:12:54 +02:00
parent 85f3c46430
commit 1667eaaca0
12 changed files with 230 additions and 162 deletions

View File

@@ -1,4 +1,4 @@
use super::SbpOperator;
use super::*;
use crate::Float;
use ndarray::{ArrayView1, ArrayViewMut1};
@@ -23,8 +23,8 @@ impl SBP4 {
];
}
impl SbpOperator for SBP4 {
fn diff1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl SbpOperator1d for SBP4 {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::BLOCK).view(),
ndarray::arr1(Self::DIAG).view(),

View File

@@ -1,4 +1,4 @@
use super::SbpOperator;
use super::*;
use crate::Float;
use ndarray::{ArrayView1, ArrayViewMut1};
@@ -27,8 +27,8 @@ impl SBP8 {
];
}
impl SbpOperator for SBP8 {
fn diff1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl SbpOperator1d for SBP8 {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::BLOCK).view(),
ndarray::arr1(Self::DIAG).view(),

View File

@@ -1,4 +1,4 @@
use super::{SbpOperator, UpwindOperator};
use super::*;
use crate::Float;
use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2, Axis};
@@ -275,8 +275,8 @@ impl Upwind4 {
];
}
impl SbpOperator for Upwind4 {
fn diff1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl SbpOperator1d for Upwind4 {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::BLOCK).view(),
ndarray::arr1(Self::DIAG).view(),
@@ -286,6 +286,12 @@ impl SbpOperator for Upwind4 {
fut,
)
}
fn h(&self) -> &'static [Float] {
Self::HBLOCK
}
}
/*
fn diffxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[1] >= 2 * Self::BLOCK.len());
@@ -307,10 +313,8 @@ impl SbpOperator for Upwind4 {
}
}
fn h(&self) -> &'static [Float] {
Self::HBLOCK
}
}
*/
#[test]
fn upwind4_test() {
@@ -326,7 +330,7 @@ fn upwind4_test() {
target[i] = 1.0;
}
res.fill(0.0);
Upwind4.diff1d(source.view(), res.view_mut());
Upwind4.diff(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res, &target, epsilon = 1e-4);
{
let source = source.to_owned().insert_axis(ndarray::Axis(0));
@@ -352,7 +356,7 @@ fn upwind4_test() {
target[i] = 2.0 * x;
}
res.fill(0.0);
Upwind4.diff1d(source.view(), res.view_mut());
Upwind4.diff(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res, &target, epsilon = 1e-4);
{
let source = source.to_owned().insert_axis(ndarray::Axis(0));
@@ -378,7 +382,7 @@ fn upwind4_test() {
target[i] = 3.0 * x * x;
}
res.fill(0.0);
Upwind4.diff1d(source.view(), res.view_mut());
Upwind4.diff(source.view(), res.view_mut());
approx::assert_abs_diff_eq!(&res, &target, epsilon = 1e-2);
{
@@ -400,8 +404,8 @@ fn upwind4_test() {
}
}
impl UpwindOperator for Upwind4 {
fn diss1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl UpwindOperator1d for Upwind4 {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::DISS_BLOCK).view(),
ndarray::arr1(Self::DISS_DIAG).view(),
@@ -411,6 +415,9 @@ impl UpwindOperator for Upwind4 {
fut,
)
}
}
/*
fn dissxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[1] >= 2 * Self::BLOCK.len());
@@ -432,6 +439,7 @@ impl UpwindOperator for Upwind4 {
}
}
}
*/
#[test]
fn upwind4_test2() {

View File

@@ -1,4 +1,4 @@
use super::{SbpOperator, UpwindOperator};
use super::*;
use crate::Float;
use ndarray::{ArrayView1, ArrayViewMut1};
@@ -36,8 +36,8 @@ impl Upwind4h2 {
];
}
impl SbpOperator for Upwind4h2 {
fn diff1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl SbpOperator1d for Upwind4h2 {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::BLOCK).view(),
ndarray::arr1(Self::DIAG).view(),
@@ -64,25 +64,25 @@ fn upwind4h2_test() {
let mut res = ndarray::Array1::zeros(nx);
Upwind4h2.diff1d(x.view(), res.view_mut());
Upwind4h2.diff(x.view(), res.view_mut());
let ans = &x * 0.0 + 1.0;
approx::assert_abs_diff_eq!(&res, &ans, epsilon = 1e-4);
res.fill(0.0);
let y = &x * &x / 2.0;
Upwind4h2.diff1d(y.view(), res.view_mut());
Upwind4h2.diff(y.view(), res.view_mut());
let ans = &x;
approx::assert_abs_diff_eq!(&res, &ans, epsilon = 1e-4);
res.fill(0.0);
let y = &x * &x * &x / 3.0;
Upwind4h2.diff1d(y.view(), res.view_mut());
Upwind4h2.diff(y.view(), res.view_mut());
let ans = &x * &x;
approx::assert_abs_diff_eq!(&res, &ans, epsilon = 1e-2);
}
impl UpwindOperator for Upwind4h2 {
fn diss1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl UpwindOperator1d for Upwind4h2 {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::DISS_BLOCK).view(),
ndarray::arr1(Self::DISS_DIAG).view(),

View File

@@ -1,4 +1,4 @@
use super::{SbpOperator, UpwindOperator};
use super::*;
use crate::Float;
use ndarray::{ArrayView1, ArrayViewMut1};
@@ -44,8 +44,8 @@ impl Upwind9 {
];
}
impl SbpOperator for Upwind9 {
fn diff1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl SbpOperator1d for Upwind9 {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::BLOCK).view(),
ndarray::arr1(Self::DIAG).view(),
@@ -61,8 +61,8 @@ impl SbpOperator for Upwind9 {
}
}
impl UpwindOperator for Upwind9 {
fn diss1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl UpwindOperator1d for Upwind9 {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::DISS_BLOCK).view(),
ndarray::arr1(Self::DISS_DIAG).view(),

View File

@@ -1,4 +1,4 @@
use super::{SbpOperator, UpwindOperator};
use super::*;
use crate::Float;
use ndarray::{ArrayView1, ArrayViewMut1};
@@ -44,8 +44,8 @@ impl Upwind9h2 {
];
}
impl SbpOperator for Upwind9h2 {
fn diff1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl SbpOperator1d for Upwind9h2 {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::BLOCK).view(),
ndarray::arr1(Self::DIAG).view(),
@@ -72,25 +72,25 @@ fn upwind9h2_test() {
let mut res = ndarray::Array1::zeros(nx);
Upwind9h2.diff1d(x.view(), res.view_mut());
Upwind9h2.diff(x.view(), res.view_mut());
let ans = &x * 0.0 + 1.0;
approx::assert_abs_diff_eq!(&res, &ans, epsilon = 1e-4);
res.fill(0.0);
let y = &x * &x / 2.0;
Upwind9h2.diff1d(y.view(), res.view_mut());
Upwind9h2.diff(y.view(), res.view_mut());
let ans = &x;
approx::assert_abs_diff_eq!(&res, &ans, epsilon = 1e-4);
res.fill(0.0);
let y = &x * &x * &x / 3.0;
Upwind9h2.diff1d(y.view(), res.view_mut());
Upwind9h2.diff(y.view(), res.view_mut());
let ans = &x * &x;
approx::assert_abs_diff_eq!(&res, &ans, epsilon = 1e-2);
}
impl UpwindOperator for Upwind9h2 {
fn diss1d(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
impl UpwindOperator1d for Upwind9h2 {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>) {
super::diff_op_1d(
ndarray::arr2(Self::DISS_BLOCK).view(),
ndarray::arr1(Self::DISS_DIAG).view(),