2020-04-03 22:29:02 +00:00
|
|
|
use super::grid::{Grid, Metrics};
|
2020-01-29 20:16:09 +00:00
|
|
|
use super::integrate;
|
2020-01-25 19:40:55 +00:00
|
|
|
use super::operators::{SbpOperator, UpwindOperator};
|
2020-02-27 19:26:43 +00:00
|
|
|
use super::Float;
|
2020-01-29 19:50:56 +00:00
|
|
|
use ndarray::azip;
|
2020-01-25 19:40:55 +00:00
|
|
|
use ndarray::prelude::*;
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
pub const GAMMA: Float = 1.4;
|
2020-01-25 19:40:55 +00:00
|
|
|
|
2020-01-28 18:31:14 +00:00
|
|
|
// A collection of buffers that allows one to efficiently
|
|
|
|
// move to the next state
|
2020-02-19 19:02:22 +00:00
|
|
|
#[derive(Debug)]
|
2020-01-28 18:31:14 +00:00
|
|
|
pub struct System<SBP: SbpOperator> {
|
|
|
|
sys: (Field, Field),
|
|
|
|
wb: WorkBuffers,
|
2020-04-03 22:29:02 +00:00
|
|
|
grid: (Grid, Metrics<SBP>),
|
2020-01-28 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<SBP: SbpOperator> System<SBP> {
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn new(x: ndarray::Array2<Float>, y: ndarray::Array2<Float>) -> Self {
|
2020-01-28 18:31:14 +00:00
|
|
|
let grid = Grid::new(x, y).expect(
|
|
|
|
"Could not create grid. Different number of elements compared to width*height?",
|
|
|
|
);
|
2020-04-03 22:29:02 +00:00
|
|
|
let metrics = grid.metrics().unwrap();
|
2020-01-28 18:31:14 +00:00
|
|
|
let nx = grid.nx();
|
|
|
|
let ny = grid.ny();
|
|
|
|
Self {
|
|
|
|
sys: (Field::new(ny, nx), Field::new(ny, nx)),
|
2020-04-03 22:29:02 +00:00
|
|
|
grid: (grid, metrics),
|
2020-01-28 18:31:14 +00:00
|
|
|
wb: WorkBuffers::new(ny, nx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn advance(&mut self, dt: Float) {
|
2020-03-30 21:15:28 +00:00
|
|
|
let bc = BoundaryCharacteristics {
|
|
|
|
north: BoundaryCharacteristic::This,
|
|
|
|
south: BoundaryCharacteristic::This,
|
|
|
|
east: BoundaryCharacteristic::This,
|
|
|
|
west: BoundaryCharacteristic::This,
|
|
|
|
};
|
2020-04-10 15:36:01 +00:00
|
|
|
let rhs_trad = |k: &mut Field, y: &Field, _time: Float, gm: &(_, _), wb: &mut _| {
|
|
|
|
let (grid, metrics) = gm;
|
2020-03-30 21:15:28 +00:00
|
|
|
let boundaries = boundary_extractor(y, grid, &bc);
|
2020-04-03 22:29:02 +00:00
|
|
|
RHS_trad(k, y, metrics, &boundaries, wb)
|
2020-02-19 20:51:01 +00:00
|
|
|
};
|
2020-01-29 20:16:09 +00:00
|
|
|
integrate::rk4(
|
2020-02-19 20:51:01 +00:00
|
|
|
rhs_trad,
|
2020-01-28 18:31:14 +00:00
|
|
|
&self.sys.0,
|
|
|
|
&mut self.sys.1,
|
2020-04-10 15:36:01 +00:00
|
|
|
&mut 0.0,
|
2020-01-28 18:31:14 +00:00
|
|
|
dt,
|
2020-01-29 19:06:44 +00:00
|
|
|
&mut self.wb.k,
|
2020-04-10 15:36:01 +00:00
|
|
|
&self.grid,
|
2020-01-29 19:06:44 +00:00
|
|
|
&mut self.wb.tmp,
|
2020-01-28 18:31:14 +00:00
|
|
|
);
|
|
|
|
std::mem::swap(&mut self.sys.0, &mut self.sys.1);
|
|
|
|
}
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn vortex(&mut self, t: Float, vortex_parameters: VortexParameters) {
|
2020-02-24 19:10:59 +00:00
|
|
|
self.sys
|
|
|
|
.0
|
2020-04-03 22:29:02 +00:00
|
|
|
.vortex(self.grid.0.x(), self.grid.0.y(), t, vortex_parameters);
|
2020-02-24 19:10:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 18:36:16 +00:00
|
|
|
#[allow(clippy::many_single_char_names)]
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn init_with_vortex(&mut self, x0: Float, y0: Float) {
|
2020-01-28 18:31:14 +00:00
|
|
|
// Should parametrise such that we have radius, drop in pressure at center, etc
|
2020-02-22 17:57:22 +00:00
|
|
|
let vortex_parameters = VortexParameters {
|
|
|
|
x0,
|
|
|
|
y0,
|
|
|
|
rstar: 1.0,
|
|
|
|
eps: 3.0,
|
|
|
|
mach: 0.5,
|
|
|
|
};
|
2020-01-28 18:31:14 +00:00
|
|
|
|
2020-04-03 22:29:02 +00:00
|
|
|
self.sys
|
|
|
|
.0
|
|
|
|
.vortex(self.grid.0.x(), self.grid.0.y(), 0.0, vortex_parameters)
|
2020-01-28 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn field(&self) -> &Field {
|
|
|
|
&self.sys.0
|
|
|
|
}
|
2020-02-24 19:10:59 +00:00
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn x(&self) -> ArrayView2<Float> {
|
2020-04-03 22:29:02 +00:00
|
|
|
self.grid.0.x.view()
|
2020-02-24 19:10:59 +00:00
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn y(&self) -> ArrayView2<Float> {
|
2020-04-03 22:29:02 +00:00
|
|
|
self.grid.0.y.view()
|
2020-02-24 19:10:59 +00:00
|
|
|
}
|
2020-01-28 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<UO: UpwindOperator> System<UO> {
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn advance_upwind(&mut self, dt: Float) {
|
2020-03-30 21:15:28 +00:00
|
|
|
let bc = BoundaryCharacteristics {
|
|
|
|
north: BoundaryCharacteristic::This,
|
|
|
|
south: BoundaryCharacteristic::This,
|
|
|
|
east: BoundaryCharacteristic::This,
|
|
|
|
west: BoundaryCharacteristic::This,
|
|
|
|
};
|
2020-04-10 15:36:01 +00:00
|
|
|
let rhs_upwind = |k: &mut Field, y: &Field, _time: Float, gm: &(_, _), wb: &mut _| {
|
|
|
|
let (grid, metrics) = gm;
|
|
|
|
let boundaries = boundary_extractor(y, grid, &bc);
|
|
|
|
RHS_upwind(k, y, metrics, &boundaries, wb)
|
|
|
|
};
|
2020-01-29 20:16:09 +00:00
|
|
|
integrate::rk4(
|
2020-02-19 20:51:01 +00:00
|
|
|
rhs_upwind,
|
2020-01-28 18:31:14 +00:00
|
|
|
&self.sys.0,
|
|
|
|
&mut self.sys.1,
|
2020-04-10 15:36:01 +00:00
|
|
|
&mut 0.0,
|
2020-01-28 18:31:14 +00:00
|
|
|
dt,
|
2020-01-29 19:06:44 +00:00
|
|
|
&mut self.wb.k,
|
2020-04-10 15:36:01 +00:00
|
|
|
&self.grid,
|
2020-01-29 19:06:44 +00:00
|
|
|
&mut self.wb.tmp,
|
2020-01-28 18:31:14 +00:00
|
|
|
);
|
|
|
|
std::mem::swap(&mut self.sys.0, &mut self.sys.1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 19:40:55 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
/// A 4 x ny x nx array
|
2020-02-27 19:26:43 +00:00
|
|
|
pub struct Field(pub(crate) Array3<Float>);
|
2020-01-25 19:40:55 +00:00
|
|
|
|
|
|
|
impl std::ops::Deref for Field {
|
2020-02-27 19:26:43 +00:00
|
|
|
type Target = Array3<Float>;
|
2020-01-25 19:40:55 +00:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::DerefMut for Field {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Field {
|
|
|
|
pub fn new(ny: usize, nx: usize) -> Self {
|
|
|
|
let field = Array3::zeros((4, ny, nx));
|
|
|
|
|
|
|
|
Self(field)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn nx(&self) -> usize {
|
|
|
|
self.0.shape()[2]
|
|
|
|
}
|
|
|
|
pub fn ny(&self) -> usize {
|
|
|
|
self.0.shape()[1]
|
|
|
|
}
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn rho(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![0, .., ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn rhou(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![1, .., ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn rhov(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![2, .., ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn e(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![3, .., ..])
|
|
|
|
}
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn rho_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice_mut(s![0, .., ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn rhou_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice_mut(s![1, .., ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn rhov_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice_mut(s![2, .., ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn e_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice_mut(s![3, .., ..])
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
pub fn components(
|
|
|
|
&self,
|
|
|
|
) -> (
|
2020-02-27 19:26:43 +00:00
|
|
|
ArrayView2<Float>,
|
|
|
|
ArrayView2<Float>,
|
|
|
|
ArrayView2<Float>,
|
|
|
|
ArrayView2<Float>,
|
2020-01-25 19:40:55 +00:00
|
|
|
) {
|
|
|
|
(self.rho(), self.rhou(), self.rhov(), self.e())
|
|
|
|
}
|
|
|
|
#[allow(unused)]
|
|
|
|
pub fn components_mut(
|
|
|
|
&mut self,
|
|
|
|
) -> (
|
2020-02-27 19:26:43 +00:00
|
|
|
ArrayViewMut2<Float>,
|
|
|
|
ArrayViewMut2<Float>,
|
|
|
|
ArrayViewMut2<Float>,
|
|
|
|
ArrayViewMut2<Float>,
|
2020-01-25 19:40:55 +00:00
|
|
|
) {
|
|
|
|
let mut iter = self.0.outer_iter_mut();
|
|
|
|
|
|
|
|
let rho = iter.next().unwrap();
|
|
|
|
let rhou = iter.next().unwrap();
|
|
|
|
let rhov = iter.next().unwrap();
|
|
|
|
let e = iter.next().unwrap();
|
|
|
|
assert_eq!(iter.next(), None);
|
|
|
|
|
|
|
|
(rho, rhou, rhov, e)
|
|
|
|
}
|
|
|
|
|
2020-03-31 22:08:55 +00:00
|
|
|
pub fn north(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![.., self.ny() - 1, ..])
|
|
|
|
}
|
2020-03-31 22:08:55 +00:00
|
|
|
pub fn south(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![.., 0, ..])
|
|
|
|
}
|
2020-03-31 22:08:55 +00:00
|
|
|
pub fn east(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![.., .., self.nx() - 1])
|
|
|
|
}
|
2020-03-31 22:08:55 +00:00
|
|
|
pub fn west(&self) -> ArrayView2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice(s![.., .., 0])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
fn north_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
let ny = self.ny();
|
|
|
|
self.slice_mut(s![.., ny - 1, ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
fn south_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice_mut(s![.., 0, ..])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
fn east_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
let nx = self.nx();
|
|
|
|
self.slice_mut(s![.., .., nx - 1])
|
|
|
|
}
|
2020-02-27 19:26:43 +00:00
|
|
|
fn west_mut(&mut self) -> ArrayViewMut2<Float> {
|
2020-01-25 19:40:55 +00:00
|
|
|
self.slice_mut(s![.., .., 0])
|
|
|
|
}
|
2020-02-22 17:57:22 +00:00
|
|
|
|
2020-02-24 19:10:59 +00:00
|
|
|
pub fn vortex(
|
2020-02-22 17:57:22 +00:00
|
|
|
&mut self,
|
2020-02-27 19:26:43 +00:00
|
|
|
x: ArrayView2<Float>,
|
|
|
|
y: ArrayView2<Float>,
|
|
|
|
t: Float,
|
2020-02-22 17:57:22 +00:00
|
|
|
vortex_param: VortexParameters,
|
|
|
|
) {
|
|
|
|
assert_eq!(x.shape(), y.shape());
|
|
|
|
assert_eq!(x.shape()[1], self.nx());
|
|
|
|
assert_eq!(x.shape()[0], self.ny());
|
|
|
|
|
|
|
|
let (rho, rhou, rhov, e) = self.components_mut();
|
2020-03-30 21:15:28 +00:00
|
|
|
let n = rho.len();
|
|
|
|
|
|
|
|
vortex(
|
|
|
|
rho.into_shape((n,)).unwrap(),
|
|
|
|
rhou.into_shape((n,)).unwrap(),
|
|
|
|
rhov.into_shape((n,)).unwrap(),
|
|
|
|
e.into_shape((n,)).unwrap(),
|
|
|
|
x.into_shape((n,)).unwrap(),
|
|
|
|
y.into_shape((n,)).unwrap(),
|
|
|
|
t,
|
|
|
|
vortex_param,
|
|
|
|
)
|
2020-02-22 17:57:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 21:07:31 +00:00
|
|
|
impl Field {
|
2020-02-25 18:44:13 +00:00
|
|
|
/// sqrt((self-other)^T*H*(self-other))
|
2020-02-27 19:26:43 +00:00
|
|
|
pub fn h2_err<SBP: SbpOperator>(&self, other: &Self) -> Float {
|
2020-02-22 21:07:31 +00:00
|
|
|
assert_eq!(self.nx(), other.nx());
|
|
|
|
assert_eq!(self.ny(), other.ny());
|
|
|
|
|
|
|
|
let h = SBP::h();
|
|
|
|
|
|
|
|
// Resulting structure should be
|
|
|
|
// serialized(F0 - F1)^T (Hx kron Hy) serialized(F0 - F1)
|
|
|
|
//
|
|
|
|
// We accomplish this by serializing along x as fastest dimension
|
|
|
|
// Since h is diagonal, it can be iterated with the following iterators
|
|
|
|
|
|
|
|
// This chains the h block into the form [h, 1, 1, 1, rev(h)],
|
|
|
|
// and multiplies with a factor
|
2020-02-27 19:26:43 +00:00
|
|
|
let itermaker = move |n: usize, factor: Float| {
|
2020-02-22 21:07:31 +00:00
|
|
|
h.iter()
|
|
|
|
.copied()
|
|
|
|
.chain(std::iter::repeat(1.0).take(n - 2 * h.len()))
|
|
|
|
.chain(h.iter().copied().rev())
|
|
|
|
.map(move |x| x * factor)
|
|
|
|
};
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
let hxiterator = itermaker(self.nx(), 1.0 / (self.nx() - 1) as Float);
|
2020-02-22 21:07:31 +00:00
|
|
|
// Repeating to get the form
|
|
|
|
// [[hx0, hx1, ..., hxn], [hx0, hx1, ..., hxn], ..., [hx0, hx1, ..., hxn]]
|
|
|
|
let hxiterator = hxiterator.into_iter().cycle().take(self.nx() * self.ny());
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
let hyiterator = itermaker(self.ny(), 1.0 / (self.ny() - 1) as Float);
|
2020-02-22 21:07:31 +00:00
|
|
|
// Repeating to get the form
|
|
|
|
// [[hy0, hy0, ..., hy0], [hy1, hy1, ..., hy1], ..., [hym, hym, ..., hym]]
|
|
|
|
let hyiterator = hyiterator
|
|
|
|
.into_iter()
|
|
|
|
.flat_map(|x| std::iter::repeat(x).take(self.nx()));
|
|
|
|
|
|
|
|
let diagiterator = hxiterator.into_iter().zip(hyiterator).cycle();
|
|
|
|
|
|
|
|
diagiterator
|
|
|
|
.into_iter()
|
|
|
|
.zip(self.0.iter())
|
|
|
|
.zip(other.0.iter())
|
|
|
|
.map(|(((hx, hy), r0), r1)| (*r0 - *r1).powi(2) * hx * hy)
|
2020-02-27 19:26:43 +00:00
|
|
|
.sum::<Float>()
|
2020-02-25 18:44:13 +00:00
|
|
|
.sqrt()
|
2020-02-22 21:07:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn h2_diff() {
|
|
|
|
let mut field0 = Field::new(20, 21);
|
|
|
|
for f in field0.0.iter_mut() {
|
|
|
|
*f = 1.0
|
|
|
|
}
|
|
|
|
let field1 = Field::new(20, 21);
|
|
|
|
|
2020-02-25 18:44:13 +00:00
|
|
|
assert!((field0.h2_err::<super::operators::Upwind4>(&field1).powi(2) - 4.0).abs() < 1e-3);
|
|
|
|
assert!((field0.h2_err::<super::operators::Upwind9>(&field1).powi(2) - 4.0).abs() < 1e-3);
|
|
|
|
assert!((field0.h2_err::<super::operators::SBP4>(&field1).powi(2) - 4.0).abs() < 1e-3);
|
|
|
|
assert!((field0.h2_err::<super::operators::SBP8>(&field1).powi(2) - 4.0).abs() < 1e-3);
|
2020-02-22 21:07:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 21:15:28 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2020-02-22 17:57:22 +00:00
|
|
|
pub struct VortexParameters {
|
2020-02-27 19:26:43 +00:00
|
|
|
pub x0: Float,
|
|
|
|
pub y0: Float,
|
|
|
|
pub rstar: Float,
|
|
|
|
pub eps: Float,
|
|
|
|
pub mach: Float,
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 21:15:28 +00:00
|
|
|
pub fn vortex(
|
|
|
|
rho: ArrayViewMut1<Float>,
|
|
|
|
rhou: ArrayViewMut1<Float>,
|
|
|
|
rhov: ArrayViewMut1<Float>,
|
|
|
|
e: ArrayViewMut1<Float>,
|
|
|
|
x: ArrayView1<Float>,
|
|
|
|
y: ArrayView1<Float>,
|
|
|
|
t: Float,
|
|
|
|
vortex_param: VortexParameters,
|
|
|
|
) {
|
|
|
|
assert_eq!(rho.len(), rhou.len());
|
|
|
|
assert_eq!(rho.len(), rhov.len());
|
|
|
|
assert_eq!(rho.len(), e.len());
|
|
|
|
assert_eq!(rho.len(), x.len());
|
|
|
|
assert_eq!(rho.len(), y.len());
|
|
|
|
assert_eq!(x.shape(), y.shape());
|
|
|
|
|
|
|
|
let eps = vortex_param.eps;
|
|
|
|
let m = vortex_param.mach;
|
|
|
|
let rstar = vortex_param.rstar;
|
|
|
|
let p_inf = 1.0 / (GAMMA * m * m);
|
|
|
|
azip!((rho in rho,
|
|
|
|
rhou in rhou,
|
|
|
|
rhov in rhov,
|
|
|
|
e in e,
|
|
|
|
x in x,
|
|
|
|
y in y)
|
|
|
|
{
|
|
|
|
use crate::consts::PI;
|
|
|
|
|
|
|
|
let dx = (x - vortex_param.x0) - t;
|
|
|
|
let dy = y - vortex_param.y0;
|
|
|
|
let f = (1.0 - (dx*dx + dy*dy))/(rstar*rstar);
|
|
|
|
|
|
|
|
*rho = Float::powf(1.0 - eps*eps*(GAMMA - 1.0)*m*m/(8.0*PI*PI*p_inf*rstar*rstar)*f.exp(), 1.0/(GAMMA - 1.0));
|
|
|
|
assert!(*rho > 0.0);
|
|
|
|
let p = Float::powf(*rho, GAMMA)*p_inf;
|
|
|
|
assert!(p > 0.0);
|
|
|
|
let u = 1.0 - eps*dy/(2.0*PI*p_inf.sqrt()*rstar*rstar)*(f/2.0).exp();
|
|
|
|
let v = eps*dx/(2.0*PI*p_inf.sqrt()*rstar*rstar)*(f/2.0).exp();
|
|
|
|
*rhou = *rho*u;
|
|
|
|
*rhov = *rho*v;
|
|
|
|
*e = p/(GAMMA - 1.0) + *rho*(u*u + v*v)/2.0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-27 19:26:43 +00:00
|
|
|
fn pressure(gamma: Float, rho: Float, rhou: Float, rhov: Float, e: Float) -> Float {
|
2020-01-25 19:40:55 +00:00
|
|
|
(gamma - 1.0) * (e - (rhou * rhou + rhov * rhov) / (2.0 * rho))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
2020-01-27 19:52:46 +00:00
|
|
|
pub(crate) fn RHS_trad<SBP: SbpOperator>(
|
2020-01-25 19:40:55 +00:00
|
|
|
k: &mut Field,
|
|
|
|
y: &Field,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics: &Metrics<SBP>,
|
2020-02-19 20:51:01 +00:00
|
|
|
boundaries: &BoundaryTerms,
|
2020-01-26 14:46:54 +00:00
|
|
|
tmp: &mut (Field, Field, Field, Field, Field, Field),
|
2020-01-25 19:40:55 +00:00
|
|
|
) {
|
|
|
|
let ehat = &mut tmp.0;
|
|
|
|
let fhat = &mut tmp.1;
|
2020-04-03 22:29:02 +00:00
|
|
|
fluxes((ehat, fhat), y, metrics);
|
2020-01-26 14:46:54 +00:00
|
|
|
let dE = &mut tmp.2;
|
|
|
|
let dF = &mut tmp.3;
|
|
|
|
|
|
|
|
SBP::diffxi(ehat.rho(), dE.rho_mut());
|
|
|
|
SBP::diffxi(ehat.rhou(), dE.rhou_mut());
|
|
|
|
SBP::diffxi(ehat.rhov(), dE.rhov_mut());
|
|
|
|
SBP::diffxi(ehat.e(), dE.e_mut());
|
|
|
|
|
|
|
|
SBP::diffeta(fhat.rho(), dF.rho_mut());
|
|
|
|
SBP::diffeta(fhat.rhou(), dF.rhou_mut());
|
|
|
|
SBP::diffeta(fhat.rhov(), dF.rhov_mut());
|
|
|
|
SBP::diffeta(fhat.e(), dF.e_mut());
|
|
|
|
|
|
|
|
azip!((out in &mut k.0,
|
|
|
|
eflux in &dE.0,
|
|
|
|
fflux in &dF.0,
|
2020-04-03 22:29:02 +00:00
|
|
|
detj in &metrics.detj.broadcast((4, y.ny(), y.nx())).unwrap()) {
|
2020-01-25 19:40:55 +00:00
|
|
|
*out = (-eflux - fflux)/detj
|
|
|
|
});
|
|
|
|
|
2020-04-03 22:29:02 +00:00
|
|
|
SAT_characteristics(k, y, metrics, boundaries);
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
2020-03-31 22:08:55 +00:00
|
|
|
pub fn RHS_upwind<UO: UpwindOperator>(
|
2020-01-25 19:40:55 +00:00
|
|
|
k: &mut Field,
|
|
|
|
y: &Field,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics: &Metrics<UO>,
|
2020-02-19 20:51:01 +00:00
|
|
|
boundaries: &BoundaryTerms,
|
2020-01-26 14:46:54 +00:00
|
|
|
tmp: &mut (Field, Field, Field, Field, Field, Field),
|
2020-01-25 19:40:55 +00:00
|
|
|
) {
|
2020-01-26 14:46:54 +00:00
|
|
|
let ehat = &mut tmp.0;
|
|
|
|
let fhat = &mut tmp.1;
|
2020-04-03 22:29:02 +00:00
|
|
|
fluxes((ehat, fhat), y, metrics);
|
2020-01-26 14:46:54 +00:00
|
|
|
let dE = &mut tmp.2;
|
|
|
|
let dF = &mut tmp.3;
|
|
|
|
|
|
|
|
UO::diffxi(ehat.rho(), dE.rho_mut());
|
|
|
|
UO::diffxi(ehat.rhou(), dE.rhou_mut());
|
|
|
|
UO::diffxi(ehat.rhov(), dE.rhov_mut());
|
|
|
|
UO::diffxi(ehat.e(), dE.e_mut());
|
|
|
|
|
|
|
|
UO::diffeta(fhat.rho(), dF.rho_mut());
|
|
|
|
UO::diffeta(fhat.rhou(), dF.rhou_mut());
|
|
|
|
UO::diffeta(fhat.rhov(), dF.rhov_mut());
|
|
|
|
UO::diffeta(fhat.e(), dF.e_mut());
|
|
|
|
|
|
|
|
let ad_xi = &mut tmp.4;
|
|
|
|
let ad_eta = &mut tmp.5;
|
2020-04-03 22:29:02 +00:00
|
|
|
upwind_dissipation((ad_xi, ad_eta), y, metrics, (&mut tmp.0, &mut tmp.1));
|
2020-01-26 14:46:54 +00:00
|
|
|
|
|
|
|
azip!((out in &mut k.0,
|
|
|
|
eflux in &dE.0,
|
|
|
|
fflux in &dF.0,
|
|
|
|
ad_xi in &ad_xi.0,
|
|
|
|
ad_eta in &ad_eta.0,
|
2020-04-03 22:29:02 +00:00
|
|
|
detj in &metrics.detj.broadcast((4, y.ny(), y.nx())).unwrap()) {
|
2020-01-26 14:46:54 +00:00
|
|
|
*out = (-eflux - fflux + ad_xi + ad_eta)/detj
|
|
|
|
});
|
2020-01-25 19:40:55 +00:00
|
|
|
|
2020-04-03 22:29:02 +00:00
|
|
|
SAT_characteristics(k, y, metrics, boundaries);
|
2020-01-26 14:46:54 +00:00
|
|
|
}
|
2020-01-25 19:40:55 +00:00
|
|
|
|
2020-01-29 18:36:16 +00:00
|
|
|
#[allow(clippy::many_single_char_names)]
|
2020-01-26 14:46:54 +00:00
|
|
|
fn upwind_dissipation<UO: UpwindOperator>(
|
|
|
|
k: (&mut Field, &mut Field),
|
|
|
|
y: &Field,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics: &Metrics<UO>,
|
2020-01-26 14:46:54 +00:00
|
|
|
tmp: (&mut Field, &mut Field),
|
|
|
|
) {
|
2020-01-27 19:17:52 +00:00
|
|
|
let n = y.nx() * y.ny();
|
|
|
|
let yview = y.view().into_shape((4, n)).unwrap();
|
|
|
|
let mut tmp0 = tmp.0.view_mut().into_shape((4, n)).unwrap();
|
|
|
|
let mut tmp1 = tmp.1.view_mut().into_shape((4, n)).unwrap();
|
|
|
|
|
|
|
|
for (
|
|
|
|
((((((y, mut tmp0), mut tmp1), detj), detj_dxi_dx), detj_dxi_dy), detj_deta_dx),
|
|
|
|
detj_deta_dy,
|
|
|
|
) in yview
|
|
|
|
.axis_iter(ndarray::Axis(1))
|
|
|
|
.zip(tmp0.axis_iter_mut(ndarray::Axis(1)))
|
|
|
|
.zip(tmp1.axis_iter_mut(ndarray::Axis(1)))
|
2020-04-03 22:29:02 +00:00
|
|
|
.zip(metrics.detj.iter())
|
|
|
|
.zip(metrics.detj_dxi_dx.iter())
|
|
|
|
.zip(metrics.detj_dxi_dy.iter())
|
|
|
|
.zip(metrics.detj_deta_dx.iter())
|
|
|
|
.zip(metrics.detj_deta_dy.iter())
|
2020-01-27 19:17:52 +00:00
|
|
|
{
|
|
|
|
let rho = y[0];
|
|
|
|
assert!(rho > 0.0);
|
|
|
|
let rhou = y[1];
|
|
|
|
let rhov = y[2];
|
|
|
|
let e = y[3];
|
|
|
|
|
|
|
|
let u = rhou / rho;
|
|
|
|
let v = rhov / rho;
|
|
|
|
|
|
|
|
let uhat = detj_dxi_dx / detj * u + detj_dxi_dy / detj * v;
|
|
|
|
let vhat = detj_deta_dx / detj * u + detj_deta_dy / detj * v;
|
|
|
|
|
|
|
|
let p = pressure(GAMMA, rho, rhou, rhov, e);
|
|
|
|
assert!(p > 0.0);
|
|
|
|
let c = (GAMMA * p / rho).sqrt();
|
|
|
|
|
|
|
|
let alpha_u = uhat.abs() + c;
|
|
|
|
let alpha_v = vhat.abs() + c;
|
|
|
|
|
|
|
|
tmp0[0] = alpha_u * rho * detj;
|
|
|
|
tmp1[0] = alpha_v * rho * detj;
|
|
|
|
|
|
|
|
tmp0[1] = alpha_u * rhou * detj;
|
|
|
|
tmp1[1] = alpha_v * rhou * detj;
|
|
|
|
|
|
|
|
tmp0[2] = alpha_u * rhov * detj;
|
|
|
|
tmp1[2] = alpha_v * rhov * detj;
|
|
|
|
|
|
|
|
tmp0[3] = alpha_u * e * detj;
|
|
|
|
tmp1[3] = alpha_v * e * detj;
|
2020-01-26 14:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UO::dissxi(tmp.0.rho(), k.0.rho_mut());
|
|
|
|
UO::dissxi(tmp.0.rhou(), k.0.rhou_mut());
|
|
|
|
UO::dissxi(tmp.0.rhov(), k.0.rhov_mut());
|
|
|
|
UO::dissxi(tmp.0.e(), k.0.e_mut());
|
|
|
|
|
|
|
|
UO::disseta(tmp.1.rho(), k.1.rho_mut());
|
|
|
|
UO::disseta(tmp.1.rhou(), k.1.rhou_mut());
|
|
|
|
UO::disseta(tmp.1.rhov(), k.1.rhov_mut());
|
|
|
|
UO::disseta(tmp.1.e(), k.1.e_mut());
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 22:29:02 +00:00
|
|
|
fn fluxes<SBP: SbpOperator>(k: (&mut Field, &mut Field), y: &Field, metrics: &Metrics<SBP>) {
|
|
|
|
let j_dxi_dx = metrics.detj_dxi_dx.view();
|
|
|
|
let j_dxi_dy = metrics.detj_dxi_dy.view();
|
|
|
|
let j_deta_dx = metrics.detj_deta_dx.view();
|
|
|
|
let j_deta_dy = metrics.detj_deta_dy.view();
|
2020-01-25 19:40:55 +00:00
|
|
|
|
|
|
|
let rho = y.rho();
|
|
|
|
let rhou = y.rhou();
|
|
|
|
let rhov = y.rhov();
|
|
|
|
let e = y.e();
|
|
|
|
|
|
|
|
for j in 0..y.ny() {
|
|
|
|
for i in 0..y.nx() {
|
|
|
|
let rho = rho[(j, i)];
|
2020-01-26 14:46:54 +00:00
|
|
|
assert!(rho > 0.0);
|
2020-01-25 19:40:55 +00:00
|
|
|
let rhou = rhou[(j, i)];
|
|
|
|
let rhov = rhov[(j, i)];
|
|
|
|
let e = e[(j, i)];
|
|
|
|
let p = pressure(GAMMA, rho, rhou, rhov, e);
|
|
|
|
|
2020-01-26 14:46:54 +00:00
|
|
|
assert!(p > 0.0);
|
|
|
|
|
2020-01-25 19:40:55 +00:00
|
|
|
let ef = [
|
|
|
|
rhou,
|
|
|
|
rhou * rhou / rho + p,
|
|
|
|
rhou * rhov / rho,
|
|
|
|
rhou * (e + p) / rho,
|
|
|
|
];
|
|
|
|
let ff = [
|
|
|
|
rhov,
|
|
|
|
rhou * rhov / rho,
|
|
|
|
rhov * rhov / rho + p,
|
|
|
|
rhov * (e + p) / rho,
|
|
|
|
];
|
|
|
|
|
|
|
|
for comp in 0..4 {
|
|
|
|
let eflux = j_dxi_dx[(j, i)] * ef[comp] + j_dxi_dy[(j, i)] * ff[comp];
|
|
|
|
let fflux = j_deta_dx[(j, i)] * ef[comp] + j_deta_dy[(j, i)] * ff[comp];
|
|
|
|
|
2020-01-26 14:46:54 +00:00
|
|
|
k.0[(comp, j, i)] = eflux;
|
|
|
|
k.1[(comp, j, i)] = fflux;
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
2020-02-19 19:00:52 +00:00
|
|
|
pub struct BoundaryTerms<'a> {
|
2020-02-27 19:26:43 +00:00
|
|
|
pub north: ArrayView2<'a, Float>,
|
|
|
|
pub south: ArrayView2<'a, Float>,
|
|
|
|
pub east: ArrayView2<'a, Float>,
|
|
|
|
pub west: ArrayView2<'a, Float>,
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 21:15:28 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum BoundaryCharacteristic {
|
|
|
|
This,
|
2020-04-02 19:36:56 +00:00
|
|
|
Grid(usize),
|
2020-03-30 21:15:28 +00:00
|
|
|
Vortex(VortexParameters),
|
|
|
|
// Vortices(Vec<VortexParameters>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct BoundaryCharacteristics {
|
2020-04-02 19:36:56 +00:00
|
|
|
pub north: BoundaryCharacteristic,
|
|
|
|
pub south: BoundaryCharacteristic,
|
|
|
|
pub east: BoundaryCharacteristic,
|
|
|
|
pub west: BoundaryCharacteristic,
|
2020-03-30 21:15:28 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 22:29:02 +00:00
|
|
|
fn boundary_extractor<'a>(
|
2020-03-30 21:15:28 +00:00
|
|
|
field: &'a Field,
|
2020-04-03 22:29:02 +00:00
|
|
|
_grid: &Grid,
|
2020-03-30 21:15:28 +00:00
|
|
|
bc: &BoundaryCharacteristics,
|
|
|
|
) -> BoundaryTerms<'a> {
|
|
|
|
BoundaryTerms {
|
|
|
|
north: match bc.north {
|
|
|
|
BoundaryCharacteristic::This => field.south(),
|
|
|
|
BoundaryCharacteristic::Vortex(_params) => todo!(),
|
2020-04-02 19:36:56 +00:00
|
|
|
BoundaryCharacteristic::Grid(_) => panic!("Only working on self grid"),
|
2020-03-30 21:15:28 +00:00
|
|
|
},
|
|
|
|
south: match bc.south {
|
|
|
|
BoundaryCharacteristic::This => field.north(),
|
|
|
|
BoundaryCharacteristic::Vortex(_params) => todo!(),
|
2020-04-02 19:36:56 +00:00
|
|
|
BoundaryCharacteristic::Grid(_) => panic!("Only working on self grid"),
|
2020-03-30 21:15:28 +00:00
|
|
|
},
|
|
|
|
west: match bc.west {
|
|
|
|
BoundaryCharacteristic::This => field.east(),
|
|
|
|
BoundaryCharacteristic::Vortex(_params) => todo!(),
|
2020-04-02 19:36:56 +00:00
|
|
|
BoundaryCharacteristic::Grid(_) => panic!("Only working on self grid"),
|
2020-03-30 21:15:28 +00:00
|
|
|
},
|
|
|
|
east: match bc.east {
|
|
|
|
BoundaryCharacteristic::This => field.west(),
|
|
|
|
BoundaryCharacteristic::Vortex(_params) => todo!(),
|
2020-04-02 19:36:56 +00:00
|
|
|
BoundaryCharacteristic::Grid(_) => panic!("Only working on self grid"),
|
2020-03-30 21:15:28 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 10:30:18 +00:00
|
|
|
pub fn extract_boundaries<'a>(
|
|
|
|
fields: &'a [Field],
|
|
|
|
bt: &[BoundaryCharacteristics],
|
|
|
|
eb: &'a mut [BoundaryStorage],
|
|
|
|
grids: &[Grid],
|
|
|
|
time: Float,
|
|
|
|
) -> Vec<BoundaryTerms<'a>> {
|
|
|
|
bt.iter()
|
|
|
|
.zip(eb)
|
|
|
|
.zip(grids)
|
|
|
|
.zip(fields)
|
|
|
|
.map(|(((bt, eb), grid), field)| BoundaryTerms {
|
|
|
|
north: match bt.north {
|
|
|
|
BoundaryCharacteristic::This => field.south(),
|
|
|
|
BoundaryCharacteristic::Grid(g) => fields[g].south(),
|
|
|
|
BoundaryCharacteristic::Vortex(v) => {
|
|
|
|
let field = eb.n.as_mut().unwrap();
|
|
|
|
vortexify(field.view_mut(), grid.north(), v, time);
|
|
|
|
field.view()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
south: match bt.south {
|
|
|
|
BoundaryCharacteristic::This => field.north(),
|
|
|
|
BoundaryCharacteristic::Grid(g) => fields[g].north(),
|
|
|
|
BoundaryCharacteristic::Vortex(v) => {
|
|
|
|
let field = eb.s.as_mut().unwrap();
|
|
|
|
vortexify(field.view_mut(), grid.south(), v, time);
|
|
|
|
field.view()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
west: match bt.west {
|
|
|
|
BoundaryCharacteristic::This => field.east(),
|
|
|
|
BoundaryCharacteristic::Grid(g) => fields[g].east(),
|
|
|
|
BoundaryCharacteristic::Vortex(v) => {
|
|
|
|
let field = eb.w.as_mut().unwrap();
|
|
|
|
vortexify(field.view_mut(), grid.west(), v, time);
|
|
|
|
field.view()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
east: match bt.east {
|
|
|
|
BoundaryCharacteristic::This => field.west(),
|
|
|
|
BoundaryCharacteristic::Grid(g) => fields[g].west(),
|
|
|
|
BoundaryCharacteristic::Vortex(v) => {
|
|
|
|
let field = eb.e.as_mut().unwrap();
|
|
|
|
vortexify(field.view_mut(), grid.east(), v, time);
|
|
|
|
field.view()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
/// Used for storing boundary elements
|
|
|
|
pub struct BoundaryStorage {
|
|
|
|
pub n: Option<ndarray::Array2<Float>>,
|
|
|
|
pub s: Option<ndarray::Array2<Float>>,
|
|
|
|
pub e: Option<ndarray::Array2<Float>>,
|
|
|
|
pub w: Option<ndarray::Array2<Float>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BoundaryStorage {
|
|
|
|
pub fn new(bt: &BoundaryCharacteristics, grid: &Grid) -> Self {
|
|
|
|
Self {
|
|
|
|
n: match bt.north {
|
|
|
|
BoundaryCharacteristic::Vortex(_) => Some(ndarray::Array2::zeros((4, grid.nx()))),
|
|
|
|
_ => None,
|
|
|
|
},
|
|
|
|
s: match bt.south {
|
|
|
|
BoundaryCharacteristic::Vortex(_) => Some(ndarray::Array2::zeros((4, grid.nx()))),
|
|
|
|
_ => None,
|
|
|
|
},
|
|
|
|
e: match bt.east {
|
|
|
|
BoundaryCharacteristic::Vortex(_) => Some(ndarray::Array2::zeros((4, grid.ny()))),
|
|
|
|
_ => None,
|
|
|
|
},
|
|
|
|
w: match bt.west {
|
|
|
|
BoundaryCharacteristic::Vortex(_) => Some(ndarray::Array2::zeros((4, grid.ny()))),
|
|
|
|
_ => None,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn vortexify(
|
|
|
|
mut field: ndarray::ArrayViewMut2<Float>,
|
|
|
|
yx: (ndarray::ArrayView1<Float>, ndarray::ArrayView1<Float>),
|
|
|
|
v: VortexParameters,
|
|
|
|
t: Float,
|
|
|
|
) {
|
|
|
|
let mut fiter = field.outer_iter_mut();
|
|
|
|
let (rho, rhou, rhov, e) = (
|
|
|
|
fiter.next().unwrap(),
|
|
|
|
fiter.next().unwrap(),
|
|
|
|
fiter.next().unwrap(),
|
|
|
|
fiter.next().unwrap(),
|
|
|
|
);
|
|
|
|
let (y, x) = yx;
|
|
|
|
vortex(rho, rhou, rhov, e, x, y, t, v);
|
|
|
|
}
|
|
|
|
|
2020-01-25 19:40:55 +00:00
|
|
|
#[allow(non_snake_case)]
|
|
|
|
/// Boundary conditions (SAT)
|
|
|
|
fn SAT_characteristics<SBP: SbpOperator>(
|
|
|
|
k: &mut Field,
|
|
|
|
y: &Field,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics: &Metrics<SBP>,
|
2020-02-19 19:00:52 +00:00
|
|
|
boundaries: &BoundaryTerms,
|
2020-01-25 19:40:55 +00:00
|
|
|
) {
|
|
|
|
// North boundary
|
|
|
|
{
|
2020-04-09 23:07:57 +00:00
|
|
|
let hi = (k.ny() - 1) as Float / SBP::h()[0];
|
2020-01-25 19:40:55 +00:00
|
|
|
let sign = -1.0;
|
|
|
|
let tau = 1.0;
|
2020-01-26 15:46:57 +00:00
|
|
|
let slice = s![y.ny() - 1, ..];
|
2020-01-25 19:40:55 +00:00
|
|
|
SAT_characteristic(
|
|
|
|
k.north_mut(),
|
|
|
|
y.north(),
|
2020-02-19 19:00:52 +00:00
|
|
|
boundaries.north,
|
2020-01-25 19:40:55 +00:00
|
|
|
hi,
|
|
|
|
sign,
|
|
|
|
tau,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics.detj.slice(slice),
|
|
|
|
metrics.detj_deta_dx.slice(slice),
|
|
|
|
metrics.detj_deta_dy.slice(slice),
|
2020-01-25 19:40:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
// South boundary
|
|
|
|
{
|
2020-04-09 23:07:57 +00:00
|
|
|
let hi = (k.ny() - 1) as Float / SBP::h()[0];
|
2020-01-25 19:40:55 +00:00
|
|
|
let sign = 1.0;
|
|
|
|
let tau = -1.0;
|
|
|
|
let slice = s![0, ..];
|
|
|
|
SAT_characteristic(
|
|
|
|
k.south_mut(),
|
|
|
|
y.south(),
|
2020-02-19 19:00:52 +00:00
|
|
|
boundaries.south,
|
2020-01-25 19:40:55 +00:00
|
|
|
hi,
|
|
|
|
sign,
|
|
|
|
tau,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics.detj.slice(slice),
|
|
|
|
metrics.detj_deta_dx.slice(slice),
|
|
|
|
metrics.detj_deta_dy.slice(slice),
|
2020-01-25 19:40:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
// West Boundary
|
|
|
|
{
|
2020-04-09 23:07:57 +00:00
|
|
|
let hi = (k.nx() - 1) as Float / SBP::h()[0];
|
2020-01-25 19:40:55 +00:00
|
|
|
let sign = 1.0;
|
|
|
|
let tau = -1.0;
|
|
|
|
let slice = s![.., 0];
|
|
|
|
SAT_characteristic(
|
|
|
|
k.west_mut(),
|
|
|
|
y.west(),
|
2020-02-19 19:00:52 +00:00
|
|
|
boundaries.west,
|
2020-01-25 19:40:55 +00:00
|
|
|
hi,
|
|
|
|
sign,
|
|
|
|
tau,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics.detj.slice(slice),
|
|
|
|
metrics.detj_dxi_dx.slice(slice),
|
|
|
|
metrics.detj_dxi_dy.slice(slice),
|
2020-01-25 19:40:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
// East Boundary
|
|
|
|
{
|
2020-04-09 23:07:57 +00:00
|
|
|
let hi = (k.nx() - 1) as Float / SBP::h()[0];
|
2020-01-25 19:40:55 +00:00
|
|
|
let sign = -1.0;
|
|
|
|
let tau = 1.0;
|
|
|
|
let slice = s![.., y.nx() - 1];
|
|
|
|
SAT_characteristic(
|
|
|
|
k.east_mut(),
|
|
|
|
y.east(),
|
2020-02-19 19:00:52 +00:00
|
|
|
boundaries.east,
|
2020-01-25 19:40:55 +00:00
|
|
|
hi,
|
|
|
|
sign,
|
|
|
|
tau,
|
2020-04-03 22:29:02 +00:00
|
|
|
metrics.detj.slice(slice),
|
|
|
|
metrics.detj_dxi_dx.slice(slice),
|
|
|
|
metrics.detj_dxi_dy.slice(slice),
|
2020-01-25 19:40:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
2020-01-29 18:36:16 +00:00
|
|
|
#[allow(clippy::many_single_char_names)]
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-01-25 19:40:55 +00:00
|
|
|
/// Boundary conditions (SAT)
|
|
|
|
fn SAT_characteristic(
|
2020-02-27 19:26:43 +00:00
|
|
|
mut k: ArrayViewMut2<Float>,
|
|
|
|
y: ArrayView2<Float>,
|
|
|
|
z: ArrayView2<Float>, // Size 4 x n (all components in line)
|
|
|
|
hi: Float,
|
|
|
|
sign: Float,
|
|
|
|
tau: Float,
|
|
|
|
detj: ArrayView1<Float>,
|
|
|
|
detj_d_dx: ArrayView1<Float>,
|
|
|
|
detj_d_dy: ArrayView1<Float>,
|
2020-01-25 19:40:55 +00:00
|
|
|
) {
|
|
|
|
assert_eq!(detj.shape(), detj_d_dx.shape());
|
|
|
|
assert_eq!(detj.shape(), detj_d_dy.shape());
|
|
|
|
assert_eq!(y.shape(), z.shape());
|
|
|
|
assert_eq!(y.shape()[0], 4);
|
|
|
|
assert_eq!(y.shape()[1], detj.shape()[0]);
|
|
|
|
|
2020-01-26 14:46:54 +00:00
|
|
|
for (((((mut k, y), z), detj), detj_d_dx), detj_d_dy) in k
|
|
|
|
.axis_iter_mut(ndarray::Axis(1))
|
|
|
|
.zip(y.axis_iter(ndarray::Axis(1)))
|
|
|
|
.zip(z.axis_iter(ndarray::Axis(1)))
|
|
|
|
.zip(detj.iter())
|
|
|
|
.zip(detj_d_dx.iter())
|
|
|
|
.zip(detj_d_dy.iter())
|
|
|
|
{
|
|
|
|
let rho = y[0];
|
|
|
|
let rhou = y[1];
|
|
|
|
let rhov = y[2];
|
|
|
|
let e = y[3];
|
2020-01-25 19:40:55 +00:00
|
|
|
|
2020-01-26 14:46:54 +00:00
|
|
|
let kx_ = detj_d_dx / detj;
|
|
|
|
let ky_ = detj_d_dy / detj;
|
2020-01-25 19:40:55 +00:00
|
|
|
|
|
|
|
let (kx, ky) = {
|
2020-02-27 19:26:43 +00:00
|
|
|
let r = Float::hypot(kx_, ky_);
|
2020-01-25 19:40:55 +00:00
|
|
|
(kx_ / r, ky_ / r)
|
|
|
|
};
|
|
|
|
|
|
|
|
let u = rhou / rho;
|
|
|
|
let v = rhov / rho;
|
|
|
|
|
|
|
|
let theta = kx * u + ky * v;
|
|
|
|
|
|
|
|
let p = pressure(GAMMA, rho, rhou, rhov, e);
|
|
|
|
let c = (GAMMA * p / rho).sqrt();
|
|
|
|
let phi2 = (GAMMA - 1.0) * (u * u + v * v) / 2.0;
|
|
|
|
|
|
|
|
let phi2_c2 = (phi2 + c * c) / (GAMMA - 1.0);
|
|
|
|
|
2020-04-09 11:31:11 +00:00
|
|
|
#[rustfmt::skip]
|
2020-01-25 19:40:55 +00:00
|
|
|
let T = [
|
2020-04-09 11:31:11 +00:00
|
|
|
[ 1.0, 0.0, 1.0, 1.0],
|
|
|
|
[ u, ky, u + kx * c, u - kx * c],
|
|
|
|
[ v, -kx, v + ky * c, v - ky * c],
|
|
|
|
[phi2 / (GAMMA - 1.0), ky * u - kx * v, phi2_c2 + c * theta, phi2_c2 - c * theta],
|
2020-01-25 19:40:55 +00:00
|
|
|
];
|
|
|
|
let U = kx_ * u + ky_ * v;
|
|
|
|
let L = [
|
|
|
|
U,
|
|
|
|
U,
|
2020-02-27 19:26:43 +00:00
|
|
|
U + c * Float::hypot(kx_, ky_),
|
|
|
|
U - c * Float::hypot(kx_, ky_),
|
2020-01-25 19:40:55 +00:00
|
|
|
];
|
|
|
|
let beta = 1.0 / (2.0 * c * c);
|
2020-04-09 11:31:11 +00:00
|
|
|
#[rustfmt::skip]
|
2020-01-25 19:40:55 +00:00
|
|
|
let TI = [
|
2020-04-09 11:31:11 +00:00
|
|
|
[ 1.0 - phi2 / (c * c), (GAMMA - 1.0) * u / (c * c), (GAMMA - 1.0) * v / (c * c), -(GAMMA - 1.0) / (c * c)],
|
|
|
|
[ -(ky * u - kx * v), ky, -kx, 0.0],
|
|
|
|
[beta * (phi2 - c * theta), beta * (kx * c - (GAMMA - 1.0) * u), beta * (ky * c - (GAMMA - 1.0) * v), beta * (GAMMA - 1.0)],
|
|
|
|
[beta * (phi2 + c * theta), -beta * (kx * c + (GAMMA - 1.0) * u), -beta * (ky * c + (GAMMA - 1.0) * v), beta * (GAMMA - 1.0)],
|
2020-01-25 19:40:55 +00:00
|
|
|
];
|
|
|
|
|
2020-01-26 14:46:54 +00:00
|
|
|
let res = [rho - z[0], rhou - z[1], rhov - z[2], e - z[3]];
|
2020-01-25 19:40:55 +00:00
|
|
|
let mut TIres = [0.0; 4];
|
2020-01-29 18:36:16 +00:00
|
|
|
#[allow(clippy::needless_range_loop)]
|
2020-01-25 19:40:55 +00:00
|
|
|
for row in 0..4 {
|
|
|
|
for col in 0..4 {
|
|
|
|
TIres[row] += TI[row][col] * res[col];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// L + sign(abs(L)) * TIres
|
|
|
|
let mut LTIres = [0.0; 4];
|
|
|
|
for row in 0..4 {
|
|
|
|
LTIres[row] = (L[row] + sign * L[row].abs()) * TIres[row];
|
|
|
|
}
|
|
|
|
|
|
|
|
// T*LTIres
|
|
|
|
let mut TLTIres = [0.0; 4];
|
2020-01-29 18:36:16 +00:00
|
|
|
#[allow(clippy::needless_range_loop)]
|
2020-01-25 19:40:55 +00:00
|
|
|
for row in 0..4 {
|
|
|
|
for col in 0..4 {
|
|
|
|
TLTIres[row] += T[row][col] * LTIres[col];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for comp in 0..4 {
|
2020-01-26 14:46:54 +00:00
|
|
|
k[comp] += hi * tau * TLTIres[comp];
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 19:02:22 +00:00
|
|
|
#[derive(Debug)]
|
2020-01-25 19:40:55 +00:00
|
|
|
pub struct WorkBuffers {
|
2020-01-29 19:06:44 +00:00
|
|
|
k: [Field; 4],
|
2020-01-26 14:46:54 +00:00
|
|
|
tmp: (Field, Field, Field, Field, Field, Field),
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl WorkBuffers {
|
|
|
|
pub fn new(nx: usize, ny: usize) -> Self {
|
|
|
|
let arr3 = Field::new(nx, ny);
|
|
|
|
Self {
|
2020-01-29 19:06:44 +00:00
|
|
|
k: [arr3.clone(), arr3.clone(), arr3.clone(), arr3.clone()],
|
2020-01-26 14:46:54 +00:00
|
|
|
tmp: (
|
|
|
|
arr3.clone(),
|
|
|
|
arr3.clone(),
|
|
|
|
arr3.clone(),
|
|
|
|
arr3.clone(),
|
|
|
|
arr3.clone(),
|
|
|
|
arr3,
|
|
|
|
),
|
2020-01-25 19:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|