I/O

Mesh I/O

class flatiron_tk.io.io.PVDWriter(filename)[source]

Bases: object

Simple .pvd (VTK Collection) writer that stores filenames (relative) per timestep. :param filename: Path to the output .pvd file. :type filename: str

add_dataset(timestep, file)[source]

Add a dataset to the collection. :param timestep: The time step associated with the dataset. :type timestep: float :param file: The path to the dataset file. :type file: str

write()[source]

Write the .pvd file to disk.

flatiron_tk.io.io.read_mesh(mesh_file, gdim=None, comm=mpi4py.MPI.COMM_WORLD)[source]

Read a mesh from a file with dolfinx.

Parameters:
  • mesh_file (str, Path to the mesh file.)

  • gdim (int, Geometric dimension of the mesh. Default is None.)

  • comm (MPI communicator. Default is MPI.COMM_WORLD.)

Returns:

  • mesh (dolfinx.mesh.Mesh, The mesh object.)

  • subdomain (dolfinx.mesh.MeshTags, The subdomain tags.)

  • boundary (dolfinx.mesh.MeshTags, The boundary tags.)

Checkpointing via ADIOS4DOLFINX

flatiron_tk.io.bp_mod.bp_get_time_steps(filepath: Path, name: str = None)[source]

Get the time steps available in a BP file. :param filepath: Path to the BP file. :type filepath: str or Path :param name: Name of the function to get time steps for. If None, the first function in the file is used. :type name: str, optional

Returns:

time_steps – List of time steps available in the BP file.

Return type:

list of float

flatiron_tk.io.bp_mod.bp_read_function(filepath: str | Path, time_id: int = 0, name: str = None, element_family: str = 'CG', element_degree: int = 1, element_shape=None)[source]

Read a function from a BP file. :param filepath: Path to the BP file. :type filepath: str or Path :param time_id: Time step index to read. Default is 0 (first time step). :type time_id: int, optional :param name: Name of the function to read. If None, the first function in the file is read. :type name: str, optional :param element_family: Finite element family. Default is ‘CG’. :type element_family: str, optional :param element_degree: Finite element degree. Default is 1. :type element_degree: int, optional :param element_shape: Shape of the element. Can be ‘scalar’, ‘vector’, or ‘tensor’. Default is None (scalar). :type element_shape: str, optional

Returns:

f – The function read from the BP file.

Return type:

dolfinx.fem.Function

flatiron_tk.io.bp_mod.bp_to_pvd(bp_filepath: str, pvd_filepath: str, name: str, time_id: str | int = None, element_family: str = 'CG', element_degree: int = 1, element_shape=None)[source]

Convert a BP file to a PVD file for visualization in Paraview. :param bp_filepath: Path to the BP file. :type bp_filepath: str or Path :param pvd_filepath: Path to the output PVD file. :type pvd_filepath: str or Path :param name: Name of the function to read from the BP file. :type name: str :param time_id: Time step index to read. If ‘all’, all time steps are read. Default is None (first time step). :type time_id: int or ‘all’, optional :param element_family: Finite element family. Default is ‘CG’. :type element_family: str, optional :param element_degree: Finite element degree. Default is 1. :type element_degree: int, optional :param element_shape: Shape of the element. Can be ‘scalar’, ‘vector’, or ‘tensor’. Default is None (scalar). :type element_shape: str, optional

Return type:

None

flatiron_tk.io.bp_mod.bp_to_xdmf(bp_filepath: str, xdmf_filepath: str, name: str, time_id: str | int = None, element_family: str = 'CG', element_degree: int = 1, element_shape=None)[source]

Convert a BP file to an XDMF file for visualization in Paraview. :param bp_filepath: Path to the BP file. :type bp_filepath: str or Path :param xdmf_filepath: Path to the output XDMF file. :type xdmf_filepath: str or Path :param name: Name of the function to read from the BP file. :type name: str :param time_id: Time step index to read. If ‘all’, all time steps are read. Default is None (first time step). :type time_id: int or ‘all’, optional :param element_family: Finite element family. Default is ‘CG’. :type element_family: str, optional :param element_degree: Finite element degree. Default is 1. :type element_degree: int, optional :param element_shape: Shape of the element. Can be ‘scalar’, ‘vector’, or ‘tensor’. Default is None (scalar). :type element_shape: str, optional

Return type:

None