diff --git a/examples/tree_2d_dgsem/elixir_advection_restart_amr.jl b/examples/tree_2d_dgsem/elixir_advection_restart_amr.jl new file mode 100644 index 00000000000..2e4ca38a3fa --- /dev/null +++ b/examples/tree_2d_dgsem/elixir_advection_restart_amr.jl @@ -0,0 +1,58 @@ + +using OrdinaryDiffEq +using Trixi + +############################################################################### +# Define time integration algorithm +alg = CarpenterKennedy2N54(williamson_condition = false) +# Create a restart file +trixi_include(@__MODULE__, joinpath(@__DIR__, "elixir_advection_extended.jl"), alg = alg, + tspan = (0.0, 3.0)) + +############################################################################### +# adapt the parameters that have changed compared to "elixir_advection_extended.jl" + +# Note: If you get a restart file from somewhere else, you need to provide +# appropriate setups in the elixir loading a restart file + +restart_filename = joinpath("out", "restart_000040.h5") +mesh = load_mesh(restart_filename) + +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) + +tspan = (load_time(restart_filename), 5.0) +dt = load_dt(restart_filename) +ode = semidiscretize(semi, tspan, restart_filename); + +# Do not overwrite the initial snapshot written by elixir_advection_extended.jl. +save_solution.condition.save_initial_solution = false + +# Add AMR callback +amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first), + base_level = 3, + med_level = 4, med_threshold = 0.8, + max_level = 5, max_threshold = 1.2) +amr_callback = AMRCallback(semi, amr_controller, + interval = 5, + adapt_initial_condition = false, + adapt_initial_condition_only_refine = true) +callbacks_ext = CallbackSet(amr_callback, callbacks.discrete_callbacks...) + +integrator = init(ode, alg, + dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback + callback = callbacks_ext, maxiters = 100_000; ode_default_options()...) + +# Load saved context for adaptive time integrator +if integrator.opts.adaptive + load_adaptive_time_integrator!(integrator, restart_filename) +end + +# Get the last time index and work with that. +load_timestep!(integrator, restart_filename) + +############################################################################### +# run the simulation + +sol = solve!(integrator) + +summary_callback() # print the timer summary diff --git a/src/meshes/mesh_io.jl b/src/meshes/mesh_io.jl index d74a0c0cea1..b74a3b4d642 100644 --- a/src/meshes/mesh_io.jl +++ b/src/meshes/mesh_io.jl @@ -370,17 +370,18 @@ function load_mesh_parallel(mesh_file::AbstractString; n_cells_max, RealT) if mesh_type == "TreeMesh" if mpi_isroot() - n_cells = h5open(mesh_file, "r") do file - read(attributes(file)["n_cells"]) + n_cells, capacity = h5open(mesh_file, "r") do file + return read(attributes(file)["n_cells"]), + read(attributes(file)["capacity"]) end - MPI.Bcast!(Ref(ndims_), mpi_root(), mpi_comm()) MPI.Bcast!(Ref(n_cells), mpi_root(), mpi_comm()) + MPI.Bcast!(Ref(capacity), mpi_root(), mpi_comm()) else - ndims_ = MPI.Bcast!(Ref(0), mpi_root(), mpi_comm())[] n_cells = MPI.Bcast!(Ref(0), mpi_root(), mpi_comm())[] + capacity = MPI.Bcast!(Ref(0), mpi_root(), mpi_comm())[] end - mesh = TreeMesh(ParallelTree{ndims_}, max(n_cells, n_cells_max)) + mesh = TreeMesh(ParallelTree{ndims_}, max(n_cells, n_cells_max, capacity)) load_mesh!(mesh, mesh_file) elseif mesh_type == "P4estMesh" if mpi_isroot() diff --git a/test/test_mpi_tree.jl b/test/test_mpi_tree.jl index 6351a405b5d..e6e00b2e6b6 100644 --- a/test/test_mpi_tree.jl +++ b/test/test_mpi_tree.jl @@ -70,6 +70,14 @@ CI_ON_WINDOWS = (get(ENV, "GITHUB_ACTIONS", false) == "true") && Sys.iswindows() coverage_override=(maxiters = 6,)) end + @trixi_testset "elixir_advection_restart_amr.jl" begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "elixir_advection_restart_amr.jl"), + l2=[7.870371848717432e-5], + linf=[0.0007374081713964475], + coverage_override=(maxiters = 50,)) + end + # Linear scalar advection with AMR # These example files are only for testing purposes and have no practical use @trixi_testset "elixir_advection_amr_refine_twice.jl" begin