Skip to content

Well-balanced mortars #45

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

Merged
merged 81 commits into from
Apr 29, 2025

Conversation

andrewwinters5000
Copy link
Member

@andrewwinters5000 andrewwinters5000 commented May 14, 2024

This seeks to rewrite the mortar projection routines specifically for the shallow water equations to preserve well-balancedness with non-conforming approximations. That is, the shallow water solver could utilize the AMR capabilities of TreeMesh or P4estMesh. The implementation might become delicate at wet/dry transition regions as one needs to take care in what solution values and/or fluxes are projected to and from the mortar while maintaining positivity.

  • Decide on file names and structure in the src/solvers folder
  • Implement and test on TreeMesh in 2D Save for a future PR
  • Implement and test on P4estMesh in 2D
    • Wet well balanced
    • Wet/dry well balanced
    • Wet perturbation with AMR
    • Wet/dry perturbation with AMR (runs but conservation errors for water height are ≈1e-5 and robustness is sensitive to velocity desingularization)

Further explorations and improvements are discussed in #77

Copy link

codecov bot commented May 14, 2024

Codecov Report

Attention: Patch coverage is 99.36709% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.33%. Comparing base (2267af4) to head (8a6a2fb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/solvers/dgsem_p4est/dg_2d.jl 98.67% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main      #45    +/-   ##
========================================
  Coverage   99.32%   99.33%            
========================================
  Files          60       66     +6     
  Lines        2801     3115   +314     
========================================
+ Hits         2782     3094   +312     
- Misses         19       21     +2     

☔ 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.

@andrewwinters5000
Copy link
Member Author

andrewwinters5000 commented May 22, 2024

The current version provides a well-balanced approximation for a fully wet configuration. The examples/p4est_2d_dgsem/elixir_shallowwater_well_balanced_wet_dry.jl crashes in the first time step. So this requires further investigation. The main issues with the fully wet version are:

  1. There are still significant allocations in the computation of the mortar fluxes.
  2. More pressing is that we require a slight modification to the P4estMortarContainer within Trixi.jl to add additional storage of the unprojected large element solution in order to have this information available to subtract off a superfluous contribution of the local physical flux in the large element. I want to avoid this because this specailized mortar treatment should only need to live within the new package.

The modification below in Trixi's src/solvers/dgsem_p4est/containers.jl is slight, but incredibly hacky. I added a third "slot" to store the large element information that I needed as given in the code snippet below. There is probably a better way to precompute and store the parent flux contributions on each mortar. I am just not familiar enough with the P4estMesh implementations and its various caches to see where one could store such information.

# Create mortar container and initialize mortar data.
function init_mortars(mesh::Union{P4estMesh, T8codeMesh}, equations, basis, elements)
    NDIMS = ndims(elements)
    uEltype = eltype(elements)

    # Initialize container
    n_mortars = count_required_surfaces(mesh).mortars

    _u = Vector{uEltype}(undef,
                         3 * nvariables(equations) * 2^(NDIMS - 1) *
                         nnodes(basis)^(NDIMS - 1) * n_mortars)
    u = unsafe_wrap(Array, pointer(_u),
                    (3, nvariables(equations), 2^(NDIMS - 1),
                     ntuple(_ -> nnodes(basis), NDIMS - 1)..., n_mortars))

    _neighbor_ids = Vector{Int}(undef, (2^(NDIMS - 1) + 1) * n_mortars)
    neighbor_ids = unsafe_wrap(Array, pointer(_neighbor_ids),
                               (2^(NDIMS - 1) + 1, n_mortars))

    _node_indices = Vector{NTuple{NDIMS, Symbol}}(undef, 2 * n_mortars)
    node_indices = unsafe_wrap(Array, pointer(_node_indices), (2, n_mortars))

    mortars = P4estMortarContainer{NDIMS, uEltype, NDIMS + 1, NDIMS + 3}(u,
                                                                         neighbor_ids,
                                                                         node_indices,
                                                                         _u,
                                                                         _neighbor_ids,
                                                                         _node_indices)

    if n_mortars > 0
        init_mortars!(mortars, mesh)
    end

    return mortars
end

UPDATE: This can be ignored as a new P4estShallowWaterMortarContainer with the required additional storage was introduced in 4821434 that avoids the need to modify the Trixi base code.

@andrewwinters5000 andrewwinters5000 added the enhancement New feature or request label Aug 21, 2024
@ranocha ranocha changed the title WIP: Well-balanced mortars Well-balanced mortars Apr 24, 2025
@andrewwinters5000
Copy link
Member Author

andrewwinters5000 commented Apr 28, 2025

I wonder if all the coveralls "noise" in the CI means we should update the reporting strategy as mentioned here

Copy link
Member

@patrickersing patrickersing left a comment

Choose a reason for hiding this comment

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

From my end this looks almost ready to merge. I just have a question and one comment that needs to be changed.

@patrickersing
Copy link
Member

I wonder if all the coveralls "noise" in the CI means we should update the reporting strategy as mentioned here

Since the coverage issue has been solved by setting a higher maxiters in the coverage run, I would say we can move the discussion about this to a separate issue.

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.

Do you want me to review the PR again? If so, please let me know (and tell me whether there is anything in particular you where you would like to have feedback). Otherwise, I am fine merging this PR when the remaining comments of Patrick are resolved.

@andrewwinters5000
Copy link
Member Author

Thanks a lot @ranocha and @patrickersing for your help getting this experimental feature over the finish line!

@andrewwinters5000 andrewwinters5000 merged commit 9cb0e39 into trixi-framework:main Apr 29, 2025
22 of 23 checks passed
@andrewwinters5000 andrewwinters5000 deleted the wb-mortars branch April 29, 2025 17:54
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.

3 participants