change to WB

This commit is contained in:
Magnus Ulimoen 2020-04-12 21:32:20 +02:00
parent 3e7b45b3be
commit 0f1f115fc3
2 changed files with 24 additions and 40 deletions

View File

@ -6,14 +6,7 @@ use structopt::StructOpt;
struct System<T: operators::UpwindOperator> {
fnow: Vec<euler::Field>,
fnext: Vec<euler::Field>,
wb: Vec<(
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
)>,
wb: Vec<euler::WorkBuffers>,
k: [Vec<euler::Field>; 4],
grids: Vec<grid::Grid>,
metrics: Vec<grid::Metrics<T>>,
@ -31,10 +24,7 @@ impl<T: operators::UpwindOperator> System<T> {
let fnext = fnow.clone();
let wb = grids
.iter()
.map(|g| {
let f = euler::Field::new(g.ny(), g.nx());
(f.clone(), f.clone(), f.clone(), f.clone(), f.clone(), f)
})
.map(|g| euler::WorkBuffers::new(g.ny(), g.nx()))
.collect();
let k = [fnow.clone(), fnow.clone(), fnow.clone(), fnow.clone()];
let metrics = grids.iter().map(|g| g.metrics().unwrap()).collect();
@ -65,14 +55,7 @@ impl<T: operators::UpwindOperator> System<T> {
fn advance(&mut self, dt: Float, pool: &rayon::ThreadPool) {
type MT<'a> = (
&'a mut [(
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
)],
&'a mut [euler::WorkBuffers],
&'a mut [euler::BoundaryStorage],
);
let rhs = move |fut: &mut [euler::Field],
@ -98,7 +81,7 @@ impl<T: operators::UpwindOperator> System<T> {
.zip(wb.iter_mut())
.zip(metrics.iter())
{
s.spawn(move |_| euler::RHS_upwind(fut, prev, metrics, &bc, wb));
s.spawn(move |_| euler::RHS_upwind(fut, prev, metrics, &bc, &mut wb.0));
}
});
};

View File

@ -12,6 +12,7 @@ pub const GAMMA: Float = 1.4;
#[derive(Debug)]
pub struct System<SBP: SbpOperator> {
sys: (Field, Field),
k: [Field; 4],
wb: WorkBuffers,
grid: (Grid, Metrics<SBP>),
}
@ -27,6 +28,12 @@ impl<SBP: SbpOperator> System<SBP> {
Self {
sys: (Field::new(ny, nx), Field::new(ny, nx)),
grid: (grid, metrics),
k: [
Field::new(ny, nx),
Field::new(ny, nx),
Field::new(ny, nx),
Field::new(ny, nx),
],
wb: WorkBuffers::new(ny, nx),
}
}
@ -49,9 +56,9 @@ impl<SBP: SbpOperator> System<SBP> {
&mut self.sys.1,
&mut 0.0,
dt,
&mut self.wb.k,
&mut self.k,
&self.grid,
&mut self.wb.tmp,
&mut self.wb.0,
);
std::mem::swap(&mut self.sys.0, &mut self.sys.1);
}
@ -109,9 +116,9 @@ impl<UO: UpwindOperator> System<UO> {
&mut self.sys.1,
&mut 0.0,
dt,
&mut self.wb.k,
&mut self.k,
&self.grid,
&mut self.wb.tmp,
&mut self.wb.0,
);
std::mem::swap(&mut self.sys.0, &mut self.sys.1);
}
@ -1008,24 +1015,18 @@ fn SAT_characteristic(
}
#[derive(Debug)]
pub struct WorkBuffers {
k: [Field; 4],
tmp: (Field, Field, Field, Field, Field, Field),
}
pub struct WorkBuffers(pub (Field, Field, Field, Field, Field, Field));
impl WorkBuffers {
pub fn new(nx: usize, ny: usize) -> Self {
let arr3 = Field::new(nx, ny);
Self {
k: [arr3.clone(), arr3.clone(), arr3.clone(), arr3.clone()],
tmp: (
arr3.clone(),
arr3.clone(),
arr3.clone(),
arr3.clone(),
arr3.clone(),
arr3,
),
}
Self((
arr3.clone(),
arr3.clone(),
arr3.clone(),
arr3.clone(),
arr3.clone(),
arr3,
))
}
}