Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0e5c171
Make volume integrals dimension agnostic
DanielDoehring Jul 21, 2025
889ed35
clean up indicators
DanielDoehring Jul 21, 2025
3df4766
bring back dim spec version
DanielDoehring Jul 21, 2025
22dff42
bring back indicators
DanielDoehring Jul 21, 2025
5f7c747
Apply suggestions from code review
DanielDoehring Jul 21, 2025
b840a20
remove create cahce
DanielDoehring Jul 21, 2025
a58364b
Merge branch 'CleanUpVolumeIntegrals' of github.com:DanielDoehring/Tr…
DanielDoehring Jul 21, 2025
660bb44
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Jul 22, 2025
06b5d99
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Jul 24, 2025
059d325
remove 3d
DanielDoehring Jul 24, 2025
263c5a9
Merge branch 'CleanUpVolumeIntegrals' of github.com:DanielDoehring/Tr…
DanielDoehring Jul 24, 2025
6de9ecc
Merge remote-tracking branch 'origin/main' into CleanUpVolumeIntegrals
DanielDoehring Aug 10, 2025
0349c35
move functions
DanielDoehring Aug 10, 2025
6b4edd5
Merge branch 'CleanUpVolumeIntegrals' of github.com:DanielDoehring/Tr…
DanielDoehring Aug 10, 2025
965446a
restructure
DanielDoehring Aug 11, 2025
d117a72
comment
DanielDoehring Aug 11, 2025
5b3f81e
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Aug 12, 2025
5331203
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Aug 19, 2025
df683ba
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Aug 28, 2025
a16fb30
comments
DanielDoehring Aug 28, 2025
e0e2938
Merge branch 'CleanUpVolumeIntegrals' of github.com:DanielDoehring/Tr…
DanielDoehring Aug 28, 2025
84cf10b
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Aug 28, 2025
756fd4f
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 2, 2025
c06b534
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 2, 2025
e7922ce
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 3, 2025
27dca5f
rename
DanielDoehring Sep 3, 2025
3ceeed2
fmt
DanielDoehring Sep 4, 2025
cf6d461
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 4, 2025
e4dac0c
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 10, 2025
d407967
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 10, 2025
fdddd11
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 12, 2025
e74b3fb
comment
DanielDoehring Sep 12, 2025
133f77c
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 12, 2025
17d6913
move
DanielDoehring Sep 12, 2025
4c8d510
Merge branch 'CleanUpVolumeIntegrals' of https://github.com/DanielDoe…
DanielDoehring Sep 12, 2025
b02cf44
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 18, 2025
635fe09
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 22, 2025
62d4c09
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 23, 2025
330dc22
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 25, 2025
9b568ad
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 28, 2025
a509dc7
test vals
DanielDoehring Sep 28, 2025
fc26c10
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 29, 2025
6fb3f08
specify solver
DanielDoehring Sep 29, 2025
249b32a
fmt
DanielDoehring Sep 29, 2025
32db41d
Merge branch 'main' into CleanUpVolumeIntegrals
DanielDoehring Sep 30, 2025
996e364
comments
DanielDoehring Sep 30, 2025
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
5 changes: 4 additions & 1 deletion examples/tree_1d_dgsem/elixir_advection_diffusion.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using OrdinaryDiffEqSDIRK, ADTypes
using Trixi
import LinearSolve: LUFactorization

###############################################################################
# semidiscretization of the linear advection diffusion equation
Expand Down Expand Up @@ -87,6 +88,8 @@ callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, sav
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
time_int_tol = 1.0e-10
time_abs_tol = 1.0e-10
sol = solve(ode, KenCarp4(autodiff = AutoFiniteDiff()); # This is an IMEX SDIRK method
# This is an IMEX SDIRK method
ode_alg = KenCarp4(autodiff = AutoFiniteDiff(), linsolve = LUFactorization())
sol = solve(ode, ode_alg;
abstol = time_abs_tol, reltol = time_int_tol,
ode_default_options()..., callback = callbacks)
95 changes: 95 additions & 0 deletions src/solvers/dgsem/calc_volume_integral.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# 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

# Dimension and meshtype agnostic, i.e., valid for all 1D, 2D, and 3D meshes
function create_cache(mesh, equations,
volume_integral::VolumeIntegralFluxDifferencing, dg::DG, uEltype)
return NamedTuple()
end

# The following `calc_volume_integral!` functions are
# dimension and meshtype agnostic, i.e., valid for all 1D, 2D, and 3D meshes.

function calc_volume_integral!(du, u, mesh,
nonconservative_terms, equations,
volume_integral::VolumeIntegralWeakForm,
dg::DGSEM, cache)
@threaded for element in eachelement(dg, cache)
weak_form_kernel!(du, u, element, mesh,
nonconservative_terms, equations,
dg, cache)
end

return nothing
end

function calc_volume_integral!(du, u, mesh,
nonconservative_terms, equations,
volume_integral::VolumeIntegralFluxDifferencing,
dg::DGSEM, cache)
@threaded for element in eachelement(dg, cache)
flux_differencing_kernel!(du, u, element, mesh, nonconservative_terms,
equations,
volume_integral.volume_flux, dg, cache)
end

return nothing
end

function calc_volume_integral!(du, u, mesh,
nonconservative_terms, equations,
volume_integral::VolumeIntegralShockCapturingHG,
dg::DGSEM, cache)
@unpack volume_flux_dg, volume_flux_fv, indicator = volume_integral

# Calculate blending factors α: u = 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
flux_differencing_kernel!(du, u, element, mesh,
nonconservative_terms, equations,
volume_flux_dg, dg, cache)
else
# Calculate DG volume integral contribution
flux_differencing_kernel!(du, u, element, mesh,
nonconservative_terms, equations,
volume_flux_dg, dg, cache, 1 - alpha_element)

# Calculate FV volume integral contribution
fv_kernel!(du, u, mesh, nonconservative_terms, equations, volume_flux_fv,
dg, cache, element, alpha_element)
end
end

return nothing
end

function calc_volume_integral!(du, u, mesh,
nonconservative_terms, equations,
volume_integral::VolumeIntegralPureLGLFiniteVolume,
dg::DGSEM, cache)
@unpack volume_flux_fv = volume_integral

# Calculate LGL FV volume integral
@threaded for element in eachelement(dg, cache)
fv_kernel!(du, u, mesh, nonconservative_terms, equations, volume_flux_fv,
dg, cache, element, true)
end

return nothing
end
end # @muladd
2 changes: 2 additions & 0 deletions src/solvers/dgsem/dgsem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ end
end
return u_mean / total_volume # normalize with the total volume
end

include("calc_volume_integral.jl")
end # @muladd
7 changes: 7 additions & 0 deletions src/solvers/dgsem_structured/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ end
Val(ndims(contravariant_vectors) - 3)))
end

# Dimension agnostic, i.e., valid for all 1D, 2D, and 3D `StructuredMesh`es.
function calc_boundary_flux!(cache, u, t, boundary_condition::BoundaryConditionPeriodic,
mesh::StructuredMesh, equations, surface_integral,
dg::DG)
@assert isperiodic(mesh)
end

@inline function calc_boundary_flux_by_direction!(surface_flux_values, u, t,
orientation,
boundary_condition::BoundaryConditionPeriodic,
Expand Down
8 changes: 0 additions & 8 deletions src/solvers/dgsem_structured/dg_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ function calc_interface_flux!(cache, u, mesh::StructuredMesh{1},
return nothing
end

# TODO: Taal dimension agnostic
function calc_boundary_flux!(cache, u, t, boundary_condition::BoundaryConditionPeriodic,
mesh::StructuredMesh{1}, equations, surface_integral,
dg::DG)
@assert isperiodic(mesh)
return nothing
end

function calc_boundary_flux!(cache, u, t, boundary_conditions::NamedTuple,
mesh::StructuredMesh{1}, equations, surface_integral,
dg::DG)
Expand Down
16 changes: 8 additions & 8 deletions src/solvers/dgsem_structured/dg_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ end
# pull the contravariant vectors and compute the average
Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors,
ii, j, element)
# average mapping terms in first coordinate direction,
# used as normal vector in the flux computation
Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)
# compute the contravariant sharp flux in the direction of the
# averaged contravariant vector
Expand All @@ -144,6 +146,8 @@ end
# pull the contravariant vectors and compute the average
Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors,
i, jj, element)
# average mapping terms in second coordinate direction,
# used as normal vector in the flux computation
Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)
# compute the contravariant sharp flux in the direction of the
# averaged contravariant vector
Expand Down Expand Up @@ -195,6 +199,8 @@ end
# pull the contravariant vectors and compute the average
Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors,
ii, j, element)
# average mapping terms in first coordinate direction,
# used as normal vector in the flux computation
Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)
# Compute the contravariant nonconservative flux.
fluxtilde1 = nonconservative_flux(u_node, u_node_ii, Ja1_avg,
Expand All @@ -209,6 +215,8 @@ end
# pull the contravariant vectors and compute the average
Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors,
i, jj, element)
# average mapping terms in second coordinate direction,
# used as normal vector in the flux computation
Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)
# compute the contravariant nonconservative flux in the direction of the
# averaged contravariant vector
Expand Down Expand Up @@ -554,14 +562,6 @@ end
return nothing
end

# TODO: Taal dimension agnostic
function calc_boundary_flux!(cache, u, t, boundary_condition::BoundaryConditionPeriodic,
mesh::Union{StructuredMesh{2}, StructuredMeshView{2}},
equations, surface_integral, dg::DG)
@assert isperiodic(mesh)
return nothing
end

function calc_boundary_flux!(cache, u, t, boundary_conditions::NamedTuple,
mesh::Union{StructuredMesh{2}, StructuredMeshView{2}},
equations, surface_integral,
Expand Down
20 changes: 12 additions & 8 deletions src/solvers/dgsem_structured/dg_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ end
# pull the contravariant vectors and compute the average
Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors,
ii, j, k, element)
# average mapping terms in first coordinate direction,
# used as normal vector in the flux computation
Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)
# compute the contravariant sharp flux in the direction of the
# averaged contravariant vector
Expand All @@ -161,6 +163,8 @@ end
# pull the contravariant vectors and compute the average
Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors,
i, jj, k, element)
# average mapping terms in second coordinate direction,
# used as normal vector in the flux computation
Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)
# compute the contravariant sharp flux in the direction of the
# averaged contravariant vector
Expand All @@ -177,6 +181,8 @@ end
# pull the contravariant vectors and compute the average
Ja3_node_kk = get_contravariant_vector(3, contravariant_vectors,
i, j, kk, element)
# average mapping terms in third coordinate direction,
# used as normal vector in the flux computation
Ja3_avg = 0.5f0 * (Ja3_node + Ja3_node_kk)
# compute the contravariant sharp flux in the direction of the
# averaged contravariant vector
Expand Down Expand Up @@ -227,6 +233,8 @@ end
# pull the contravariant vectors and compute the average
Ja1_node_ii = get_contravariant_vector(1, contravariant_vectors,
ii, j, k, element)
# average mapping terms in first coordinate direction,
# used as normal vector in the flux computation
Ja1_avg = 0.5f0 * (Ja1_node + Ja1_node_ii)
# compute the contravariant nonconservative flux in the direction of the
# averaged contravariant vector
Expand All @@ -242,6 +250,8 @@ end
# pull the contravariant vectors and compute the average
Ja2_node_jj = get_contravariant_vector(2, contravariant_vectors,
i, jj, k, element)
# average mapping terms in second coordinate direction,
# used as normal vector in the flux computation
Ja2_avg = 0.5f0 * (Ja2_node + Ja2_node_jj)
# compute the contravariant nonconservative flux in the direction of the
# averaged contravariant vector
Expand All @@ -257,6 +267,8 @@ end
# pull the contravariant vectors and compute the average
Ja3_node_kk = get_contravariant_vector(3, contravariant_vectors,
i, j, kk, element)
# average mapping terms in third coordinate direction,
# used as normal vector in the flux computation
Ja3_avg = 0.5f0 * (Ja3_node + Ja3_node_kk)
# compute the contravariant nonconservative flux in the direction of the
# averaged contravariant vector
Expand Down Expand Up @@ -690,14 +702,6 @@ end
return nothing
end

# TODO: Taal dimension agnostic
function calc_boundary_flux!(cache, u, t, boundary_condition::BoundaryConditionPeriodic,
mesh::StructuredMesh{3}, equations, surface_integral,
dg::DG)
@assert isperiodic(mesh)
return nothing
end

function calc_boundary_flux!(cache, u, t, boundary_conditions::NamedTuple,
mesh::StructuredMesh{3}, equations, surface_integral,
dg::DG)
Expand Down
18 changes: 8 additions & 10 deletions src/solvers/dgsem_tree/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
@muladd begin
#! format: noindent

# du .= zero(eltype(du)) doesn't scale when using multiple threads.
# See https://github.com/trixi-framework/Trixi.jl/pull/924 for a performance comparison.
function reset_du!(du, dg, cache)
@threaded for element in eachelement(dg, cache)
du[.., element] .= zero(eltype(du))
end

return nothing
end

function volume_jacobian(element, mesh::TreeMesh, cache)
return inv(cache.elements.inverse_jacobian[element])^ndims(mesh)
end
Expand All @@ -25,6 +15,14 @@ end
return inverse_jacobian[element]
end

# Dimension agnostic, i.e., valid for all 1D, 2D, and 3D `TreeMesh`es.
function calc_boundary_flux!(cache, t, boundary_condition::BoundaryConditionPeriodic,
mesh::TreeMesh, equations, surface_integral, dg::DG)
@assert isempty(eachboundary(dg, cache))

return nothing
end

# Indicators used for shock-capturing and AMR
include("indicators.jl")
include("indicators_1d.jl")
Expand Down
Loading
Loading