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

Usage of ndims(mesh) at many avoidable places #2080

Closed
DanielDoehring opened this issue Sep 17, 2024 · 3 comments
Closed

Usage of ndims(mesh) at many avoidable places #2080

DanielDoehring opened this issue Sep 17, 2024 · 3 comments
Labels
consistency Make Michael happy discussion low-priority refactoring Refactoring code without functional changes

Comments

@DanielDoehring
Copy link
Contributor

We often dispatch functions based on the spatial dimensionality of the mesh, see for instance

function limiter_zhang_shu!(u, threshold::Real, variable,
mesh::AbstractMesh{1}, equations, dg::DGSEM, cache)

Nevetheless, in these functions the dimensionality of the mesh is still often queried:

u_mean = u_mean / 2^ndims(mesh)

While the overhead for this is hopefully negligible due to optimizations, this is (in my opinion) bad style, as this code suggests some variability in the method which is not there.

@DanielDoehring DanielDoehring added discussion low-priority consistency Make Michael happy refactoring Refactoring code without functional changes labels Sep 17, 2024
@ranocha
Copy link
Member

ranocha commented Sep 17, 2024

It should be compiled away since it just returns a compile-time constant. In the specific case you mentioned, it makes it much clearer how the magic numbers appear there. For example, it would be hard for me to see how to generalize it if I just saw / 4 in the 2D case.

Having said that, it would be great if you could make some concrete suggestions on how to clarify and improve the code.

@DanielDoehring
Copy link
Contributor Author

I would suggest to put the dimensionality right there and leave the usage of this function for the places where the mesh is actually generic.

If this leads to confusion, one could think about adding comments (in the example above, there is for instance already a comment explaining the 2.)

@DanielDoehring
Copy link
Contributor Author

See discussion in #2081

@DanielDoehring DanielDoehring closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consistency Make Michael happy discussion low-priority refactoring Refactoring code without functional changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants