From 9e9e99e1c591f462f184795503d74796211bdfe0 Mon Sep 17 00:00:00 2001 From: bennibolm Date: Thu, 19 Oct 2023 14:59:39 +0200 Subject: [PATCH 1/3] Rework calculation of bounds --- src/callbacks_stage/subcell_bounds_check.jl | 2 +- .../subcell_bounds_check_2d.jl | 31 ++++++++++--------- src/solvers/dgsem_tree/subcell_limiters_2d.jl | 4 +-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/callbacks_stage/subcell_bounds_check.jl b/src/callbacks_stage/subcell_bounds_check.jl index 81e7007f5a3..d62cf501054 100644 --- a/src/callbacks_stage/subcell_bounds_check.jl +++ b/src/callbacks_stage/subcell_bounds_check.jl @@ -118,7 +118,7 @@ end if positivity for v in limiter.positivity_variables_cons println("$(variables[v]):\n- positivity: ", - idp_bounds_delta[Symbol("$(v)_min")]) + idp_bounds_delta[Symbol("$(v)_min")][2]) end end println("─"^100 * "\n") diff --git a/src/callbacks_stage/subcell_bounds_check_2d.jl b/src/callbacks_stage/subcell_bounds_check_2d.jl index 79b0925c444..2df10d0a757 100644 --- a/src/callbacks_stage/subcell_bounds_check_2d.jl +++ b/src/callbacks_stage/subcell_bounds_check_2d.jl @@ -12,35 +12,36 @@ (; variable_bounds) = limiter.cache.subcell_limiter_coefficients (; idp_bounds_delta) = limiter.cache - if save_errors - open("$output_directory/deviations.txt", "a") do f - print(f, iter, ", ", time) - end - end if positivity for v in limiter.positivity_variables_cons key = Symbol("$(v)_min") - deviation_min = zero(eltype(u)) + deviation = idp_bounds_delta[key] for element in eachelement(solver, cache), j in eachnode(solver), i in eachnode(solver) var = u[v, i, j, element] - deviation_min = max(deviation_min, - variable_bounds[key][i, j, element] - var) - end - idp_bounds_delta[key] = max(idp_bounds_delta[key], deviation_min) - if save_errors - deviation_min_ = deviation_min - open("$output_directory/deviations.txt", "a") do f - print(f, ", ", deviation_min_) - end + deviation[1] = max(deviation[1], + variable_bounds[key][i, j, element] - var) end + deviation[2] = max(deviation[2], deviation[1]) end end if save_errors + # Print to output file open("$output_directory/deviations.txt", "a") do f + print(f, iter, ", ", time) + if positivity + for v in limiter.positivity_variables_cons + key = Symbol("$(v)_min") + print(f, ", ", idp_bounds_delta[key][1]) + end + end println(f) end + # Reset first entries of idp_bounds_delta + for (key, _) in idp_bounds_delta + idp_bounds_delta[key][1] = zero(eltype(idp_bounds_delta[key][1])) + end end return nothing diff --git a/src/solvers/dgsem_tree/subcell_limiters_2d.jl b/src/solvers/dgsem_tree/subcell_limiters_2d.jl index 690646e9b5a..4d32272898b 100644 --- a/src/solvers/dgsem_tree/subcell_limiters_2d.jl +++ b/src/solvers/dgsem_tree/subcell_limiters_2d.jl @@ -13,9 +13,9 @@ function create_cache(limiter::Type{SubcellLimiterIDP}, equations::AbstractEquat nnodes(basis), bound_keys) - idp_bounds_delta = Dict{Symbol, real(basis)}() + idp_bounds_delta = Dict{Symbol, Vector{real(basis)}}() for key in bound_keys - idp_bounds_delta[key] = zero(real(basis)) + idp_bounds_delta[key] = zeros(real(basis), 2) end return (; subcell_limiter_coefficients, idp_bounds_delta) From aa44953a52df0be9fbf93017035778943477e8a2 Mon Sep 17 00:00:00 2001 From: bennibolm Date: Thu, 19 Oct 2023 15:26:01 +0200 Subject: [PATCH 2/3] Add comment --- src/solvers/dgsem_tree/subcell_limiters_2d.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/solvers/dgsem_tree/subcell_limiters_2d.jl b/src/solvers/dgsem_tree/subcell_limiters_2d.jl index 4d32272898b..e529394c660 100644 --- a/src/solvers/dgsem_tree/subcell_limiters_2d.jl +++ b/src/solvers/dgsem_tree/subcell_limiters_2d.jl @@ -13,6 +13,9 @@ function create_cache(limiter::Type{SubcellLimiterIDP}, equations::AbstractEquat nnodes(basis), bound_keys) + # Memory for bounds checking routine with `BoundsCheckCallback`. + # The first entry of each vector contains the maximum deviation since the last export. + # The second one contains the total maximum deviation. idp_bounds_delta = Dict{Symbol, Vector{real(basis)}}() for key in bound_keys idp_bounds_delta[key] = zeros(real(basis), 2) From c509ef5a24806aba20c78af91ae57cb9d63ee766 Mon Sep 17 00:00:00 2001 From: bennibolm Date: Fri, 20 Oct 2023 12:50:22 +0200 Subject: [PATCH 3/3] Replace construction of `Symbol`s --- src/callbacks_stage/subcell_bounds_check.jl | 6 +++--- src/callbacks_stage/subcell_bounds_check_2d.jl | 4 ++-- src/solvers/dgsem_tree/subcell_limiters.jl | 2 +- src/solvers/dgsem_tree/subcell_limiters_2d.jl | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/callbacks_stage/subcell_bounds_check.jl b/src/callbacks_stage/subcell_bounds_check.jl index d076a4aaa0f..55b5841c227 100644 --- a/src/callbacks_stage/subcell_bounds_check.jl +++ b/src/callbacks_stage/subcell_bounds_check.jl @@ -86,7 +86,7 @@ function init_callback(callback::BoundsCheckCallback, semi, limiter::SubcellLimi print(f, "# iter, simu_time") if positivity for v in limiter.positivity_variables_cons - print(f, ", $(variables[v])_min") + print(f, ", " * string(variables[v]) * "_min") end end println(f) @@ -117,8 +117,8 @@ end println("─"^100) if positivity for v in limiter.positivity_variables_cons - println("$(variables[v]):\n- positivity: ", - idp_bounds_delta[Symbol("$(v)_min")][2]) + println(string(variables[v]) * ":\n- positivity: ", + idp_bounds_delta[Symbol(string(v), "_min")][2]) end end println("─"^100 * "\n") diff --git a/src/callbacks_stage/subcell_bounds_check_2d.jl b/src/callbacks_stage/subcell_bounds_check_2d.jl index 2df10d0a757..8159becb503 100644 --- a/src/callbacks_stage/subcell_bounds_check_2d.jl +++ b/src/callbacks_stage/subcell_bounds_check_2d.jl @@ -14,7 +14,7 @@ if positivity for v in limiter.positivity_variables_cons - key = Symbol("$(v)_min") + key = Symbol(string(v), "_min") deviation = idp_bounds_delta[key] for element in eachelement(solver, cache), j in eachnode(solver), i in eachnode(solver) @@ -32,7 +32,7 @@ print(f, iter, ", ", time) if positivity for v in limiter.positivity_variables_cons - key = Symbol("$(v)_min") + key = Symbol(string(v), "_min") print(f, ", ", idp_bounds_delta[key][1]) end end diff --git a/src/solvers/dgsem_tree/subcell_limiters.jl b/src/solvers/dgsem_tree/subcell_limiters.jl index ab519ff8db0..3a508dd180e 100644 --- a/src/solvers/dgsem_tree/subcell_limiters.jl +++ b/src/solvers/dgsem_tree/subcell_limiters.jl @@ -53,7 +53,7 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis; positivity_correction_factor = 0.1) positivity = (length(positivity_variables_cons) > 0) - bound_keys = Tuple(Symbol("$(i)_min") for i in positivity_variables_cons) + bound_keys = Tuple(Symbol(string(v), "_min") for v in positivity_variables_cons) cache = create_cache(SubcellLimiterIDP, equations, basis, bound_keys) diff --git a/src/solvers/dgsem_tree/subcell_limiters_2d.jl b/src/solvers/dgsem_tree/subcell_limiters_2d.jl index e529394c660..5e00ab4e903 100644 --- a/src/solvers/dgsem_tree/subcell_limiters_2d.jl +++ b/src/solvers/dgsem_tree/subcell_limiters_2d.jl @@ -68,7 +68,7 @@ end (; positivity_correction_factor) = limiter (; variable_bounds) = limiter.cache.subcell_limiter_coefficients - var_min = variable_bounds[Symbol("$(variable)_min")] + var_min = variable_bounds[Symbol(string(variable), "_min")] @threaded for element in eachelement(dg, semi.cache) inverse_jacobian = cache.elements.inverse_jacobian[element]