sparse upwind operators

This commit is contained in:
Magnus Ulimoen 2020-06-15 22:01:42 +02:00
parent 9e22f239c2
commit ad6564eeb1
5 changed files with 64 additions and 0 deletions

View File

@ -94,12 +94,18 @@ impl<SBP: SbpOperator1d + Copy> SbpOperator2d for SBP {
pub trait UpwindOperator1d: SbpOperator1d + Send + Sync { pub trait UpwindOperator1d: SbpOperator1d + Send + Sync {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>); fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>);
fn as_sbp(&self) -> &dyn SbpOperator1d; fn as_sbp(&self) -> &dyn SbpOperator1d;
#[cfg(feature = "sparse")]
fn diss_matrix(&self, n: usize) -> sprs::CsMat<Float>;
} }
pub trait UpwindOperator2d: SbpOperator2d + Send + Sync { pub trait UpwindOperator2d: SbpOperator2d + Send + Sync {
fn dissxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>); fn dissxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>);
fn disseta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>); fn disseta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>);
fn as_sbp(&self) -> &dyn SbpOperator2d; fn as_sbp(&self) -> &dyn SbpOperator2d;
fn op_xi(&self) -> &dyn UpwindOperator1d;
fn op_eta(&self) -> &dyn UpwindOperator1d;
} }
impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (&UOeta, &UOxi) { impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (&UOeta, &UOxi) {
@ -116,6 +122,13 @@ impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (&UOe
fn as_sbp(&self) -> &dyn SbpOperator2d { fn as_sbp(&self) -> &dyn SbpOperator2d {
self self
} }
fn op_xi(&self) -> &dyn UpwindOperator1d {
self.1
}
fn op_eta(&self) -> &dyn UpwindOperator1d {
self.0
}
} }
impl<UO: UpwindOperator1d + Copy> UpwindOperator2d for UO { impl<UO: UpwindOperator1d + Copy> UpwindOperator2d for UO {
@ -128,6 +141,13 @@ impl<UO: UpwindOperator1d + Copy> UpwindOperator2d for UO {
fn as_sbp(&self) -> &dyn SbpOperator2d { fn as_sbp(&self) -> &dyn SbpOperator2d {
self self
} }
fn op_xi(&self) -> &dyn UpwindOperator1d {
self
}
fn op_eta(&self) -> &dyn UpwindOperator1d {
self
}
} }
pub trait InterpolationOperator: Send + Sync { pub trait InterpolationOperator: Send + Sync {

View File

@ -354,6 +354,17 @@ impl UpwindOperator1d for Upwind4 {
fn as_sbp(&self) -> &dyn SbpOperator1d { fn as_sbp(&self) -> &dyn SbpOperator1d {
self self
} }
#[cfg(feature = "sparse")]
fn diss_matrix(&self, n: usize) -> sprs::CsMat<Float> {
super::sparse_from_block(
Self::DISS_BLOCK,
Self::DISS_DIAG,
super::Symmetry::Symmetric,
super::OperatorType::Normal,
n,
)
}
} }
impl<UO: UpwindOperator1d> UpwindOperator2d for (&UO, &Upwind4) { impl<UO: UpwindOperator1d> UpwindOperator2d for (&UO, &Upwind4) {

View File

@ -175,4 +175,15 @@ impl UpwindOperator1d for Upwind4h2 {
fn as_sbp(&self) -> &dyn SbpOperator1d { fn as_sbp(&self) -> &dyn SbpOperator1d {
self self
} }
#[cfg(feature = "sparse")]
fn diss_matrix(&self, n: usize) -> sprs::CsMat<Float> {
super::sparse_from_block(
Self::DISS_BLOCK,
Self::DISS_DIAG,
super::Symmetry::Symmetric,
super::OperatorType::H2,
n,
)
}
} }

View File

@ -119,6 +119,17 @@ impl UpwindOperator1d for Upwind9 {
fn as_sbp(&self) -> &dyn SbpOperator1d { fn as_sbp(&self) -> &dyn SbpOperator1d {
self self
} }
#[cfg(feature = "sparse")]
fn diss_matrix(&self, n: usize) -> sprs::CsMat<Float> {
super::sparse_from_block(
Self::DISS_BLOCK,
Self::DISS_DIAG,
super::Symmetry::Symmetric,
super::OperatorType::Normal,
n,
)
}
} }
impl<UO: UpwindOperator1d> UpwindOperator2d for (&UO, &Upwind9) { impl<UO: UpwindOperator1d> UpwindOperator2d for (&UO, &Upwind9) {

View File

@ -146,6 +146,17 @@ impl UpwindOperator1d for Upwind9h2 {
fn as_sbp(&self) -> &dyn SbpOperator1d { fn as_sbp(&self) -> &dyn SbpOperator1d {
self self
} }
#[cfg(feature = "sparse")]
fn diss_matrix(&self, n: usize) -> sprs::CsMat<Float> {
super::sparse_from_block(
Self::DISS_BLOCK,
Self::DISS_DIAG,
super::Symmetry::Symmetric,
super::OperatorType::H2,
n,
)
}
} }
impl<UO: UpwindOperator1d> UpwindOperator2d for (&UO, &Upwind9h2) { impl<UO: UpwindOperator1d> UpwindOperator2d for (&UO, &Upwind9h2) {