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

Remove ndims where not necessary #2081

Conversation

DanielDoehring
Copy link
Contributor

Closes #2080

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

Review checklist

This checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging.

Purpose and scope

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md with its PR number.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 96.34%. Comparing base (288d41d) to head (f17e398).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/callbacks_step/amr_dg2d.jl 71.43% 2 Missing ⚠️
src/callbacks_step/amr_dg3d.jl 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2081      +/-   ##
==========================================
+ Coverage   96.32%   96.34%   +0.02%     
==========================================
  Files         470      470              
  Lines       37485    37494       +9     
==========================================
+ Hits        36106    36121      +15     
+ Misses       1379     1373       -6     
Flag Coverage Δ
unittests 96.34% <81.25%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 315 to 317
resize!(u_ode,
nvariables(equations) * nnodes(dg)^ndims(mesh) * nelements(dg, cache))
nvariables(equations) * nnodes(dg)^2 * nelements(dg, cache))
u = wrap_array(u_ode, mesh, equations, dg, cache)
Copy link
Member

Choose a reason for hiding this comment

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

I think parts like these become much harder to understand with this PR. What do you think, @sloede?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I have to agree with Hendrik.

The advantage of explicitly adding ndims(mesh) is that it makes the factor self-explanatory. Also in the other parts of the code, one avoids having to explain why a factor is what it is and how it was computed, or even how to change it when switching to another dimension.

I see the argument for more "elegant" code (avoiding the impression of having a varying dimension). However, I've seen too many codes where "magic" constants appear out of nowhere, and everyone reading it after 3 years has to re-understand what the intent/thought process of the original author was.

IMHO, the current version is concise and self-explanatory in terms of what is being done, thus I'd prefer to keep it as it is.

Copy link
Member

Choose a reason for hiding this comment

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

To throw in my two cents. I want to keep the ndims calls in the code. I think it is much more informative to have terms like 2^ndims(mesh) - 1 rather than values like 3 and 7. This is coming from the perspective of someone who recently became very familiar with the AMR implementation as I debugged and tracked down the loss of conservation. I think the current code is perfectly understandable.

Copy link
Contributor Author

@DanielDoehring DanielDoehring Sep 24, 2024

Choose a reason for hiding this comment

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

Ok, I will close this PR then. Opinions about the status of the issue?

Copy link
Member

Choose a reason for hiding this comment

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

I would close it in light of the comments above

@@ -330,7 +330,7 @@ function coarsen!(u_ode::AbstractVector, adaptor,
# If an element is to be removed, sanity check if the following elements
# are also marked - otherwise there would be an error in the way the
# cells/elements are sorted
@assert all(to_be_removed[old_element_id:(old_element_id + 2^ndims(mesh) - 1)]) "bad cell/element order"
@assert all(to_be_removed[old_element_id:(old_element_id + 2^2 - 1)]) "bad cell/element order"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One could move skip = 3 already up here

@@ -250,7 +250,7 @@ function coarsen!(u_ode::AbstractVector, adaptor,
# If an element is to be removed, sanity check if the following elements
# are also marked - otherwise there would be an error in the way the
# cells/elements are sorted
@assert all(to_be_removed[old_element_id:(old_element_id + 2^ndims(mesh) - 1)]) "bad cell/element order"
@assert all(to_be_removed[old_element_id:(old_element_id + 2^3 - 1)]) "bad cell/element order"
Copy link
Contributor Author

@DanielDoehring DanielDoehring Sep 17, 2024

Choose a reason for hiding this comment

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

One could move skip = 7 already up here

@@ -187,13 +187,15 @@ function coarsen!(u_ode::AbstractVector, adaptor, mesh::TreeMesh{1},
# If an element is to be removed, sanity check if the following elements
# are also marked - otherwise there would be an error in the way the
# cells/elements are sorted
@assert all(to_be_removed[old_element_id:(old_element_id + 2^ndims(mesh) - 1)]) "bad cell/element order"
@assert all(to_be_removed[old_element_id:(old_element_id + 2 - 1)]) "bad cell/element order"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One could move skip = 1 already up here

@DanielDoehring
Copy link
Contributor Author

See discussion

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 this pull request may close these issues.

Usage of ndims(mesh) at many avoidable places
4 participants