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

Generalize one-sided limiting #125

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ surface_flux = flux_lax_friedrichs
volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = ["rho"],
math_entropy = true)
local_twosided_variables_cons = ["rho"],
local_onesided_variables_nonlinear = [(Trixi.entropy_math,
max)])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ surface_flux = flux_lax_friedrichs
volume_flux = flux_chandrashekar
basis = LobattoLegendreBasis(3)
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = ["rho"],
spec_entropy = true)
local_twosided_variables_cons = ["rho"],
local_onesided_variables_nonlinear = [(Trixi.entropy_spec,
min)])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)

limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = ["rho" * string(i)
for i in eachcomponent(equations)])
local_twosided_variables_cons = ["rho" * string(i)
for i in eachcomponent(equations)])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)
Expand Down
41 changes: 21 additions & 20 deletions src/callbacks_stage/subcell_bounds_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,27 @@ function init_callback(callback::BoundsCheckCallback, semi, limiter::SubcellLimi
return nothing
end

(; local_minmax, positivity, spec_entropy, math_entropy) = limiter
(; local_twosided, positivity, local_onesided) = limiter
(; output_directory) = callback
variables = varnames(cons2cons, semi.equations)

mkpath(output_directory)
open("$output_directory/deviations.txt", "a") do f
print(f, "# iter, simu_time")
if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
variable_string = string(variables[v])
print(f, ", " * variable_string * "_min, " * variable_string * "_max")
end
end
if spec_entropy
print(f, ", specEntr_min")
end
if math_entropy
print(f, ", mathEntr_max")
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
print(f, ", " * string(variable) * "_" * string(operator))
end
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
print(f, ", " * string(variables[v]) * "_min")
Expand Down Expand Up @@ -126,15 +125,15 @@ end

@inline function finalize_callback(callback::BoundsCheckCallback, semi,
limiter::SubcellLimiterIDP)
(; local_minmax, positivity, spec_entropy, math_entropy) = limiter
(; local_twosided, positivity, local_onesided) = limiter
(; idp_bounds_delta_global) = limiter.cache
variables = varnames(cons2cons, semi.equations)

println("─"^100)
println("Maximum deviation from bounds:")
println("─"^100)
if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
v_string = string(v)
println("$(variables[v]):")
println("- lower bound: ",
Expand All @@ -143,17 +142,19 @@ end
idp_bounds_delta_global[Symbol(v_string, "_max")])
end
end
if spec_entropy
println("spec. entropy:\n- lower bound: ",
idp_bounds_delta_global[:spec_entropy_min])
end
if math_entropy
println("math. entropy:\n- upper bound: ",
idp_bounds_delta_global[:math_entropy_max])
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
variable_string = string(variable)
operator_string = string(operator)
println("$variable_string:")
println("- $operator_string bound: ",
idp_bounds_delta_global[Symbol(variable_string, "_",
operator_string)])
end
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
println(string(variables[v]) * ":\n- positivity: ",
Expand Down
60 changes: 26 additions & 34 deletions src/callbacks_stage/subcell_bounds_check_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@inline function check_bounds(u, mesh::AbstractMesh{2}, equations, solver, cache,
limiter::SubcellLimiterIDP,
time, iter, output_directory, save_errors)
(; local_minmax, positivity, spec_entropy, math_entropy) = solver.volume_integral.limiter
(; local_twosided, positivity, local_onesided) = solver.volume_integral.limiter
(; variable_bounds) = limiter.cache.subcell_limiter_coefficients
(; idp_bounds_delta_local, idp_bounds_delta_global) = limiter.cache

Expand All @@ -21,8 +21,8 @@
# Since there are no processors with caches over 128B, we use `n = 128B / size(uEltype)`
stride_size = div(128, sizeof(eltype(u))) # = n

if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
v_string = string(v)
key_min = Symbol(v_string, "_min")
key_max = Symbol(v_string, "_max")
Expand All @@ -43,35 +43,26 @@
end
end
end
if spec_entropy
key = :spec_entropy_min
deviation_threaded = idp_bounds_delta_local[key]
@threaded for element in eachelement(solver, cache)
deviation = deviation_threaded[stride_size * Threads.threadid()]
for j in eachnode(solver), i in eachnode(solver)
s = entropy_spec(get_node_vars(u, equations, solver, i, j, element),
equations)
deviation = max(deviation, variable_bounds[key][i, j, element] - s)
end
deviation_threaded[stride_size * Threads.threadid()] = deviation
end
end
if math_entropy
key = :math_entropy_max
deviation_threaded = idp_bounds_delta_local[key]
@threaded for element in eachelement(solver, cache)
deviation = deviation_threaded[stride_size * Threads.threadid()]
for j in eachnode(solver), i in eachnode(solver)
s = entropy_math(get_node_vars(u, equations, solver, i, j, element),
if local_onesided
foreach(limiter.local_onesided_variables_nonlinear) do (variable, operator)
key = Symbol(string(variable), "_", string(operator))
factor = operator === max ? 1.0 : -1.0
deviation_threaded = idp_bounds_delta_local[key]
@threaded for element in eachelement(solver, cache)
deviation = deviation_threaded[stride_size * Threads.threadid()]
for j in eachnode(solver), i in eachnode(solver)
v = variable(get_node_vars(u, equations, solver, i, j, element),
equations)
deviation = max(deviation, s - variable_bounds[key][i, j, element])
deviation = max(deviation,
factor * (v - variable_bounds[key][i, j, element]))
end
deviation_threaded[stride_size * Threads.threadid()] = deviation
end
deviation_threaded[stride_size * Threads.threadid()] = deviation
end
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
key = Symbol(string(v), "_min")
Expand Down Expand Up @@ -115,24 +106,25 @@
# Print to output file
open("$output_directory/deviations.txt", "a") do f
print(f, iter, ", ", time)
if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
v_string = string(v)
print(f, ", ",
idp_bounds_delta_local[Symbol(v_string, "_min")][stride_size],
", ",
idp_bounds_delta_local[Symbol(v_string, "_max")][stride_size])
end
end
if spec_entropy
print(f, ", ", idp_bounds_delta_local[:spec_entropy_min][stride_size])
end
if math_entropy
print(f, ", ", idp_bounds_delta_local[:math_entropy_max][stride_size])
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
print(f, ", ",
idp_bounds_delta_local[Symbol(string(variable), "_",
string(operator))][stride_size])
end
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
print(f, ", ",
Expand Down
Loading
Loading