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 normal_direction_ll for nonconservative terms #2062

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

patrickersing
Copy link
Contributor

@patrickersing patrickersing commented Sep 4, 2024

This PR simplifies the nonconservative terms to only depend on a single averaged normal_direction, instead of both normal_direction_average and normal_direction_ll (see #2049).
This should also enable setting boundary conditions for nonconservative terms #1445

Copy link
Contributor

github-actions bot commented Sep 4, 2024

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.

@patrickersing
Copy link
Contributor Author

As expected changing the normal directions caused slightly different results and with that some failing mhd tests.
The p4est and t8code test results are almost the same and only the psi value fails testing with differences in L2 between 1e-8 and 1e-10.
For UnstructuredMesh and StructuredMesh there are more failing tests, but the differences in the L2-Error remain relatively small between 1e-5 and 1e-8. The reason is probably that we use a very coarse mesh for the testing, with only four elements per dimension, which leads to larger differences in the normal direction.
Entropy is still conserved in all relevant tests.

For validation I additionally ran convergence tests using structured_2d/elixir_mhd_alfen_wave.jl and compared the result with the previous implementation using normal_direction_ll. The results show almost identical convergence rates.

polydeg=3, normal_direction_average:
Convergence_structured2D_P3_average

polydeg=3, normal_direction_ll:
Convergence_structured2D_P3_inner

polydeg=4, normal_direction_average:
Convergence_structured2D_P4_average

polydeg=4, normal_direction_ll:
Convergence_structured2D_P4_inner

Looking at these results, I think it would be fine to introduce the averaged normal direction and update the test values.
It would be great if someone working with MHD (maybe @amrueda @SimonCan @andrewwinters5000) can have a look at this and let me know if they think this is fine or if more validation is needed.

Another open problem is that the test dgmulti_2d/elixir_mhd_reflective_wall.jl is failing. @jlchan do you have any idea why this test could be failing?

@jlchan
Copy link
Contributor

jlchan commented Sep 5, 2024

Another open problem is that the test dgmulti_2d/elixir_mhd_reflective_wall.jl is failing. @jlchan do you have any idea why this test could be failing?

Thanks for testing it out in DGMulti too! I'll take a look this afternoon.

Since the test is failing due to domain error (negative density or pressure) I think it's a real failure. My guess is that it's related to the boundary condition imposition

noncons_flux_at_face_node = boundary_condition(u_face_values[i, f],
face_normal,
face_coordinates,
t,
nonconservative_flux,
equations)

since all the other MHD tests still pass.

@patrickersing
Copy link
Contributor Author

Since the test is failing due to domain error (negative density or pressure) I think it's a real failure. My guess is that it's related to the boundary condition imposition

That makes sense. I just looked at the boundary conditions that are used in the elixir and noticed that BoundaryConditionDoNothing needs to be adapted. Currently this always calls the flux function (even if we call it with the nonconservative term) so this definitely imposes a wrong boundary condition.

I will try to replace this with

@inline function (::BoundaryConditionDoNothing)(u_inner,
                                                outward_direction::AbstractVector,
                                                x, t, surface_flux, equations)
    #return flux(u_inner, outward_direction, equations)
    return surface_flux(u_inner, u_inner, outward_direction, equations)
end```

@jlchan
Copy link
Contributor

jlchan commented Sep 6, 2024

@patrickersing looks like your new BoundaryConditionDoNothing fixed the issue; the failing tests for unstructured_dgmulti now just seem to be due to floating point differences.

@patrickersing patrickersing changed the title [WIP] Remove normal_direction_ll for nonconservative terms Remove normal_direction_ll for nonconservative terms Sep 10, 2024
@DanielDoehring
Copy link
Contributor

Once this is ready to go we can schedule the next breaking release 0.9, cf. #1997

@patrickersing patrickersing marked this pull request as ready for review September 12, 2024 09:58
Copy link
Member

@andrewwinters5000 andrewwinters5000 left a comment

Choose a reason for hiding this comment

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

LGTM! I just left one question for Andrés. It would be good to get this PR ship-shape and ready for the next breaking release. Can you have a look @amrueda or @SimonCan as you both more actively work with the MHD system.

src/equations/ideal_glm_mhd_2d.jl Show resolved Hide resolved
@DanielDoehring DanielDoehring mentioned this pull request Sep 18, 2024
10 tasks
Copy link
Contributor

@amrueda amrueda left a comment

Choose a reason for hiding this comment

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

It looks good. I leave here only a couple of comments.

@@ -71,14 +71,14 @@ struct BoundaryConditionDoNothing end
orientation_or_normal_direction,
direction::Integer, x, t, surface_flux,
equations)
return flux(u_inner, orientation_or_normal_direction, equations)
return surface_flux(u_inner, u_inner, orientation_or_normal_direction, equations)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to use surface_flux here? isn't that adding computational complexity for the same output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This became necessary, since we now also apply the boundary condition for nonconservative terms.
When you call BoundaryConditionDoNothing with nonconservative terms, the old implementation still evaluates the inner flux instead of the inner nonconservative term. Therefore, we erroneously impose the conservative flux twice.
For conservative fluxes this increases the computational complexity, but the modification is necessary to return a consistent boundary condition for both conservative and nonconservative terms.

end

# This version can be called by hyperbolic solvers on unstructured, curved meshes
@inline function (::BoundaryConditionDoNothing)(u_inner,
outward_direction::AbstractVector,
x, t, surface_flux, equations)
return flux(u_inner, outward_direction, equations)
return surface_flux(u_inner, u_inner, outward_direction, equations)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

contravariant vector (normal direction) at the current node and the averaged
one. This is different from numerical fluxes used to discretize conservative
terms.

## References
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be mentioned here that this term is not exactly equivalent to the one proposed by Bohm et al., as the "metrics dealiasing" is done in a different manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an additional comment about this to the docstring in 95d846a

contravariant vector (normal direction) at the current node and the averaged
one. This is different from numerical fluxes used to discretize conservative
terms.

## References
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

@ranocha
Copy link
Member

ranocha commented Sep 30, 2024

A lot of tests fail. Could you please check what's going on?

@patrickersing
Copy link
Contributor Author

A lot of tests fail. Could you please check what's going on?

Most tests are failing, because we get slightly different results with the averaged normal direction. Since there haven't been any objections, I will proceed and update the reference values to fix the tests.

To fix the downstream test for TrixiShallowWater.jl I prepared a corresponding PR trixi-framework/TrixiShallowWater.jl#58, that needs to be merged after this one.

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.34%. Comparing base (fa43fb2) to head (be1f9e2).

Files with missing lines Patch % Lines
src/solvers/dgmulti/flux_differencing.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2062      +/-   ##
==========================================
+ Coverage   89.86%   96.34%   +6.48%     
==========================================
  Files         470      470              
  Lines       37486    37495       +9     
==========================================
+ Hits        33685    36123    +2438     
+ Misses       3801     1372    -2429     
Flag Coverage Δ
unittests 96.34% <96.30%> (+6.48%) ⬆️

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.

@ranocha
Copy link
Member

ranocha commented Oct 2, 2024

@amrueda Could you please review this PR again?

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Could you please add some NEWS.md?

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