I/O and checkpointing
HDF5 and JLD2 checkpointing, and VTK output.
JustRelax.DataIO.VTKDataSeries Type
VTKDataSeries(full_name::String, xi)A ParaView collection (.pvd) accumulating a time series of VTK snapshots on the grid xi, written under full_name. Add each time step with Base.append!.
JustRelax.DataIO.add_field! Method
add_field!(vtk, name, array, npoints, ncells, precision)Write array to vtk as point data or cell data, whichever its size matches. A vertex grid holds one cell fewer than it has nodes per dimension, so the two sizes are always distinguishable.
JustRelax.DataIO.append! Method
append!(data_series::VTKDataSeries, data::NamedTuple, time_step, seconds)Write data as a new VTK snapshot on data_series's grid and add it to the time series at time seconds, under the name time_step.
JustRelax.DataIO.center_coordinates Method
center_coordinates(grid::Geometry)The cell-center coordinate vectors of grid (grid.xci), collected into plain Vectors for serialization.
JustRelax.DataIO.checkpointing_hdf5 Method
checkpointing_hdf5(dst, stokes, T, η, time, timestep)Save necessary data in dst as and HDF5 file to restart the model from the state at time
JustRelax.DataIO.checkpointing_jld2 Method
checkpointing_jld2(dst, stokes, [thermal,] time, timestep[, igg]; kwargs...)Save necessary data in dst as a jld2 file to restart the model from the state at time. If run in parallel, the file will be named after the corresponidng rank e.g. checkpoint0000.jld2 and thus can be loaded by the processor while restarting the simulation. If you want to restart your simulation from the checkpoint you can use load() and specify the MPI rank by providing a dollar sign and the rank number.
Arguments
dst: The destination directory where the checkpoint file will be saved.stokes: The stokes flow variables to be saved.thermal: (Optional) The thermal variables to be saved.time: The current simulation time.timestep: The current timestep.igg: (Optional) The IGG struct for parallel runs.
Keyword Arguments
kwargs...: Additional variables to be saved in the checkpoint file. These will be added to the base checkpoint data. Examplejulia
JustRelax.DataIO.load_checkpoint_hdf5 Method
load_checkpoint_hdf5(file_path)Load the state of the simulation from an .h5 file.
Arguments
file_path: The path to the .h5 file.
Returns
P: The loaded state of the pressure variable.T: The loaded state of the temperature variable.Vx: The loaded state of the x-component of the velocity variable.Vy: The loaded state of the y-component of the velocity variable.Vz: The loaded state of the z-component of the velocity variable.η: The loaded state of the viscosity variable.t: The loaded simulation time.dt: The loaded simulation time.
Example
# Define the path to the .h5 file
file_path = "path/to/your/file.h5"
# Use the load_checkpoint function to load the variables from the file
P, T, Vx, Vy, Vz, η, t, dt = `load_checkpoint(file_path)``JustRelax.DataIO.load_checkpoint_jld2 Method
load_checkpoint_jld2(file_path)Load the state of the simulation from a .jld2 file.
Arguments
file_path: The path to the .jld2 file.
Returns
stokes: The loaded state of the stokes variable.thermal: The loaded state of the thermal variable. Can benothingif not present in the file.time: The loaded simulation time.timestep: The loaded time step.igg: The IGG struct if needed for parallel runs.
Example
stokes, thermal, time, timestep = load_checkpoint_jld2("path/to/checkpoint.jld2", igg)or without thermal
stokes, _, time, timestep = load_checkpoint_jld2("path/to/checkpoint.jld2")JustRelax.DataIO.metadata Method
metadata(src, dst, files...)Copy files..., Manifest.toml, and Project.toml from src to dst
JustRelax.DataIO.pack_velocity Function
pack_velocity(velocity::Tuple, precision, slices = nothing)Pack the velocity components into the (3, size...) array expected for a VTK vector attribute. Readers copy three values per tuple regardless of the declared NumberOfComponents, so a two-component array leaves the third component undefined and ParaView orients its glyphs from uninitialized memory. Components beyond N are written as zeros.
slices optionally restricts each component to a sub-range (used to trim the ghost layer of MPI-distributed arrays).
JustRelax.DataIO.save_data Method
save_data(file, data, precision)
save_data(file, grid::Geometry)Write data (converted to precision) into the open HDF5 file under its own variable name. The Geometry method instead writes the cell-center/vertex coordinate vectors (Xc/Yc[/Zc], Xv/Yv[/Zv]). Used internally by save_hdf5.
JustRelax.DataIO.save_hdf5 Method
function save_hdf5(dst, fname, data)Save data as the fname.h5 HDF5 file in the folder dst
JustRelax.DataIO.save_hdf5 Method
function save_hdf5(fname, data)Save data as the fname.h5 HDF5 file
JustRelax.DataIO.save_marker_chain Method
save_marker_chain(fname::String, chain::MarkerChain; conversion=1.0e3, pvd=nothing, t=0.0)Save a vector of points as a line in a VTK file.
Arguments
fname::String: The name of the VTK file to save. The extension.vtkwill be appended to the name.chain::MarkerChain: Marker chain object from JustPIC.jl.conversion: Conversion factor for coordinates (default: 1.0e3)pvd::Union{Nothing, String}: Optional ParaView collection filename for time seriest::Number: Time value (default: 0.0)
JustRelax.DataIO.save_particles Method
save_particles(particles::Particles{B, 2}, pPhases; conversion = 1e3, fname::String = "./particles", pvd=nothing, t=0.0) where BSave particle data and their material phase to a VTK file.
Arguments
particles::Particles{B, 2}: The particle data, whereBis the type of the particle coordinates.pPhases: The phases of the particles.conversion: A conversion factor for the particle coordinates (default is 1e3).fname::String: The name of the VTK file to save (default is "./particles").pvd::Union{Nothing, String}: Optional ParaView collection filename for time seriest::Number: Time value (default: 0.0)
JustRelax.DataIO.save_particles Method
save_particles(particles, igg::IGG; pPhases=nothing, conversion=1e3, fname="./particles", pvd=nothing, t=0.0, precision=Float32)Parallel (MPI) counterpart of save_particles: each rank writes its own active particles as an unstructured .vtu piece, tied together by <fname>.pvtu. Works for 2D and 3D particles. pPhases (a CellArray of phase ids) is written as the phase point field when given, otherwise a constant is used. If pvd is given, the .pvtu datasets are appended to <pvd>.pvd at time t to build a time series (only rank 0 touches the collection).
JustRelax.DataIO.save_particles Method
save_particles(particles::Particles{B, 2}; conversion = 1e3, fname::String = "./particles", pvd=nothing, t=0.0) where BSave particle data to a VTK file.
Arguments
particles::Particles{B, 2}: The particle data, whereBis the type of the particle coordinates.conversion: A conversion factor for the particle coordinates (default is 1e3).fname::String: The name of the VTK file to save (default is "./particles").pvd::Union{Nothing, String}: Optional ParaView collection filename for time seriest::Number: Time value (default: 0.0)
JustRelax.DataIO.save_pvtk Method
save_pvtk(fname, di::NTuple{N}, data_v::NamedTuple, data_c::NamedTuple, velocity::Tuple, igg::IGG; t=nothing, precision=Float32, pvd=nothing)Parallel (MPI) counterpart of the serial save_vtk for an ImplicitGlobalGrid-distributed grid (requires ImplicitGlobalGrid ≥ 0.17). Writes vertex fields data_v + velocity to <fname>_vertex.pvti and cell fields data_c to <fname>_center.pvti, one .vti piece per rank. di is the global grid spacing (e.g. grid.di.center). Ranks overlap by one ghost layer, so update_halo! before writing. If pvd is given, the datasets are appended to <pvd>_vertex.pvd / <pvd>_center.pvd at time t.
JustRelax.DataIO.save_vtk Method
save_vtk(fname::String, xvi, xci, data_v::NamedTuple, data_c::NamedTuple, velocity; t=0, pvd=nothing)Save vertex and cell data to a single VTK file. The file holds the grid spanned by the vertices xvi; data_v and velocity are written as point data and data_c as cell data of that same grid.
Arguments
fname::String: The filename for the VTK file (without extension)xvi: Vertex coordinates (tuple of coordinate arrays)xci: Cell center coordinates (tuple of coordinate arrays); must have one entry fewer per dimension thanxvidata_v::NamedTuple: Data defined at verticesdata_c::NamedTuple: Data defined at cell centers. Fields ofdata_vanddata_care written as point or cell data according to their size, so a cell-centered field passed indata_vstill lands on the cellsvelocity::Tuple: Velocity components, each an array defined at the verticest::Number: Time value (default: 0)pvd::Union{Nothing, String}: Optional ParaView collection filename. If provided, the VTK file will be added to a time series collection. WriteVTK.jl automatically handles creating new collections or appending to existing ones.
Examples
# Basic usage
save_vtk("output", xvi, xci, data_v, data_c, velocity; t=1.0)
# With ParaView collection for time series
save_vtk("timestep_001", xvi, xci, data_v, data_c, velocity; t=1.0, pvd="simulation")
save_vtk("timestep_002", xvi, xci, data_v, data_c, velocity; t=2.0, pvd="simulation")
# This creates simulation.pvd containing the time series
# Time series example
times = 0:0.1:10
for (i, t) in enumerate(times)
fname = "timestep_$(lpad(i, 3, '0'))"
save_vtk(fname, xvi, xci, data_v, data_c, velocity; t=t, pvd="full_simulation")
endJustRelax.DataIO.save_vtk Method
save_vtk(fname::String, xci, data_c::NamedTuple, velocity; t=nothing, pvd=nothing)Save VTK data with cell-centered data and velocity field.
Arguments
fname::String: The filename for the VTK file (without extension)xci: Cell center coordinates (tuple of coordinate arrays)data_c::NamedTuple: Data defined at cell centersvelocity::Tuple: Velocity components, each an array defined on the grid nodest::Number: Time value (default: nothing)pvd::Union{Nothing, String}: Optional ParaView collection filename. If provided, the VTK file will be added to a time series collection. WriteVTK.jl automatically handles creating new collections or appending to existing ones.
Examples
# Basic usage
save_vtk("output", xci, data_c, velocity; t=1.0)
# With ParaView collection
save_vtk("timestep_001", xci, data_c, velocity; t=1.0, pvd="simulation")JustRelax.DataIO.vertex_coordinates Method
vertex_coordinates(grid::Geometry)The cell-vertex coordinate vectors of grid (grid.xvi), collected into plain Vectors for serialization.