Skip to content

Commit afdb486

Browse files
amruedaJoshuaLampertsloede
authored
Unify create_cache for ControllerThreeLevel* and the different mesh types (#2285)
* Unify create_cache for ControllerThreeLevel and ControllerThreeLevelCombined, and the different meshes * Moved create_cache function for ControllerThreeLevel* into amr_dg.jl * Use three-level AMR controller for p4est 3D test --------- Co-authored-by: Joshua Lampert <[email protected]> Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
1 parent fd412c6 commit afdb486

File tree

6 files changed

+26
-43
lines changed

6 files changed

+26
-43
lines changed

examples/p4est_3d_dgsem/elixir_euler_weak_blast_wave_amr.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
8787
alive_callback = AliveCallback(analysis_interval = analysis_interval)
8888

8989
amr_indicator = IndicatorLöhner(semi, variable = Trixi.density)
90-
amr_controller = ControllerThreeLevel(semi, amr_indicator,
91-
base_level = 1,
92-
med_level = 2, med_threshold = 0.05,
93-
max_level = 3, max_threshold = 0.15)
90+
amr_controller = ControllerThreeLevelCombined(semi, amr_indicator, indicator_sc,
91+
base_level = 1,
92+
med_level = 2, med_threshold = 0.05, # med_level = current level
93+
max_level = 3, max_threshold = 0.15,
94+
max_threshold_secondary = indicator_sc.alpha_max)
95+
9496
amr_callback = AMRCallback(semi, amr_controller,
9597
interval = 1,
9698
adapt_initial_condition = false,

src/callbacks_step/amr_dg.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,14 @@ function rebalance_solver!(u_ode::AbstractVector,
9090
end
9191
end # GC.@preserve old_u_ode
9292
end
93+
94+
# Construct cache for ControllerThreeLevel and ControllerThreeLevelCombined.
95+
# This method is called when a controller is constructed
96+
function create_cache(::Union{Type{ControllerThreeLevel},
97+
Type{ControllerThreeLevelCombined}},
98+
mesh::Union{TreeMesh, P4estMesh, T8codeMesh},
99+
equations, dg::DG, cache)
100+
controller_value = Vector{Int}(undef, nelements(dg, cache))
101+
return (; controller_value)
102+
end
93103
end # @muladd

src/callbacks_step/amr_dg1d.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,4 @@ function coarsen_elements!(u::AbstractArray{<:Any, 3}, element_id,
283283
set_node_vars!(u, acc, equations, dg, i, element_id)
284284
end
285285
end
286-
287-
# this method is called when an `ControllerThreeLevel` is constructed
288-
function create_cache(::Type{ControllerThreeLevel}, mesh::TreeMesh{1}, equations,
289-
dg::DG, cache)
290-
controller_value = Vector{Int}(undef, nelements(dg, cache))
291-
return (; controller_value)
292-
end
293-
294-
function create_cache(::Type{ControllerThreeLevelCombined}, mesh::TreeMesh,
295-
equations, dg::DG, cache)
296-
controller_value = Vector{Int}(undef, nelements(dg, cache))
297-
return (; controller_value)
298-
end
299286
end # @muladd

src/callbacks_step/amr_dg2d.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,4 @@ function adapt!(u_ode::AbstractVector, adaptor, mesh::T8codeMesh{2}, equations,
570570

571571
return nothing
572572
end
573-
574-
# this method is called when an `ControllerThreeLevel` is constructed
575-
function create_cache(::Type{ControllerThreeLevel},
576-
mesh::Union{TreeMesh{2}, P4estMesh{2}, T8codeMesh{2}}, equations,
577-
dg::DG, cache)
578-
controller_value = Vector{Int}(undef, nelements(dg, cache))
579-
return (; controller_value)
580-
end
581573
end # @muladd

src/callbacks_step/amr_dg3d.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,6 @@ function coarsen_elements!(u::AbstractArray{<:Any, 5}, element_id,
381381
return nothing
382382
end
383383

384-
# this method is called when an `ControllerThreeLevel` is constructed
385-
function create_cache(::Type{ControllerThreeLevel},
386-
mesh::Union{TreeMesh{3}, P4estMesh{3}, T8codeMesh{3}},
387-
equations, dg::DG, cache)
388-
controller_value = Vector{Int}(undef, nelements(dg, cache))
389-
return (; controller_value)
390-
end
391-
392384
# Coarsen and refine elements in the DG solver based on a difference list.
393385
function adapt!(u_ode::AbstractVector, adaptor, mesh::T8codeMesh{3}, equations,
394386
dg::DGSEM, cache, difference)

test/test_p4est_3d.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,18 +682,18 @@ end
682682
@trixi_testset "elixir_euler_weak_blast_wave_amr.jl" begin
683683
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_weak_blast_wave_amr.jl"),
684684
l2=[
685-
0.011345993108796831,
686-
0.018525073963833696,
687-
0.019102348105917946,
688-
0.01920515438943838,
689-
0.15060493968460148
685+
0.012046270976464931,
686+
0.01894521652831441,
687+
0.01951983946363743,
688+
0.019748755875702628,
689+
0.15017285006198244
690690
],
691691
linf=[
692-
0.2994949779783401,
693-
0.5530175050084679,
694-
0.5335803757792128,
695-
0.5647252867336123,
696-
3.6462732329242566
692+
0.3156585581400839,
693+
0.6653806948576124,
694+
0.5451454769741236,
695+
0.558669830478818,
696+
3.6406796982784635
697697
],
698698
tspan=(0.0, 0.025),)
699699
# Ensure that we do not have excessive memory allocations

0 commit comments

Comments
 (0)