Skip to content

EC mortars: Tree 2D #2302

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

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

DanielDoehring
Copy link
Contributor

I tried to port #247 to Trixi's current state. Does currently not work - not sure if I did a mistake or if the original draft was flawed.

@amrueda

Copy link
Contributor

github-actions bot commented Mar 5, 2025

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 Mar 6, 2025

Codecov Report

Attention: Patch coverage is 97.29730% with 4 lines in your changes missing coverage. Please review.

Project coverage is 96.91%. Comparing base (dc8cd7e) to head (d3085f0).

Files with missing lines Patch % Lines
src/solvers/dgsem/basis_lobatto_legendre.jl 83.33% 3 Missing ⚠️
src/solvers/dgsem_tree/dg_2d.jl 98.97% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2302      +/-   ##
==========================================
- Coverage   96.91%   96.91%   -0.00%     
==========================================
  Files         496      497       +1     
  Lines       41140    41267     +127     
==========================================
+ Hits        39870    39993     +123     
- Misses       1270     1274       +4     
Flag Coverage Δ
unittests 96.91% <97.30%> (-<0.01%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sloede
Copy link
Member

sloede commented Mar 20, 2025

Does currently not work - not sure if I did a mistake or if the original draft was flawed.

What exactly does not work? IIRC (though that's from >4 years ago), the final version of the original PR was fully functional for at least one test setup and did show proper convergence behavior as well as EC properties.

@DanielDoehring
Copy link
Contributor Author

What exactly does not work? IIRC (though that's from >4 years ago), the final version of the original PR was fully functional for at least one test setup and did show proper convergence behavior as well as EC properties.

Not sure, the current version seems to be correct - (although there are some allocations that need to be removed). My first try did not work, this is why I have not touched this for a long time. I believe #2134 resolved this.

@DanielDoehring DanielDoehring changed the title Ec mortars EC mortars Mar 25, 2025
@DanielDoehring DanielDoehring changed the title EC mortars EC mortars: Tree 2D Mar 26, 2025
@DanielDoehring DanielDoehring added the enhancement New feature or request label Mar 26, 2025
@DanielDoehring DanielDoehring marked this pull request as ready for review March 26, 2025 10:04
@DanielDoehring DanielDoehring requested a review from jlchan March 26, 2025 10:04
@DanielDoehring DanielDoehring requested a review from amrueda March 26, 2025 10:04
Comment on lines +119 to +123
MA3d = MArray{Tuple{nvariables(equations), nnodes(mortar_ec), nnodes(mortar_ec)},
uEltype, 3,
nvariables(equations) * nnodes(mortar_ec) * nnodes(mortar_ec)}
fstar_upper_correction_threaded = MA3d[MA3d(undef) for _ in 1:Threads.nthreads()]
fstar_lower_correction_threaded = MA3d[MA3d(undef) for _ in 1:Threads.nthreads()]
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 is the only true difference to the L2 mortar.

Comment on lines 1131 to 1163
for i in 1:nnodes(dg)
# Loop over all variables
for v in eachvariable(equations)
# Calculate flux corrections for i'th node
flux_correction = zero(eltype(fstar_upper_correction))

# Loop over inner-element nodes (see Fig. 3) of
# Chan, Bencomo, Del Rey Fernández (2021).
# Mortar-based Entropy-Stable Discontinuous Galerkin Methods on
# Non-conforming Quadrilateral and Hexahedral Meshes.
# https://doi.org/10.1007/s10915-021-01652-3
for j in 1:nnodes(dg)
# j-local flux: "Forward" flux
f_j_upper = fstar_upper_correction[v, i, j]
f_j_lower = fstar_lower_correction[v, i, j]

# Subtract "forward" flux
for k in 1:nnodes(dg)
f_j_upper -= mortar_ec.forward_upper[j, k] *
fstar_upper_correction[v, k, j]
f_j_lower -= mortar_ec.forward_lower[j, k] *
fstar_lower_correction[v, k, j]
end

# Add to flux correction involving "reverse" flux
flux_correction += mortar_ec.reverse_upper[i, j] * f_j_upper
flux_correction += mortar_ec.reverse_lower[i, j] * f_j_lower
end

# Finally, add to surface flux values
surface_flux_values[v, i, direction, large_element_id] += flux_correction
end
end
Copy link
Contributor Author

@DanielDoehring DanielDoehring Mar 26, 2025

Choose a reason for hiding this comment

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

Maybe this can be made more efficient using multiply_dimensionwise!?

@DanielDoehring
Copy link
Contributor Author

DanielDoehring commented Mar 26, 2025

Convergence test:

####################################################################################################
l2
rho                 rho_v1              rho_v2              rho_e               
error     EOC       error     EOC       error     EOC       error     EOC       
6.13e-04  -         2.49e-02  -         2.64e-02  -         5.80e-02  -         
8.40e-05  2.87      3.43e-03  2.86      3.74e-03  2.82      8.20e-03  2.82      
2.98e-06  4.82      1.58e-04  4.44      1.52e-04  4.62      3.19e-04  4.68      
7.15e-08  5.38      4.71e-06  5.06      3.94e-06  5.27      7.94e-06  5.33      

mean      4.35      mean      4.12      mean      4.24      mean      4.28      
----------------------------------------------------------------------------------------------------
linf
rho                 rho_v1              rho_v2              rho_e               
error     EOC       error     EOC       error     EOC       error     EOC       
1.15e-02  -         3.02e-01  -         2.88e-01  -         1.04e+00  -         
1.68e-03  2.77      4.73e-02  2.67      5.28e-02  2.45      1.69e-01  2.63      
7.23e-05  4.54      2.67e-03  4.15      2.42e-03  4.45      7.14e-03  4.57      
2.35e-06  4.95      1.28e-04  4.38      1.21e-04  4.32      2.61e-04  4.78      

mean      4.08      mean      3.73      mean      3.74      mean      3.99      
----------------------------------------------------------------------------------------------------

I suspect that the superconvergence is due to the refinement patch.

For the standard L2 mortar:

####################################################################################################
l2
rho                 rho_v1              rho_v2              rho_e               
error     EOC       error     EOC       error     EOC       error     EOC       
6.11e-04  -         2.48e-02  -         2.61e-02  -         5.78e-02  -         
8.47e-05  2.85      3.49e-03  2.83      3.75e-03  2.80      8.30e-03  2.80      
2.86e-06  4.89      1.52e-04  4.52      1.46e-04  4.68      3.03e-04  4.78      
5.60e-08  5.68      3.57e-06  5.41      3.19e-06  5.52      6.13e-06  5.63      

mean      4.47      mean      4.25      mean      4.33      mean      4.40      
----------------------------------------------------------------------------------------------------
linf
rho                 rho_v1              rho_v2              rho_e               
error     EOC       error     EOC       error     EOC       error     EOC       
1.14e-02  -         3.02e-01  -         2.85e-01  -         1.04e+00  -         
1.70e-03  2.75      4.86e-02  2.64      5.22e-02  2.45      1.70e-01  2.61      
7.21e-05  4.56      2.67e-03  4.19      2.33e-03  4.48      6.95e-03  4.62      
1.89e-06  5.25      7.37e-05  5.18      6.75e-05  5.11      1.62e-04  5.42      

mean      4.19      mean      4.00      mean      4.01      mean      4.22      
----------------------------------------------------------------------------------------------------

To test the entropy-conservation property I probably need to run this with an EC integrator.

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.

Thanks! This is just a quick first review. I leave reviewing the details of the algorithm to the others.

Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
Copy link
Contributor

@jlchan jlchan left a comment

Choose a reason for hiding this comment

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

Thanks for adding this! This is a very initial pass through; I'll take a closer look (in particular at the 3d and p4est parts) afterwards.

A broader question - why are the parabolic routines modified? the mortars should only impact the hyperbolic interface flux computations?

@sloede
Copy link
Member

sloede commented Mar 27, 2025

To test the entropy-conservation property I probably need to run this with an EC integrator.

Yes, but an arguably easier test would be to have a refined mesh and use it with an entropy-generating setup, and to then verify that a call to rhs! will produce an EC update.

For example, the weak blast wave is usually such a test, since it does want to produce entropy. Another option for an initial condition is to just randomly initialize the conservative variables (in a physically valid state of course) such that you get small jumps - that would ordinarily produce entropy - everywhere.

@DanielDoehring
Copy link
Contributor Author

A broader question - why are the parabolic routines modified? the mortars should only impact the hyperbolic interface flux computations?

Yeah that looks a bit odd. The reason is that the p4est mesh reuses the rhs! from the TreeMesh, which now passes also the u vector as an argument. As the parabolic p4est implementation re-uses some functions of the hyperbolic p4est implementation we have now the observed changes.

@DanielDoehring
Copy link
Contributor Author

So something is not quite working yet. I do not yet get entropy conservation, but more importantly, conservation of cons. variables is violated.

@DanielDoehring DanielDoehring marked this pull request as draft March 27, 2025 20:19
@DanielDoehring
Copy link
Contributor Author

The current implementation of the mortars has primary and secondary fluxes, while the implementation had only one (probably primary) . Maybe the bug is somewhere there.

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

Successfully merging this pull request may close these issues.

4 participants