revisit SBP Traits
This commit is contained in:
		@@ -1,15 +1,12 @@
 | 
			
		||||
use either::*;
 | 
			
		||||
use structopt::StructOpt;
 | 
			
		||||
 | 
			
		||||
use sbp::operators::{SbpOperator2d, UpwindOperator2d};
 | 
			
		||||
use sbp::operators::SbpOperator2d;
 | 
			
		||||
use sbp::*;
 | 
			
		||||
 | 
			
		||||
mod file;
 | 
			
		||||
mod parsing;
 | 
			
		||||
use file::*;
 | 
			
		||||
 | 
			
		||||
pub(crate) type DiffOp = Either<Box<dyn SbpOperator2d>, Box<dyn UpwindOperator2d>>;
 | 
			
		||||
 | 
			
		||||
struct System {
 | 
			
		||||
    fnow: Vec<euler::Field>,
 | 
			
		||||
    fnext: Vec<euler::Field>,
 | 
			
		||||
@@ -20,14 +17,14 @@ struct System {
 | 
			
		||||
    bt: Vec<euler::BoundaryCharacteristics>,
 | 
			
		||||
    eb: Vec<euler::BoundaryStorage>,
 | 
			
		||||
    time: Float,
 | 
			
		||||
    operators: Vec<DiffOp>,
 | 
			
		||||
    operators: Vec<Box<dyn SbpOperator2d>>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl System {
 | 
			
		||||
    fn new(
 | 
			
		||||
        grids: Vec<grid::Grid>,
 | 
			
		||||
        bt: Vec<euler::BoundaryCharacteristics>,
 | 
			
		||||
        operators: Vec<DiffOp>,
 | 
			
		||||
        operators: Vec<Box<dyn SbpOperator2d>>,
 | 
			
		||||
    ) -> Self {
 | 
			
		||||
        let fnow = grids
 | 
			
		||||
            .iter()
 | 
			
		||||
@@ -42,10 +39,7 @@ impl System {
 | 
			
		||||
        let metrics = grids
 | 
			
		||||
            .iter()
 | 
			
		||||
            .zip(&operators)
 | 
			
		||||
            .map(|(g, op)| {
 | 
			
		||||
                let sbpop: &dyn SbpOperator2d = op.as_ref().either(|op| &**op, |uo| uo.as_sbp());
 | 
			
		||||
                g.metrics(sbpop).unwrap()
 | 
			
		||||
            })
 | 
			
		||||
            .map(|(g, op)| g.metrics(&**op).unwrap())
 | 
			
		||||
            .collect::<Vec<_>>();
 | 
			
		||||
 | 
			
		||||
        let eb = bt
 | 
			
		||||
@@ -97,13 +91,10 @@ impl System {
 | 
			
		||||
                {
 | 
			
		||||
                    s.spawn(move |_| {
 | 
			
		||||
                        let bc = euler::boundary_extracts(prev_all, bt, prev, grid, eb, time);
 | 
			
		||||
                        match op.as_ref() {
 | 
			
		||||
                            Left(sbp) => {
 | 
			
		||||
                                euler::RHS_trad(&**sbp, fut, prev, metrics, &bc, &mut wb.0);
 | 
			
		||||
                            }
 | 
			
		||||
                            Right(uo) => {
 | 
			
		||||
                                euler::RHS_upwind(&**uo, fut, prev, metrics, &bc, &mut wb.0);
 | 
			
		||||
                            }
 | 
			
		||||
                        if op.upwind().is_some() {
 | 
			
		||||
                            euler::RHS_upwind(&**op, fut, prev, metrics, &bc, &mut wb.0);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            euler::RHS_trad(&**op, fut, prev, metrics, &bc, &mut wb.0);
 | 
			
		||||
                        }
 | 
			
		||||
                    })
 | 
			
		||||
                }
 | 
			
		||||
@@ -130,12 +121,10 @@ impl System {
 | 
			
		||||
 | 
			
		||||
    /// Suggested maximum dt for this problem
 | 
			
		||||
    fn max_dt(&self) -> Float {
 | 
			
		||||
        let is_h2 = self.operators.iter().any(|op| {
 | 
			
		||||
            op.as_ref().either(
 | 
			
		||||
                |op| op.is_h2xi() || op.is_h2eta(),
 | 
			
		||||
                |op| op.is_h2xi() || op.is_h2eta(),
 | 
			
		||||
            )
 | 
			
		||||
        });
 | 
			
		||||
        let is_h2 = self
 | 
			
		||||
            .operators
 | 
			
		||||
            .iter()
 | 
			
		||||
            .any(|op| op.is_h2xi() || op.is_h2eta());
 | 
			
		||||
        let c_max = if is_h2 { 0.5 } else { 1.0 };
 | 
			
		||||
        let mut max_dt: Float = Float::INFINITY;
 | 
			
		||||
 | 
			
		||||
@@ -283,8 +272,7 @@ fn main() {
 | 
			
		||||
        for ((fmod, grid), op) in sys.fnow.iter().zip(&sys.grids).zip(&sys.operators) {
 | 
			
		||||
            let mut fvort = fmod.clone();
 | 
			
		||||
            fvort.vortex(grid.x(), grid.y(), time, &vortexparams);
 | 
			
		||||
            let sbpop: &dyn SbpOperator2d = op.as_ref().either(|op| &**op, |uo| uo.as_sbp());
 | 
			
		||||
            e += fmod.h2_err(&fvort, sbpop);
 | 
			
		||||
            e += fmod.h2_err(&fvort, &**op);
 | 
			
		||||
        }
 | 
			
		||||
        println!("Total error: {:e}", e);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
use super::DiffOp;
 | 
			
		||||
use either::*;
 | 
			
		||||
use sbp::operators::SbpOperator2d;
 | 
			
		||||
use sbp::utils::h2linspace;
 | 
			
		||||
use sbp::Float;
 | 
			
		||||
 | 
			
		||||
@@ -148,7 +147,7 @@ pub struct RuntimeConfiguration {
 | 
			
		||||
    pub names: Vec<String>,
 | 
			
		||||
    pub grids: Vec<sbp::grid::Grid>,
 | 
			
		||||
    pub bc: Vec<euler::BoundaryCharacteristics>,
 | 
			
		||||
    pub op: Vec<DiffOp>,
 | 
			
		||||
    pub op: Vec<Box<dyn SbpOperator2d>>,
 | 
			
		||||
    pub integration_time: Float,
 | 
			
		||||
    pub vortex: euler::VortexParameters,
 | 
			
		||||
}
 | 
			
		||||
@@ -223,32 +222,19 @@ impl Configuration {
 | 
			
		||||
 | 
			
		||||
                use sbp::operators::*;
 | 
			
		||||
                use Operator as op;
 | 
			
		||||
                match (eta, xi) {
 | 
			
		||||
                    (op::Upwind4, op::Upwind4) => {
 | 
			
		||||
                        Right(Box::new(Upwind4) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
 | 
			
		||||
                let matcher = |op| -> Box<dyn SbpOperator2d> {
 | 
			
		||||
                    match op {
 | 
			
		||||
                        op::Upwind4 => Box::new(Upwind4),
 | 
			
		||||
                        op::Upwind4h2 => Box::new(Upwind4h2),
 | 
			
		||||
                        op::Upwind9 => Box::new(Upwind9),
 | 
			
		||||
                        op::Upwind9h2 => Box::new(Upwind9h2),
 | 
			
		||||
                        op::Sbp4 => Box::new(SBP4),
 | 
			
		||||
                        op::Sbp8 => Box::new(SBP8),
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind4h2, op::Upwind4h2) => {
 | 
			
		||||
                        Right(Box::new(Upwind4h2) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind9, op::Upwind9) => {
 | 
			
		||||
                        Right(Box::new(Upwind9) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind9h2, op::Upwind9h2) => {
 | 
			
		||||
                        Right(Box::new(Upwind9h2) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind4, op::Upwind4h2) => {
 | 
			
		||||
                        Right(Box::new((&Upwind4, &Upwind4h2)) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind9, op::Upwind9h2) => {
 | 
			
		||||
                        Right(Box::new((&Upwind9, &Upwind9h2)) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind9h2, op::Upwind9) => {
 | 
			
		||||
                        Right(Box::new((&Upwind9h2, &Upwind9)) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Sbp4, op::Sbp4) => Left(Box::new(SBP4) as Box<dyn SbpOperator2d>),
 | 
			
		||||
                    (op::Sbp8, op::Sbp8) => Left(Box::new(SBP8) as Box<dyn SbpOperator2d>),
 | 
			
		||||
                    _ => todo!("Combination {:?}, {:?} not implemented", eta, xi),
 | 
			
		||||
                }
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
                Box::new((matcher(eta), matcher(xi))) as Box<dyn SbpOperator2d>
 | 
			
		||||
            })
 | 
			
		||||
            .collect();
 | 
			
		||||
        let bc = self
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user