-
Notifications
You must be signed in to change notification settings - Fork 151
Adaptive Volume Integral for DGMulti: WF & FD, Polynomial() & Affine
#2850
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
DanielDoehring
merged 40 commits into
trixi-framework:main
from
DanielDoehring:AVI_DGMulti_Clean
Mar 11, 2026
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c6ea5be
ex
DanielDoehring d7170e6
ana
DanielDoehring 501f2fa
fd
DanielDoehring 189ef6f
types
DanielDoehring 4dd8516
use volume_integral_kernel
DanielDoehring 229cb87
Merge branch 'main' into AVI_DGMulti
DanielDoehring d9f271c
Merge branch 'main' into AVI_DGMulti
DanielDoehring bea57a5
Merge branch 'main' into AVI_DGMulti
DanielDoehring e14ba5a
Merge branch 'main' into AVI_DGMulti
DanielDoehring 66f4233
Merge branch 'main' into AVI_DGMulti
DanielDoehring 59b880a
Merge branch 'main' into AVI_DGMulti
DanielDoehring 44c0b42
revisit analysis routines
DanielDoehring c03cdc8
clean up
DanielDoehring 6a47cc2
compute du after WF VI
DanielDoehring e17b592
get Polynomial with AVI to work
DanielDoehring f51329f
rm SBP
DanielDoehring 3a8ccff
paper version
DanielDoehring fc939d7
Merge branch 'main' into AVI_DGMulti
DanielDoehring 8cd4231
Merge branch 'main' into AVI_DGMulti
DanielDoehring 603ff36
Merge branch 'main' into AVI_DGMulti
DanielDoehring e8d0c5e
Merge branch 'main' into AVI_DGMulti
DanielDoehring 69ab800
Merge branch 'AVI_DGMulti' of github.com:DanielDoehring/Trixi.jl into…
DanielDoehring a8a5d09
Merge branch 'main' into AVI_DGMulti
DanielDoehring 12ada83
generalize
DanielDoehring 46a4437
refactor
DanielDoehring 41bf177
restrict
DanielDoehring e09b23e
comments
DanielDoehring 1728a10
shorten
DanielDoehring afa4188
test
DanielDoehring 1f6066e
test
DanielDoehring 72facbe
restrict
DanielDoehring c479f74
Merge branch 'main' into AVI_DGMulti_Clean
ranocha 4fdb050
Update src/callbacks_step/analysis_dgmulti.jl
DanielDoehring d6a8639
shorten
DanielDoehring fdcf15d
Update src/solvers/dgmulti/volume_integral_adaptive.jl
jlchan d976331
Merge branch 'main' into AVI_DGMulti_Clean
DanielDoehring 1ed0f4b
restrict
DanielDoehring 185debe
Update src/callbacks_step/analysis_dgmulti.jl
DanielDoehring d97814f
Update src/callbacks_step/analysis_dgmulti.jl
DanielDoehring 4b4c5e9
Apply suggestions from code review
DanielDoehring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
examples/dgmulti_2d/elixir_euler_kelvin_helmholtz_instability_adaptive_vol_int.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| using OrdinaryDiffEqLowStorageRK | ||
| using Trixi | ||
|
|
||
| volume_integral_weakform = VolumeIntegralWeakForm() | ||
| volume_integral_fluxdiff = VolumeIntegralFluxDifferencing(flux_ranocha) | ||
|
|
||
| # This indicator compares the entropy production of the weak form to the | ||
| # true entropy evolution in that cell. | ||
| # If the weak form does not increase entropy beyond `maximum_entropy_increase`, | ||
| # we keep the weak form result. Otherwise, we switch to the stabilized/EC volume integral. | ||
| indicator = IndicatorEntropyChange(maximum_entropy_increase = 5e-3) | ||
|
|
||
| # Adaptive volume integral using the entropy production comparison indicator to perform the | ||
| # stabilized/EC volume integral when needed. | ||
| volume_integral = VolumeIntegralAdaptive(volume_integral_default = volume_integral_weakform, | ||
| volume_integral_stabilized = volume_integral_fluxdiff, | ||
| indicator = indicator) | ||
|
|
||
| dg = DGMulti(polydeg = 3, | ||
| # `Tri()` and `Polynomial()` make flux differencing really(!) expensive | ||
| element_type = Tri(), approximation_type = Polynomial(), | ||
jlchan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| surface_integral = SurfaceIntegralWeakForm(flux_hllc), | ||
| volume_integral = volume_integral) | ||
|
|
||
| equations = CompressibleEulerEquations2D(1.4) | ||
|
|
||
| """ | ||
| initial_condition_kelvin_helmholtz_instability(x, t, equations::CompressibleEulerEquations2D) | ||
|
|
||
| A version of the classical Kelvin-Helmholtz instability based on | ||
| - Andrés M. Rueda-Ramírez, Gregor J. Gassner (2021) | ||
| A Subcell Finite Volume Positivity-Preserving Limiter for DGSEM Discretizations | ||
| of the Euler Equations | ||
| [arXiv: 2102.06017](https://arxiv.org/abs/2102.06017) | ||
| """ | ||
| function initial_condition_kelvin_helmholtz_instability(x, t, | ||
| equations::CompressibleEulerEquations2D) | ||
| # change discontinuity to tanh | ||
| # typical resolution 128^2, 256^2 | ||
| # domain size is [-1,+1]^2 | ||
| slope = 15 | ||
| amplitude = 0.02 | ||
| B = tanh(slope * x[2] + 7.5) - tanh(slope * x[2] - 7.5) | ||
| rho = 0.5 + 0.75 * B | ||
| v1 = 0.5 * (B - 1) | ||
| v2 = 0.1 * sin(2 * pi * x[1]) | ||
| p = 1.0 | ||
| return prim2cons(SVector(rho, v1, v2, p), equations) | ||
| end | ||
| initial_condition = initial_condition_kelvin_helmholtz_instability | ||
|
|
||
| cells_per_dimension = (32, 32) | ||
| mesh = DGMultiMesh(dg, cells_per_dimension; periodicity = true) | ||
|
|
||
| semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, dg; | ||
| boundary_conditions = boundary_condition_periodic) | ||
|
|
||
| tspan = (0.0, 4.6) # stable time for limited entropy-increase adaptive volume integral | ||
|
|
||
| ode = semidiscretize(semi, tspan) | ||
|
|
||
| summary_callback = SummaryCallback() | ||
| alive_callback = AliveCallback(alive_interval = 50) | ||
|
|
||
| stepsize_callback = StepsizeCallback(cfl = 1.0) | ||
|
|
||
| analysis_interval = 10 | ||
| analysis_callback = AnalysisCallback(semi, interval = analysis_interval, uEltype = real(dg), | ||
| save_analysis = true, | ||
| analysis_errors = Symbol[], | ||
| extra_analysis_integrals = (entropy,)) | ||
|
|
||
| save_solution = SaveSolutionCallback(interval = 1000, | ||
| solution_variables = cons2prim) | ||
|
|
||
| callbacks = CallbackSet(summary_callback, | ||
| alive_callback, | ||
| stepsize_callback, | ||
| analysis_callback, | ||
| save_solution) | ||
|
|
||
| ############################################################################### | ||
| # run the simulation | ||
|
|
||
| sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false); | ||
| dt = 1.0, ode_default_options()..., callback = callbacks); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # basic types and functions for DGMulti solvers | ||
| include("types.jl") | ||
| include("dg.jl") | ||
|
|
||
| # flux differencing solver routines for DGMulti solvers | ||
| include("flux_differencing_gauss_sbp.jl") | ||
| include("flux_differencing.jl") | ||
|
|
||
| # adaptive volume integral solver | ||
| include("volume_integral_adaptive.jl") | ||
|
|
||
| # integration of SummationByPartsOperators.jl | ||
| include("sbp.jl") | ||
|
|
||
| # specialization of DGMulti to specific equations | ||
| include("flux_differencing_compressible_euler.jl") | ||
|
|
||
| # shock capturing | ||
| include("shock_capturing.jl") | ||
|
|
||
| # parabolic terms for DGMulti solvers | ||
| include("dg_parabolic.jl") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # By default, Julia/LLVM does not use fused multiply-add operations (FMAs). | ||
| # Since these FMAs can increase the performance of many numerical algorithms, | ||
| # we need to opt-in explicitly. | ||
| # See https://ranocha.de/blog/Optimizing_EC_Trixi for further details. | ||
| @muladd begin | ||
| #! format: noindent | ||
|
|
||
| function create_cache(mesh::DGMultiMesh, equations, | ||
| dg::DGMulti{NDIMS, ElemType, <:Polynomial, | ||
| <:SurfaceIntegralWeakForm, | ||
| <:VolumeIntegralAdaptive{<:IndicatorEntropyChange, | ||
| <:VolumeIntegralWeakForm, | ||
| <:VolumeIntegralFluxDifferencing}}, | ||
| RealT, uEltype) where {NDIMS, ElemType} | ||
| # Construct temporary solvers for each sub-integral to reuse the `create_cache` functions | ||
|
|
||
| # `VolumeIntegralAdaptive` for `DGMulti` currently limited to Weak Form & Flux Differencing combi | ||
| dg_WF = DG(dg.basis, dg.mortar, dg.surface_integral, | ||
| dg.volume_integral.volume_integral_default) | ||
| dg_FD = DG(dg.basis, dg.mortar, dg.surface_integral, | ||
| dg.volume_integral.volume_integral_stabilized) | ||
|
|
||
| cache_WF = create_cache(mesh, equations, dg_WF, RealT, uEltype) | ||
| cache_FD = create_cache(mesh, equations, dg_FD, RealT, uEltype) | ||
|
|
||
| # Set up structures required for `IndicatorEntropyChange` | ||
| rd = dg.basis | ||
| nvars = nvariables(equations) | ||
|
|
||
| # Required for entropy change computation (`entropy_change_reference_element`) | ||
| du_values = similar(cache_FD.u_values) | ||
|
|
||
| # Thread-local buffer for face interpolation, which is required | ||
| # for computation of entropy potential at interpolated face nodes | ||
| # (`surface_integral_reference_element`) | ||
| u_face_local_threaded = [allocate_nested_array(uEltype, nvars, (rd.Nfq,), dg) | ||
| for _ in 1:Threads.maxthreadid()] | ||
|
|
||
| return (; cache_FD..., | ||
| # Weak-form-specific fields for the default volume integral | ||
| weak_differentiation_matrices = cache_WF.weak_differentiation_matrices, | ||
| flux_threaded = cache_WF.flux_threaded, | ||
| rotated_flux_threaded = cache_WF.rotated_flux_threaded, # For non-affine meshes | ||
| # Required for `IndicatorEntropyChange` | ||
| du_values, u_face_local_threaded) | ||
| end | ||
|
|
||
| # version for affine meshes (currently only supported one for `VolumeIntegralAdaptive`) | ||
| function calc_volume_integral!(du, u, mesh::DGMultiMesh, | ||
| have_nonconservative_terms::False, equations, | ||
| volume_integral::VolumeIntegralAdaptive{<:IndicatorEntropyChange}, | ||
| dg::DGMultiFluxDiff, cache) | ||
| @unpack volume_integral_default, volume_integral_stabilized = volume_integral | ||
| @unpack maximum_entropy_increase = volume_integral.indicator | ||
|
|
||
| # For weak form integral | ||
| @unpack u_values = cache | ||
|
|
||
| # For entropy production computation | ||
| rd = dg.basis | ||
| @unpack du_values = cache | ||
|
|
||
| # interpolate to quadrature points | ||
| apply_to_each_field(mul_by!(rd.Vq), u_values, u) # required for weak form trial | ||
|
|
||
| @threaded for e in eachelement(dg, cache) | ||
| # Try default volume integral first | ||
| volume_integral_kernel!(du, u, e, mesh, | ||
| have_nonconservative_terms, equations, | ||
| volume_integral_default, dg, cache) | ||
|
|
||
| # Interpolate `du` to quadrature points after WF integral for entropy production calculation | ||
| du_local = view(du, :, e) | ||
| du_values_local = view(du_values, :, e) | ||
| apply_to_each_field(mul_by!(rd.Vq), du_values_local, du_local) # required for entropy production calculation | ||
|
|
||
| # Compute entropy production of this volume integral | ||
| u_values_local = view(u_values, :, e) | ||
| dS_WF = -entropy_change_reference_element(du_values_local, u_values_local, | ||
| mesh, equations, | ||
| dg, cache) | ||
|
|
||
| dS_true = surface_integral_reference_element(entropy_potential, u, e, | ||
| mesh, equations, dg, cache) | ||
|
|
||
| entropy_change = dS_WF - dS_true | ||
| if entropy_change > maximum_entropy_increase # Recompute using EC FD volume integral | ||
| # Reset default volume integral contribution. | ||
| # Note that this assumes that the volume terms are computed first, | ||
| # before any surface terms are added. | ||
| fill!(du_local, zero(eltype(du_local))) | ||
|
|
||
| # Recompute using stabilized volume integral. Note that the calculation of this volume integral requires the calculation of the entropy projection, which is done in `rhs!` specialized on the `DGMultiFluxDiff` solver type. | ||
| volume_integral_kernel!(du, u, e, mesh, | ||
| have_nonconservative_terms, equations, | ||
| volume_integral_stabilized, dg, cache) | ||
| end | ||
| end | ||
|
|
||
| return nothing | ||
| end | ||
| end # @muladd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.