Skip to content
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

Implement subcell limiting for non-conservative systems #1670

Merged
merged 49 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
99c1782
Added first (ugly) implementation of subcell limiting for non-conserv…
amrueda Oct 5, 2023
67e379f
Modified non-conservative fluxes to revert src/solvers/dgsem_tree/dg_…
amrueda Oct 6, 2023
12c6c1d
Subcell limiting: Added the possibility to use multiple nonconservati…
amrueda Oct 10, 2023
7017914
Added some comments and improved formatting
amrueda Oct 10, 2023
5119d97
Added expected results for MHD subcell limiting test
amrueda Oct 10, 2023
ad6177e
Restored old Powell source term and created a new function name for t…
amrueda Oct 10, 2023
9158093
Fixed bug
amrueda Oct 10, 2023
3dcccc4
Fixed bug
amrueda Oct 10, 2023
adb930e
Moved new multiple-dispatch structs for to equations.jl
amrueda Oct 11, 2023
b0e3aad
Improved allocations
amrueda Oct 11, 2023
e0a3fdf
Avoid double computation of local part of non-conservative flux
amrueda Oct 11, 2023
86884e8
Improved subcell volume integral in y direction and formatting
amrueda Oct 11, 2023
0d61cfd
Apply suggestions from code review
amrueda Oct 12, 2023
b0caf8e
Added timers and corrected docstrings
amrueda Oct 12, 2023
6dae80a
Improved formatting
amrueda Oct 12, 2023
0c2e24e
Reduced testing time
amrueda Oct 12, 2023
20abe7b
Renamed variables for consistency
amrueda Oct 16, 2023
505cbbb
Merge branch 'main' into subcell_limiting_noncons
amrueda Oct 16, 2023
cf05403
Removed some unnecessary operations in the Powell/GLM non-conservativ…
amrueda Oct 16, 2023
c2ec8c1
Added two elixirs to compare performance
amrueda Oct 17, 2023
781e839
avoid repeated memory writing/reading
ranocha Oct 20, 2023
c3377ec
format
ranocha Oct 20, 2023
a1131d9
Merge branch 'main' into subcell_limiting_noncons
ranocha Oct 20, 2023
4729149
Merge branch 'main' into subcell_limiting_noncons
amrueda Oct 23, 2023
842399d
Replaced scalar-vector product with scalar-scalar product
amrueda Oct 23, 2023
4fa45bc
Removed timers that are not compatible with multi-threading
amrueda Oct 23, 2023
e40f0ea
Added bounds check for GLM-MHD subcell positivity example
amrueda Oct 23, 2023
9053e17
Removed unneeded elixirs
amrueda Oct 23, 2023
6605c41
format
amrueda Oct 23, 2023
2b21e6a
Cherry-picked changes done in PR (https://github.com/bennibolm/Trixi.…
amrueda Oct 20, 2023
10cb3b2
Merge branch 'main' into subcell_limiting_noncons
sloede Oct 23, 2023
41dc2a1
Apply suggestions from code review
amrueda Oct 23, 2023
50be874
Renamed flux_nonconservative_powell2 to flux_nonconservative_powell_l…
amrueda Oct 24, 2023
e7d1b08
Merge branch 'main' into subcell_limiting_noncons
amrueda Oct 24, 2023
c7c3ca0
Increased maximum allowed allocation bound for subcell limiting simul…
amrueda Oct 24, 2023
120f9ba
Added explanatory comments about different non-conservative fluxes an…
amrueda Oct 24, 2023
81d40e2
Changed variable name noncons_term to nonconservative_term
amrueda Oct 24, 2023
c7dd7f5
Update docstrin of flux_nonconservative_powell_local_symmetric
amrueda Oct 24, 2023
7910993
Renamed function nnoncons as n_nonconservative_terms
amrueda Oct 24, 2023
3f9f0fe
format
amrueda Oct 24, 2023
b6646ad
Apply suggestions from code review
amrueda Oct 24, 2023
0eee721
Non-conservative subcell limiting cache only allocated for non-conser…
amrueda Oct 24, 2023
df12f03
Merge branch 'main' into subcell_limiting_noncons
amrueda Oct 24, 2023
91662db
Merge branch 'main' into subcell_limiting_noncons
ranocha Oct 25, 2023
f0b3ea4
Update src/equations/equations.jl
amrueda Oct 25, 2023
cc4b4fa
Declare `n_nonconservative_terms` in equations.jl as a function witho…
amrueda Oct 25, 2023
48f7c14
Changed if
amrueda Oct 25, 2023
4e65fe0
Merge branch 'main' into subcell_limiting_noncons
amrueda Oct 30, 2023
e836b7f
format
amrueda Oct 30, 2023
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
10 changes: 6 additions & 4 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,13 @@ The return value will be `True()` or `False()` to allow dispatching on the retur
"""
have_nonconservative_terms(::AbstractEquations) = False()
"""
nnoncons(equations)
Number of nonconservative terms for a particular equation. The default is 0 and
it must be defined for each nonconservative equation independently.
n_nonconservative_terms(equations)

Number of nonconservative terms in the form local * symmetric for a particular equation.
This function needs to be specialized only if equations with nonconservative terms are
combined with certain solvers (e.g., subcell limiting).
"""
nnoncons(::AbstractEquations) = 0
function n_nonconservative_terms(::AbstractEquations) end
amrueda marked this conversation as resolved.
Show resolved Hide resolved
have_constant_speed(::AbstractEquations) = False()

default_analysis_errors(::AbstractEquations) = (:l2_error, :linf_error)
Expand Down
16 changes: 8 additions & 8 deletions src/equations/ideal_glm_mhd_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function IdealGlmMhdEquations2D(gamma; initial_c_h = convert(typeof(gamma), NaN)
end

have_nonconservative_terms(::IdealGlmMhdEquations2D) = True()
nnoncons(::IdealGlmMhdEquations2D) = 2
n_nonconservative_terms(::IdealGlmMhdEquations2D) = 2

function varnames(::typeof(cons2cons), ::IdealGlmMhdEquations2D)
("rho", "rho_v1", "rho_v2", "rho_v3", "rho_e", "B1", "B2", "B3", "psi")
Expand Down Expand Up @@ -295,7 +295,7 @@ of local and symmetric parts. It is equivalent to the non-conservative flux of B
et al. (`flux_nonconservative_powell`) for conforming meshes but it yields different
results on non-conforming meshes(!).
amrueda marked this conversation as resolved.
Show resolved Hide resolved

The two functions below, which share the same name, return yield either the local
The two other flux functions with the same name return either the local
or symmetric portion of the non-conservative flux based on the type of the
nonconservative_type argument, employing multiple dispatch. They are used to
compute the subcell fluxes in dg_2d_subcell_limiters.jl.
Expand All @@ -317,9 +317,9 @@ compute the subcell fluxes in dg_2d_subcell_limiters.jl.

# Powell nonconservative term: (0, B_1, B_2, B_3, v⋅B, v_1, v_2, v_3, 0)
# Galilean nonconservative term: (0, 0, 0, 0, ψ v_{1,2}, 0, 0, 0, v_{1,2})
psi_avg = (psi_ll + psi_rr) #* 0.5 # We remove the 0.5 because the flux is always multiplied by 0.5
psi_avg = (psi_ll + psi_rr) #* 0.5 # The flux is already multiplied by 0.5 wherever it is used in the code
if orientation == 1
B1_avg = (B1_ll + B1_rr) #* 0.5 # We remove the 0.5 because the flux is always multiplied by 0.5
B1_avg = (B1_ll + B1_rr) #* 0.5 # The flux is already multiplied by 0.5 wherever it is used in the code
f = SVector(0,
B1_ll * B1_avg,
B2_ll * B1_avg,
Expand All @@ -330,7 +330,7 @@ compute the subcell fluxes in dg_2d_subcell_limiters.jl.
v3_ll * B1_avg,
v1_ll * psi_avg)
else # orientation == 2
B2_avg = (B2_ll + B2_rr) #* 0.5 # We remove the 0.5 because the flux is always multiplied by 0.5
B2_avg = (B2_ll + B2_rr) #* 0.5 # The flux is already multiplied by 0.5 wherever it is used in the code
f = SVector(0,
B1_ll * B2_avg,
B2_ll * B2_avg,
Expand Down Expand Up @@ -430,7 +430,7 @@ This function is used to compute the subcell fluxes in dg_2d_subcell_limiters.jl
if nonconservative_term == 1
# Powell nonconservative term: (0, B_1, B_2, B_3, v⋅B, v_1, v_2, v_3, 0)
if orientation == 1
B1_avg = (B1_ll + B1_rr)#* 0.5 # We remove the 0.5 because the flux is always multiplied by 0.5
B1_avg = (B1_ll + B1_rr)#* 0.5 # The flux is already multiplied by 0.5 wherever it is used in the code
f = SVector(0,
B1_avg,
B1_avg,
Expand All @@ -441,7 +441,7 @@ This function is used to compute the subcell fluxes in dg_2d_subcell_limiters.jl
B1_avg,
0)
else # orientation == 2
B2_avg = (B2_ll + B2_rr)#* 0.5 # We remove the 0.5 because the flux is always multiplied by 0.5
B2_avg = (B2_ll + B2_rr)#* 0.5 # The flux is already multiplied by 0.5 wherever it is used in the code
f = SVector(0,
B2_avg,
B2_avg,
Expand All @@ -454,7 +454,7 @@ This function is used to compute the subcell fluxes in dg_2d_subcell_limiters.jl
end
else #nonconservative_term == 2
# Galilean nonconservative term: (0, 0, 0, 0, ψ v_{1,2}, 0, 0, 0, v_{1,2})
psi_avg = (psi_ll + psi_rr)#* 0.5 # We remove the 0.5 because the flux is always multiplied by 0.5
psi_avg = (psi_ll + psi_rr)#* 0.5 # The flux is already multiplied by 0.5 wherever it is used in the code
f = SVector(0,
0,
0,
Expand Down
51 changes: 29 additions & 22 deletions src/solvers/dgsem_tree/dg_2d_subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,33 @@ function create_cache(mesh::TreeMesh{2}, equations,
nnodes(dg) + 1) for _ in 1:Threads.nthreads()]
flux_temp_threaded = A3d[A3d(undef, nvariables(equations), nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]
flux_nonconservative_temp_threaded = A4d[A4d(undef, nvariables(equations),
nnoncons(equations),
nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]
fhat_temp_threaded = A3d[A3d(undef, nvariables(equations), nnodes(dg),
nnodes(dg))
for _ in 1:Threads.nthreads()]
fhat_nonconservative_temp_threaded = A4d[A4d(undef, nvariables(equations),
nnoncons(equations),
nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]

phi_threaded = A4d[A4d(undef, nvariables(equations),
nnoncons(equations),
nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]

antidiffusive_fluxes = Trixi.ContainerAntidiffusiveFlux2D{uEltype}(0,
nvariables(equations),
nnodes(dg))

if typeof(have_nonconservative_terms(equations)) == True
amrueda marked this conversation as resolved.
Show resolved Hide resolved
flux_nonconservative_temp_threaded = A4d[A4d(undef, nvariables(equations),
n_nonconservative_terms(equations),
nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]
fhat_nonconservative_temp_threaded = A4d[A4d(undef, nvariables(equations),
n_nonconservative_terms(equations),
nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]
phi_threaded = A4d[A4d(undef, nvariables(equations),
n_nonconservative_terms(equations),
nnodes(dg), nnodes(dg))
for _ in 1:Threads.nthreads()]
cache = (; cache..., flux_nonconservative_temp_threaded,
fhat_nonconservative_temp_threaded, phi_threaded)
end

return (; cache..., antidiffusive_fluxes,
fhat1_L_threaded, fhat2_L_threaded, fhat1_R_threaded, fhat2_R_threaded,
flux_temp_threaded, flux_nonconservative_temp_threaded, fhat_temp_threaded,
fhat_nonconservative_temp_threaded, phi_threaded)
flux_temp_threaded, fhat_temp_threaded)
end

function calc_volume_integral!(du, u,
Expand Down Expand Up @@ -253,7 +256,7 @@ end
equations, dg, i, j)
multiply_add_to_node_vars!(flux_temp, derivative_split[ii, i], flux1,
equations, dg, ii, j)
for noncons in 1:nnoncons(equations)
for noncons in 1:n_nonconservative_terms(equations)
# We multiply by 0.5 because that is done in other parts of Trixi
flux1_noncons = volume_flux_noncons(u_node, u_node_ii, 1, equations,
NonConservativeSymmetric(), noncons)
Expand Down Expand Up @@ -281,7 +284,7 @@ end
# Compute local contribution to non-conservative flux
for j in eachnode(dg), i in eachnode(dg)
u_local = get_node_vars(u, equations, dg, i, j, element)
for noncons in 1:nnoncons(equations)
for noncons in 1:n_nonconservative_terms(equations)
set_node_vars!(phi,
volume_flux_noncons(u_local, 1, equations,
NonConservativeLocal(), noncons),
Expand All @@ -298,7 +301,9 @@ end
fhat1_R[v, i + 1, j] = value
end
# Nonconservative part
for noncons in 1:nnoncons(equations), v in eachvariable(equations)
for noncons in 1:n_nonconservative_terms(equations),
v in eachvariable(equations)

value = fhat_noncons_temp[v, noncons, i, j] +
weights[i] * flux_noncons_temp[v, noncons, i, j]
fhat_noncons_temp[v, noncons, i + 1, j] = value
Expand All @@ -322,7 +327,7 @@ end
equations, dg, i, j)
multiply_add_to_node_vars!(flux_temp, derivative_split[jj, j], flux2,
equations, dg, i, jj)
for noncons in 1:nnoncons(equations)
for noncons in 1:n_nonconservative_terms(equations)
# We multiply by 0.5 because that is done in other parts of Trixi
flux2_noncons = volume_flux_noncons(u_node, u_node_jj, 2, equations,
NonConservativeSymmetric(), noncons)
Expand Down Expand Up @@ -350,7 +355,7 @@ end
# Compute local contribution to non-conservative flux
for j in eachnode(dg), i in eachnode(dg)
u_local = get_node_vars(u, equations, dg, i, j, element)
for noncons in 1:nnoncons(equations)
for noncons in 1:n_nonconservative_terms(equations)
set_node_vars!(phi,
volume_flux_noncons(u_local, 2, equations,
NonConservativeLocal(), noncons),
Expand All @@ -367,7 +372,9 @@ end
fhat2_R[v, i, j + 1] = value
end
# Nonconservative part
for noncons in 1:nnoncons(equations), v in eachvariable(equations)
for noncons in 1:n_nonconservative_terms(equations),
v in eachvariable(equations)

value = fhat_noncons_temp[v, noncons, i, j] +
weights[j] * flux_noncons_temp[v, noncons, i, j]
fhat_noncons_temp[v, noncons, i, j + 1] = value
Expand Down
Loading