sparseSpatialSampling.data module

Module containing classes for handling input and output of S^3 data.

  • Dataloader: Class for loading data from the HDF5 output file of \(S^3\) and assembling the data matrix.

  • Datawriter: Class for writing data generated by \(S^3\) to an HDF5 file.

  • XDMFwriter: Class for generating an XDMF file based on a given HDF5 file from \(S^3\).

class sparseSpatialSampling.data.Dataloader(load_path, file_name, dtype=torch.float32)[source]

Bases: object

Load data from the HDF5 output file of \(S^3\) and assemble the data matrix.

Parameters:
  • load_path (str) – Path to the HDF5 file

  • file_name (str) – Name of the HDF5 file

  • dtype (pt.dtype) – Data type of the tensor; default is float32 (single precision)

property faces: torch.Tensor

Load the cell faces of the grid.

Returns:

Tensor containing the indices of the cell faces of the grid

Return type:

pt.Tensor

property field_names: dict

Create a dictionary of available fields for each time step.

The dictionary keys are the available time steps, and the values are lists of fields available at each corresponding time step.

Returns:

Dictionary mapping each time step to its available fields

Return type:

dict[int, list]

property file_name: str

Get the current file name.

Returns:

Current file name

Return type:

str

property levels: torch.Tensor

Load the refinement levels of the cells in the grid.

Returns:

Tensor containing the cell levels of the grid

Return type:

pt.Tensor

property load_path: str

Get the current load path.

Returns:

Current load path

Return type:

str

load_snapshot(field_name, write_times=None)[source]

Load snapshots for the specified field(s) and time steps.

Parameters:
  • field_name (str) – Name of the field for which the data matrix should be created

  • write_times (Union[str, List[str], None]) – Time steps for which the data matrix should be created. If None, all available time steps will be used.

Returns:

  • Data matrix containing snapshots:
    • [N_cells, N_dimensions, N_snapshots] for vector fields

    • [N_cells, N_snapshots] for scalar fields

  • Or a list of data matrices if multiple fields are loaded

Return type:

Union[pt.Tensor, List[pt.Tensor]]

property metric: torch.Tensor

Load the metric field used to generate the grid

Returns:

Tensor containing the metric field used to generate the grid

Return type:

pt.Tensor

property nodes: torch.Tensor

Load the cell nodes of the grid.

Returns:

Tensor containing the cell nodes of the grid

Return type:

pt.Tensor

property vertices: torch.Tensor

Load the cell centers of the grid.

Returns:

Tensor containing the cell centers of the grid

Return type:

pt.Tensor

property weights: torch.Tensor

Load and compute the cell areas (2D) or volumes (3D) of the grid.

Returns:

Tensor containing cell areas (2D) or volumes (3D)

Return type:

pt.Tensor

property write_times: List[str]

Load all available time steps present in the HDF5 file.

The time steps at which a specific field is present are stored in the field_names property.

Returns:

List of available write times

Return type:

list

class sparseSpatialSampling.data.Datawriter(file_path, file_name, mode='w', mixed=False)[source]

Bases: object

Initialize a Datawriter for writing data generated by \(S^3\) to an HDF5 file and optionally create an XDMF file for visualization in ParaView or other software.

Inspired and partially adopted from the flowtorch Datawriter: https://github.com/FlowModelingControl/flowtorch/blob/main/flowtorch/data/hdf5_file.py

Parameters:
  • file_path (str) – Path where the HDF5 file should be saved

  • file_name (str) – Name of the HDF5 file (including extension, e.g., data.h5)

  • mode (str) – File access mode: - 'w': create a new file (overwriting any existing file with the same name) - 'a': append to an existing HDF5 file The mode can be changed after instantiation.

  • mixed (bool) – Flag indicating if the grid is of type ‘Mixed’ (for unstructured grids not created with \(S^3\)); only relevant for writing the XDMF file

close()[source]

Close the HDF5 writer

Returns:

None

Return type:

None

property file_name: str

Get the name of the HDF5 file.

Returns:

File name

Return type:

str

property mode: str

Get the current file access mode for the HDF5 file (e.g., 'r' for read, 'w' for write).

Returns:

File access mode

Return type:

str

property n_cells: int | None

Get the number of cells in the grid from \(S^3\). :return: Number of cells from the \(S^3\) Dataloader. :rtype: Union[int, None]

write_data(name, data, group='constant', time_step=None)[source]

Write data to an HDF5 file.

Parameters:
  • name (str) – Name of the dataset to be created

  • data (any) – Data to write

  • group (str) – Target group for the data. Available groups are: - 'constant': arbitrary values and fields without time dependency - 'grid': grid datasets including 'centers', 'vertices', and 'faces' from \(S^3\) - 'data': temporal data such as flow fields

  • time_step (int | float | str | None) – Time step associated with the field when writing temporal data. If None and the group is 'data', the data will be written to the zeroth time step ('data/0')

Returns:

None

Return type:

None

write_grid(loader)[source]

Write the grid to a new HDF5 file based on a given Dataloader.

Parameters:

loader (Dataloader) – Dataloader instance containing the path to the HDF5 file from which the grid should be loaded

Returns:

None

Return type:

None

write_xdmf_file()[source]

Write an XDMF file based on the contents of a given HDF5 file.

Returns:

None

Return type:

None

class sparseSpatialSampling.data.XDMFWriter(file_path, file_name, grid_name='grid_s_cube', mixed=False)[source]

Bases: object

Initialize the XDMF writer for a given HDF5 file from \(S^3\).

Parameters:
  • file_path (str) – Path to the HDF5 file for which the XDMF file should be created

  • file_name (str) – Name of the HDF5 file (including extension, e.g., data.h5)

  • grid_name (str) – Name of the grid (used inside the XDMF file)

  • mixed (bool) – Flag indicating if the grid is of type ‘Mixed’ (for unstructured grids not created with \(S^3\)); only relevant for writing the XDMF file

write_xdmf()[source]

Wrapper function for writing the XDMF file.

Returns:

None

Return type:

None