Skip to content

Commit

Permalink
Merge pull request #3037 from boutproject/fvops-clang-tidy-perf
Browse files Browse the repository at this point in the history
Performance improvements for Fix lots of clang-tidy issues in fv_ops
  • Loading branch information
ZedThree authored Feb 14, 2025
2 parents d8ca2f7 + 8617316 commit 2c51549
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions include/bout/fv_ops.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ Field3D D4DY4_index(const Field3D& f_in, bool bndry_flux = true);
*/
struct Stencil1D {
// Cell centre values
#if CHECK > 0
BoutReal c = BoutNaN, m = BoutNaN, p = BoutNaN, mm = BoutNaN, pp = BoutNaN;

// Left and right cell face values
BoutReal L = BoutNaN, R = BoutNaN;
#else
BoutReal c, m, p, mm, pp;

// Left and right cell face values
BoutReal L, R;
#endif
};

/*!
Expand Down Expand Up @@ -436,14 +443,12 @@ Field3D Div_f_v(const Field3D& n_in, const Vector3D& v, bool bndry_flux) {
if ((i.x() == mesh->xend) && (mesh->lastX())) {
// At right boundary in X
if (bndry_flux) {
BoutReal flux = BoutNaN;
if (v_R > 0.0) {
// Flux to boundary
flux = v_R * stencil.R;
} else {
// Flux in from boundary
flux = v_R * 0.5 * (n_in[i.xp()] + n_in[i]);
}
const BoutReal flux = v_R > 0.0 ?
// Flux to boundary
v_R * stencil.R
:
// Flux in from boundary
v_R * 0.5 * (n_in[i.xp()] + n_in[i]);
result[i] += flux / (coord->dx[i] * coord->J[i]);
result[i.xp()] -= flux / (coord->dx[i.xp()] * coord->J[i.xp()]);
}
Expand All @@ -463,14 +468,12 @@ Field3D Div_f_v(const Field3D& n_in, const Vector3D& v, bool bndry_flux) {
// At left boundary in X

if (bndry_flux) {
BoutReal flux = BoutNaN;
if (v_L < 0.0) {
// Flux to boundary
flux = v_L * stencil.L;
} else {
// Flux in from boundary
flux = v_L * 0.5 * (n_in[i.xm()] + n_in[i]);
}
const BoutReal flux = (v_L < 0.0) ?
// Flux to boundary
v_L * stencil.L
:
// Flux in from boundary
v_L * 0.5 * (n_in[i.xm()] + n_in[i]);
result[i] -= flux / (coord->dx[i] * coord->J[i]);
result[i.xm()] += flux / (coord->dx[i.xm()] * coord->J[i.xm()]);
}
Expand Down

0 comments on commit 2c51549

Please sign in to comment.