flowtorch.data¶
flowtorch.data.dataloader¶
Definition of a common interface for all dataloaders.
This abstract base class should be used as parent class when defining new dataloaders, e.g., to support additional file formats.
-
class
flowtorch.data.dataloader.
Dataloader
[source]¶ Bases:
abc.ABC
Abstract base class to define a common interface for dataloaders.
-
abstract property
field_names
¶ Create a dictionary containing availale fields
- Returns
dictionary with write times as keys and field names as values
- Return type
Dict[str, List[str]]
-
abstract
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
abstract property
vertices
¶ Get the vertices at which field values are defined.
- Returns
coordinates of vertices
- Return type
Tensor
-
abstract property
weights
¶ Get the weights for field values.
In a standard finite volume method, the weights are the cell volumes. For other methods, the definition of the weight is described in the Dataloader implementation.
- Returns
weight for field values
- Return type
Tensor
-
abstract property
write_times
¶ Available write times.
- Returns
list of available write times
- Return type
List[str]
-
abstract property
flowtorch.data.foam_dataloader¶
Classes to work with OpenFOAM cases, meshes, and fields.
The FOAMDataloader
class allows to load fields from
an OpenFOAM simulation folder. Currently, only the ESI-OpenCFD
branch of OpenFOAM is supported (v1912, v2006). The FOAMCase
class assembles information about the folder and file structure
of a simulation. The FOAMMesh
allows loading and parsing
the finite volume mesh.
-
class
flowtorch.data.foam_dataloader.
FOAMCase
(path: str)[source]¶ Bases:
object
Class to access and parse OpenFOAM cases.
Most of the attributes and methods are private because they are typically accessed via a
FOAMDataloader
instance.-
_eval_distributed
() → bool[source]¶ Check if the simulation case is distributed (parallel).
Warning
Collated output is currently not supported/not detected.
- Returns
True if distributed
- Return type
bool
-
_eval_processors
() → int[source]¶ Get number of processor folders.
- Returns
number of processor folders or 1 for serial runs
- Return type
int
-
_eval_write_times
() → List[str][source]¶ Assemble a list of all write times.
- Returns
a list of all time folders
- Return type
list(str)
Warning
For distributed simulations, it is assumed that all processor folders contain the same time folders.
-
_eval_field_names
() → Dict[str, List[str]][source]¶ Get a dictionary of all fields and files in all time folders.
Warning
For distributed cases, only processor0 is evaluated. The fields for all other processors are assumed to be the same.
- Returns
dictionary with write times as keys and a list of field names for each time as values
- Return type
dict
-
build_file_path
(field_name: str, time: str, processor: int = 0) → str[source]¶ Create the path to file inside the time folder of a simulation.
- Parameters
field_name (str) – name of the field or file, e.g., “U” or “p”
time (str) – name of the time folder, e.g., “0.01”
processor (int, optional) – processor folder to load the data from; ignored in serial simulation cases; defaults to 0
- Returns
path to file inside a time folder
- Return type
str
Examples
>>> from flowtorch.data import FOAMCase >>> case = FOAMCase("./cavity_binary_parallel/") >>> case._distributed True >>> case._processors 4 >>> case._time_folders ['0', '0.1', '0.2', '0.3', '0.4', '0.5'] >>> case._field_names {'0': ['U', 'p'], '0.1': ['U', 'p', 'phi'], '0.2': ['U', 'p', 'phi'], '0.3': [ 'U', 'p', 'phi'], '0.4': ['U', 'p', 'phi'], '0.5': ['U', 'p', 'phi']} >>> case.build_file_path("U", "0.1", 1) './cavity_binary_parallel/processor1/0.1/U'
-
-
class
flowtorch.data.foam_dataloader.
FOAMDataloader
(path: str, dtype: str = torch.float32)[source]¶ Bases:
flowtorch.data.dataloader.Dataloader
Load internal fields and mesh properties of OpenFOAM cases.
The project ofpp by Xu Xianghua has been a great help to implement some of the methods.
Examples
>>> from flowtorch import DATASETS >>> from flowtorch.data import FOAMDataloader >>> path = DATASETS["of_cavity_ascii_parallel"] >>> loader = FOAMDataloader(path) >>> loader.write_times ['0', '0.1', '0.2', '0.3', '0.4', '0.5'] >>> loader.field_names {'0': ['p', 'U'], '0.1': ['p', 'phi', 'U'], '0.2': ['p', 'phi', 'U'], '0.3': [ 'p', 'phi', 'U'], '0.4': ['p', 'phi', 'U'], '0.5': ['p', 'phi', 'U']} >>> vertices = loader.vertices >>> vertices[:3] tensor([[0.0025, 0.0025, 0.0050], [0.0075, 0.0025, 0.0050], [0.0125, 0.0025, 0.0050]]) >>> loader.weights[:3] # cell volumes tensor([2.5000e-07, 2.5000e-07, 2.5000e-07]) >>> p = loader.load_snapshot("p", "0.5") >>> p.shape torch.Size([400]) >>> p[:3] tensor([ 4.2993e-06, -5.8226e-03, -1.2960e-02])
-
property
field_names
¶ Access to the available field names for all available write times via
FOAMCase._eval_field_names()
.- Getter
returns names of availabe fields
- Type
Dict[str, List[str]]
-
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
property
vertices
¶ In OpenFOAM, field for post-processing are defined at the control volume’s center (vol<Type>Fields). Therefore, the vertices property enables access to cell center locations via
FOAMMesh
.- Getter
returns control volume centers
- Type
pt.Tensor
-
property
weights
¶ For results obtained using a finite volume method with co-located arrangement (OpenFOAM), a sensible weight for a cell-centered value is the cell volume. The cell volumes are availabe via the
FOAMMesh
class.- Getter
returns cell volumes
- Type
pt.Tensor
-
property
write_times
¶ Access to available snapshot/write times via
FOAMCase._eval_write_times()
.- Getter
returns the available write times
- Type
List[str]
-
property
-
class
flowtorch.data.foam_dataloader.
FOAMMesh
(case: flowtorch.data.foam_dataloader.FOAMCase, dtype: str = torch.float32)[source]¶ Bases:
object
Class to load and process OpenFOAM meshes.
OpenFOAM stores the finite volume mesh as a collection of several files located in constant/polyMesh or in processorXX/constant/polyMesh for serial and distributed cases, respectively. Even though OpenFOAM is a cell-centered finite volume method, the cell-centers and volumes are not explicitly stored. Instead, a so-called face-addressing storage is used. All internal faces have an owner cell and a neighbor cell. Boundary faces only have an owner cell. The mesh attributes are defined in several files:
points: list of vertices forming cell faces; the list index of a point is used as label
faces: list of all cell faces defined as point labels
owner: list of cell labels that are face owners
neighbour: list of cell labels that are face neighbors; BE spelling
boundary: definition of faces belonging to a patch
Examples
>>> from flowtorch.data import FOAMMesh >>> mesh = FOAMMesh.from_path("./") >>> centers = mesh.get_cell_centers() >>> centers.size() torch.Size([400, 3]) >>> centers[:2] tensor([[0.0025, 0.0025, 0.0050], [0.0075, 0.0025, 0.0050]]) >>> volumes = mesh.get_cell_volumes() >>> volumes.size() torch.Size([400]) >>> volumes[:2] tensor([2.5000e-07, 2.5000e-07])
Warning
Dynamically changing meshes are currently not supported.
Warning
Distributed meshes may be parsed and concatenated, but the cell centers and volumes won’t have the same ordering as when computed from a reconstructed mesh.
-
_compute_face_centers_and_areas
(points: torch.Tensor, faces: torch.Tensor, n_points_faces: torch.Tensor) → Tuple[torch.Tensor, torch.Tensor][source]¶ Compute face centers and areas.
The implemented algorithm is close to the one in makeFaceCentresAndAreas. The main steps are:
compute an estimate of the face center by averaging all face vertices
decompose the face into triangles
compute the sum over all area-weighted triangle centroids, triangle areas, and face area normal vectors
compute the face centroid and face area normal from the (weighted) sums
-
_compute_cell_centers_and_volumes
(mesh_path: str) → Tuple[torch.Tensor, torch.Tensor][source]¶ Compute the cell centers and volumes of an OpenFOAM mesh.
The implemented algorithm is close to the one in makeCellCentresAndVols. The following steps are involved:
compute an estimate of the cell center as the average over all face centers
compute centroids and volumes of all pyramids formed by the cell faces and and the center estimate
the cell volume equals the sum over all pyramid volumes
the cell center is the volume-weighted average of all pyramid centroids
-
classmethod
from_path
(path: str, dtype: str = torch.float32)[source]¶ Create FOAMMesh object based on path to OpenFOAM simulation case.
flowtorch.data.hdf5_file¶
Module to read and write the internal flowTorch data format.
The HDF5Writer
class allows to write field and mesh data
into an HDF5 file. It also creates an XDMF accessor file for postprocessing
in ParaView. The XDMF file creation is implemented in the XDMFWriter
class. The HDF5Dataloader
class is the complementary writer for the
flowTorch data format. Moreover, the FOAM2HDF5
class allows conversion
of reconstructed OpenFOAM simulation cases into the HDF5-based flowTorch format.
-
class
flowtorch.data.hdf5_file.
FOAM2HDF5
(path: str, dtype=torch.float32)[source]¶ Bases:
object
Convert reconstructed OpenFOAM cases to flowTorch HDF5 format.
If the simulation case is decomposed into processor folders/domains, an info statement is displayed and no conversion is performed.
Examples
>>> from flowtorch import DATASETS >>> from flowtorch.data import FOAM2HDF5 >>> converter = FOAM2HDF5(DATASETS["of_cavity_ascii"]) >>> converter.convert("cavity.hdf5", skip_zero=True)
-
class
flowtorch.data.hdf5_file.
HDF5Dataloader
(file_path: str, dtype: str = torch.float32)[source]¶ Bases:
flowtorch.data.dataloader.Dataloader
Load HDF5-based flowTorch data.
Examples
>>> from flowtorch import HDF5Dataloader >>> loader = HDF5Dataloader("flowtorch.hdf5") >>> times = loader.write_times >>> p, U = loader.load_snapshot(["p", "U"], write_times) >>> vertices = loader.vertices
-
property
field_names
¶ Create a dictionary containing availale fields
- Returns
dictionary with write times as keys and field names as values
- Return type
Dict[str, List[str]]
-
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
property
vertices
¶ Get the vertices at which field values are defined.
- Returns
coordinates of vertices
- Return type
Tensor
-
property
weights
¶ Get the weights for field values.
In a standard finite volume method, the weights are the cell volumes. For other methods, the definition of the weight is described in the Dataloader implementation.
- Returns
weight for field values
- Return type
Tensor
-
property
write_times
¶ Available write times.
- Returns
list of available write times
- Return type
List[str]
-
property
-
class
flowtorch.data.hdf5_file.
HDF5Writer
(file: str)[source]¶ Bases:
object
Class to write flowTorch data to HDF5 file.
Two types of data are supported: - variable: (field) data that changes with times, e.g, snapshots - constant: constant data like mesh vertices or cell volumes
An XDMF accessor file can be created to support visual post-processing with ParaView and other XDMF-compatible software packages.
Examples
>>> import torch as pt >>> from flowtorch.data import HDF5Writer >>> writer = HDF5Writer("test_file.hdf5") >>> writer.write("ones", (3, 2), pt.ones((3, 2)), "0.01") >>> int_data = pt.ones((3, 2), dtype=pt.int32) >>> writer.write("ones_int", (3, 2), int_data, dtype=pt.int32)
-
write
(name: str, size: tuple, data: Optional[torch.Tensor] = None, time: Optional[str] = None, dtype: str = torch.float32)[source]¶ Write data to HDF5 file.
- Parameters
name (str) – dataset name
size (tuple) – dataset shape
data (pt.Tensor, optional) – data to write; if None, dataset is only allocated
time (str, optional) – snapshot time, dataset if created in VAR_GROUP if present
dtype (str, optional) – data type, defaults to pt.float32
-
-
class
flowtorch.data.hdf5_file.
XDMFWriter
(file_path: str, hdf5_file: h5py._hl.files.File)[source]¶ Bases:
object
Create XDMF file to open flowTorch HDF5 files in ParaView.
Example
>>> from flowtorch.data import XDMFWriter >>> writer = XDMFWriter("flowtorch.hdf5") >>> writer.create_xdmf("flowtorch.xdmf")
flowtorch.data.psp_dataloader¶
Module to load FOR2895 iPSP data.
The PSPDataloader
class allows to load
instationary pressure-sensitive paint (iPSP) data provided by
DLR (Deutsches Luft- und Raumfahrtzentrum) within the FOR2895
research group.
-
class
flowtorch.data.psp_dataloader.
PSPDataloader
(path: str, dtype: str = torch.float32)[source]¶ Bases:
flowtorch.data.dataloader.Dataloader
Load iPSP data and meta data.
iPSP data comes as an HDF5 file with datasets organized in different zones. Each zone has additional meta data related to flow conditions and camera setting. The active zone may be switched by seeting the zone attribute.
Examples
>>> from flowtorch import PSPDataloader >>> loader = PSPDataloader("0226.hdf5") >>> loader.zone_names ['Zone0000', 'Zone0001'] >>> loader.info.keys() ['AngleAttackAlpha', 'DateOfRecording', 'Mach', ...] >>> loader.info["Mach"] (0.903, 'Mach number') >>> loader.zone_info.keys() ['ExposureTime', 'NumberImages', 'PSPDeviceName', 'SamplingFrequency', 'ZoneName'] >>> loader.zone Zone0000 >>> loader.zone = "Zone0001" >>> loader.zone_info["ZoneName"] HTP >>> cp = loader.load_snapshot("Cp", loader.write_times[:10]) >>> cp.shape torch.Size([250, 75, 10])
-
property
field_names
¶ Create a dictionary containing availale fields
- Returns
dictionary with write times as keys and field names as values
- Return type
Dict[str, List[str]]
-
property
info
¶
-
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
property
vertices
¶ Get the vertices at which field values are defined.
- Returns
coordinates of vertices
- Return type
Tensor
-
property
weights
¶ Get the weights for field values.
In a standard finite volume method, the weights are the cell volumes. For other methods, the definition of the weight is described in the Dataloader implementation.
- Returns
weight for field values
- Return type
Tensor
-
property
write_times
¶ Available write times.
- Returns
list of available write times
- Return type
List[str]
-
property
zone
¶
-
property
zone_info
¶
-
property
zone_names
¶
-
property
flowtorch.data.vtk_dataloader¶
Class and tools to read Visualization Toolkit (VTK) data.
-
class
flowtorch.data.vtk_dataloader.
VTKDataloader
(path: str, vtk_reader: Union[vtkmodules.vtkIOLegacy.vtkUnstructuredGridReader, vtkmodules.vtkIOXML.vtkXMLUnstructuredGridReader], prefix: str = '', suffix: str = '', dtype: str = torch.float32)[source]¶ Bases:
flowtorch.data.dataloader.Dataloader
Load unstructured VTK files and time series.
The loader assumes that snapshots are stored in individual VTK files. Currently, only unstructured mesh data are supported.
Examples
>>> from flowtorch import DATASETS >>> from flowtorch.data import VTKDataloader >>> path = DATASETS["vtk_cylinder_re200_flexi"] >>> loader = VTKDataloader.from_flexi(path, "Cylinder_Re200_Solution_") >>> loader.write_times ["0000000", "0000005", "0000300"] >>> loader.field_names {'0000000': ['Density', 'MomentumX', 'MomentumY', 'MomentumZ']} >>> density = loader.load_snapshot("Density", loader.write_times) >>> density.shape torch.Size([729000, 3])
>>> from flowtorch import DATASETS >>> from flowtorch.data import VTKDataloader >>> path = DATASETS["vtk_su2_airfoil_2D"] >>> loader = VTKDataloader.from_su2(path, "flow_") >>> p, U = loader.load_snapshot(["Pressure", "Velocity"], loader.write_times[0]) >>> U.shape torch.Size([214403, 3])
-
property
field_names
¶ Create a dictionary containing availale fields
- Returns
dictionary with write times as keys and field names as values
- Return type
Dict[str, List[str]]
-
classmethod
from_flexi
(path: str, prefix: str = '', suffix: str = '.000000000.vtu', dtype: str = torch.float32)[source]¶ Create loader instance from VTK files generated by Flexi.
Flexi supports the output of field and surface data as unstructured XML-based VTK files.
- Parameters
path (str) – path to folder containing VTK files
prefix (str, optional) – part of file name before time value, defaults to “”
suffix (str, optional) – part of file name after time value, defaults to “.000000000.vtu”
dtype (str, optional) – tensor type, defaults to DEFAULT_DTYPE
-
classmethod
from_su2
(path: str, prefix: str = '', suffix: str = '.vtk', dtype: str = torch.float32)[source]¶ Create loader instance from VTK files generated by SU2.
- Parameters
path (str) – path to folder containing VTK files
prefix (str, optional) – part of file name before time value, defaults to “”
suffix (str, optional) – part of file name after time value, defaults to “.vtk”
dtype (str, optional) – tensor type, defaults to DEFAULT_DTYPE
-
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
property
vertices
¶ Get the vertices at which field values are defined.
- Returns
coordinates of vertices
- Return type
Tensor
-
property
weights
¶ Get the weights for field values.
In a standard finite volume method, the weights are the cell volumes. For other methods, the definition of the weight is described in the Dataloader implementation.
- Returns
weight for field values
- Return type
Tensor
-
property
write_times
¶ Available write times.
- Returns
list of available write times
- Return type
List[str]
-
property
flowtorch.data.csv_dataloader¶
Dataloader and accompanying tools to work with CSV files.
A lot of scientific data is exchanged as comma separated value (CSV) files. While there are many Python packages available to read such data, one has to understand how the data is organized in the CSV file before being able to use the readers properly. Moreover, time series data sometimes come as individual files in a single folder or as time folders with the respective snapshot data inside that folder. This subpackages simplifies access to common CSV-based time series data by trying to figure out appropriate reader settings automatically.
-
class
flowtorch.data.csv_dataloader.
CSVDataloader
(path: str, prefix: str, suffix: str, read_options: dict, time_folders: bool, dtype: str = torch.float32)[source]¶ Bases:
flowtorch.data.dataloader.Dataloader
Load CSV files from different sources.
This class allows to load generic CSV files based on Pandas’s load_csv function. Multiple specific formats are supported via class methods.
Examples
>>> from flowtorch import DATASETS >>> from flowtorch.data import CSVDataloader >>> davis_data = DATASETS["csv_aoa8_beta0_xc100_stereopiv"] >>> loader = CSVDataloader.from_davis(davis_data, "B") >>> times = loader.write_times >>> times[:5] ['00001', '00002', '00003', '00004', '00005'] >>> loader.field_names {'00001': ['Vx', 'Vy', 'Vz']} >>> Vx, Vy, Vz = loader.load_snapshot(['Vx', 'Vy', 'Vz'], times[:5]) >>> Vx.shape torch.Size([3741, 5])
>>> foam_data = DATASETS["csv_naca0012_alpha4_surface"] >>> loader = CSVDataloader.from_foam_surface(foam_data, "total(p)_coeff_airfoil.raw", "cp") >>> times = loader.write_times >>> times[:5] ['0.001', '0.002', '0.003', '0.004', '0.005'] >>> loader.field_names {'0.001': ['cp']} >>> snapshots = loader.load_snapshot("cp", times[:10]) >>> snapshots.shape torch.Size([28892, 10]) >>> vertices = loader.vertices >>> vertices.shape torch.Size([28892, 3]) >>> vertices[0, :] tensor([0.0000e+00, 0.0000e+00, 4.1706e-18])
-
property
field_names
¶ Create a dictionary containing availale fields
- Returns
dictionary with write times as keys and field names as values
- Return type
Dict[str, List[str]]
-
classmethod
from_davis
(path: str, prefix: str = '', suffix: str = '.dat', dtype: str = torch.float32)[source]¶ Create CSVDataloader instance for DaVis output files.
- Parameters
path (str) – path to location of time series data
prefix (str) – part of the file name before the time/snapshot number; e.g., if the file name B00001.dat, the prefix is B; defaults to empty string
suffix (str) – part of the file name of the time/snapshot number; e.g., if the file name is B00001.dat, the suffix is .dat; defaults to .dat
dtype (str) – floating point precision; defaults to pt.float32 (single precision)
-
classmethod
from_foam_surface
(path: str, file_name: str, field_name: Optional[str] = None, dtype: str = torch.float32)[source]¶ Create CSVDataloader instance to load OpenFOAM surface sample data.
The class method simplifies to load data generated by OpenFOAM’s sampling function object if the type is set to surfaces and the surfaceFormat is set to raw. The time series data are stored in individual time folders. The file name remains the same.
- Parameters
path (str) – path to location of time folders
file_name (str) – file name of individual CSV files, e.g., p_airfoil.raw
field_name (str) – each CSV contains only one field; this parameter allows to prescribe a descriptive access name; defaults to None, which chooses the generic field name f.
dtype (str) – floating point precision; defaults to pt.float32 (single precision)
-
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
property
vertices
¶ Get the vertices at which field values are defined.
- Returns
coordinates of vertices
- Return type
Tensor
-
property
weights
¶ Get the weights for field values.
In a standard finite volume method, the weights are the cell volumes. For other methods, the definition of the weight is described in the Dataloader implementation.
- Returns
weight for field values
- Return type
Tensor
-
property
write_times
¶ Available write times.
- Returns
list of available write times
- Return type
List[str]
-
property
flowtorch.data.tau_dataloader¶
Direct access to TAU simulation data.
The DRL (Deutsches Luft- und Raumfahrtzentrum) TAU code saves
snapshots in the NetCFD format. The TAUDataloader
is a
wrapper around the NetCFD Python bindings to simplify the access
to snapshot data.
-
class
flowtorch.data.tau_dataloader.
TAUDataloader
(path: str, base_name: str, dtype: str = torch.float32)[source]¶ Bases:
flowtorch.data.dataloader.Dataloader
Load TAU simulation data.
TAU simulations output results in several netCDF files, one for each write time. The mesh is stored in a separated file with the extension .grd. Currently, the loader only enables access to field data but not to boundaries.
Examples
>>> from flowtorch import DATASETS >>> from flowtorch.data import TAUDataloader >>> path = DATASETS["tau_backward_facing_step"] >>> loader = TAUDataloader(path, base_name="sol.pval.unsteady_") >>> times = loader.write_times >>> fields = loader.field_names[times[0]] >>> fields ['density', 'x_velocity', 'y_velocity', ...] >>> density = loader.load_snapshot("density", times) >>> density.shape torch.Size([1119348, 10])
-
property
field_names
¶ Create a dictionary containing availale fields
- Returns
dictionary with write times as keys and field names as values
- Return type
Dict[str, List[str]]
-
load_snapshot
(field_name: Union[List[str], str], time: Union[List[str], str]) → Union[List[torch.Tensor], torch.Tensor][source]¶ Load one or more snapshots of one or more fields.
- Parameters
field_name (Union[List[str], str]) – name of the field to load
time (Union[List[str], str]) – snapshot time
- Returns
field values
- Return type
Union[List[Tensor], Tensor]
-
property
vertices
¶ Get the vertices at which field values are defined.
- Returns
coordinates of vertices
- Return type
Tensor
-
property
weights
¶ Get the weights for field values.
In a standard finite volume method, the weights are the cell volumes. For other methods, the definition of the weight is described in the Dataloader implementation.
- Returns
weight for field values
- Return type
Tensor
-
property
write_times
¶ Available write times.
- Returns
list of available write times
- Return type
List[str]
-
property
flowtorch.data.selection_tools¶
Helper tools for building data matrices.
-
flowtorch.data.selection_tools.
mask_box
(vertices: torch.Tensor, lower: List[float], upper: List[float]) → torch.Tensor[source]¶ Create a boolean mask to select all vertices in a box.
This function may be used in conjunction with torch.masked_select to select all field values in a box, e.g., when building data matrices.
- Parameters
vertices (pt.Tensor) – tensor of vertices, where each column corresponds to a coordinate
lower (List[float]) – lower bounds of box; one value for each coordinate must be given
upper (List[float]) – upper bounds of box; one value for each coordinate must be given
- Returns
boolean mask that’s True for every vertex inside the box
- Return type
pt.Tensor
-
flowtorch.data.selection_tools.
mask_sphere
(vertices: torch.Tensor, center: List[float], radius: float) → torch.Tensor[source]¶ Create a boolean mask to select all vertices in a sphere.
This function may be used in conjunction with torch.masked_select to select all field values within a sphere, e.g., when building data matrices.
- Parameters
vertices (pt.Tensor) – tensor of vertices, where each column corresponds to a coordinate
center (List[float]) – the sphere’s center
radius (float) – the sphere’s radius
- Returns
boolean mask that’s True for every vertex inside the sphere
- Return type
pt.Tensor
flowtorch.data.utils¶
Collection of utilities realted to data and dataloaders.
-
flowtorch.data.utils.
check_and_standardize_path
(path: str, folder: bool = True)[source]¶ Check if path exists and remove trailing slash if present.
- Parameters
path (str) – path to folder or file
folder (bool) – True if path points to folder; False if path points to file
- Returns
standardized path to file or folder
- Return type
str
-
flowtorch.data.utils.
check_list_or_str
(arg_value: Union[List[str], str], arg_name: str)[source]¶ Check if argument is of type list or string.
If the input is a list, an additional check is performed to ensure that the list has at list one entry and that all entries are strings.
- Parameters
arg_value (Union[List[str], str]) – object to perform the check on
arg_name – additional argument name to provide informative error message
arg_name – str
-
flowtorch.data.utils.
format_byte_size
(size: int) → Tuple[float, str][source]¶ Convert number of bytes into human-readable format.
The function is based on this <https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb> Stackoverflow question.
- Parameters
size – size in bytes
- Returns
converted size corresponding unit
- Return type
tuple(float, str)