Skip to content

Remove doubled saving of subcell limiting factors#2588

Merged
DanielDoehring merged 8 commits intotrixi-framework:mainfrom
bennibolm:remove-alpha12
Sep 30, 2025
Merged

Remove doubled saving of subcell limiting factors#2588
DanielDoehring merged 8 commits intotrixi-framework:mainfrom
bennibolm:remove-alpha12

Conversation

@bennibolm
Copy link
Copy Markdown
Contributor

@bennibolm bennibolm commented Sep 25, 2025

Before we had alpha, alpha1 and alpha2 in ContainerSubcellLimiterIDP2D.
In alpha, we saved the node-wise limiting factor. In alpha1 and alpha2, basically, we only saved the maximum limiting factor between two nodes

alpha1[i, j, element] = max(alpha[i - 1, j, element], alpha[i, j, element])
alpha2[i, j, element] = max(alpha[i, j - 1, element], alpha[i, j, element])

, which was used only once afterward.
This was convenient since we didn't need any if clause later in the correction stage.
In this PR, I removed alpha1 and alpha2 and compute the maximum when actually needed.

Moreover, to have the nice flux-differencing update in the correction stage

u[v, i, j, element] += dt * inverse_jacobian *
                                       (inverse_weights[i] *
                                        (alpha_flux1_ip1[v] - alpha_flux1[v]) +
                                        inverse_weights[j] *
                                        (alpha_flux2_jp1[v] - alpha_flux2[v]))

we calculated e.g.

alpha_flux1 = (1 - alpha1[i, j, element]) *
                          get_node_vars(antidiffusive_flux1_R, equations, dg,
                                        i, j, element)

for every node, although antidiffusive_flux1 was zero at the element interfaces (i=1 or i=nnodes+1).

To avoid unnecessary access to and further computation with zero entries, we directly use zero vectors in those cases now.
With that, we can keep the nice flux-differencing update from above.

@bennibolm bennibolm requested a review from amrueda September 25, 2025 15:40
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 25, 2025

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2588   +/-   ##
=======================================
  Coverage   96.79%   96.79%           
=======================================
  Files         525      525           
  Lines       42708    42699    -9     
=======================================
- Hits        41337    41329    -8     
+ Misses       1371     1370    -1     
Flag Coverage Δ
unittests 96.79% <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.

@DanielDoehring DanielDoehring added the refactoring Refactoring code without functional changes label Sep 26, 2025
@bennibolm
Copy link
Copy Markdown
Contributor Author

bennibolm commented Sep 26, 2025

I just noticed that it is not necessary to set the antidiffusive flux at the interfaces to zero in each rhs! call as it is done here.

antidiffusive_flux1_L[:, 1, :, element] .= zero(eltype(antidiffusive_flux1_L))
antidiffusive_flux1_L[:, nnodes(dg) + 1, :, element] .= zero(eltype(antidiffusive_flux1_L))
antidiffusive_flux1_R[:, 1, :, element] .= zero(eltype(antidiffusive_flux1_R))
antidiffusive_flux1_R[:, nnodes(dg) + 1, :, element] .= zero(eltype(antidiffusive_flux1_R))
antidiffusive_flux2_L[:, :, 1, element] .= zero(eltype(antidiffusive_flux2_L))
antidiffusive_flux2_L[:, :, nnodes(dg) + 1, element] .= zero(eltype(antidiffusive_flux2_L))
antidiffusive_flux2_R[:, :, 1, element] .= zero(eltype(antidiffusive_flux2_R))
antidiffusive_flux2_R[:, :, nnodes(dg) + 1, element] .= zero(eltype(antidiffusive_flux2_R))

Note: Continued in #2589

@bennibolm bennibolm marked this pull request as ready for review September 29, 2025 07:44
@bennibolm
Copy link
Copy Markdown
Contributor Author

@DanielDoehring Could you please take a look at this?

Copy link
Copy Markdown
Member

@DanielDoehring DanielDoehring left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@DanielDoehring DanielDoehring merged commit db9e8a1 into trixi-framework:main Sep 30, 2025
39 checks passed
@bennibolm bennibolm deleted the remove-alpha12 branch October 1, 2025 09:01
@bennibolm bennibolm removed the request for review from amrueda October 10, 2025 12:47
DanielDoehring added a commit to DanielDoehring/Trixi.jl that referenced this pull request Feb 19, 2026
* Remove `alpha1` and `alpha2`

* Adapt comment

* Apply suggestions from code review

* Apply suggestions from code review

* Update src/callbacks_stage/subcell_limiter_idp_correction_2d.jl

* Update src/callbacks_stage/subcell_limiter_idp_correction_2d.jl

---------

Co-authored-by: Daniel Doehring <daniel.doehring@rwth-aachen.de>
Co-authored-by: Daniel Doehring <doehringd2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Refactoring code without functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants