diff --git a/multigrid/Cargo.toml b/multigrid/Cargo.toml index 7de1251..f6cedce 100644 --- a/multigrid/Cargo.toml +++ b/multigrid/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] -sbp = { path = "../sbp", features = ["rayon", "serde"] } +sbp = { path = "../sbp", features = ["rayon", "serde1"] } euler = { path = "../euler", features = ["serde1"] } hdf5 = "0.7.0" rayon = "1.3.0" diff --git a/sbp/Cargo.toml b/sbp/Cargo.toml index 7895675..76d5b46 100644 --- a/sbp/Cargo.toml +++ b/sbp/Cargo.toml @@ -17,6 +17,7 @@ serde = { version = "1.0.115", optional = true, default-features = false, featur # Use f32 as precision, default is f64 f32 = [] sparse = ["sprs"] +serde1 = ["serde", "ndarray/serde"] [dev-dependencies] criterion = "0.3.2" diff --git a/sbp/src/grid.rs b/sbp/src/grid.rs index cb9c9d4..8711998 100644 --- a/sbp/src/grid.rs +++ b/sbp/src/grid.rs @@ -1,8 +1,11 @@ use super::operators::SbpOperator2d; use crate::Float; -use ndarray::{Array2, ArrayView2}; +use ndarray::{Array2, ArrayView2, ArrayViewMut2}; +#[cfg(feature = "serde1")] +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct Grid { pub(crate) x: Array2, pub(crate) y: Array2, @@ -30,12 +33,21 @@ impl Grid { self.x.shape()[0] } - pub fn x(&self) -> ndarray::ArrayView2 { + pub fn x(&self) -> ArrayView2 { self.x.view() } - pub fn y(&self) -> ndarray::ArrayView2 { + pub fn x_mut(&mut self) -> ArrayViewMut2 { + self.x.view_mut() + } + pub fn y(&self) -> ArrayView2 { self.y.view() } + pub fn y_mut(&mut self) -> ArrayViewMut2 { + self.y.view_mut() + } + pub fn components(&mut self) -> (ArrayViewMut2, ArrayViewMut2) { + (self.x.view_mut(), self.y.view_mut()) + } pub fn metrics(&self, op: &dyn SbpOperator2d) -> Result { Metrics::new(self, op)