Skip to content
Merged
Show file tree
Hide file tree
Changes from 144 commits
Commits
Show all changes
200 commits
Select commit Hold shift + click to select a range
f355e1b
Make volume integral computation adaptive
DanielDoehring Jul 20, 2025
552d717
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Jul 21, 2025
3ca63fc
towards 2d
DanielDoehring Jul 21, 2025
147e896
simplify
DanielDoehring Jul 21, 2025
2eec5d8
towards 2d
DanielDoehring Jul 21, 2025
8e9949b
try
DanielDoehring Jul 21, 2025
d823ff5
non cons does not work with weak form
DanielDoehring Jul 21, 2025
7bc660a
example
DanielDoehring Jul 21, 2025
fc0347a
whiteapce
DanielDoehring Jul 21, 2025
724335a
vis
DanielDoehring Jul 22, 2025
3166699
Compute first mean, then entropy (much cheaper)
DanielDoehring Aug 10, 2025
c0b1f0b
move u mean
DanielDoehring Aug 10, 2025
9876f85
benchmark
DanielDoehring Aug 10, 2025
dde3c81
Merge branch 'VolumeIntegralAdaptive' of github.com:DanielDoehring/Tr…
DanielDoehring Aug 11, 2025
6ec9287
comment
DanielDoehring Aug 11, 2025
a96827b
work
DanielDoehring Aug 11, 2025
004adba
u_mean
DanielDoehring Aug 31, 2025
7409fdb
rm
DanielDoehring Aug 31, 2025
0bec762
fmt
DanielDoehring Aug 31, 2025
e7ae7a2
shorten
DanielDoehring Aug 31, 2025
32e4c75
work
DanielDoehring Oct 13, 2025
0a38976
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Oct 13, 2025
1375fa7
shorten
DanielDoehring Oct 13, 2025
64c123a
shorten
DanielDoehring Oct 13, 2025
0dac510
move
DanielDoehring Oct 13, 2025
58db43b
bt
DanielDoehring Oct 13, 2025
5f885d6
examples
DanielDoehring Oct 13, 2025
224b84d
restz
DanielDoehring Oct 13, 2025
eaefcc1
todo
DanielDoehring Oct 13, 2025
e27d62a
rename
DanielDoehring Oct 13, 2025
ab8cb7f
test
DanielDoehring Oct 13, 2025
a755aa6
fmt
DanielDoehring Oct 13, 2025
7535812
rm amr cap
DanielDoehring Oct 13, 2025
7533ad0
covergae
DanielDoehring Oct 13, 2025
624113c
SAVE Sol
DanielDoehring Oct 13, 2025
a618ec5
ex
DanielDoehring Oct 13, 2025
56ac3ef
test vals
DanielDoehring Oct 13, 2025
a5fb02b
Update test/test_tree_1d_euler.jl
DanielDoehring Oct 13, 2025
26dc558
Update test/test_tree_1d_euler.jl
DanielDoehring Oct 14, 2025
80d6754
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Oct 14, 2025
ebb2e21
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Oct 15, 2025
257480f
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Oct 17, 2025
2c35e7f
rm int
DanielDoehring Oct 20, 2025
6b324f7
Update src/solvers/dgsem/calc_volume_integral.jl
DanielDoehring Oct 20, 2025
80b91ca
rev
DanielDoehring Oct 20, 2025
dd741d7
rev
DanielDoehring Oct 20, 2025
48cad6b
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Nov 17, 2025
5ebe81f
better indicator
DanielDoehring Nov 17, 2025
e3b6e37
prototype
DanielDoehring Nov 17, 2025
da268d3
ft
DanielDoehring Nov 18, 2025
5df5340
fmt
DanielDoehring Nov 18, 2025
38ab686
rm
DanielDoehring Nov 18, 2025
b94c156
3d test
DanielDoehring Nov 19, 2025
2f22b19
cont
DanielDoehring Nov 19, 2025
eae242d
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Nov 26, 2025
a100e9f
rename
DanielDoehring Nov 26, 2025
cfd4a39
more examples
DanielDoehring Nov 27, 2025
e55da26
cont
DanielDoehring Nov 28, 2025
84ababa
Update src/solvers/dgsem/dgsem.jl
DanielDoehring Nov 29, 2025
68e7ac5
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 1, 2025
75ca8e0
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 6, 2025
ca84e57
Update src/solvers/dgsem_tree/indicators.jl
DanielDoehring Dec 7, 2025
9011796
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 13, 2025
e046615
3d non std
DanielDoehring Dec 13, 2025
1b6bb01
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 16, 2025
34e53ab
alive cb
DanielDoehring Dec 16, 2025
0c4d712
incr
DanielDoehring Dec 16, 2025
ecced9c
clean up
DanielDoehring Dec 16, 2025
dd82e11
shorten
DanielDoehring Dec 16, 2025
93e863e
tests
DanielDoehring Dec 16, 2025
b30f30d
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 20, 2025
aa29627
WF & SC
DanielDoehring Dec 20, 2025
59ea821
ac
DanielDoehring Dec 20, 2025
cb3ba22
12.5
DanielDoehring Dec 20, 2025
22408a3
restruct
DanielDoehring Dec 20, 2025
db543c6
fix
DanielDoehring Dec 20, 2025
59665f1
test more print
DanielDoehring Dec 20, 2025
a2aafc2
Update src/solvers/dgsem_tree/indicators.jl
DanielDoehring Dec 21, 2025
c518f87
Update src/solvers/dgsem_tree/indicators.jl
DanielDoehring Dec 21, 2025
1f0a657
Update src/solvers/dgsem_tree/indicators.jl
DanielDoehring Dec 21, 2025
f84b246
safety check
DanielDoehring Dec 21, 2025
bf0da64
Update src/solvers/dgsem_tree/indicators.jl
DanielDoehring Dec 21, 2025
d3f24e4
Update src/solvers/dg.jl
DanielDoehring Dec 21, 2025
92d3e3b
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 22, 2025
3014939
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Dec 23, 2025
67f60f5
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Jan 1, 2026
0dff5da
change
DanielDoehring Jan 3, 2026
6311cfa
Merge branch 'VolumeIntegralAdaptive' of github.com:DanielDoehring/Tr…
DanielDoehring Jan 3, 2026
871b1b0
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Jan 3, 2026
d2bc478
change
DanielDoehring Jan 4, 2026
1390907
jacobian
DanielDoehring Jan 5, 2026
2ffe01d
use negative matrix
DanielDoehring Jan 5, 2026
aec137b
investigate
DanielDoehring Jan 5, 2026
7ee24ba
hllc
DanielDoehring Jan 5, 2026
d7a7d71
jac business
DanielDoehring Jan 6, 2026
f8acba2
move indicator
DanielDoehring Jan 6, 2026
bc92ae8
more indicators
DanielDoehring Jan 6, 2026
67b7cf2
docstrings, test
DanielDoehring Jan 6, 2026
197deed
experiment threshold adjustment
DanielDoehring Jan 7, 2026
f63653a
try clever update of target entropy decay
DanielDoehring Jan 7, 2026
7ab06e9
rm example
DanielDoehring Jan 7, 2026
2f77491
storage-computation tradeoff
DanielDoehring Jan 7, 2026
d2b64c4
store entropy
DanielDoehring Jan 7, 2026
c6a43bc
3d sedov blast
DanielDoehring Jan 7, 2026
7270d74
all reference
DanielDoehring Jan 8, 2026
3d2bcb8
update
DanielDoehring Jan 8, 2026
e87e00d
Merge branch 'VolumeIntegralAdaptive' of github.com:DanielDoehring/Tr…
DanielDoehring Jan 8, 2026
cd82ac1
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Jan 8, 2026
f6fd807
Adaptive & RRG
DanielDoehring Jan 8, 2026
b704d88
update target decay
DanielDoehring Jan 8, 2026
9ca53ac
idea
DanielDoehring Jan 8, 2026
4b19950
try update again
DanielDoehring Jan 8, 2026
0188262
float
DanielDoehring Jan 9, 2026
04cab37
params
DanielDoehring Jan 9, 2026
0ec2c60
naca0012 NSF separation
DanielDoehring Jan 9, 2026
e103142
use sd7003 for separation example
DanielDoehring Jan 12, 2026
f863332
restart
DanielDoehring Jan 12, 2026
5c07b56
fi xorder cbs
DanielDoehring Jan 12, 2026
db0f140
rm save sol
DanielDoehring Jan 12, 2026
5e99fcb
restart
DanielDoehring Jan 14, 2026
9a53da1
add
DanielDoehring Jan 14, 2026
4c4bc81
run longer non-ref
DanielDoehring Jan 14, 2026
d3dc47b
rev
DanielDoehring Jan 14, 2026
f171029
check with AMR 3
DanielDoehring Jan 15, 2026
5d60788
remove `calc_entropy_delta`: Trade computations for storage
DanielDoehring Jan 16, 2026
5d173a2
rm update
DanielDoehring Jan 16, 2026
ab1e404
2 lvl indicator
DanielDoehring Jan 16, 2026
a83ac24
change
DanielDoehring Jan 16, 2026
c61ceb3
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Jan 16, 2026
95598b5
toml
DanielDoehring Jan 16, 2026
22e84d5
rm
DanielDoehring Jan 16, 2026
fd9e6af
conclude sd7003 sim
DanielDoehring Jan 16, 2026
3bbab7d
Merge branch 'main' into VolumeIntegralAdaptive
DanielDoehring Jan 19, 2026
a16e541
compare runtimes
DanielDoehring Jan 19, 2026
10e42f4
rename
DanielDoehring Jan 20, 2026
6801e20
reduce to entropy diffusion
DanielDoehring Jan 20, 2026
dbde5bb
linear stab
DanielDoehring Jan 20, 2026
28f3641
reference
DanielDoehring Jan 20, 2026
dd862b3
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 20, 2026
17c3d71
fix
DanielDoehring Jan 20, 2026
8f7ca33
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 20, 2026
b69e989
test vals
DanielDoehring Jan 20, 2026
ac8a189
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 23, 2026
181ffc0
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 24, 2026
45e1441
Update src/callbacks_step/analysis_dg2d.jl
DanielDoehring Jan 25, 2026
b8d8182
comments
DanielDoehring Jan 25, 2026
cb7cee1
Update src/solvers/dgsem/calc_volume_integral.jl
DanielDoehring Jan 25, 2026
66a9882
safe guarding
DanielDoehring Jan 25, 2026
d93c196
comment
DanielDoehring Jan 25, 2026
11e059c
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 25, 2026
9aee330
cfl
DanielDoehring Jan 25, 2026
a5be4a5
rename
DanielDoehring Jan 25, 2026
f1d6165
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 26, 2026
4ff6f21
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Jan 27, 2026
0e1575c
make more similar to Jessse PR
DanielDoehring Feb 2, 2026
adac3e4
move comment
DanielDoehring Feb 2, 2026
50e6a72
fix
DanielDoehring Feb 2, 2026
a09c446
fix
DanielDoehring Feb 2, 2026
01164f7
comments
DanielDoehring Feb 2, 2026
6a82590
adapt to jesse info
DanielDoehring Feb 3, 2026
cd36868
docstrings
DanielDoehring Feb 3, 2026
89d0784
fix
DanielDoehring Feb 3, 2026
9ea3cb2
export
DanielDoehring Feb 3, 2026
21b9f1f
rename
DanielDoehring Feb 3, 2026
f777c74
fix
DanielDoehring Feb 3, 2026
06518b7
fix
DanielDoehring Feb 3, 2026
ee9b4b1
comment
DanielDoehring Feb 3, 2026
c0c6e23
Merge branch 'main' into VolumeIntegralAdaptive_Start
JoshuaLampert Feb 4, 2026
2537158
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 4, 2026
33b3f30
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 4, 2026
f021569
Update src/solvers/dgsem/indicators.jl
DanielDoehring Feb 4, 2026
d01c58b
retrieve
DanielDoehring Feb 4, 2026
656e0bc
Merge branch 'VolumeIntegralAdaptive_Start' of github.com:DanielDoehr…
DanielDoehring Feb 4, 2026
560df63
exchange
DanielDoehring Feb 4, 2026
4565dbb
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 4, 2026
4c73871
Update src/equations/compressible_euler_2d.jl
DanielDoehring Feb 6, 2026
6d798d1
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 6, 2026
8f987dc
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 6, 2026
63f0b34
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 6, 2026
33b78fb
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 6, 2026
7809af8
Merge branch 'VolumeIntegralAdaptive_Start' of github.com:DanielDoehr…
DanielDoehring Feb 6, 2026
71ade6f
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 8, 2026
3fdc40b
ii => i
DanielDoehring Feb 8, 2026
a6ee470
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 8, 2026
fab3586
bcs
DanielDoehring Feb 9, 2026
d77d215
Merge branch 'VolumeIntegralAdaptive_Start' of github.com:DanielDoehr…
DanielDoehring Feb 9, 2026
3681cdf
mesh periodi
DanielDoehring Feb 9, 2026
d3d8ac0
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 13, 2026
62b4d29
move create cache
DanielDoehring Feb 13, 2026
6d937bf
Apply suggestions from code review
DanielDoehring Feb 13, 2026
971402c
Fix
DanielDoehring Feb 13, 2026
76679b9
rm defaults
DanielDoehring Feb 13, 2026
428f959
Merge branch 'main' into VolumeIntegralAdaptive_Start
DanielDoehring Feb 13, 2026
6616bfa
generalize comments
DanielDoehring Feb 13, 2026
61a59ac
comments
DanielDoehring Feb 13, 2026
d7704b7
format
ranocha Feb 13, 2026
85e6cc1
Update src/solvers/dg.jl
DanielDoehring Feb 13, 2026
79dd955
change
DanielDoehring Feb 13, 2026
e1c0d66
Merge branch 'VolumeIntegralAdaptive_Start' of github.com:DanielDoehr…
DanielDoehring Feb 13, 2026
d88ef7b
Update src/solvers/dg.jl
DanielDoehring Feb 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions examples/tree_2d_dgsem/elixir_euler_density_wave_adaptive_VI.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using OrdinaryDiffEqLowStorageRK
using Trixi

###############################################################################
# semidiscretization of the compressible Euler equations
equations = CompressibleEulerEquations2D(1.4)

# We repeat test case for stability of EC fluxes from paper
#- Gregor J. Gassner, Magnus Svärd, Florian J. Hindenlang (2020)
# Stability issues of entropy-stable and/or split-form high-order schemes
# [DOI: 10.1007/s10915-021-01720-8](https://doi.org/10.1007/s10915-021-01720-8)
initial_condition = initial_condition_density_wave

surface_flux = flux_lax_friedrichs
volume_flux = flux_chandrashekar

polydeg = 5
basis = LobattoLegendreBasis(polydeg)

volume_integral_weakform = VolumeIntegralWeakForm()
volume_integral_fluxdiff = VolumeIntegralFluxDifferencing(volume_flux)

# This indicator compares the entropy production of the weak form to the
# entropy-conserving flux-differencing volume integral.
# If the entropy production of the weak form is lower than that of the
# flux-differencing form, we use the flux-differencing form to stabilize the solution.
indicator = IndicatorEntropyDiffusion(equations, basis)

# Adaptive volume integral using the entropy production comparison indicator to perform the
# stabilized/EC volume integral when needed and keeping the weak form if it is more diffusive.
volume_integral = VolumeIntegralAdaptive(volume_integral_default = volume_integral_weakform,
volume_integral_stabilized = volume_integral_fluxdiff,
indicator = indicator)

#volume_integral = volume_integral_weakform # Stable, but unphysical entropy increase!
#volume_integral = volume_integral_fluxdiff # Crashes!

solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux,
volume_integral = volume_integral)

coordinates_min = (-1.0, -1.0)
coordinates_max = (1.0, 1.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 2, # 4 x 4 elements
n_cells_max = 30_000)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 5.0)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 1000
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_integrals = (entropy,))

alive_callback = AliveCallback(analysis_interval = analysis_interval)

stepsize_callback = StepsizeCallback(cfl = 0.9) # In paper, CFL = 0.05 is used

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
stepsize_callback)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
dt = 1.0, ode_default_options()..., callback = callbacks);
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using OrdinaryDiffEqLowStorageRK
using Trixi

###############################################################################
# semidiscretization of the compressible Euler equations
gamma = 1.4
equations = CompressibleEulerEquations2D(gamma)

"""
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
RealT = eltype(x)
slope = 15
B = tanh(slope * x[2] + 7.5f0) - tanh(slope * x[2] - 7.5f0)
rho = 0.5f0 + 0.75f0 * B
v1 = 0.5f0 * (B - 1)
v2 = convert(RealT, 0.1) * sinpi(2 * x[1])
p = 1
return prim2cons(SVector(rho, v1, v2, p), equations)
end
initial_condition = initial_condition_kelvin_helmholtz_instability

surface_flux = flux_hllc
volume_flux = flux_ranocha
polydeg = 3
basis = LobattoLegendreBasis(polydeg)

volume_integral_weakform = VolumeIntegralWeakForm()
volume_integral_fluxdiff = VolumeIntegralFluxDifferencing(volume_flux)

# This indicator compares the entropy production of the weak form to the
# entropy-conserving flux-differencing volume integral.
# If the entropy production of the weak form is lower than that of the
# flux-differencing form, we use the flux-differencing form to stabilize the solution.
indicator = IndicatorEntropyDiffusion(equations, basis)

# Adaptive volume integral using the entropy production comparison indicator to perform the
# stabilized/EC volume integral when needed and keeping the weak form if it is more diffusive.
volume_integral = VolumeIntegralAdaptive(volume_integral_default = volume_integral_weakform,
volume_integral_stabilized = volume_integral_fluxdiff,
indicator = indicator)

#volume_integral = volume_integral_weakform # Crashes
#volume_integral = volume_integral_fluxdiff # Crashes as well!

solver = DGSEM(basis, surface_flux, volume_integral)

coordinates_min = (-1.0, -1.0)
coordinates_max = (1.0, 1.0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 6,
n_cells_max = 100_000)
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 5.25)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 1000
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
analysis_errors = Symbol[],
extra_analysis_integrals = (entropy,),
save_analysis = true)

alive_callback = AliveCallback(alive_interval = 200)

stepsize_callback = StepsizeCallback(cfl = 1.8)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
stepsize_callback)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
ode_default_options()..., callback = callbacks);
1 change: 1 addition & 0 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export DG,
VolumeIntegralFluxDifferencing,
VolumeIntegralPureLGLFiniteVolume, VolumeIntegralPureLGLFiniteVolumeO2,
VolumeIntegralShockCapturingHG, VolumeIntegralShockCapturingRRG,
VolumeIntegralAdaptive, IndicatorEntropyDiffusion,
IndicatorHennemannGassner,
VolumeIntegralUpwind,
SurfaceIntegralWeakForm, SurfaceIntegralStrongForm,
Expand Down
25 changes: 23 additions & 2 deletions src/callbacks_step/analysis_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,27 @@ function calc_error_norms(func, u, t, analyzer,
return l2_error, linf_error
end

# used in `calc_entropy_change_element`
function integrate_element_ref(func::Func, u, element,
mesh::AbstractMesh{2}, equations, dg::DGSEM, cache,
args...) where {Func}
@unpack weights = dg.basis
Comment thread
DanielDoehring marked this conversation as resolved.
Outdated

# Initialize integral with zeros of the right shape
element_integral = zero(func(u, 1, 1, 1, equations, dg, args...))
Comment thread
DanielDoehring marked this conversation as resolved.
Outdated

# Use quadrature to numerically integrate element.
# We do not multiply with the Jacobian to stay in reference space.
# This avoids the need to divide the RHS of the DG scheme by the Jacobian when computing
# the time derivative of entropy, see `calc_entropy_change_element`.
for j in eachnode(dg), i in eachnode(dg)
element_integral += weights[i] * weights[j] *
func(u, i, j, element, equations, dg, args...)
end

return element_integral
end

function integrate_via_indices(func::Func, u,
mesh::TreeMesh{2}, equations, dg::DGSEM, cache,
args...; normalize = true) where {Func}
Expand Down Expand Up @@ -214,8 +235,8 @@ function integrate_via_indices(func::Func, u,
mesh::Union{StructuredMesh{2}, StructuredMeshView{2},
UnstructuredMesh2D, P4estMesh{2},
T8codeMesh{2}},
equations,
dg::DGSEM, cache, args...; normalize = true) where {Func}
equations, dg::DGSEM, cache,
args...; normalize = true) where {Func}
@unpack weights = dg.basis

# Initialize integral with zeros of the right shape
Expand Down
52 changes: 52 additions & 0 deletions src/solvers/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,58 @@ function Base.show(io::IO, mime::MIME"text/plain",
end
end

"""
VolumeIntegralAdaptive(;
volume_integral_default = VolumeIntegralWeakForm(),
volume_integral_stabilized = VolumeIntegralFluxDifferencing(flux_central),
Comment thread
DanielDoehring marked this conversation as resolved.
Outdated
indicator = IndicatorEntropyDiffusion())

!!! warning "Experimental code"
This code is experimental and may change in any future release.

Possible combinations:
- [`VolumeIntegralWeakForm`](@ref), [`VolumeIntegralFluxDifferencing`](@ref), and [`IndicatorEntropyDiffusion()`](@ref)
"""
struct VolumeIntegralAdaptive{VolumeIntegralDefault, VolumeIntegralStabilized,
Indicator} <: AbstractVolumeIntegral
volume_integral_default::VolumeIntegralDefault # Cheap(er) default volume integral to be used in non-critical regions
volume_integral_stabilized::VolumeIntegralStabilized # More expensive volume integral with stabilizing effect
indicator::Indicator
end
Comment on lines +286 to +302

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This new version should also work for you @jlchan, right? we would then dispatch calc_volume_integral only on the indicator and could keep the stuff related to volume integrals fully general.

@jlchan jlchan Feb 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes! I actually also made the change recently in

Trixi.jl/src/solvers/dg.jl

Lines 309 to 315 in 97504dd

struct VolumeIntegralEntropyCorrection{VolumeIntegralDefault,
VolumeIntegralEntropyStable, Indicator} <:
AbstractVolumeIntegralShockCapturing
volume_integral_default::VolumeIntegralDefault
volume_integral_entropy_stable::VolumeIntegralEntropyStable
indicator::Indicator
end

Happy to unify things under VolumeIntegralAdaptive when it's ready.

Comment thread
DanielDoehring marked this conversation as resolved.

function VolumeIntegralAdaptive(;
volume_integral_default = VolumeIntegralWeakForm(),
volume_integral_stabilized = VolumeIntegralFluxDifferencing(flux_central),
indicator = IndicatorEntropyDiffusion())
return VolumeIntegralAdaptive{typeof(volume_integral_default),
typeof(volume_integral_stabilized),
typeof(indicator)}(volume_integral_default,
volume_integral_stabilized,
indicator)
end

function Base.show(io::IO, mime::MIME"text/plain",
integral::VolumeIntegralAdaptive)
@nospecialize integral # reduce precompilation time

if get(io, :compact, false)
show(io, integral)
else
summary_header(io, "VolumeIntegralAdaptive")
summary_line(io, "volume integral default",
integral.volume_integral_default)
summary_line(io, "volume integral stabilized",
integral.volume_integral_stabilized)
if integral.indicator === nothing
summary_line(io, "indicator", integral.indicator)
else
summary_line(io, "indicator", integral.indicator |> typeof |> nameof)
show(increment_indent(io), mime, integral.indicator)
end
summary_footer(io)
end
end

# Abstract supertype for first-order `VolumeIntegralPureLGLFiniteVolume` and
# second-order `VolumeIntegralPureLGLFiniteVolumeO2` subcell-based finite volume
# volume integrals.
Expand Down
73 changes: 73 additions & 0 deletions src/solvers/dgsem/calc_volume_integral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ function create_cache(mesh, equations,
return NamedTuple()
end

function create_cache(mesh, equations,
volume_integral::VolumeIntegralAdaptive,
dg::DG, cache_containers, uEltype)
# This assumes that `volume_integral.volume_integral_default` needs no special cache!
@assert volume_integral.volume_integral_default isa VolumeIntegralWeakForm

return create_cache(mesh, equations,
volume_integral.volume_integral_stabilized,
dg, cache_containers, uEltype)
end

Comment thread
DanielDoehring marked this conversation as resolved.
Outdated
# The following `calc_volume_integral!` functions are
# dimension and meshtype agnostic, i.e., valid for all 1D, 2D, and 3D meshes.

Expand Down Expand Up @@ -123,6 +134,68 @@ function calc_volume_integral!(du, u, mesh,
return nothing
end

# Calculate ∫_e (∂S/∂u ⋅ ∂u/∂t) dΩ_e where "e" is an element
function calc_entropy_change_element(du, u, element,
mesh::AbstractMesh{2}, equations, dg, cache)
return integrate_element_ref(u, element, mesh, equations, dg, cache,
du) do u, i, j, element, equations, dg, du
u_node = get_node_vars(u, equations, dg, i, j, element)
du_node = get_node_vars(du, equations, dg, i, j, element)
# Minus sign because of the flipped sign in the DG RHS.
# No scaling by inverse Jacobian here, as there is no Jacobian multiplication
# in `integrate_element_ref`.
-dot(cons2entropy(u_node, equations), du_node)
end
end
Comment thread
DanielDoehring marked this conversation as resolved.
Outdated

function calc_volume_integral!(du, u, mesh,
have_nonconservative_terms, equations,
volume_integral::VolumeIntegralAdaptive{VolumeIntegralWeakForm,
VolumeIntegralFD,
Indicator},
Comment thread
DanielDoehring marked this conversation as resolved.
Outdated
dg::DGSEM,
cache) where {
VolumeIntegralFD <:
VolumeIntegralFluxDifferencing,
Indicator <: IndicatorEntropyDiffusion}
@unpack volume_integral_default, volume_integral_stabilized = volume_integral
@unpack du_element_threaded = volume_integral.indicator

@threaded for element in eachelement(dg, cache)
# Compute weak form volume integral
weak_form_kernel!(du, u, element, mesh,
have_nonconservative_terms, equations,
dg, cache)

# Compute entropy production of WF volume integral
entropy_delta_WF = calc_entropy_change_element(du, u, element,
mesh, equations, dg, cache)
# Store weak form result
du_element_WF = du_element_threaded[Threads.threadid()]
@views du_element_WF .= du[.., element]

# Reset weak form volume integral
du[.., element] .= zero(eltype(du))

# Recompute using entropy-conservative volume integral
flux_differencing_kernel!(du, u, element, mesh,
have_nonconservative_terms, equations,
volume_integral_stabilized.volume_flux,
dg, cache)
Comment thread
DanielDoehring marked this conversation as resolved.
Outdated

# Compute entropy production of FD volume integral
entropy_delta_FD = calc_entropy_change_element(du, u, element,
mesh, equations, dg, cache)

entropy_delta = entropy_delta_WF - entropy_delta_FD
if entropy_delta < 0 # Use weak form if it is more stable
@views du[.., element] .= du_element_WF
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is the something I'm a little concerned about - it's a hard switch between two different volume integral evaluations, which I don't think is differentiable with respect to the solution and can lead to a large number of adaptive time-steps.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If there is a way to make this differentiable it might improve adaptive time-stepping performance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess you could also blend the central (weak form) flux and the EC flux - I fear that this might destroy accuracy though

end

return nothing
end

function calc_volume_integral!(du, u, mesh,
have_nonconservative_terms, equations,
volume_integral::VolumeIntegralPureLGLFiniteVolume,
Expand Down
1 change: 1 addition & 0 deletions src/solvers/dgsem/dgsem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ end
end

include("containers.jl")
include("indicators.jl")
include("calc_volume_integral.jl")
end # @muladd
Loading
Loading