From ad6564eeb1581f65d4cb5bacfb66769ec9501037 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 15 Jun 2020 22:01:42 +0200 Subject: [PATCH] sparse upwind operators --- sbp/src/operators.rs | 20 ++++++++++++++++++++ sbp/src/operators/upwind4.rs | 11 +++++++++++ sbp/src/operators/upwind4h2.rs | 11 +++++++++++ sbp/src/operators/upwind9.rs | 11 +++++++++++ sbp/src/operators/upwind9h2.rs | 11 +++++++++++ 5 files changed, 64 insertions(+) diff --git a/sbp/src/operators.rs b/sbp/src/operators.rs index 2906c94..8479510 100644 --- a/sbp/src/operators.rs +++ b/sbp/src/operators.rs @@ -94,12 +94,18 @@ impl SbpOperator2d for SBP { pub trait UpwindOperator1d: SbpOperator1d + Send + Sync { fn diss(&self, prev: ArrayView1, fut: ArrayViewMut1); fn as_sbp(&self) -> &dyn SbpOperator1d; + + #[cfg(feature = "sparse")] + fn diss_matrix(&self, n: usize) -> sprs::CsMat; } pub trait UpwindOperator2d: SbpOperator2d + Send + Sync { fn dissxi(&self, prev: ArrayView2, fut: ArrayViewMut2); fn disseta(&self, prev: ArrayView2, fut: ArrayViewMut2); fn as_sbp(&self) -> &dyn SbpOperator2d; + + fn op_xi(&self) -> &dyn UpwindOperator1d; + fn op_eta(&self) -> &dyn UpwindOperator1d; } impl UpwindOperator2d for (&UOeta, &UOxi) { @@ -116,6 +122,13 @@ impl UpwindOperator2d for (&UOe fn as_sbp(&self) -> &dyn SbpOperator2d { self } + + fn op_xi(&self) -> &dyn UpwindOperator1d { + self.1 + } + fn op_eta(&self) -> &dyn UpwindOperator1d { + self.0 + } } impl UpwindOperator2d for UO { @@ -128,6 +141,13 @@ impl UpwindOperator2d for UO { fn as_sbp(&self) -> &dyn SbpOperator2d { self } + + fn op_xi(&self) -> &dyn UpwindOperator1d { + self + } + fn op_eta(&self) -> &dyn UpwindOperator1d { + self + } } pub trait InterpolationOperator: Send + Sync { diff --git a/sbp/src/operators/upwind4.rs b/sbp/src/operators/upwind4.rs index d943dfc..69fb97f 100644 --- a/sbp/src/operators/upwind4.rs +++ b/sbp/src/operators/upwind4.rs @@ -354,6 +354,17 @@ impl UpwindOperator1d for Upwind4 { fn as_sbp(&self) -> &dyn SbpOperator1d { self } + + #[cfg(feature = "sparse")] + fn diss_matrix(&self, n: usize) -> sprs::CsMat { + super::sparse_from_block( + Self::DISS_BLOCK, + Self::DISS_DIAG, + super::Symmetry::Symmetric, + super::OperatorType::Normal, + n, + ) + } } impl UpwindOperator2d for (&UO, &Upwind4) { diff --git a/sbp/src/operators/upwind4h2.rs b/sbp/src/operators/upwind4h2.rs index 5c6ee61..6346313 100644 --- a/sbp/src/operators/upwind4h2.rs +++ b/sbp/src/operators/upwind4h2.rs @@ -175,4 +175,15 @@ impl UpwindOperator1d for Upwind4h2 { fn as_sbp(&self) -> &dyn SbpOperator1d { self } + + #[cfg(feature = "sparse")] + fn diss_matrix(&self, n: usize) -> sprs::CsMat { + super::sparse_from_block( + Self::DISS_BLOCK, + Self::DISS_DIAG, + super::Symmetry::Symmetric, + super::OperatorType::H2, + n, + ) + } } diff --git a/sbp/src/operators/upwind9.rs b/sbp/src/operators/upwind9.rs index 62722b4..e4e473a 100644 --- a/sbp/src/operators/upwind9.rs +++ b/sbp/src/operators/upwind9.rs @@ -119,6 +119,17 @@ impl UpwindOperator1d for Upwind9 { fn as_sbp(&self) -> &dyn SbpOperator1d { self } + + #[cfg(feature = "sparse")] + fn diss_matrix(&self, n: usize) -> sprs::CsMat { + super::sparse_from_block( + Self::DISS_BLOCK, + Self::DISS_DIAG, + super::Symmetry::Symmetric, + super::OperatorType::Normal, + n, + ) + } } impl UpwindOperator2d for (&UO, &Upwind9) { diff --git a/sbp/src/operators/upwind9h2.rs b/sbp/src/operators/upwind9h2.rs index 15c3290..143af1f 100644 --- a/sbp/src/operators/upwind9h2.rs +++ b/sbp/src/operators/upwind9h2.rs @@ -146,6 +146,17 @@ impl UpwindOperator1d for Upwind9h2 { fn as_sbp(&self) -> &dyn SbpOperator1d { self } + + #[cfg(feature = "sparse")] + fn diss_matrix(&self, n: usize) -> sprs::CsMat { + super::sparse_from_block( + Self::DISS_BLOCK, + Self::DISS_DIAG, + super::Symmetry::Symmetric, + super::OperatorType::H2, + n, + ) + } } impl UpwindOperator2d for (&UO, &Upwind9h2) {