rewrite fluxes in a vectoriser friendly format

This commit is contained in:
Magnus Ulimoen 2020-05-05 20:15:44 +02:00
parent fa3b848c6c
commit 1aa4700479
1 changed files with 46 additions and 36 deletions

View File

@ -526,7 +526,7 @@ pub fn RHS_trad(
) { ) {
let ehat = &mut tmp.0; let ehat = &mut tmp.0;
let fhat = &mut tmp.1; let fhat = &mut tmp.1;
fluxes((ehat, fhat), y, metrics); fluxes((ehat, fhat), y, metrics, &mut tmp.2);
let dE = &mut tmp.2; let dE = &mut tmp.2;
let dF = &mut tmp.3; let dF = &mut tmp.3;
@ -561,7 +561,7 @@ pub fn RHS_upwind(
) { ) {
let ehat = &mut tmp.0; let ehat = &mut tmp.0;
let fhat = &mut tmp.1; let fhat = &mut tmp.1;
fluxes((ehat, fhat), y, metrics); fluxes((ehat, fhat), y, metrics, &mut tmp.2);
let dE = &mut tmp.2; let dE = &mut tmp.2;
let dF = &mut tmp.3; let dF = &mut tmp.3;
@ -660,49 +660,59 @@ fn upwind_dissipation(
op.disseta(tmp.1.e(), k.1.e_mut()); op.disseta(tmp.1.e(), k.1.e_mut());
} }
fn fluxes(k: (&mut Field, &mut Field), y: &Field, metrics: &Metrics) { /// Computes the fluxes
let j_dxi_dx = metrics.detj_dxi_dx(); ///
let j_dxi_dy = metrics.detj_dxi_dy(); /// eflux = [rhou, rhou*rhou/rho + p, rhou*rhov/rho, rhou*(e+p)/rho]
let j_deta_dx = metrics.detj_deta_dx(); /// fflux = [rhov, rhou*rhov/rho, rhov*rhov/rho + p, rhov*(e+p)/rho]
let j_deta_dy = metrics.detj_deta_dy(); fn fluxes(k: (&mut Field, &mut Field), y: &Field, metrics: &Metrics, wb: &mut Field) {
let rho = y.rho(); let rho = y.rho();
let rhou = y.rhou(); let rhou = y.rhou();
let rhov = y.rhov(); let rhov = y.rhov();
let e = y.e(); let e = y.e();
for j in 0..y.ny() { let mut p = wb.rho_mut();
for i in 0..y.nx() { azip!((p in &mut p, &rho in &rho, &rhou in &rhou, &rhov in &rhov, &e in &e) {
let rho = rho[(j, i)]; *p = pressure(GAMMA, rho, rhou, rhov, e)
assert!(rho > 0.0); });
let rhou = rhou[(j, i)];
let rhov = rhov[(j, i)];
let e = e[(j, i)];
let p = pressure(GAMMA, rho, rhou, rhov, e);
assert!(p > 0.0); k.0.rho_mut().assign(&rhou);
azip!((eflux in k.0.rhou_mut(), rho in &rho, rhou in &rhou, p in &p) {
*eflux = rhou*rhou/rho + p;
});
azip!((eflux in k.0.rhov_mut(), rho in &rho, rhou in &rhou, rhov in &rhov) {
*eflux = rhou*rhov/rho;
});
azip!((eflux in k.0.e_mut(), rho in &rho, rhou in &rhou, e in &e, p in &p) {
*eflux = rhou*(e + p)/rho;
});
let ef = [ k.1.rho_mut().assign(&rhov);
rhou, k.1.rhou_mut().assign(&k.0.rhov_mut());
rhou * rhou / rho + p, azip!((fflux in k.1.rhov_mut(), rho in &rho, rhov in &rhov, p in &p) {
rhou * rhov / rho, *fflux = rhov*rhov/rho + p;
rhou * (e + p) / rho, });
]; azip!((fflux in k.1.e_mut(), rho in &rho, rhov in &rhov, e in &e, p in &p) {
let ff = [ *fflux = rhov*(e + p)/rho;
rhov, });
rhou * rhov / rho,
rhov * rhov / rho + p,
rhov * (e + p) / rho,
];
let j_dxi_dx = metrics.detj_dxi_dx();
let j_dxi_dy = metrics.detj_dxi_dy();
let j_deta_dx = metrics.detj_deta_dx();
let j_deta_dy = metrics.detj_deta_dy();
// Let grid metrics modify the fluxes
for comp in 0..4 { for comp in 0..4 {
let eflux = j_dxi_dx[(j, i)] * ef[comp] + j_dxi_dy[(j, i)] * ff[comp]; azip!((ef in k.0.slice_mut(s![comp, .., ..]),
let fflux = j_deta_dx[(j, i)] * ef[comp] + j_deta_dy[(j, i)] * ff[comp]; ff in k.1.slice_mut(s![comp, .., ..]),
j_dxi_dx in &j_dxi_dx,
j_dxi_dy in &j_dxi_dy,
j_deta_dx in &j_deta_dx,
j_deta_dy in &j_deta_dy) {
k.0[(comp, j, i)] = eflux; let eflux = *ef;
k.1[(comp, j, i)] = fflux; let fflux = *ff;
} *ef = j_dxi_dx * eflux + j_dxi_dy * fflux;
} *ff = j_deta_dx * eflux + j_deta_dy * fflux;
})
} }
} }