From 09d78e3a8385488df9ec2ba05c3310b1ce98989b Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Thu, 13 May 2021 07:49:07 +0200 Subject: [PATCH 1/4] added if-case for the UnstructuredQuadMesh loading for visualization via Trixi2Vtk --- src/mesh/mesh_io.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mesh/mesh_io.jl b/src/mesh/mesh_io.jl index a941d472ab0..18eba79a9a1 100644 --- a/src/mesh/mesh_io.jl +++ b/src/mesh/mesh_io.jl @@ -196,6 +196,11 @@ function load_mesh_serial(mesh_file::AbstractString; n_cells_max, RealT) end mesh = CurvedMesh(size, mapping; RealT=RealT, unsaved_changes=false, mapping_as_string=mapping_as_string) + elseif mesh_type == "UnstructuredQuadMesh" + mesh_filename = h5open(mesh_file, "r") do file + return read(attributes(file)["mesh_filename"]) + end + mesh = UnstructuredQuadMesh(mesh_filename; RealT=RealT, periodicity=false, unsaved_changes=false) else error("Unknown mesh type!") end From 14c576bfd543911a664eb82c781742239bf0c7f7 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Thu, 13 May 2021 08:31:58 +0200 Subject: [PATCH 2/4] Add restart capabilities to UnstructuredQuadMesh --- .../elixir_euler_unstructured_quad_basic.jl | 4 +++ ...r_euler_unstructured_quad_basic_restart.jl | 35 +++++++++++++++++++ src/callbacks_step/save_restart_dg.jl | 7 ++-- test/test_examples_2d_unstructured_quad.jl | 6 ++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 examples/2d/elixir_euler_unstructured_quad_basic_restart.jl diff --git a/examples/2d/elixir_euler_unstructured_quad_basic.jl b/examples/2d/elixir_euler_unstructured_quad_basic.jl index fdb426db42a..788d7a2168a 100644 --- a/examples/2d/elixir_euler_unstructured_quad_basic.jl +++ b/examples/2d/elixir_euler_unstructured_quad_basic.jl @@ -53,6 +53,9 @@ analysis_callback = AnalysisCallback(semi, interval=analysis_interval) alive_callback = AliveCallback(analysis_interval=analysis_interval) +save_restart = SaveRestartCallback(interval=50, + save_final_restart=true) + save_solution = SaveSolutionCallback(interval=10, save_initial_solution=true, save_final_solution=true) @@ -62,6 +65,7 @@ stepsize_callback = StepsizeCallback(cfl=0.9) callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, + save_restart, save_solution, stepsize_callback) diff --git a/examples/2d/elixir_euler_unstructured_quad_basic_restart.jl b/examples/2d/elixir_euler_unstructured_quad_basic_restart.jl new file mode 100644 index 00000000000..af3429c57cd --- /dev/null +++ b/examples/2d/elixir_euler_unstructured_quad_basic_restart.jl @@ -0,0 +1,35 @@ + +using OrdinaryDiffEq +using Trixi + +############################################################################### +# create a restart file + +trixi_include(@__MODULE__, joinpath(@__DIR__, "elixir_euler_unstructured_quad_basic.jl")) + + +############################################################################### +# 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_000050.h5") +mesh = load_mesh(restart_filename) + +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + source_terms=source_terms, + boundary_conditions=boundary_conditions) + +tspan = (load_time(restart_filename), 1.0) +ode = semidiscretize(semi, tspan, restart_filename); + + +############################################################################### +# run the simulation + +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); +summary_callback() # print the timer summary + diff --git a/src/callbacks_step/save_restart_dg.jl b/src/callbacks_step/save_restart_dg.jl index c33a4391f48..cf8ff82a8ee 100644 --- a/src/callbacks_step/save_restart_dg.jl +++ b/src/callbacks_step/save_restart_dg.jl @@ -1,6 +1,7 @@ function save_restart_file(u, time, dt, timestep, - mesh::Union{SerialTreeMesh,CurvedMesh}, equations, dg::DG, cache, + mesh::Union{SerialTreeMesh, CurvedMesh, UnstructuredQuadMesh}, + equations, dg::DG, cache, restart_callback) @unpack output_directory = restart_callback @@ -39,7 +40,8 @@ function save_restart_file(u, time, dt, timestep, end -function load_restart_file(mesh::Union{SerialTreeMesh,CurvedMesh}, equations, dg::DG, cache, restart_file) +function load_restart_file(mesh::Union{SerialTreeMesh,CurvedMesh,UnstructuredQuadMesh}, + equations, dg::DG, cache, restart_file) # allocate memory u_ode = allocate_coefficients(mesh, equations, dg, cache) @@ -69,7 +71,6 @@ function load_restart_file(mesh::Union{SerialTreeMesh,CurvedMesh}, equations, dg end # Read variable - println("Reading variables_$v ($name)...") u[v, .., :] = read(file["variables_$v"]) end end diff --git a/test/test_examples_2d_unstructured_quad.jl b/test/test_examples_2d_unstructured_quad.jl index 236162a42ce..bcdc7982cfc 100644 --- a/test/test_examples_2d_unstructured_quad.jl +++ b/test/test_examples_2d_unstructured_quad.jl @@ -36,6 +36,12 @@ EXAMPLES_DIR = joinpath(pathof(Trixi) |> dirname |> dirname, "examples", "2d") linf = [0.004476908674416524, 0.0052614635050272085, 0.004926298866533951, 0.018058026023565432], tspan = (0.0, 1.0)) end + + @testset "elixir_euler_unstructured_quad_basic_restart.jl" begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_unstructured_quad_basic_restart.jl"), + l2 = [0.0007258658867098887, 0.000676268065087451, 0.0006316238024054346, 0.0014729738442086392], + linf = [0.004476908674416524, 0.0052614635050272085, 0.004926298866533951, 0.018058026023565432]) + end end end # module From abc2b2931c0958f3f93a3859d9ce8a6b574a9de4 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Thu, 13 May 2021 08:34:48 +0200 Subject: [PATCH 3/4] Remove `n_cells_max` from load_mesh --- examples/2d/elixir_advection_restart.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/2d/elixir_advection_restart.jl b/examples/2d/elixir_advection_restart.jl index 19426a102a2..1707f8d56c7 100644 --- a/examples/2d/elixir_advection_restart.jl +++ b/examples/2d/elixir_advection_restart.jl @@ -15,7 +15,7 @@ trixi_include(@__MODULE__, joinpath(@__DIR__, "elixir_advection_extended.jl")) # appropriate setups in the elixir loading a restart file restart_filename = joinpath("out", "restart_000040.h5") -mesh = load_mesh(restart_filename, n_cells_max=30_000) +mesh = load_mesh(restart_filename) semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) From ddb997ed983dbf8cad939d360543cdcbfed7ad66 Mon Sep 17 00:00:00 2001 From: Andrew Winters Date: Thu, 13 May 2021 09:32:57 +0200 Subject: [PATCH 4/4] added FIXME for the load mesh issue with unstructured, periodic and restart --- src/mesh/mesh_io.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesh/mesh_io.jl b/src/mesh/mesh_io.jl index 18eba79a9a1..c64c48e4af7 100644 --- a/src/mesh/mesh_io.jl +++ b/src/mesh/mesh_io.jl @@ -197,6 +197,8 @@ function load_mesh_serial(mesh_file::AbstractString; n_cells_max, RealT) mesh = CurvedMesh(size, mapping; RealT=RealT, unsaved_changes=false, mapping_as_string=mapping_as_string) elseif mesh_type == "UnstructuredQuadMesh" + # FIXME: This works for visualization purposes via Trixi2Vtk however one currently cannot + # restrat an unstructured and periodic simulation mesh_filename = h5open(mesh_file, "r") do file return read(attributes(file)["mesh_filename"]) end