Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lots of clang-tidy issues in fv_ops #3007

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open

Conversation

ZedThree
Copy link
Member

Mostly:

  • include required headers
  • rename some short identifiers
  • make some local variables const
    • in a few cases, this involved renaming them to avoid reuse of the
      same variable for different cases (e.g. left/right fluxes)

This is mostly to avoid getting the clang-tidy warnings in #2873

Mostly:

- include required headers
- rename some short identifiers
- make some local variables `const`
   - in a few cases, this involved renaming them to avoid reuse of the
     same variable for different cases (e.g. left/right fluxes)
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@dschwoerer dschwoerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit worried about adding not-needed writes by default.
I would be fine if they would only be present with -DCHECK>0 as I do not expect that they add significant overhead, but it still does not feels like something we should be doing for -DCHECK=0

#include "bout/utils.hxx"
#include <bout/mesh.hxx>
#include <cmath>
#include <cstdlib>

namespace FV {
/*!
* Div ( a Grad_perp(f) ) -- ∇⊥ ( a ⋅ ∇⊥ f) -- Vorticity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Div ( a Grad_perp(f) ) -- ∇⊥ ( a ⋅ ∇⊥ f) -- Vorticity
* Div ( a Grad_perp(f) ) -- ∇⊥ ( a_coef ⋅ ∇⊥ f) -- Vorticity

Comment on lines +86 to +89
BoutReal c = BoutNaN, m = BoutNaN, p = BoutNaN, mm = BoutNaN, pp = BoutNaN;

// Left and right cell face values
BoutReal L, R;
BoutReal L = BoutNaN, R = BoutNaN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not worried about performance implications?


////////////////////////////////////////////
// Right boundary

// Calculate velocity at right boundary (y+1/2)
BoutReal vpar = 0.5 * (v(i, j, k) + v(i, j + 1, k));
BoutReal flux;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance implications?


if ((i.x() == mesh->xend) && (mesh->lastX())) {
// At right boundary in X
if (bndry_flux) {
BoutReal flux;
if (vR > 0.0) {
BoutReal flux = BoutNaN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance? Apparently the compiler cannot deduct that flux is always written, and thus cannot optimize the not-needed write ...

@@ -451,21 +463,21 @@ const Field3D Div_f_v(const Field3D& n_in, const Vector3D& v, bool bndry_flux) {
// At left boundary in X

if (bndry_flux) {
BoutReal flux;
if (vL < 0.0) {
BoutReal flux = BoutNaN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance?

@ZedThree
Copy link
Member Author

Not too concerned about performance really, initialisation doesn't tend to have much a real world impact, especially given all the conditionals we've got in this loops.

Initialising to zero (instead of NaN) is one option, this basically has no impact as it can be done for free using allocation via zero-pages.

Some of these at least could be rewritten as ternaries, allowing us to make the variable const too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants