sparseSpatialSampling.export module
Interpolate CFD data for the specified fields and time steps onto the coarse grid sampled using the \(S^3\) algorithm. Export the interpolated data to HDF5 and XDMF to enable visualization in ParaView.
- class sparseSpatialSampling.export.ExportData(s_cube, write_new_file_for_each_field=False, n_jobs=None, n_neighbors=None, interpolate_at_vertices=False, write_times=None, append_existing=False)[source]
Bases:
objectInitialize an Export object for interpolating original snapshots onto the grid generated by \(S^3\) and exporting them to HDF5.
- Parameters:
s_cube (SparseSpatialSampling) –
SparseSpatialSamplingobject containing the sampled gridwrite_new_file_for_each_field (bool) – If True, each field is written to a separate HDF5 file; if False, all fields are written to a single file. Gets disables if append_existing = True
n_jobs (int | None) – Number of CPUs used for interpolation. If None, the same number of CPUs used for executing \(S^3\) will be used
n_neighbors (int | None) – Number of neighbors for the KNN. If None, defaults are 8 for 2D and 26 for 3D
interpolate_at_vertices (bool) – If True, interpolate a solution at cell vertices in addition to cell centers
write_times (str | list[int | float | str] | None) – Numerical time steps of the simulation to be exported
append_existing (bool) –
flag to append a field to an existing HFD5 file.
Note
The s_cube objects and therefore the meshes must be identical in order to append the field. The mesh consistency is not checked.
- export(coordinates, data, field_name, n_snapshots_total=None, chunk_size=100000)[source]
Interpolate the provided CFD data onto the grid generated by \(S^3\) and export it to HDF5 and XDMF files for all specified time steps.
Note
The field data from CFD must have dimensions
[N_cells, N_dimensions, N_snapshots]. For scalar fields,N_dimensions = 1.- Parameters:
coordinates (pt.Tensor) – Coordinates of the original CFD grid
data (pt.Tensor) – Original field data with dimensions
[N_cells, N_dimensions, N_snapshots]. -N_snapshotscan represent all snapshots, a batch of snapshots, or a single snapshotfield_name (str) – Name of the field to export (e.g.,
'p'for the pressure field)n_snapshots_total (int | None) – Total number of snapshots to export - If
None, it is assumed that all snapshots are included indatachunk_size (int) – Number of cells to interpolate at once. Helpful if the memory is the restricting factor and
- Return type:
None
the batch size is already 1. The memory requirements scale linearly with the chunks size, so decreasing it saves memory. :type chunk_size: int :return: None :rtype: None
- property new_file: bool
Flag indicating whether a new HDF5 file will be created for each field.
- Returns:
True if a new file is created for each field, False otherwise
- Return type:
bool
- property save_dir: str
Get the directory where output files will be saved.
- Returns:
Path of the save directory
- Return type:
str
- property save_name: str
Get the base name of the output files.
- Returns:
Name of the file used for saving the grid and data
- Return type:
str
- property write_times: list
Get the list of available write times
- Returns:
List of time steps
- Return type:
list
- class sparseSpatialSampling.export.Fields(centers=None, vertices=None)[source]
Bases:
objectInitialize a container for storing interpolated field values at cell centers and vertices.
- Parameters:
centers (pt.Tensor | None) – Interpolated field values at cell centers
vertices (pt.Tensor | None) – Interpolated field values at cell vertices
- sparseSpatialSampling.export.interpolate_data(weights, idx_weights, data, chunk_size=100000)[source]
Interpolate the data matrix from CFD onto the \(S^3\) grid. To avoid memory issues, we loop over chunks of cells
- Parameters:
weights (pt.Tensor) – computed KNN weights for each point in the CFD grid
idx_weights (pt.Tensor) – indices of the k nearest neighbors for each point in the CFD grid
data (pt.Tensor) – data matrix from CFD, which should be interpolated
chunk_size (int) – number of cells to be interpolated at once
- Returns:
interpolated datamatrix
- Return type:
pt.Tensor