add dyn cast to sbp

This commit is contained in:
Magnus Ulimoen 2020-04-15 17:36:45 +02:00
parent d089df6d54
commit 5068a6123c
5 changed files with 23 additions and 0 deletions

View File

@ -72,11 +72,13 @@ impl<SBP: SbpOperator1d + Copy> SbpOperator2d for SBP {
pub trait UpwindOperator1d: SbpOperator1d + Send + Sync {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>);
fn as_sbp(&self) -> &dyn SbpOperator1d;
}
pub trait UpwindOperator2d: SbpOperator2d + Send + Sync {
fn dissxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>);
fn disseta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>);
fn as_sbp(&self) -> &dyn SbpOperator2d;
}
impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (&UOeta, &UOxi) {
@ -90,6 +92,9 @@ impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (&UOe
let ba = (self.1, self.0);
ba.dissxi(prev.reversed_axes(), fut.reversed_axes())
}
fn as_sbp(&self) -> &dyn SbpOperator2d {
self
}
}
impl<UO: UpwindOperator1d + Copy> UpwindOperator2d for UO {
@ -99,6 +104,9 @@ impl<UO: UpwindOperator1d + Copy> UpwindOperator2d for UO {
fn disseta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) {
<(&UO, &UO) as UpwindOperator2d>::disseta(&(self, self), prev, fut)
}
fn as_sbp(&self) -> &dyn SbpOperator2d {
self
}
}
pub trait InterpolationOperator: Send + Sync {

View File

@ -413,6 +413,10 @@ impl UpwindOperator1d for Upwind4 {
fut,
)
}
fn as_sbp(&self) -> &dyn SbpOperator1d {
self
}
}
impl<SBP: UpwindOperator1d> UpwindOperator2d for (&Upwind4, &SBP) {

View File

@ -92,4 +92,8 @@ impl UpwindOperator1d for Upwind4h2 {
fut,
)
}
fn as_sbp(&self) -> &dyn SbpOperator1d {
self
}
}

View File

@ -72,6 +72,10 @@ impl UpwindOperator1d for Upwind9 {
fut,
)
}
fn as_sbp(&self) -> &dyn SbpOperator1d {
self
}
}
#[test]

View File

@ -100,4 +100,7 @@ impl UpwindOperator1d for Upwind9h2 {
fut,
)
}
fn as_sbp(&self) -> &dyn SbpOperator1d {
self
}
}