move integrator to module
This commit is contained in:
parent
92c86c2c41
commit
e957a4fff7
46
src/euler.rs
46
src/euler.rs
|
@ -1,7 +1,8 @@
|
|||
use super::integrate::integrate_rk4;
|
||||
use super::operators::{SbpOperator, UpwindOperator};
|
||||
use super::Grid;
|
||||
use ndarray::azip;
|
||||
use ndarray::prelude::*;
|
||||
use ndarray::{azip, Zip};
|
||||
|
||||
pub const GAMMA: f32 = 1.4;
|
||||
|
||||
|
@ -224,49 +225,6 @@ impl Field {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn integrate_rk4<'a, F: 'a, SBP, RHS, WB>(
|
||||
rhs: RHS,
|
||||
prev: &F,
|
||||
fut: &mut F,
|
||||
dt: f32,
|
||||
grid: &Grid<SBP>,
|
||||
k: &mut [F; 4],
|
||||
mut wb: &mut WB,
|
||||
) where
|
||||
F: std::ops::Deref<Target = Array3<f32>> + std::ops::DerefMut<Target = Array3<f32>>,
|
||||
SBP: SbpOperator,
|
||||
RHS: Fn(&mut F, &F, &Grid<SBP>, &mut WB),
|
||||
{
|
||||
assert_eq!(prev.shape(), fut.shape());
|
||||
|
||||
for i in 0..4 {
|
||||
// y = y0 + c*kn
|
||||
fut.assign(prev);
|
||||
match i {
|
||||
0 => {}
|
||||
1 | 2 => {
|
||||
fut.scaled_add(1.0 / 2.0 * dt, &k[i - 1]);
|
||||
}
|
||||
3 => {
|
||||
fut.scaled_add(dt, &k[i - 1]);
|
||||
}
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
};
|
||||
|
||||
rhs(&mut k[i], &fut, grid, &mut wb);
|
||||
}
|
||||
|
||||
Zip::from(&mut **fut)
|
||||
.and(&**prev)
|
||||
.and(&*k[0])
|
||||
.and(&*k[1])
|
||||
.and(&*k[2])
|
||||
.and(&*k[3])
|
||||
.apply(|y1, &y0, &k1, &k2, &k3, &k4| *y1 = y0 + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4));
|
||||
}
|
||||
|
||||
fn pressure(gamma: f32, rho: f32, rhou: f32, rhov: f32, e: f32) -> f32 {
|
||||
(gamma - 1.0) * (e - (rhou * rhou + rhov * rhov) / (2.0 * rho))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
use super::grid::Grid;
|
||||
use super::operators::SbpOperator;
|
||||
use ndarray::{Array3, Zip};
|
||||
|
||||
pub(crate) fn integrate_rk4<'a, F: 'a, SBP, RHS, WB>(
|
||||
rhs: RHS,
|
||||
prev: &F,
|
||||
fut: &mut F,
|
||||
dt: f32,
|
||||
grid: &Grid<SBP>,
|
||||
k: &mut [F; 4],
|
||||
mut wb: &mut WB,
|
||||
) where
|
||||
F: std::ops::Deref<Target = Array3<f32>> + std::ops::DerefMut<Target = Array3<f32>>,
|
||||
SBP: SbpOperator,
|
||||
RHS: Fn(&mut F, &F, &Grid<SBP>, &mut WB),
|
||||
{
|
||||
assert_eq!(prev.shape(), fut.shape());
|
||||
|
||||
for i in 0..4 {
|
||||
// y = y0 + c*kn
|
||||
fut.assign(prev);
|
||||
match i {
|
||||
0 => {}
|
||||
1 | 2 => {
|
||||
fut.scaled_add(1.0 / 2.0 * dt, &k[i - 1]);
|
||||
}
|
||||
3 => {
|
||||
fut.scaled_add(dt, &k[i - 1]);
|
||||
}
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
};
|
||||
|
||||
rhs(&mut k[i], &fut, grid, &mut wb);
|
||||
}
|
||||
|
||||
Zip::from(&mut **fut)
|
||||
.and(&**prev)
|
||||
.and(&*k[0])
|
||||
.and(&*k[1])
|
||||
.and(&*k[2])
|
||||
.and(&*k[3])
|
||||
.apply(|y1, &y0, &k1, &k2, &k3, &k4| *y1 = y0 + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4));
|
||||
}
|
|
@ -2,6 +2,7 @@ use wasm_bindgen::prelude::*;
|
|||
|
||||
pub mod euler;
|
||||
mod grid;
|
||||
pub(crate) mod integrate;
|
||||
mod maxwell;
|
||||
pub mod operators;
|
||||
pub use crate::maxwell::{Field, WorkBuffers};
|
||||
|
|
Loading…
Reference in New Issue