From d089df6d54dcf10f66665d82aca84154bfad4f3a Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 15 Apr 2020 17:17:48 +0200 Subject: [PATCH] change trait signaturs --- sbp/src/euler.rs | 24 ++++++++++++------------ sbp/src/grid.rs | 4 ++-- sbp/src/maxwell.rs | 16 ++++++++-------- sbp/src/operators.rs | 32 ++++++++++++++++---------------- sbp/src/operators/upwind4.rs | 4 ++-- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/sbp/src/euler.rs b/sbp/src/euler.rs index a1be52c..70b527d 100644 --- a/sbp/src/euler.rs +++ b/sbp/src/euler.rs @@ -23,7 +23,7 @@ impl System { let grid = Grid::new(x, y).expect( "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 ny = grid.ny(); Self { @@ -47,7 +47,7 @@ impl System { east: 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 (grid, metrics) = gm; let boundaries = boundary_extractor(y, grid, &bc); @@ -108,7 +108,7 @@ impl System { east: 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 (grid, metrics) = gm; let boundaries = boundary_extractor(y, grid, &bc); @@ -272,7 +272,7 @@ impl Field { impl Field { /// sqrt((self-other)^T*H*(self-other)) - pub fn h2_err(&self, op: SBP, other: &Self) -> Float { + pub fn h2_err(&self, other: &Self, op: &SBP) -> Float { assert_eq!(self.nx(), other.nx()); assert_eq!(self.ny(), other.ny()); @@ -339,10 +339,10 @@ fn h2_diff() { 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((Upwind9, Upwind9), &field1).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((SBP8, SBP8), &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(&field1, &Upwind9).powi(2) - 4.0).abs() < 1e-3); + assert!((field0.h2_err(&field1, &SBP4).powi(2) - 4.0).abs() < 1e-3); + assert!((field0.h2_err(&field1, &SBP8).powi(2) - 4.0).abs() < 1e-3); } #[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)] pub fn RHS_trad( - op: SBP, + op: &SBP, k: &mut Field, y: &Field, metrics: &Metrics, @@ -442,7 +442,7 @@ pub fn RHS_trad( #[allow(non_snake_case)] pub fn RHS_upwind( - op: UO, + op: &UO, k: &mut Field, y: &Field, metrics: &Metrics, @@ -483,7 +483,7 @@ pub fn RHS_upwind( #[allow(clippy::many_single_char_names)] fn upwind_dissipation( - op: UO, + op: &UO, k: (&mut Field, &mut Field), y: &Field, metrics: &Metrics, @@ -844,7 +844,7 @@ fn vortexify( #[allow(non_snake_case)] /// Boundary conditions (SAT) fn SAT_characteristics( - op: SBP, + op: &SBP, k: &mut Field, y: &Field, metrics: &Metrics, diff --git a/sbp/src/grid.rs b/sbp/src/grid.rs index 76fb5f8..64090c1 100644 --- a/sbp/src/grid.rs +++ b/sbp/src/grid.rs @@ -38,7 +38,7 @@ impl Grid { pub fn metrics( &self, - op: SBP, + op: &SBP, ) -> Result { Metrics::new(self, op) } @@ -72,7 +72,7 @@ impl Grid { impl Metrics { fn new( grid: &Grid, - op: SBP, + op: &SBP, ) -> Result { let ny = grid.ny(); let nx = grid.nx(); diff --git a/sbp/src/maxwell.rs b/sbp/src/maxwell.rs index 1bcab95..9c4c3dd 100644 --- a/sbp/src/maxwell.rs +++ b/sbp/src/maxwell.rs @@ -89,7 +89,7 @@ impl System { let nx = x.shape()[1]; let grid = Grid::new(x, y).unwrap(); - let metrics = grid.metrics(op).unwrap(); + let metrics = grid.metrics(&op).unwrap(); Self { op, @@ -117,7 +117,7 @@ impl System { } pub fn advance(&mut self, dt: Float) { - let op = self.op; + let op = &self.op; let rhs_adaptor = move |fut: &mut Field, prev: &Field, _time: Float, @@ -149,7 +149,7 @@ impl System { impl System { /// Using artificial dissipation with the upwind operator pub fn advance_upwind(&mut self, dt: Float) { - let op = self.op; + let op = &self.op; let rhs_adaptor = move |fut: &mut Field, prev: &Field, _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 fn RHS( - op: SBP, + op: &SBP, k: &mut Field, y: &Field, _grid: &Grid, @@ -231,7 +231,7 @@ fn RHS( #[allow(non_snake_case)] fn RHS_upwind( - op: UO, + op: &UO, k: &mut Field, y: &Field, _grid: &Grid, @@ -256,7 +256,7 @@ fn RHS_upwind( } fn fluxes( - op: SBP, + op: &SBP, k: &mut Field, y: &Field, metrics: &Metrics, @@ -331,7 +331,7 @@ fn fluxes( } fn dissipation( - op: UO, + op: &UO, k: &mut Field, y: &Field, metrics: &Metrics, @@ -433,7 +433,7 @@ pub struct BoundaryTerms { #[allow(non_snake_case)] /// Boundary conditions (SAT) fn SAT_characteristics( - op: SBP, + op: &SBP, k: &mut Field, y: &Field, metrics: &Metrics, diff --git a/sbp/src/operators.rs b/sbp/src/operators.rs index 4d99597..10b0a02 100644 --- a/sbp/src/operators.rs +++ b/sbp/src/operators.rs @@ -4,7 +4,7 @@ use crate::Float; use ndarray::{ArrayView1, ArrayView2, ArrayViewMut1, ArrayViewMut2}; -pub trait SbpOperator1d: Copy + Clone + core::fmt::Debug { +pub trait SbpOperator1d: Send + Sync { fn diff(&self, prev: ArrayView1, fut: ArrayViewMut1); 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, fut: ArrayViewMut2); fn diffeta(&self, prev: ArrayView2, fut: ArrayViewMut2); @@ -24,7 +24,7 @@ pub trait SbpOperator2d: Copy + Clone { fn is_h2eta(&self) -> bool; } -impl SbpOperator2d for (SBPeta, SBPxi) { +impl SbpOperator2d for (&SBPeta, &SBPxi) { default fn diffxi(&self, prev: ArrayView2, mut fut: ArrayViewMut2) { assert_eq!(prev.shape(), fut.shape()); for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) { @@ -49,37 +49,37 @@ impl SbpOperator2d for (SBPeta, SBP } } -impl SbpOperator2d for SBP { +impl SbpOperator2d for SBP { fn diffxi(&self, prev: ArrayView2, fut: ArrayViewMut2) { - <(SBP, SBP) as SbpOperator2d>::diffxi(&(*self, *self), prev, fut) + <(&SBP, &SBP) as SbpOperator2d>::diffxi(&(self, self), prev, fut) } fn diffeta(&self, prev: ArrayView2, fut: ArrayViewMut2) { - <(SBP, SBP) as SbpOperator2d>::diffeta(&(*self, *self), prev, fut) + <(&SBP, &SBP) as SbpOperator2d>::diffeta(&(self, self), prev, fut) } fn hxi(&self) -> &'static [Float] { - <(SBP, SBP) as SbpOperator2d>::hxi(&(*self, *self)) + <(&SBP, &SBP) as SbpOperator2d>::hxi(&(self, self)) } fn heta(&self) -> &'static [Float] { - <(SBP, SBP) as SbpOperator2d>::heta(&(*self, *self)) + <(&SBP, &SBP) as SbpOperator2d>::heta(&(self, self)) } 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 { - <(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, fut: ArrayViewMut1); } -pub trait UpwindOperator2d: SbpOperator2d + Copy + Clone { +pub trait UpwindOperator2d: SbpOperator2d + Send + Sync { fn dissxi(&self, prev: ArrayView2, fut: ArrayViewMut2); fn disseta(&self, prev: ArrayView2, fut: ArrayViewMut2); } -impl UpwindOperator2d for (UOeta, UOxi) { +impl UpwindOperator2d for (&UOeta, &UOxi) { default fn dissxi(&self, prev: ArrayView2, mut fut: ArrayViewMut2) { assert_eq!(prev.shape(), fut.shape()); for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) { @@ -92,12 +92,12 @@ impl UpwindOperator2d for (UOet } } -impl UpwindOperator2d for UO { +impl UpwindOperator2d for UO { fn dissxi(&self, prev: ArrayView2, fut: ArrayViewMut2) { - <(UO, UO) as UpwindOperator2d>::dissxi(&(*self, *self), prev, fut) + <(&UO, &UO) as UpwindOperator2d>::dissxi(&(self, self), prev, fut) } fn disseta(&self, prev: ArrayView2, fut: ArrayViewMut2) { - <(UO, UO) as UpwindOperator2d>::disseta(&(*self, *self), prev, fut) + <(&UO, &UO) as UpwindOperator2d>::disseta(&(self, self), prev, fut) } } diff --git a/sbp/src/operators/upwind4.rs b/sbp/src/operators/upwind4.rs index 85c5b3c..00f3cc3 100644 --- a/sbp/src/operators/upwind4.rs +++ b/sbp/src/operators/upwind4.rs @@ -291,7 +291,7 @@ impl SbpOperator1d for Upwind4 { } } -impl SbpOperator2d for (Upwind4, SBP) { +impl SbpOperator2d for (&Upwind4, &SBP) { fn diffxi(&self, prev: ArrayView2, mut fut: ArrayViewMut2) { assert_eq!(prev.shape(), fut.shape()); assert!(prev.shape()[1] >= 2 * Upwind4::BLOCK.len()); @@ -415,7 +415,7 @@ impl UpwindOperator1d for Upwind4 { } } -impl UpwindOperator2d for (Upwind4, SBP) { +impl UpwindOperator2d for (&Upwind4, &SBP) { fn dissxi(&self, prev: ArrayView2, mut fut: ArrayViewMut2) { assert_eq!(prev.shape(), fut.shape()); assert!(prev.shape()[1] >= 2 * Upwind4::BLOCK.len());