diff --git a/multigrid/src/main.rs b/multigrid/src/main.rs index 252a4fc..6507f99 100644 --- a/multigrid/src/main.rs +++ b/multigrid/src/main.rs @@ -9,7 +9,6 @@ mod parsing; use file::*; mod eval; mod system; -use system::*; #[derive(Debug, FromArgs)] /// Options for configuring and running the solver @@ -77,35 +76,22 @@ fn main() { let parsing::RuntimeConfiguration { names, grids, - grid_connections, + boundary_conditions, op: operators, integration_time, initial_conditions, - boundary_conditions: _, } = config.into_runtime(); - let mut sys = System::new(grids, grid_connections, operators); - match &initial_conditions { - /* - parsing::InitialConditions::File(f) => { - for grid in &sys.grids { - // Copy initial conditions from file, requires name of field - todo!() - } - } - */ - parsing::InitialConditions::Vortex(vortexparams) => sys.vortex(0.0, &vortexparams), - parsing::InitialConditions::Expressions(expr) => { - let t = 0.0; - for (grid, field) in sys.grids.iter().zip(sys.fnow.iter_mut()) { - // Evaluate the expressions on all variables - let x = grid.x(); - let y = grid.y(); - let (rho, rhou, rhov, e) = field.components_mut(); - (*expr).evaluate(t, x, y, rho, rhou, rhov, e); - } - } - } + let basesystem = system::BaseSystem::new( + names.clone(), + grids, + 0.0, + operators, + boundary_conditions, + initial_conditions.clone(), + ); + let mut sys = basesystem.create(); + // System::new(grids, grid_connections, operators); let dt = sys.max_dt(); diff --git a/multigrid/src/parsing.rs b/multigrid/src/parsing.rs index 5d87324..035ff70 100644 --- a/multigrid/src/parsing.rs +++ b/multigrid/src/parsing.rs @@ -27,7 +27,7 @@ pub enum InitialConditions { } #[derive(Clone, Debug)] -pub enum BoundaryConditions { +enum BoundaryConditions { Vortex(euler::VortexParameters), Expressions(std::sync::Arc), NotNeeded, @@ -36,11 +36,10 @@ pub enum BoundaryConditions { pub struct RuntimeConfiguration { pub names: Vec, pub grids: Vec, - pub grid_connections: Vec, + pub boundary_conditions: Vec, pub op: Vec>, pub integration_time: Float, pub initial_conditions: InitialConditions, - pub boundary_conditions: BoundaryConditions, } impl input::Configuration { @@ -165,7 +164,7 @@ impl input::Configuration { Box::new((matcher(eta), matcher(xi))) as Box }) .collect(); - let grid_connections = self + let boundary_conditions = self .grids .iter() .map(|(name, g)| { @@ -226,11 +225,10 @@ impl input::Configuration { RuntimeConfiguration { names, grids, - grid_connections, + boundary_conditions, op, integration_time: self.integration_time, initial_conditions, - boundary_conditions, } } } diff --git a/multigrid/src/system.rs b/multigrid/src/system.rs index 27ca5b4..034a7d8 100644 --- a/multigrid/src/system.rs +++ b/multigrid/src/system.rs @@ -1,3 +1,4 @@ +use crate::parsing; use crate::utils::Direction; use crossbeam_channel::{Receiver, Select, Sender}; use euler::{ @@ -10,6 +11,60 @@ use sbp::operators::{InterpolationOperator, SbpOperator2d}; use sbp::*; use std::sync::{Arc, Barrier}; +pub struct BaseSystem { + pub names: Vec, + pub grids: Vec, + pub time: Float, + pub boundary_conditions: Vec, + pub initial_conditions: crate::parsing::InitialConditions, + pub operators: Vec>, +} + +impl BaseSystem { + pub fn new( + names: Vec, + grids: Vec, + time: Float, + operators: Vec>, + boundary_conditions: Vec, + initial_conditions: crate::parsing::InitialConditions, + ) -> Self { + Self { + names, + grids, + time, + boundary_conditions, + initial_conditions, + operators, + } + } + pub fn create(self) -> System { + let mut sys = System::new(self.grids, self.boundary_conditions, self.operators); + match &self.initial_conditions { + /* + parsing::InitialConditions::File(f) => { + for grid in &sys.grids { + // Copy initial conditions from file, requires name of field + todo!() + } + } + */ + parsing::InitialConditions::Vortex(vortexparams) => sys.vortex(0.0, &vortexparams), + parsing::InitialConditions::Expressions(expr) => { + let t = 0.0; + for (grid, field) in sys.grids.iter().zip(sys.fnow.iter_mut()) { + // Evaluate the expressions on all variables + let x = grid.x(); + let y = grid.y(); + let (rho, rhou, rhov, e) = field.components_mut(); + (*expr).evaluate(t, x, y, rho, rhou, rhov, e); + } + } + } + sys + } +} + pub struct System { pub fnow: Vec, pub fnext: Vec,