1- from typing import Optional
2-
31from mpi4py import MPI
42
53import basix
@@ -25,8 +23,9 @@ class OpenFOAMReader:
2523 filename: the filename
2624 cell_type: cell type id (12 corresponds to HEXAHEDRON)
2725 reader: pyvista OpenFOAM reader for .foam files
26+ times: list of time values in the OpenFOAM file
2827 multidomain: boolean indicating if the mesh is multi-domain
29- OF_meshes_dict: dictionary of meshes from the openfoam file
28+ OF_meshes_dict: dictionary of meshes from the OpenFOAM file
3029 OF_cells_dict: dictionary of arrays of the cells with associated vertices
3130 connectivities_dict: dictionary of the OpenFOAM mesh cell connectivity with
3231 vertices reordered in a sorted order for mapping with the dolfinx mesh.
@@ -44,6 +43,7 @@ class OpenFOAMReader:
4443 cell_type : int
4544
4645 reader : pyvista .POpenFOAMReader
46+ times : list [float ]
4747 multidomain : bool
4848 OF_meshes_dict : dict [str , pyvista .pyvista_ndarray | pyvista .DataSet ]
4949 OF_cells_dict : dict [str , np .ndarray ]
@@ -55,6 +55,7 @@ def __init__(self, filename, cell_type: int = 12):
5555 self .cell_type = cell_type
5656
5757 self .reader = pyvista .POpenFOAMReader (self .filename )
58+ self .times = self .reader .time_values
5859 self .multidomain = False
5960 self .OF_meshes_dict = {}
6061 self .OF_cells_dict = {}
@@ -71,14 +72,14 @@ def cell_type(self, value):
7172 raise TypeError ("cell_type value should be an int" )
7273 self ._cell_type = value
7374
74- def _read_with_pyvista (self , t : float , subdomain : Optional [ str ] = "default" ):
75+ def _read_with_pyvista (self , t : float , subdomain : str | None = "default" ):
7576 """
76- Reads the openfoam data in the filename provided, passes details of the
77- openfoam mesh to OF_mesh and details of the cells to OF_cells.
77+ Reads the OpenFOAM data in the filename provided, passes details of the
78+ OpenFOAM mesh to OF_mesh and details of the cells to OF_cells.
7879
7980 Args:
8081 t: timestamp of the data to read
81- subdomain: Name of the subdmain in the openfoam file, from which a field is
82+ subdomain: Name of the subdmain in the OpenFOAM file, from which a field is
8283 extracted
8384
8485 """
@@ -124,7 +125,7 @@ def _read_with_pyvista(self, t: float, subdomain: Optional[str] = "default"):
124125 f"{ cell_types_in_mesh } "
125126 )
126127
127- def _create_dolfinx_mesh (self , subdomain : Optional [ str ] = "default" ):
128+ def _create_dolfinx_mesh (self , subdomain : str | None = "default" ):
128129 """Creates a dolfinx.mesh.Mesh based on the elements within the OpenFOAM mesh"""
129130
130131 # Define mesh element and define args conn based on the OF cell type
@@ -184,21 +185,21 @@ def _create_dolfinx_mesh(self, subdomain: Optional[str] = "default"):
184185 )
185186
186187 def create_dolfinx_function (
187- self , t : float , name : str = "U" , subdomain : Optional [ str ] = "default"
188+ self , t : float , name : str = "U" , subdomain : str | None = "default"
188189 ) -> dolfinx .fem .Function :
189190 """Creates a dolfinx.fem.Function from the OpenFOAM file.
190191
191192 Args:
192193 t: timestamp of the data to read
193- name: Name of the field in the openfoam file, defaults to "U" for velocity
194- subdomain: Name of the subdmain in the openfoam file, from which a field is
194+ name: Name of the field in the OpenFOAM file, defaults to "U" for velocity
195+ subdomain: Name of the subdmain in the OpenFOAM file, from which a field is
195196 extracted
196197
197198 Returns:
198199 the dolfinx function
199200 """
200201
201- # read the openfoam data in the filename provided
202+ # read the OpenFOAM data in the filename provided
202203 self ._read_with_pyvista (t = t , subdomain = subdomain )
203204
204205 # create the dolfinx mesh
0 commit comments