Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/foam2dolfinx/open_foam_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from mpi4py import MPI

import basix
Expand All @@ -25,8 +23,9 @@ class OpenFOAMReader:
filename: the filename
cell_type: cell type id (12 corresponds to HEXAHEDRON)
reader: pyvista OpenFOAM reader for .foam files
times: list of time values in the OpenFOAM file
multidomain: boolean indicating if the mesh is multi-domain
OF_meshes_dict: dictionary of meshes from the openfoam file
OF_meshes_dict: dictionary of meshes from the OpenFOAM file
OF_cells_dict: dictionary of arrays of the cells with associated vertices
connectivities_dict: dictionary of the OpenFOAM mesh cell connectivity with
vertices reordered in a sorted order for mapping with the dolfinx mesh.
Expand All @@ -44,6 +43,7 @@ class OpenFOAMReader:
cell_type: int

reader: pyvista.POpenFOAMReader
times: list[float]
multidomain: bool
OF_meshes_dict: dict[str, pyvista.pyvista_ndarray | pyvista.DataSet]
OF_cells_dict: dict[str, np.ndarray]
Expand All @@ -55,6 +55,7 @@ def __init__(self, filename, cell_type: int = 12):
self.cell_type = cell_type

self.reader = pyvista.POpenFOAMReader(self.filename)
self.times = self.reader.time_values
self.multidomain = False
self.OF_meshes_dict = {}
self.OF_cells_dict = {}
Expand All @@ -71,14 +72,14 @@ def cell_type(self, value):
raise TypeError("cell_type value should be an int")
self._cell_type = value

def _read_with_pyvista(self, t: float, subdomain: Optional[str] = "default"):
def _read_with_pyvista(self, t: float, subdomain: str | None = "default"):
"""
Reads the openfoam data in the filename provided, passes details of the
openfoam mesh to OF_mesh and details of the cells to OF_cells.
Reads the OpenFOAM data in the filename provided, passes details of the
OpenFOAM mesh to OF_mesh and details of the cells to OF_cells.

Args:
t: timestamp of the data to read
subdomain: Name of the subdmain in the openfoam file, from which a field is
subdomain: Name of the subdmain in the OpenFOAM file, from which a field is
extracted

"""
Expand Down Expand Up @@ -124,7 +125,7 @@ def _read_with_pyvista(self, t: float, subdomain: Optional[str] = "default"):
f"{cell_types_in_mesh}"
)

def _create_dolfinx_mesh(self, subdomain: Optional[str] = "default"):
def _create_dolfinx_mesh(self, subdomain: str | None = "default"):
"""Creates a dolfinx.mesh.Mesh based on the elements within the OpenFOAM mesh"""

# Define mesh element and define args conn based on the OF cell type
Expand Down Expand Up @@ -184,21 +185,21 @@ def _create_dolfinx_mesh(self, subdomain: Optional[str] = "default"):
)

def create_dolfinx_function(
self, t: float, name: str = "U", subdomain: Optional[str] = "default"
self, t: float, name: str = "U", subdomain: str | None = "default"
) -> dolfinx.fem.Function:
"""Creates a dolfinx.fem.Function from the OpenFOAM file.

Args:
t: timestamp of the data to read
name: Name of the field in the openfoam file, defaults to "U" for velocity
subdomain: Name of the subdmain in the openfoam file, from which a field is
name: Name of the field in the OpenFOAM file, defaults to "U" for velocity
subdomain: Name of the subdmain in the OpenFOAM file, from which a field is
extracted

Returns:
the dolfinx function
"""

# read the openfoam data in the filename provided
# read the OpenFOAM data in the filename provided
self._read_with_pyvista(t=t, subdomain=subdomain)

# create the dolfinx mesh
Expand Down
Loading