use dynamic dispatch

This commit is contained in:
Magnus Ulimoen 2020-04-15 17:47:17 +02:00
parent 5068a6123c
commit 655d76f47d
2 changed files with 13 additions and 18 deletions

View File

@ -272,7 +272,7 @@ impl Field {
impl Field { impl Field {
/// sqrt((self-other)^T*H*(self-other)) /// sqrt((self-other)^T*H*(self-other))
pub fn h2_err<SBP: SbpOperator2d>(&self, other: &Self, op: &SBP) -> Float { pub fn h2_err(&self, other: &Self, op: &dyn SbpOperator2d) -> Float {
assert_eq!(self.nx(), other.nx()); assert_eq!(self.nx(), other.nx());
assert_eq!(self.ny(), other.ny()); assert_eq!(self.ny(), other.ny());
@ -406,8 +406,8 @@ fn pressure(gamma: Float, rho: Float, rhou: Float, rhov: Float, e: Float) -> Flo
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn RHS_trad<SBP: SbpOperator2d>( pub fn RHS_trad(
op: &SBP, op: &dyn SbpOperator2d,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -441,8 +441,8 @@ pub fn RHS_trad<SBP: SbpOperator2d>(
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn RHS_upwind<UO: UpwindOperator2d>( pub fn RHS_upwind(
op: &UO, op: &dyn UpwindOperator2d,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -478,12 +478,12 @@ pub fn RHS_upwind<UO: UpwindOperator2d>(
*out = (-eflux - fflux + ad_xi + ad_eta)/detj *out = (-eflux - fflux + ad_xi + ad_eta)/detj
}); });
SAT_characteristics(op, k, y, metrics, boundaries); SAT_characteristics(op.as_sbp(), k, y, metrics, boundaries);
} }
#[allow(clippy::many_single_char_names)] #[allow(clippy::many_single_char_names)]
fn upwind_dissipation<UO: UpwindOperator2d>( fn upwind_dissipation(
op: &UO, op: &dyn UpwindOperator2d,
k: (&mut Field, &mut Field), k: (&mut Field, &mut Field),
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -843,8 +843,8 @@ fn vortexify(
#[allow(non_snake_case)] #[allow(non_snake_case)]
/// Boundary conditions (SAT) /// Boundary conditions (SAT)
fn SAT_characteristics<SBP: SbpOperator2d>( fn SAT_characteristics(
op: &SBP, op: &dyn SbpOperator2d,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,

View File

@ -1,3 +1,4 @@
use super::operators::SbpOperator2d;
use crate::Float; use crate::Float;
use ndarray::Array2; use ndarray::Array2;
@ -36,10 +37,7 @@ impl Grid {
self.y.view() self.y.view()
} }
pub fn metrics<SBP: super::operators::SbpOperator2d>( pub fn metrics(&self, op: &dyn SbpOperator2d) -> Result<Metrics, ndarray::ShapeError> {
&self,
op: &SBP,
) -> Result<Metrics, ndarray::ShapeError> {
Metrics::new(self, op) Metrics::new(self, op)
} }
@ -70,10 +68,7 @@ impl Grid {
} }
impl Metrics { impl Metrics {
fn new<SBP: super::operators::SbpOperator2d>( fn new(grid: &Grid, op: &dyn SbpOperator2d) -> Result<Self, ndarray::ShapeError> {
grid: &Grid,
op: &SBP,
) -> Result<Self, ndarray::ShapeError> {
let ny = grid.ny(); let ny = grid.ny();
let nx = grid.nx(); let nx = grid.nx();
let x = &grid.x; let x = &grid.x;