OpenFOAM-backend#
Reads OpenFOAM cases through the OpenFOAM reader of
pyvista (pip install io4dolfinx[openfoam]). The backend
is read-only. Pass the .foam file of the case, which can be created with
touch case.foam. All file access happens on rank 0.
The backend reads:
The mesh, of hexahedra, prisms, pyramids or tetrahedra. A mesh with several of these cell types is read as a mixed mesh.
Cell fields with
io4dolfinx.read_cell_data(), as DG-0 functions, and point fields withio4dolfinx.read_point_data(), at any time step listed byio4dolfinx.read_timestamps().Mesh tags of the boundary patches and the cell, face and point zones:
"cell"for all cell zones,"facet"for all patches and face zones, and"peak"for all point zones, or a single patch or zone by its name."regions"tags the cells by region. Useio4dolfinx.backends.openfoam.backend.read_ids()to list the ids.Cases with several regions, merged into one mesh. Read a single region with
backend_args={"region": name}.
mesh = io4dolfinx.read_mesh("case.foam", MPI.COMM_WORLD, backend="openfoam")
T = io4dolfinx.read_cell_data("case.foam", "T", mesh, time=1.0, backend="openfoam")
facets = io4dolfinx.read_meshtags("case.foam", mesh, "facet", backend="openfoam")
inlet = io4dolfinx.read_meshtags("case.foam", mesh, "inlet", backend="openfoam")
Polyhedral cells are not supported, as DOLFINx has no polyhedra. Fields and mesh tags
cannot be read on mixed meshes, and facet tags not on prism or pyramid meshes. Cell
fields are not interpolated to point data. The points and fields are read in single
precision, and returned in backend_args["dtype"], by default
dolfinx.default_real_type.
OpenFOAM interface to io4dolfinx.
Reads the mesh, fields, boundary patches and zones of an OpenFOAM case through the
VTK OpenFOAM reader of pyvista. The file is the .foam file
in the case directory (create it with touch case.foam). All file access happens on
rank 0.
The cells are the cells of the internal mesh. Hexahedra, prisms, pyramids and tetrahedra are supported; meshes with several of them are read as mixed meshes. Polyhedra are not supported, as DOLFINx has no polyhedral cells.
Cell-centred fields (
vol*Field) are read withread_cell_data(), and point fields (point*Field) withread_point_data(). Fields are not interpolated between the two.Boundary patches and cell, face and point zones are read from the
polyMeshfiles by their labels, seeread_meshtags_data().The regions of a multi-region case are merged into one mesh, joined where their points coincide exactly, unless one region is selected with the
regionbackend argument.
VTK reads points and fields in single precision. They are returned in the dtype
backend argument, by default dolfinx.default_real_type.
SPDX License identifier: MIT
Copyright: Jørgen S. Dokken and Simula Research Laboratory
- io4dolfinx.backends.openfoam.backend.get_default_backend_args(arguments: dict[str, Any] | None) dict[str, Any][source]#
Get default backend arguments given a set of input arguments.
- Parameters:
arguments – Input backend arguments
- Returns:
"dtype": Floating point type of the points and fields returned,dolfinx.default_real_type. VTK reads them in single precision."region": Region of a multi-region case to read,""for the default region.None(default) merges all regions into one mesh.
- Return type:
The arguments, with defaults for
- io4dolfinx.backends.openfoam.backend.read_cell_data(filename: Path | str, name: str, comm: Comm, time: str | float | None, backend_args: dict[str, Any] | None) tuple[ndarray[tuple[Any, ...], dtype[int64]], ndarray][source]#
Read a cell-centred OpenFOAM field (
vol*Field).For several regions, the field must exist in every region. Only meshes of one cell type are supported.
- Parameters:
filename – Path to the
.foamfile of the casename – Name of the field
comm – Communicator to launch IO on.
time – The time step, the first one if
Nonebackend_args – The backend arguments, see
get_default_backend_args()
- Returns:
A tuple (topology, values), where topology holds the input node indices of each cell on rank 0, and values the value of each cell
- io4dolfinx.backends.openfoam.backend.read_function_names(filename: Path | str, comm: Comm, backend_args: dict[str, Any] | None) list[str][source]#
Read the names of the cell and point fields of a case.
- Parameters:
filename – Path to the
.foamfile of the casecomm – MPI communicator to launch IO on.
backend_args – Arguments to backend
- Returns:
The names of the cell fields, then of the point fields
- io4dolfinx.backends.openfoam.backend.read_ids(filename: Path | str, comm: Comm, backend_args: dict[str, Any] | None = None) dict[str, dict[str, int]][source]#
The ids of the zones, patches and regions of a case, as tagged by
read_meshtags_data().- Parameters:
filename – Path to the
.foamfile of the casecomm – MPI communicator
backend_args – Arguments to backend, see
get_default_backend_args()
- Returns:
Map from
"cell"(cell zones),"facet"(boundary patches, then face zones),"peak"(point zones) and"regions"to a map from each name to its id
- io4dolfinx.backends.openfoam.backend.read_mesh_data(filename: Path | str, comm: Comm, time: str | float | None = None, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None) ReadMeshData | ReadMixedMeshData[source]#
Read the internal mesh of an OpenFOAM case.
Input node
iand celliare OpenFOAM point and cell labelifor a single region. Several regions are merged: their cells follow each other in region order, and the points are joined where they coincide. A mesh with several cell types is read as a mixed mesh, with its cells grouped by type.- Parameters:
filename – Path to the
.foamfile of the casecomm – MPI communicator to distribute the mesh over
time – Time step of the mesh, the first one if
Noneread_from_partition – Read mesh with partition from file (not supported)
backend_args – Arguments to backend, see
get_default_backend_args()
- Returns:
Internal data structure for the mesh data read from file
- io4dolfinx.backends.openfoam.backend.read_meshtags_data(filename: Path | str, comm: Comm, name: str, backend_args: dict[str, Any] | None = None) MeshTagsData[source]#
Read the zones, boundary patches or regions of a case as mesh tags.
Zones and patches are read from the
polyMeshfiles (boundary,faces,cellZones,faceZones,pointZones) by their labels. In a case with several regions, their names are"<region>/<name>". Ids are numbered from 1 for each dimension, in the order below and of the files, andread_ids()lists them.- Parameters:
filename – Path to the
.foamfile of the casecomm – MPI communicator
name –
One of:
"cell": the cells of all cell zones."facet": the facets of all boundary patches, then of all face zones."peak": the vertices of all point zones (vertices are the peaks of a 3D mesh, as indolfinx.io.gmsh.model_to_mesh())."regions": all cells, tagged with the region id.The name of a single patch or zone.
The sets combined must not overlap, as a mesh tag holds one value per entity, except for the two interface patches of neighbouring regions, which hold the same facets: those are tagged with the first.
backend_args – Arguments to backend, see
get_default_backend_args()
- Returns:
Internal data structure for the mesh tags read from file, on rank 0
- Raises:
KeyError – For an unknown name.
ValueError – If the sets combined overlap.
NotImplementedError – On a mesh with several cell types, and for facets on a mesh of prisms or pyramids, as mesh tags hold entities of one type.
- io4dolfinx.backends.openfoam.backend.read_point_data(filename: Path | str, name: str, comm: Comm, time: float | str | None, backend_args: dict[str, Any] | None) tuple[ndarray, int][source]#
Read an OpenFOAM point field (
point*Field).Cell-centred fields are not interpolated to the points; read them with
read_cell_data(). Only meshes of one region and one cell type are supported.- Parameters:
filename – Path to the
.foamfile of the casename – Name of the field
comm – Communicator to launch IO on.
time – The time step, the first one if
Nonebackend_args – The backend arguments, see
get_default_backend_args()
- Returns:
The values at the points, of shape
(num_points, num_components), on rank 0, and the global start of the data on this process,0
- io4dolfinx.backends.openfoam.backend.read_timestamps(filename: Path | str, comm: Comm, function_name: str, backend_args: dict[str, Any] | None) ndarray[tuple[Any, ...], dtype[float64 | str]][source]#
Read the time steps at which a field exists, in every region read.
- Parameters:
filename – Path to the
.foamfile of the casecomm – MPI communicator used in storage
function_name – Name of the field
backend_args – Arguments to backend, see
get_default_backend_args()
- Returns:
The time steps, in increasing order