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

Feature: Checkpointing for T8codeMesh #1980

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8120409
Backup.
Jun 13, 2024
3ad3515
Add save callback to elixir.
Jun 14, 2024
6e90adf
Merge branch 'main' into feature-t8codemesh-checkpointing
Jun 17, 2024
23714f1
Backup.
Jun 18, 2024
3f8ded2
Refined code. Make it work in parallel.
Jun 19, 2024
2f5d224
Added support for parallelt8codemesh save solution callback.
Jun 19, 2024
d3a1b49
Applied formatter.
Jun 19, 2024
9ef91c6
Updated examples and tests.
Jun 20, 2024
7c80560
Merge branch 'main' into feature-t8codemesh-checkpointing
Jun 20, 2024
2f96869
Applied formatter.
Jun 20, 2024
df2bdf4
Minor adjustments.
Jun 21, 2024
7ee23b6
Code refinement. Enabled partitioning after mesh loading.
Jun 24, 2024
0404f3b
Applied formatter and fixed typos.
Jun 24, 2024
03d0194
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jun 24, 2024
99972cc
Removed commented out section.
Jun 24, 2024
f59322c
Added missing union type member.
Jun 24, 2024
be2fcdd
Switching from UInt64 to UInt128 in global interface/mortar id comput…
Jun 26, 2024
0283428
Switching from UInt64 to UInt128 in global interface/mortar id comput…
Jun 26, 2024
db9d4c6
Adding more tests.
Jun 26, 2024
b6e1333
Applied formatter.
Jun 26, 2024
36c7517
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jun 26, 2024
1aea5cd
Removed Printf.
Jun 26, 2024
dae7aaa
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jun 28, 2024
b603823
Incorporated review comments and code polish.
Jun 28, 2024
6ef17a4
Applied formatter.
Jun 28, 2024
69b7ac1
Fixed typos.
Jun 28, 2024
ad0fba1
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 1, 2024
e03f57d
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 1, 2024
9fc72c4
Merge branch 'main' into feature-t8codemesh-checkpointing
JoshuaLampert Jul 2, 2024
e65b1a5
Merge branch 'main' into feature-t8codemesh-checkpointing
ranocha Jul 2, 2024
3bbd3a1
Update examples/t8code_2d_dgsem/elixir_advection_restart.jl
jmark Jul 2, 2024
ab9c33f
Update examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl
jmark Jul 2, 2024
9e49219
Update examples/t8code_3d_dgsem/elixir_advection_restart.jl
jmark Jul 2, 2024
677236f
Update src/meshes/mesh_io.jl
jmark Jul 2, 2024
6396931
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 2, 2024
404fc85
Update examples/t8code_3d_dgsem/elixir_advection_restart.jl
jmark Jul 4, 2024
611a576
Update src/meshes/t8code_mesh.jl
jmark Jul 4, 2024
c8c5c20
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 4, 2024
7161d1b
Update src/meshes/t8code_mesh.jl
jmark Jul 4, 2024
15cdc0b
Removing last test in t8code 2D MPI to investigate problems in Github…
Jul 5, 2024
de00b40
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 8, 2024
971d2cf
Refactored a bit.
Jul 8, 2024
a3c169c
Applied formatter.
Jul 8, 2024
6383520
Removed commented code.
Jul 8, 2024
41ebc07
Added LOG_LEVEL variable.
Jul 9, 2024
e268b33
Added t8code interface simplfication and stitched memory leak.
Jul 9, 2024
0ef1d55
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 9, 2024
1e00cb6
Applied formatter.
Jul 9, 2024
8493c8e
Simplifying finailze behavior for T8codeMesh.
Jul 22, 2024
2d4bfb3
Addeing finalize call to T8codeMesh examples.
Jul 22, 2024
a102101
Merge branch 'main' into feature-t8codemesh-checkpointing
jmark Jul 22, 2024
573133a
Applied formatter.
Jul 22, 2024
438e232
Merge branch 'main' into feature-t8codemesh-checkpointing
benegee Oct 14, 2024
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ StaticArrays = "1.5"
StrideArrays = "0.1.26"
StructArrays = "0.6.11"
SummationByPartsOperators = "0.5.41"
T8code = "0.5"
T8code = "0.6"
TimerOutputs = "0.5.7"
Triangulate = "2.2"
TriplotBase = "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

amr_controller = ControllerThreeLevel(semi,
TrixiExtension.IndicatorSolutionIndependent(semi),
base_level = 4,
Expand All @@ -124,12 +129,20 @@
amr_callback = AMRCallback(semi, amr_controller,
interval = 5,
adapt_initial_condition = true,
adapt_initial_condition_only_refine = true)
adapt_initial_condition_only_refine = true,
dynamic_load_balancing = false)
# We disable `dynamic_load_balancing` for now, since t8code does not support
# partitioning for coarsening yet. That is, a complete family of elements always
# stays on rank and is not split up due to partitioning. Without this feature
# dynamic AMR simulations are not pefectly deterministic regarding to

Check warning on line 137 in examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"pefectly" should be "perfectly".
# convergent tests. Once this feature is available in t8code load balancing is
# enabled again.

stepsize_callback = StepsizeCallback(cfl = 1.6)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_solution,
amr_callback, stepsize_callback);

###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval,

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_restart = SaveRestartCallback(interval = 100,
save_final_restart = true)

save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
base_level = 1,
med_level = 2, med_threshold = 0.1,
Expand All @@ -68,6 +76,7 @@ stepsize_callback = StepsizeCallback(cfl = 0.7)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_restart, save_solution,
amr_callback, stepsize_callback)

###############################################################################
Expand Down
89 changes: 89 additions & 0 deletions examples/t8code_2d_dgsem/elixir_advection_extended.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

using OrdinaryDiffEq
using Trixi

###############################################################################
# semidiscretization of the linear advection equation

advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

initial_condition = initial_condition_convergence_test

# BCs must be passed as Dict
boundary_condition = BoundaryConditionDirichlet(initial_condition)
boundary_conditions = Dict(:x_neg => boundary_condition,
:x_pos => boundary_condition,
:y_neg => boundary_condition,
:y_pos => boundary_condition)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

# The initial condition is 2-periodic
coordinates_min = (-1.5, 1.3) # minimum coordinates (min(x), min(y))
coordinates_max = (0.5, 5.3) # maximum coordinates (max(x), max(y))

trees_per_dimension = (19, 37)

# Create curved mesh with 19 x 37 elements
mesh = T8codeMesh(trees_per_dimension, polydeg = 3,
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
periodicity = false)

# A semidiscretization collects data structures and functions for the spatial discretization
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_conditions)

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 1.0
tspan = (0.0, 1.0)
ode = semidiscretize(semi, tspan);

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_integrals = (entropy, energy_total))

# The AliveCallback prints short status information in regular intervals
alive_callback = AliveCallback(analysis_interval = analysis_interval)

# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted
save_restart = SaveRestartCallback(interval = 100,
save_final_restart = true)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl = 1.6)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_restart, save_solution,
stepsize_callback)

###############################################################################
# run the simulation

# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ summary_callback = SummaryCallback()
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_callback = AnalysisCallback(semi, interval = 100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
solution_variables = cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl = 1.6)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
stepsize_callback)

###############################################################################
# run the simulation
Expand Down
47 changes: 47 additions & 0 deletions examples/t8code_2d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

using OrdinaryDiffEq
using Trixi

###############################################################################
# create a restart file

elixir_file = "elixir_advection_extended.jl"
restart_file = "restart_000000021.h5"

trixi_include(@__MODULE__, joinpath(@__DIR__, elixir_file))

###############################################################################
# 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_file)
mesh = load_mesh(restart_filename)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_conditions)

tspan = (load_time(restart_filename), 2.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

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks, maxiters = 100_000);

# 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

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
66 changes: 66 additions & 0 deletions examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

using OrdinaryDiffEq
using Trixi

###############################################################################
# create a restart file

elixir_file = "elixir_advection_extended.jl"
restart_file = "restart_000000021.h5"

trixi_include(@__MODULE__, joinpath(@__DIR__, elixir_file))

###############################################################################
# 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_file)
mesh = load_mesh(restart_filename)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_conditions)

tspan = (load_time(restart_filename), 2.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 = 0,
med_level = 0, med_threshold = 0.8,
max_level = 1, max_threshold = 1.2)
amr_callback = AMRCallback(semi, amr_controller,
interval = 5,
adapt_initial_condition = true,
adapt_initial_condition_only_refine = true,
dynamic_load_balancing = false)
# We disable `dynamic_load_balancing` for now, since t8code does not support
# partitioning for coarsening yet. That is, a complete family of elements always
# stays on rank and is not split up due to partitioning. Without this feature
# dynamic AMR simulations are not pefectly deterministic regarding to

Check warning on line 45 in examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"pefectly" should be "perfectly".
# convergent tests. Once this feature is available in t8code load balancing is
# enabled again.

callbacks_ext = CallbackSet(amr_callback, callbacks.discrete_callbacks...)

integrator = init(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks_ext, maxiters = 100_000);

# 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

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ summary_callback = SummaryCallback()
# prints the results.
analysis_callback = AnalysisCallback(semi, interval = 100)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval = 100,
solution_variables = cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each
# time step.
stepsize_callback = StepsizeCallback(cfl = 1.4)

# Create a CallbackSet to collect all callbacks such that they can be passed to
# the ODE solver.
callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
stepsize_callback)

###############################################################################
# Run the simulation.
Expand Down
6 changes: 6 additions & 0 deletions examples/t8code_2d_dgsem/elixir_euler_free_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 2.0)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_solution,
stepsize_callback)

###############################################################################
Expand Down
5 changes: 5 additions & 0 deletions examples/t8code_2d_dgsem/elixir_euler_sedov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 300,
save_initial_solution = true,
save_final_solution = true)

stepsize_callback = StepsizeCallback(cfl = 0.5)

callbacks = CallbackSet(summary_callback,
analysis_callback,
alive_callback,
save_solution,
stepsize_callback)

###############################################################################
Expand Down
6 changes: 6 additions & 0 deletions examples/t8code_2d_dgsem/elixir_euler_shockcapturing_ec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 1.0)

callbacks = CallbackSet(summary_callback,
analysis_callback,
alive_callback,
save_solution,
stepsize_callback)

###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ analysis_callback = AnalysisCallback(semi, interval = analysis_interval)

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_restart = SaveRestartCallback(interval = 100,
save_final_restart = true)

save_solution = SaveSolutionCallback(interval = 100,
save_initial_solution = true,
save_final_solution = true,
solution_variables = cons2prim)

stepsize_callback = StepsizeCallback(cfl = 0.8)

callbacks = CallbackSet(summary_callback,
analysis_callback, alive_callback,
save_restart, save_solution,
stepsize_callback)
###############################################################################
# run the simulation
Expand Down
Loading
Loading