Commit 9818d481 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Reduced number of divisions in cell slope limiter. Code formatting.

parent f32fd3df
......@@ -95,7 +95,6 @@ __attribute__((always_inline)) INLINE static void hydro_gradients_predict(
struct part* restrict pi, struct part* restrict pj, float hi, float hj,
const float* dx, float r, const float* xij_i, float* Wi, float* Wj) {
/* perform gradient reconstruction in space and time */
/* Compute interface position (relative to pj, since we don't need the actual
* position) eqn. (8) */
......
......@@ -459,8 +459,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_fluxes_common(
#ifndef GIZMO_TOTAL_ENERGY
const float ekin_j = 0.5f * (pj->primitives.v[0] * pj->primitives.v[0] +
pj->primitives.v[1] * pj->primitives.v[1] +
pj->primitives.v[2] * pj->primitives.v[2]);
pj->primitives.v[1] * pj->primitives.v[1] +
pj->primitives.v[2] * pj->primitives.v[2]);
pj->conserved.flux.energy -= totflux[1] * pj->primitives.v[0];
pj->conserved.flux.energy -= totflux[2] * pj->primitives.v[1];
pj->conserved.flux.energy -= totflux[3] * pj->primitives.v[2];
......
......@@ -90,8 +90,7 @@ hydro_slope_limit_cell_collect(struct part* pi, struct part* pj, float r) {
__attribute__((always_inline)) INLINE static void hydro_slope_limit_cell(
struct part* p) {
float gradrho[3], gradv[3][3], gradP[3];
float gradtrue, gradmax, gradmin, alpha;
float gradtrue, gradrho[3], gradv[3][3], gradP[3];
gradrho[0] = p->primitives.gradients.rho[0];
gradrho[1] = p->primitives.gradients.rho[1];
......@@ -117,9 +116,11 @@ __attribute__((always_inline)) INLINE static void hydro_slope_limit_cell(
gradrho[2] * gradrho[2]);
if (gradtrue) {
gradtrue *= p->primitives.limiter.maxr;
gradmax = p->primitives.limiter.rho[1] - p->primitives.rho;
gradmin = p->primitives.rho - p->primitives.limiter.rho[0];
alpha = min3(1.0f, gradmax / gradtrue, gradmin / gradtrue);
const float gradmax = p->primitives.limiter.rho[1] - p->primitives.rho;
const float gradmin = p->primitives.rho - p->primitives.limiter.rho[0];
const float gradtrue_inv = 1.f / gradtrue;
const float alpha =
min3(1.0f, gradmax * gradtrue_inv, gradmin * gradtrue_inv);
p->primitives.gradients.rho[0] *= alpha;
p->primitives.gradients.rho[1] *= alpha;
p->primitives.gradients.rho[2] *= alpha;
......@@ -129,9 +130,11 @@ __attribute__((always_inline)) INLINE static void hydro_slope_limit_cell(
gradv[0][2] * gradv[0][2]);
if (gradtrue) {
gradtrue *= p->primitives.limiter.maxr;
gradmax = p->primitives.limiter.v[0][1] - p->primitives.v[0];
gradmin = p->primitives.v[0] - p->primitives.limiter.v[0][0];
alpha = min3(1.0f, gradmax / gradtrue, gradmin / gradtrue);
const float gradmax = p->primitives.limiter.v[0][1] - p->primitives.v[0];
const float gradmin = p->primitives.v[0] - p->primitives.limiter.v[0][0];
const float gradtrue_inv = 1.f / gradtrue;
const float alpha =
min3(1.0f, gradmax * gradtrue_inv, gradmin * gradtrue_inv);
p->primitives.gradients.v[0][0] *= alpha;
p->primitives.gradients.v[0][1] *= alpha;
p->primitives.gradients.v[0][2] *= alpha;
......@@ -141,9 +144,11 @@ __attribute__((always_inline)) INLINE static void hydro_slope_limit_cell(
gradv[1][2] * gradv[1][2]);
if (gradtrue) {
gradtrue *= p->primitives.limiter.maxr;
gradmax = p->primitives.limiter.v[1][1] - p->primitives.v[1];
gradmin = p->primitives.v[1] - p->primitives.limiter.v[1][0];
alpha = min3(1.0f, gradmax / gradtrue, gradmin / gradtrue);
const float gradmax = p->primitives.limiter.v[1][1] - p->primitives.v[1];
const float gradmin = p->primitives.v[1] - p->primitives.limiter.v[1][0];
const float gradtrue_inv = 1.f / gradtrue;
const float alpha =
min3(1.0f, gradmax * gradtrue_inv, gradmin * gradtrue_inv);
p->primitives.gradients.v[1][0] *= alpha;
p->primitives.gradients.v[1][1] *= alpha;
p->primitives.gradients.v[1][2] *= alpha;
......@@ -153,9 +158,11 @@ __attribute__((always_inline)) INLINE static void hydro_slope_limit_cell(
gradv[2][2] * gradv[2][2]);
if (gradtrue) {
gradtrue *= p->primitives.limiter.maxr;
gradmax = p->primitives.limiter.v[2][1] - p->primitives.v[2];
gradmin = p->primitives.v[2] - p->primitives.limiter.v[2][0];
alpha = min3(1.0f, gradmax / gradtrue, gradmin / gradtrue);
const float gradmax = p->primitives.limiter.v[2][1] - p->primitives.v[2];
const float gradmin = p->primitives.v[2] - p->primitives.limiter.v[2][0];
const float gradtrue_inv = 1.f / gradtrue;
const float alpha =
min3(1.0f, gradmax * gradtrue_inv, gradmin * gradtrue_inv);
p->primitives.gradients.v[2][0] *= alpha;
p->primitives.gradients.v[2][1] *= alpha;
p->primitives.gradients.v[2][2] *= alpha;
......@@ -165,9 +172,11 @@ __attribute__((always_inline)) INLINE static void hydro_slope_limit_cell(
sqrtf(gradP[0] * gradP[0] + gradP[1] * gradP[1] + gradP[2] * gradP[2]);
if (gradtrue) {
gradtrue *= p->primitives.limiter.maxr;
gradmax = p->primitives.limiter.P[1] - p->primitives.P;
gradmin = p->primitives.P - p->primitives.limiter.P[0];
alpha = min3(1.0f, gradmax / gradtrue, gradmin / gradtrue);
const float gradmax = p->primitives.limiter.P[1] - p->primitives.P;
const float gradmin = p->primitives.P - p->primitives.limiter.P[0];
const float gradtrue_inv = 1.f / gradtrue;
const float alpha =
min3(1.0f, gradmax * gradtrue_inv, gradmin * gradtrue_inv);
p->primitives.gradients.P[0] *= alpha;
p->primitives.gradients.P[1] *= alpha;
p->primitives.gradients.P[2] *= alpha;
......
......@@ -88,8 +88,8 @@ hydro_slope_limit_face_quantity(float phi_i, float phi_j, float phi_mid0,
* @param r Distance between particle i and particle j.
*/
__attribute__((always_inline)) INLINE static void hydro_slope_limit_face(
float *Wi, float *Wj, float *dWi, float *dWj, const float *xij_i, const float *xij_j,
float r) {
float *Wi, float *Wj, float *dWi, float *dWj, const float *xij_i,
const float *xij_j, float r) {
const float xij_i_norm =
sqrtf(xij_i[0] * xij_i[0] + xij_i[1] * xij_i[1] + xij_i[2] * xij_i[2]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment