Skip to content

Commit

Permalink
Added unctionality of writing out mesh files for StructuredMeshView
Browse files Browse the repository at this point in the history
for different time steps.
  • Loading branch information
SimonCan committed Dec 14, 2023
1 parent 0b56f47 commit 076fd24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/meshes/mesh_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/semidiscretization/semidiscretization_coupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 076fd24

Please sign in to comment.