Skip to content

Unify implementation VolumeIntegralShockCapturingHG and VolumeIntegralShockCapturingRRG#2802

Merged
DanielDoehring merged 40 commits intotrixi-framework:mainfrom
DanielDoehring:UnifyHG_RRG_SC
Feb 16, 2026
Merged

Unify implementation VolumeIntegralShockCapturingHG and VolumeIntegralShockCapturingRRG#2802
DanielDoehring merged 40 commits intotrixi-framework:mainfrom
DanielDoehring:UnifyHG_RRG_SC

Conversation

@DanielDoehring
Copy link
Copy Markdown
Member

@DanielDoehring DanielDoehring commented Feb 13, 2026

Having merged #2800 it is now possible to unify VolumeIntegralShockCapturingHG and VolumeIntegralShockCapturingRRG.

I changed the internal name to VolumeIntegralShockCapturingHGType - not sure if this is a good choice.
Furthermore, what we ultimately want is something like

struct VolumeIntegralShockCapturingHGGeneralized{VolumeIntegralDGDefault, VolumeIntegralDGStabilized,
                                                 VolumeIntegralFV, Indicator} <:
       AbstractVolumeIntegralShockCapturing
    volume_integral_dg_default::VolumeIntegralDGDefault
    volume_integral_dg_stabilized::VolumeIntegralDGStabilized
    volume_integral_fv::VolumeIntegralFV # non-symmetric in general, e.g. entropy-dissipative
    indicator::Indicator
end

which would allow us to use e.g. weak form in the non-troubled regions like this:

function calc_volume_integral!(du, u, mesh,
                               have_nonconservative_terms, equations,
                               volume_integral::VolumeIntegralShockCapturingHGType,
                               dg::DGSEM, cache)
    @unpack volume_integral_dg_default, volume_integral_dg_stabilized, volume_integral_fv, indicator = volume_integral

    # Calculate DG-FV blending factors α a-priori for: u_{DG-FV} = u_DG * (1 - α) + u_FV * α
    alpha = @trixi_timeit timer() "blending factors" indicator(u, mesh, equations,
                                                               dg, cache)

    # For `Float64`, this gives 1.8189894035458565e-12
    # For `Float32`, this gives 1.1920929f-5
    RealT = eltype(alpha)
    atol = max(100 * eps(RealT), eps(RealT)^convert(RealT, 0.75f0))
    @threaded for element in eachelement(dg, cache)
        alpha_element = alpha[element]
        # Clip blending factor for values close to zero (-> pure DG)
        dg_only = isapprox(alpha_element, 0, atol = atol)

        if dg_only
            volume_integral_kernel!(du, u, element, mesh,
                                    have_nonconservative_terms, equations,
                                    volume_integral_dg_default, dg, cache)
        else
            # Calculate DG volume integral contribution
            volume_integral_kernel!(du, u, element, mesh,
                                    have_nonconservative_terms, equations,
                                    volume_integral_dg_stabilized, dg, cache, 1 - alpha_element)

            # Calculate FV volume integral contribution
            volume_integral_kernel!(du, u, element, mesh,
                                    have_nonconservative_terms, equations,
                                    volume_integral_fv, dg, cache, alpha_element)
        end
    end

    return nothing
end

Question: Should we do this generalization already here, and set for the existing ones volume_integral_dg_default = volume_integral_dg_stabilized?

@DanielDoehring DanielDoehring added discussion refactoring Refactoring code without functional changes labels Feb 13, 2026
@github-actions
Copy link
Copy Markdown
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.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.09%. Comparing base (c4e5ed0) to head (605d396).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2802      +/-   ##
==========================================
+ Coverage   97.08%   97.09%   +0.01%     
==========================================
  Files         586      588       +2     
  Lines       45463    45486      +23     
==========================================
+ Hits        44136    44161      +25     
+ Misses       1327     1325       -2     
Flag Coverage Δ
unittests 97.09% <100.00%> (+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.

@ranocha
Copy link
Copy Markdown
Member

ranocha commented Feb 13, 2026

Question: Should we do this generalization already here, and set for the existing ones volume_integral_dg_default = volume_integral_dg_stabilized?

Since we already touched on this here, it makes sense to me to do so now.

@DanielDoehring
Copy link
Copy Markdown
Member Author

Since we already touched on this here, it makes sense to me to do so now.

Ok, yeah makes sense.

There are two things that came to my mind while working on this:

  1. Should we restrict the DG volume integral in the blending to Flux-Differencing volume integral?
  2. Should we restrict the FV volume integral to LGLSubcell volume integral type?
  3. Should we restrict the indicator to HennemannGassner indicator?

This would taking some responsibility from the user away, but of course also limit extentability.

@ranocha
Copy link
Copy Markdown
Member

ranocha commented Feb 13, 2026

  1. Should we restrict the DG volume integral in the blending to Flux-Differencing volume integral?

No. If someone implements a new equation without specialized two-point fluxes, they would be forced to use flux differencing with flux_central, which would be a waste of time.

  1. Should we restrict the FV volume integral to LGLSubcell volume integral type?

I cannot think of something reasonable we have already implemented that should be used instead. However, I do not have a strong opinion here.

  1. Should we restrict the indicator to HennemannGassner indicator?

This is the only option we have been using so far, isn't it? I also do not have a strong opinion here. Do we restrict it currently? If not, it would be (mildly) breaking to restrict it now.

Copy link
Copy Markdown
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.

This is already looking pretty good in my opinion

@jlchan
Copy link
Copy Markdown
Contributor

jlchan commented Feb 13, 2026

1. Should we restrict the DG volume integral in the blending to Flux-Differencing volume integral?

2. Should we restrict the FV volume integral to LGLSubcell volume integral type?

3. Should we restrict the indicator to HennemannGassner indicator?

I don't think it's necessary to restrict any of these

@DanielDoehring
Copy link
Copy Markdown
Member Author

Yeah I agree. I think I found a nice naming of the volume integrals with

# In classic HG shock capturing this is also `VolumeIntegralBlendHighOrder`.
# This implementation is a generalization, which allows also usage of e.g. 
# the (potentially) cheaper weak form volume integral.
volume_integral_default::VolumeIntegralDefault

# The volume integral used for the DG portion in the convex blending.
# Usually symmetric, e.g. split-form with entropy-conserative flux.
volume_integral_blend_high_order::VolumeIntegralBlendHighOrder

# Typically a first- or second-order finite volume method on the DG subcells.
# Non-symmetric, e.g. entropy-dissipative, to achieve shock-capturing behaviour.
volume_integral_blend_low_order::VolumeIntegralBlendLowOrder

This reflects the generality of the approach, while also pointing people sufficiently into the right direction.

@DanielDoehring DanielDoehring added downstream changes affecting downstream packages enhancement New feature or request labels Feb 14, 2026
@jlchan
Copy link
Copy Markdown
Contributor

jlchan commented Feb 14, 2026

Yeah I agree. I think I found a nice naming of the volume integrals with

# In classic HG shock capturing this is also `VolumeIntegralBlendHighOrder`.

# This implementation is a generalization, which allows also usage of e.g. 

# the (potentially) cheaper weak form volume integral.

volume_integral_default::VolumeIntegralDefault



# The volume integral used for the DG portion in the convex blending.

# Usually symmetric, e.g. split-form with entropy-conserative flux.

volume_integral_blend_high_order::VolumeIntegralBlendHighOrder



# Typically a first- or second-order finite volume method on the DG subcells.

# Non-symmetric, e.g. entropy-dissipative, to achieve shock-capturing behaviour.

volume_integral_blend_low_order::VolumeIntegralBlendLowOrder

This reflects the generality of the approach, while also pointing people sufficiently into the right direction.

I like this name; I actually prefer it slightly over VolumeIntegralAdaptive for the entropy correction stuff.

ranocha
ranocha previously approved these changes Feb 16, 2026
Copy link
Copy Markdown
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!

@ranocha
Copy link
Copy Markdown
Member

ranocha commented Feb 16, 2026

@jlchan should also review this PR because some DGMulti code has changed a bit.

Copy link
Copy Markdown
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 @DanielDoehring - I only have one minor question on the DGMulti implementation.

Copy link
Copy Markdown
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!

@DanielDoehring DanielDoehring enabled auto-merge (squash) February 16, 2026 19:43
@DanielDoehring DanielDoehring merged commit e0715f1 into trixi-framework:main Feb 16, 2026
39 checks passed
@DanielDoehring DanielDoehring deleted the UnifyHG_RRG_SC branch February 16, 2026 19:43
DanielDoehring added a commit to DanielDoehring/Trixi.jl that referenced this pull request Feb 19, 2026
…gralShockCapturingRRG` (trixi-framework#2802)

* Unify implementation `VolumeIntegralShockCapturingHG` and `VolumeIntegralShockCapturingRRG`

* adjust print

* bf

* fix

* two dg volume integrals

* Update src/solvers/dg.jl

Co-authored-by: Jesse Chan <1156048+jlchan@users.noreply.github.com>

* adapt

* db

* export

* test sedov

* fix

* try

* example flix

* bracket

* examples

* shorten

* Apply suggestions from code review

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

* example

* tv

* checks

* news

* news

* dgmulti

* remove

* revert

* Update NEWS.md

* rm

* Apply suggestions from code review

* change

---------

Co-authored-by: Jesse Chan <1156048+jlchan@users.noreply.github.com>
Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion enhancement New feature or request refactoring Refactoring code without functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants