From 076fd24a1d51750c8df36f93c7156bd97a132f7c Mon Sep 17 00:00:00 2001 From: SimonCan Date: Thu, 14 Dec 2023 14:42:13 +0000 Subject: [PATCH] Added unctionality of writing out mesh files for StructuredMeshView for different time steps. --- src/meshes/mesh_io.jl | 25 ++++++++++++++++++- .../semidiscretization_coupled.jl | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/meshes/mesh_io.jl b/src/meshes/mesh_io.jl index 9bfb759039c..3ed419ef433 100644 --- a/src/meshes/mesh_io.jl +++ b/src/meshes/mesh_io.jl @@ -96,7 +96,7 @@ end # of the mesh, like its size and the type of boundary mapping function. # Then, within Trixi2Vtk, the StructuredMesh and its node coordinates are reconstructured from # these attributes for plotting purposes -function save_mesh_file(mesh::Union{StructuredMesh, StructuredMeshView}, output_directory; system = "") +function save_mesh_file(mesh::StructuredMesh, output_directory; system = "", timestep = 0) # Create output directory (if it does not exist) mkpath(output_directory) @@ -118,6 +118,29 @@ function save_mesh_file(mesh::Union{StructuredMesh, StructuredMeshView}, output_ return filename end +# Does not save the mesh itself to an HDF5 file. Instead saves important attributes +# of the mesh, like its size and the type of boundary mapping function. +# Then, within Trixi2Vtk, the StructuredMesh and its node coordinates are reconstructured from +# these attributes for plotting purposes +function save_mesh_file(mesh::StructuredMeshView, output_directory; system = "", timestep = 0) + # Create output directory (if it does not exist) + mkpath(output_directory) + + # filename = joinpath(output_directory, @sprintf("mesh_%s.h5", system)) + filename = joinpath(output_directory, @sprintf("mesh_%s_%06d.h5", system, timestep)) + + # Open file (clobber existing content) + h5open(filename, "w") do file + # Add context information as attributes + attributes(file)["mesh_type"] = get_name(mesh) + attributes(file)["ndims"] = ndims(mesh) + attributes(file)["size"] = collect(size(mesh)) + attributes(file)["mapping"] = mesh.mapping_as_string + end + + return filename +end + # Does not save the mesh itself to an HDF5 file. Instead saves important attributes # of the mesh, like its size and the corresponding `.mesh` file used to construct the mesh. # Then, within Trixi2Vtk, the UnstructuredMesh2D and its node coordinates are reconstructured diff --git a/src/semidiscretization/semidiscretization_coupled.jl b/src/semidiscretization/semidiscretization_coupled.jl index 3b85c63cdc7..a2390f9bad8 100644 --- a/src/semidiscretization/semidiscretization_coupled.jl +++ b/src/semidiscretization/semidiscretization_coupled.jl @@ -296,7 +296,7 @@ function save_mesh(semi::SemidiscretizationCoupled, output_directory, timestep = mesh, _, _, _ = mesh_equations_solver_cache(semi.semis[i]) if mesh.unsaved_changes - mesh.current_filename = save_mesh_file(mesh, output_directory, system = i) + mesh.current_filename = save_mesh_file(mesh, output_directory; system = i, timestep = timestep) mesh.unsaved_changes = false end end