FELiCS.IO.Reader#

Module Contents#

Classes#

Reader

A class for reading and interpolating data from HDF5 files onto FELiCS meshes.

Attributes#

FELiCS.IO.Reader.logger#
class FELiCS.IO.Reader.Reader(sourceDir: str = '', needInterpolation: bool = True, felicsMeshFilePath: str | None = None, cacheData: bool = True)#

A class for reading and interpolating data from HDF5 files onto FELiCS meshes.

This class manages the loading of data from HDF5 files, handles interpolation or direct mapping to the calculation mesh, and assigns the data to FELiCS fields. It supports caching for performance and can handle complex-valued data.

Variables:
  • _sourceDir (str) – The source directory for data files.

  • _needInterpolation (bool) – Whether to interpolate data onto the FELiCS mesh.

  • _felicsMeshFilePath (str or None) – Path to the FELiCS mesh file.

  • _isComplex (bool) – Whether the data is complex-valued.

  • _cacheData (bool) – Whether to cache loaded data for reuse.

  • _sourceKey (tuple or None) – Current source key (filePath, groupName).

  • _availableVars (list or None) – List of available variables in the current source.

  • _rawDataDict (dict) – Raw data dictionary from HDF5 files.

  • _dataForField (dict) – Processed data for fields.

  • _calcMeshCoords (numpy.ndarray or None) – Coordinates of the calculation mesh.

  • _calcMeshP1Coords (numpy.ndarray or None) – Coordinates of the P1 calculation mesh.

  • _mappingImportToCalc (numpy.ndarray or None) – Mapping from import to calculation mesh.

  • _fullAxisNames (list or None) – Full axis names.

  • _meshAxisNames (list or None) – Mesh axis names.

  • _numDoFsCalcMeshP2 (int) – Number of DoFs for P2 calculation mesh.

  • _numDoFsCalcMeshP1 (int) – Number of DoFs for P1 calculation mesh.

  • _spacesDegrees (list or None) – Degrees of spaces.

Notes

  • Caching is per-file and cleared when switching sources.

  • Interpolation uses Delaunay triangulation for efficiency.

  • Retro-compatibility with previous FELiCS files with groupNames is ensured (for now).

Raises:
  • FileNotFoundError – If the specified file does not exist.

  • RuntimeError – If environment is not bound or source is not set.

  • NotImplementedError – For unsupported field types like mixed function spaces.

meshAxisNames()#

Names of the full spatial dimensions: mesh + spectral.

Returns:

The full dimension names (e.g., [‘x’, ‘y’, ‘z’]).

Return type:

list of str

Raises:

RuntimeError – If accessed before bind_env is called.

fullAxisNames()#

Get the names of all spatial dimensions: mesh + spectral.

Returns:

The full dimension names (e.g., [‘x’, ‘y’, ‘z’]).

Return type:

list of str

Raises:

RuntimeError – If accessed before bind_env is called.

calcMeshP2Coords()#

Get the coordinates of the calculation mesh.

Returns:

Array of shape (nPoints, nDimMesh) with the coordinates of the calculation mesh.

Return type:

numpy.ndarray

calcMeshP1Coords()#

Get the coordinates of the P1 calculation mesh.

Returns:

Array of shape (nPoints, nDimMesh) with the coordinates of the P1 calculation mesh.

Return type:

numpy.ndarray

mappingImportToCalcP2()#

Get the mapping from import mesh to calculation mesh (P2).

Returns:

The mapping array if no interpolation is needed, otherwise None.

Return type:

numpy.ndarray or None

importMeshCoords()#

Get the coordinates of the import mesh based on the configuration.

Three scenarios: 1. Interpolation needed, original mesh file provided: load from original mesh file. 2. Interpolation needed, no original mesh file: load from main file under group name. 3. No interpolation needed: load from FELiCS exported mesh file.

Returns:

Array of shape (nPoints, nDimMesh) with the coordinates of the import mesh.

Return type:

numpy.ndarray

clear_cached_properties(cachedProps: List[str] = []) None#

Remove all cached @cached_property values from this Reader instance.

They will be recomputed on the next access.

Parameters:

cachedProps (list of str, optional) – List of property names to clear. If empty, clears default properties.

importInField(field: Any, filePath: str, groupName: str) Tuple[Any, List[str]]#

Import data from the specified file/group into the given field.

Automatically clears per-file caches when file/group changes.

Parameters:
  • field (object) – The FELiCS field to import data into.

  • filePath (str) – Path to the HDF5 file.

  • groupName (str) – Name of the group in the HDF5 file.

Returns:

(updated field, list of missing variables)

Return type:

tuple

Raises:
  • FileNotFoundError – If the file does not exist.

  • NotImplementedError – If the field type is not supported.