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

Read in capacity for parallel TreeMesh #1913

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
58 changes: 58 additions & 0 deletions examples/tree_2d_dgsem/elixir_advection_restart_amr.jl
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions src/meshes/mesh_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions test/test_mpi_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading