allow selection of operators
This commit is contained in:
parent
0f1f115fc3
commit
cde8755c15
|
@ -3,20 +3,32 @@ use sbp::utils::json_to_grids;
|
||||||
use sbp::*;
|
use sbp::*;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
struct System<T: operators::UpwindOperator> {
|
struct System {
|
||||||
fnow: Vec<euler::Field>,
|
fnow: Vec<euler::Field>,
|
||||||
fnext: Vec<euler::Field>,
|
fnext: Vec<euler::Field>,
|
||||||
wb: Vec<euler::WorkBuffers>,
|
wb: Vec<euler::WorkBuffers>,
|
||||||
k: [Vec<euler::Field>; 4],
|
k: [Vec<euler::Field>; 4],
|
||||||
grids: Vec<grid::Grid>,
|
grids: Vec<grid::Grid>,
|
||||||
metrics: Vec<grid::Metrics<T>>,
|
metrics: Vec<Metrics>,
|
||||||
bt: Vec<euler::BoundaryCharacteristics>,
|
bt: Vec<euler::BoundaryCharacteristics>,
|
||||||
eb: Vec<euler::BoundaryStorage>,
|
eb: Vec<euler::BoundaryStorage>,
|
||||||
time: Float,
|
time: Float,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: operators::UpwindOperator> System<T> {
|
enum Metrics {
|
||||||
fn new(grids: Vec<grid::Grid>, bt: Vec<euler::BoundaryCharacteristics>) -> Self {
|
Upwind4(grid::Metrics<operators::Upwind4>),
|
||||||
|
Upwind9(grid::Metrics<operators::Upwind9>),
|
||||||
|
Upwind4h2(grid::Metrics<operators::Upwind4h2>),
|
||||||
|
Trad4(grid::Metrics<operators::SBP4>),
|
||||||
|
Trad8(grid::Metrics<operators::SBP8>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl System {
|
||||||
|
fn new(
|
||||||
|
grids: Vec<grid::Grid>,
|
||||||
|
bt: Vec<euler::BoundaryCharacteristics>,
|
||||||
|
operator: &str,
|
||||||
|
) -> Self {
|
||||||
let fnow = grids
|
let fnow = grids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|g| euler::Field::new(g.ny(), g.nx()))
|
.map(|g| euler::Field::new(g.ny(), g.nx()))
|
||||||
|
@ -27,7 +39,18 @@ impl<T: operators::UpwindOperator> System<T> {
|
||||||
.map(|g| euler::WorkBuffers::new(g.ny(), g.nx()))
|
.map(|g| euler::WorkBuffers::new(g.ny(), g.nx()))
|
||||||
.collect();
|
.collect();
|
||||||
let k = [fnow.clone(), fnow.clone(), fnow.clone(), fnow.clone()];
|
let k = [fnow.clone(), fnow.clone(), fnow.clone(), fnow.clone()];
|
||||||
let metrics = grids.iter().map(|g| g.metrics().unwrap()).collect();
|
let metrics = grids
|
||||||
|
.iter()
|
||||||
|
.map(|g| match operator {
|
||||||
|
"upwind4" => Metrics::Upwind4(g.metrics::<operators::Upwind4>().unwrap()),
|
||||||
|
"upwind9" => Metrics::Upwind9(g.metrics::<operators::Upwind9>().unwrap()),
|
||||||
|
"upwind4h2" => Metrics::Upwind4h2(g.metrics::<operators::Upwind4h2>().unwrap()),
|
||||||
|
"trad4" => Metrics::Trad4(g.metrics::<operators::SBP4>().unwrap()),
|
||||||
|
"trad8" => Metrics::Trad8(g.metrics::<operators::SBP8>().unwrap()),
|
||||||
|
op => panic!("operator {} not known", op),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let eb = bt
|
let eb = bt
|
||||||
.iter()
|
.iter()
|
||||||
.zip(&grids)
|
.zip(&grids)
|
||||||
|
@ -58,16 +81,13 @@ impl<T: operators::UpwindOperator> System<T> {
|
||||||
&'a mut [euler::WorkBuffers],
|
&'a mut [euler::WorkBuffers],
|
||||||
&'a mut [euler::BoundaryStorage],
|
&'a mut [euler::BoundaryStorage],
|
||||||
);
|
);
|
||||||
|
let metrics = &self.metrics;
|
||||||
let rhs = move |fut: &mut [euler::Field],
|
let rhs = move |fut: &mut [euler::Field],
|
||||||
prev: &[euler::Field],
|
prev: &[euler::Field],
|
||||||
time: Float,
|
time: Float,
|
||||||
c: &(
|
c: &(&[grid::Grid], &[euler::BoundaryCharacteristics]),
|
||||||
&[grid::Grid],
|
|
||||||
&[grid::Metrics<_>],
|
|
||||||
&[euler::BoundaryCharacteristics],
|
|
||||||
),
|
|
||||||
mt: &mut MT| {
|
mt: &mut MT| {
|
||||||
let (grids, metrics, bt) = c;
|
let (grids, bt) = c;
|
||||||
let (wb, eb) = mt;
|
let (wb, eb) = mt;
|
||||||
|
|
||||||
let bc = euler::extract_boundaries::<operators::Interpolation4>(
|
let bc = euler::extract_boundaries::<operators::Interpolation4>(
|
||||||
|
@ -81,10 +101,27 @@ impl<T: operators::UpwindOperator> System<T> {
|
||||||
.zip(wb.iter_mut())
|
.zip(wb.iter_mut())
|
||||||
.zip(metrics.iter())
|
.zip(metrics.iter())
|
||||||
{
|
{
|
||||||
s.spawn(move |_| euler::RHS_upwind(fut, prev, metrics, &bc, &mut wb.0));
|
s.spawn(move |_| match metrics {
|
||||||
|
Metrics::Upwind4(metrics) => {
|
||||||
|
euler::RHS_upwind(fut, prev, metrics, &bc, &mut wb.0)
|
||||||
|
}
|
||||||
|
Metrics::Upwind9(metrics) => {
|
||||||
|
euler::RHS_upwind(fut, prev, metrics, &bc, &mut wb.0)
|
||||||
|
}
|
||||||
|
Metrics::Upwind4h2(metrics) => {
|
||||||
|
euler::RHS_upwind(fut, prev, metrics, &bc, &mut wb.0)
|
||||||
|
}
|
||||||
|
Metrics::Trad4(metrics) => {
|
||||||
|
euler::RHS_trad(fut, prev, metrics, &bc, &mut wb.0)
|
||||||
|
}
|
||||||
|
Metrics::Trad8(metrics) => {
|
||||||
|
euler::RHS_trad(fut, prev, metrics, &bc, &mut wb.0)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut k = self
|
let mut k = self
|
||||||
.k
|
.k
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
|
@ -97,7 +134,7 @@ impl<T: operators::UpwindOperator> System<T> {
|
||||||
&mut self.time,
|
&mut self.time,
|
||||||
dt,
|
dt,
|
||||||
&mut k,
|
&mut k,
|
||||||
&(&self.grids, &self.metrics, &self.bt),
|
&(&self.grids, &self.bt),
|
||||||
&mut (&mut self.wb, &mut self.eb),
|
&mut (&mut self.wb, &mut self.eb),
|
||||||
pool,
|
pool,
|
||||||
);
|
);
|
||||||
|
@ -173,7 +210,9 @@ fn main() {
|
||||||
|
|
||||||
let integration_time: Float = json["integration_time"].as_number().unwrap().into();
|
let integration_time: Float = json["integration_time"].as_number().unwrap().into();
|
||||||
|
|
||||||
let mut sys = System::<SBP>::new(grids, bt);
|
let operator = json["operator"].as_str().unwrap_or("upwind4");
|
||||||
|
|
||||||
|
let mut sys = System::new(grids, bt, operator);
|
||||||
sys.vortex(0.0, vortexparams);
|
sys.vortex(0.0, vortexparams);
|
||||||
|
|
||||||
let max_n = {
|
let max_n = {
|
||||||
|
|
|
@ -400,7 +400,7 @@ fn pressure(gamma: Float, rho: Float, rhou: Float, rhov: Float, e: Float) -> Flo
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub(crate) fn RHS_trad<SBP: SbpOperator>(
|
pub fn RHS_trad<SBP: SbpOperator>(
|
||||||
k: &mut Field,
|
k: &mut Field,
|
||||||
y: &Field,
|
y: &Field,
|
||||||
metrics: &Metrics<SBP>,
|
metrics: &Metrics<SBP>,
|
||||||
|
|
Loading…
Reference in New Issue