change trait signaturs

This commit is contained in:
Magnus Ulimoen 2020-04-15 17:17:48 +02:00
parent 6df4632719
commit d089df6d54
5 changed files with 40 additions and 40 deletions

View File

@ -23,7 +23,7 @@ impl<SBP: SbpOperator2d> System<SBP> {
let grid = Grid::new(x, y).expect( let grid = Grid::new(x, y).expect(
"Could not create grid. Different number of elements compared to width*height?", "Could not create grid. Different number of elements compared to width*height?",
); );
let metrics = grid.metrics(op).unwrap(); let metrics = grid.metrics(&op).unwrap();
let nx = grid.nx(); let nx = grid.nx();
let ny = grid.ny(); let ny = grid.ny();
Self { Self {
@ -47,7 +47,7 @@ impl<SBP: SbpOperator2d> System<SBP> {
east: BoundaryCharacteristic::This, east: BoundaryCharacteristic::This,
west: BoundaryCharacteristic::This, west: BoundaryCharacteristic::This,
}; };
let op = self.op; let op = &self.op;
let rhs_trad = |k: &mut Field, y: &Field, _time: Float, gm: &(_, _), wb: &mut _| { let rhs_trad = |k: &mut Field, y: &Field, _time: Float, gm: &(_, _), wb: &mut _| {
let (grid, metrics) = gm; let (grid, metrics) = gm;
let boundaries = boundary_extractor(y, grid, &bc); let boundaries = boundary_extractor(y, grid, &bc);
@ -108,7 +108,7 @@ impl<UO: UpwindOperator2d> System<UO> {
east: BoundaryCharacteristic::This, east: BoundaryCharacteristic::This,
west: BoundaryCharacteristic::This, west: BoundaryCharacteristic::This,
}; };
let op = self.op; let op = &self.op;
let rhs_upwind = |k: &mut Field, y: &Field, _time: Float, gm: &(_, _), wb: &mut _| { let rhs_upwind = |k: &mut Field, y: &Field, _time: Float, gm: &(_, _), wb: &mut _| {
let (grid, metrics) = gm; let (grid, metrics) = gm;
let boundaries = boundary_extractor(y, grid, &bc); let boundaries = boundary_extractor(y, grid, &bc);
@ -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, op: SBP, other: &Self) -> Float { pub fn h2_err<SBP: SbpOperator2d>(&self, other: &Self, op: &SBP) -> 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());
@ -339,10 +339,10 @@ fn h2_diff() {
use super::operators::{Upwind4, Upwind9, SBP4, SBP8}; use super::operators::{Upwind4, Upwind9, SBP4, SBP8};
assert!((field0.h2_err((Upwind4, Upwind4), &field1).powi(2) - 4.0).abs() < 1e-3); assert!((field0.h2_err(&field1, &Upwind4).powi(2) - 4.0).abs() < 1e-3);
assert!((field0.h2_err((Upwind9, Upwind9), &field1).powi(2) - 4.0).abs() < 1e-3); assert!((field0.h2_err(&field1, &Upwind9).powi(2) - 4.0).abs() < 1e-3);
assert!((field0.h2_err((SBP4, SBP4), &field1).powi(2) - 4.0).abs() < 1e-3); assert!((field0.h2_err(&field1, &SBP4).powi(2) - 4.0).abs() < 1e-3);
assert!((field0.h2_err((SBP8, SBP8), &field1).powi(2) - 4.0).abs() < 1e-3); assert!((field0.h2_err(&field1, &SBP8).powi(2) - 4.0).abs() < 1e-3);
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -407,7 +407,7 @@ 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<SBP: SbpOperator2d>(
op: SBP, op: &SBP,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -442,7 +442,7 @@ pub fn RHS_trad<SBP: SbpOperator2d>(
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn RHS_upwind<UO: UpwindOperator2d>( pub fn RHS_upwind<UO: UpwindOperator2d>(
op: UO, op: &UO,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -483,7 +483,7 @@ pub fn RHS_upwind<UO: UpwindOperator2d>(
#[allow(clippy::many_single_char_names)] #[allow(clippy::many_single_char_names)]
fn upwind_dissipation<UO: UpwindOperator2d>( fn upwind_dissipation<UO: UpwindOperator2d>(
op: UO, op: &UO,
k: (&mut Field, &mut Field), k: (&mut Field, &mut Field),
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -844,7 +844,7 @@ fn vortexify(
#[allow(non_snake_case)] #[allow(non_snake_case)]
/// Boundary conditions (SAT) /// Boundary conditions (SAT)
fn SAT_characteristics<SBP: SbpOperator2d>( fn SAT_characteristics<SBP: SbpOperator2d>(
op: SBP, op: &SBP,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,

View File

@ -38,7 +38,7 @@ impl Grid {
pub fn metrics<SBP: super::operators::SbpOperator2d>( pub fn metrics<SBP: super::operators::SbpOperator2d>(
&self, &self,
op: SBP, op: &SBP,
) -> Result<Metrics, ndarray::ShapeError> { ) -> Result<Metrics, ndarray::ShapeError> {
Metrics::new(self, op) Metrics::new(self, op)
} }
@ -72,7 +72,7 @@ impl Grid {
impl Metrics { impl Metrics {
fn new<SBP: super::operators::SbpOperator2d>( fn new<SBP: super::operators::SbpOperator2d>(
grid: &Grid, grid: &Grid,
op: SBP, op: &SBP,
) -> Result<Self, ndarray::ShapeError> { ) -> Result<Self, ndarray::ShapeError> {
let ny = grid.ny(); let ny = grid.ny();
let nx = grid.nx(); let nx = grid.nx();

View File

@ -89,7 +89,7 @@ impl<SBP: SbpOperator2d> System<SBP> {
let nx = x.shape()[1]; let nx = x.shape()[1];
let grid = Grid::new(x, y).unwrap(); let grid = Grid::new(x, y).unwrap();
let metrics = grid.metrics(op).unwrap(); let metrics = grid.metrics(&op).unwrap();
Self { Self {
op, op,
@ -117,7 +117,7 @@ impl<SBP: SbpOperator2d> System<SBP> {
} }
pub fn advance(&mut self, dt: Float) { pub fn advance(&mut self, dt: Float) {
let op = self.op; let op = &self.op;
let rhs_adaptor = move |fut: &mut Field, let rhs_adaptor = move |fut: &mut Field,
prev: &Field, prev: &Field,
_time: Float, _time: Float,
@ -149,7 +149,7 @@ impl<SBP: SbpOperator2d> System<SBP> {
impl<UO: UpwindOperator2d> System<UO> { impl<UO: UpwindOperator2d> System<UO> {
/// Using artificial dissipation with the upwind operator /// Using artificial dissipation with the upwind operator
pub fn advance_upwind(&mut self, dt: Float) { pub fn advance_upwind(&mut self, dt: Float) {
let op = self.op; let op = &self.op;
let rhs_adaptor = move |fut: &mut Field, let rhs_adaptor = move |fut: &mut Field,
prev: &Field, prev: &Field,
_time: Float, _time: Float,
@ -206,7 +206,7 @@ fn gaussian(x: Float, x0: Float, y: Float, y0: Float) -> Float {
/// ///
/// This is used both in fluxes and SAT terms /// This is used both in fluxes and SAT terms
fn RHS<SBP: SbpOperator2d>( fn RHS<SBP: SbpOperator2d>(
op: SBP, op: &SBP,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
_grid: &Grid, _grid: &Grid,
@ -231,7 +231,7 @@ fn RHS<SBP: SbpOperator2d>(
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn RHS_upwind<UO: UpwindOperator2d>( fn RHS_upwind<UO: UpwindOperator2d>(
op: UO, op: &UO,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
_grid: &Grid, _grid: &Grid,
@ -256,7 +256,7 @@ fn RHS_upwind<UO: UpwindOperator2d>(
} }
fn fluxes<SBP: super::operators::SbpOperator2d>( fn fluxes<SBP: super::operators::SbpOperator2d>(
op: SBP, op: &SBP,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -331,7 +331,7 @@ fn fluxes<SBP: super::operators::SbpOperator2d>(
} }
fn dissipation<UO: UpwindOperator2d>( fn dissipation<UO: UpwindOperator2d>(
op: UO, op: &UO,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,
@ -433,7 +433,7 @@ pub struct BoundaryTerms {
#[allow(non_snake_case)] #[allow(non_snake_case)]
/// Boundary conditions (SAT) /// Boundary conditions (SAT)
fn SAT_characteristics<SBP: SbpOperator2d>( fn SAT_characteristics<SBP: SbpOperator2d>(
op: SBP, op: &SBP,
k: &mut Field, k: &mut Field,
y: &Field, y: &Field,
metrics: &Metrics, metrics: &Metrics,

View File

@ -4,7 +4,7 @@
use crate::Float; use crate::Float;
use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2}; use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2};
pub trait SbpOperator1d: Copy + Clone + core::fmt::Debug { pub trait SbpOperator1d: Send + Sync {
fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>); fn diff(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>);
fn h(&self) -> &'static [Float]; fn h(&self) -> &'static [Float];
@ -13,7 +13,7 @@ pub trait SbpOperator1d: Copy + Clone + core::fmt::Debug {
} }
} }
pub trait SbpOperator2d: Copy + Clone { pub trait SbpOperator2d: Send + Sync {
fn diffxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>); fn diffxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>);
fn diffeta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>); fn diffeta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>);
@ -24,7 +24,7 @@ pub trait SbpOperator2d: Copy + Clone {
fn is_h2eta(&self) -> bool; fn is_h2eta(&self) -> bool;
} }
impl<SBPeta: SbpOperator1d, SBPxi: SbpOperator1d> SbpOperator2d for (SBPeta, SBPxi) { impl<SBPeta: SbpOperator1d, SBPxi: SbpOperator1d> SbpOperator2d for (&SBPeta, &SBPxi) {
default fn diffxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) { default fn diffxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
assert_eq!(prev.shape(), fut.shape()); assert_eq!(prev.shape(), fut.shape());
for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) { for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) {
@ -49,37 +49,37 @@ impl<SBPeta: SbpOperator1d, SBPxi: SbpOperator1d> SbpOperator2d for (SBPeta, SBP
} }
} }
impl<SBP: SbpOperator1d> SbpOperator2d for SBP { impl<SBP: SbpOperator1d + Copy> SbpOperator2d for SBP {
fn diffxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) { fn diffxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) {
<(SBP, SBP) as SbpOperator2d>::diffxi(&(*self, *self), prev, fut) <(&SBP, &SBP) as SbpOperator2d>::diffxi(&(self, self), prev, fut)
} }
fn diffeta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) { fn diffeta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) {
<(SBP, SBP) as SbpOperator2d>::diffeta(&(*self, *self), prev, fut) <(&SBP, &SBP) as SbpOperator2d>::diffeta(&(self, self), prev, fut)
} }
fn hxi(&self) -> &'static [Float] { fn hxi(&self) -> &'static [Float] {
<(SBP, SBP) as SbpOperator2d>::hxi(&(*self, *self)) <(&SBP, &SBP) as SbpOperator2d>::hxi(&(self, self))
} }
fn heta(&self) -> &'static [Float] { fn heta(&self) -> &'static [Float] {
<(SBP, SBP) as SbpOperator2d>::heta(&(*self, *self)) <(&SBP, &SBP) as SbpOperator2d>::heta(&(self, self))
} }
fn is_h2xi(&self) -> bool { fn is_h2xi(&self) -> bool {
<(SBP, SBP) as SbpOperator2d>::is_h2xi(&(*self, *self)) <(&SBP, &SBP) as SbpOperator2d>::is_h2xi(&(self, self))
} }
fn is_h2eta(&self) -> bool { fn is_h2eta(&self) -> bool {
<(SBP, SBP) as SbpOperator2d>::is_h2eta(&(*self, *self)) <(&SBP, &SBP) as SbpOperator2d>::is_h2eta(&(self, self))
} }
} }
pub trait UpwindOperator1d: SbpOperator1d + Copy + Clone { pub trait UpwindOperator1d: SbpOperator1d + Send + Sync {
fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>); fn diss(&self, prev: ArrayView1<Float>, fut: ArrayViewMut1<Float>);
} }
pub trait UpwindOperator2d: SbpOperator2d + Copy + Clone { 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>);
} }
impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (UOeta, UOxi) { impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (&UOeta, &UOxi) {
default fn dissxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) { default fn dissxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
assert_eq!(prev.shape(), fut.shape()); assert_eq!(prev.shape(), fut.shape());
for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) { for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) {
@ -92,12 +92,12 @@ impl<UOeta: UpwindOperator1d, UOxi: UpwindOperator1d> UpwindOperator2d for (UOet
} }
} }
impl<UO: UpwindOperator1d> UpwindOperator2d for UO { impl<UO: UpwindOperator1d + Copy> UpwindOperator2d for UO {
fn dissxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) { fn dissxi(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) {
<(UO, UO) as UpwindOperator2d>::dissxi(&(*self, *self), prev, fut) <(&UO, &UO) as UpwindOperator2d>::dissxi(&(self, self), prev, fut)
} }
fn disseta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) { fn disseta(&self, prev: ArrayView2<Float>, fut: ArrayViewMut2<Float>) {
<(UO, UO) as UpwindOperator2d>::disseta(&(*self, *self), prev, fut) <(&UO, &UO) as UpwindOperator2d>::disseta(&(self, self), prev, fut)
} }
} }

View File

@ -291,7 +291,7 @@ impl SbpOperator1d for Upwind4 {
} }
} }
impl<SBP: SbpOperator1d> SbpOperator2d for (Upwind4, SBP) { impl<SBP: SbpOperator1d> SbpOperator2d for (&Upwind4, &SBP) {
fn diffxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) { fn diffxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
assert_eq!(prev.shape(), fut.shape()); assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[1] >= 2 * Upwind4::BLOCK.len()); assert!(prev.shape()[1] >= 2 * Upwind4::BLOCK.len());
@ -415,7 +415,7 @@ impl UpwindOperator1d for Upwind4 {
} }
} }
impl<SBP: UpwindOperator1d> UpwindOperator2d for (Upwind4, SBP) { impl<SBP: UpwindOperator1d> UpwindOperator2d for (&Upwind4, &SBP) {
fn dissxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) { fn dissxi(&self, prev: ArrayView2<Float>, mut fut: ArrayViewMut2<Float>) {
assert_eq!(prev.shape(), fut.shape()); assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[1] >= 2 * Upwind4::BLOCK.len()); assert!(prev.shape()[1] >= 2 * Upwind4::BLOCK.len());