Simplify vortex using Evaluator trait
This commit is contained in:
parent
92ad7bc580
commit
94e49ff9b5
|
@ -7,9 +7,9 @@ use sbp::utils::Direction;
|
||||||
use sbp::Float;
|
use sbp::Float;
|
||||||
|
|
||||||
pub mod eval;
|
pub mod eval;
|
||||||
|
use eval::Evaluator;
|
||||||
mod vortex;
|
mod vortex;
|
||||||
pub use vortex::{vortex, VortexParameters, Vortice};
|
pub use vortex::{VortexParameters, Vortice};
|
||||||
|
|
||||||
pub const GAMMA: Float = 1.4;
|
pub const GAMMA: Float = 1.4;
|
||||||
|
|
||||||
|
@ -320,23 +320,8 @@ impl Field {
|
||||||
time: Float,
|
time: Float,
|
||||||
vortex_param: &VortexParameters,
|
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();
|
let (rho, rhou, rhov, e) = self.components_mut();
|
||||||
let n = rho.len();
|
vortex_param.evaluate(time, x, y, rho, rhou, rhov, e)
|
||||||
|
|
||||||
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(),
|
|
||||||
time,
|
|
||||||
&vortex_param,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
fn iter(&self) -> impl ExactSizeIterator<Item = FieldValue> + '_ {
|
fn iter(&self) -> impl ExactSizeIterator<Item = FieldValue> + '_ {
|
||||||
let n = self.nx() * self.ny();
|
let n = self.nx() * self.ny();
|
||||||
|
@ -949,7 +934,7 @@ fn vortexify(
|
||||||
fiter.next().unwrap(),
|
fiter.next().unwrap(),
|
||||||
);
|
);
|
||||||
let (y, x) = yx;
|
let (y, x) = yx;
|
||||||
vortex(rho, rhou, rhov, e, x, y, time, &vparams);
|
vparams.evaluate(time, x, y, rho, rhou, rhov, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -20,26 +20,20 @@ pub struct VortexParameters {
|
||||||
pub mach: Float,
|
pub mach: Float,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
impl<D: Dimension> eval::Evaluator<D> for VortexParameters {
|
||||||
#[allow(clippy::many_single_char_names)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn vortex(
|
#[allow(clippy::many_single_char_names)]
|
||||||
rho: ArrayViewMut1<Float>,
|
fn evaluate(
|
||||||
rhou: ArrayViewMut1<Float>,
|
&self,
|
||||||
rhov: ArrayViewMut1<Float>,
|
|
||||||
e: ArrayViewMut1<Float>,
|
|
||||||
x: ArrayView1<Float>,
|
|
||||||
y: ArrayView1<Float>,
|
|
||||||
time: Float,
|
time: Float,
|
||||||
vortex_param: &VortexParameters,
|
x: ArrayView<Float, D>,
|
||||||
) {
|
y: ArrayView<Float, D>,
|
||||||
assert_eq!(rho.len(), rhou.len());
|
rho: ArrayViewMut<Float, D>,
|
||||||
assert_eq!(rho.len(), rhov.len());
|
rhou: ArrayViewMut<Float, D>,
|
||||||
assert_eq!(rho.len(), e.len());
|
rhov: ArrayViewMut<Float, D>,
|
||||||
assert_eq!(rho.len(), x.len());
|
e: ArrayViewMut<Float, D>,
|
||||||
assert_eq!(rho.len(), y.len());
|
) {
|
||||||
assert_eq!(x.shape(), y.shape());
|
let m = self.mach;
|
||||||
|
|
||||||
let m = vortex_param.mach;
|
|
||||||
let p_inf = 1.0 / (GAMMA * m * m);
|
let p_inf = 1.0 / (GAMMA * m * m);
|
||||||
|
|
||||||
let rho_inf: Float = 1.0;
|
let rho_inf: Float = 1.0;
|
||||||
|
@ -55,7 +49,7 @@ pub fn vortex(
|
||||||
y in y)
|
y in y)
|
||||||
{
|
{
|
||||||
|
|
||||||
let mut iterator = vortex_param.vortices.iter();
|
let mut iterator = self.vortices.iter();
|
||||||
|
|
||||||
match iterator.next() {
|
match iterator.next() {
|
||||||
None => {
|
None => {
|
||||||
|
@ -115,4 +109,5 @@ pub fn vortex(
|
||||||
*e += (p/(GAMMA - 1.0) + rho_vortice*(u*u + v*v)/2.0) - e_inf;
|
*e += (p/(GAMMA - 1.0) + rho_vortice*(u*u + v*v)/2.0) - e_inf;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue