foam_graph.utils package

Submodules

foam_graph.utils.foam_from_graph module

foam_graph.utils.foam_from_graph.write_foam(case_name: str, time_out: float, data_out: torch_geometric.data.data.Data, data_names: Iterable[str], fields_base: Iterable[str], fields_out: Iterable[str], time_base: float = 0)None

Writes attributes in a graph as OpenFOAM fields, based on templates.

Parameters
  • case_name (str) – Path to the folder containg an OpenFOAM case.

  • time_out (float) – Time where fields will be saved.

  • data_out (Data) – Graph to be saved.

  • data_names (Iterable[str]) – Attributes selected.

  • fields_base (Iterable[str]) – Names of the template fields.

  • fields_out (Iterable[str]) – Names of the output fields.

  • time_base (float, optional) – Time where template fields are located. Defaults to 0.

foam_graph.utils.graph_from_foam module

class foam_graph.utils.graph_from_foam.FoamMesh(path, read_boundaries=False)

Bases: object

boundary_cells(bd)
read_cell_centres(fn)
foam_graph.utils.graph_from_foam.parse_boundary_field(fn)
foam_graph.utils.graph_from_foam.parse_field_all(fn)
foam_graph.utils.graph_from_foam.read_foam(case_path: str, field_names: Iterable[str], read_boundaries: bool = True, times: Optional[Iterable[float]] = None, times_indices: Optional[Iterable[Union[slice, int]]] = None, boundary_encoding: Callable[[Optional[str], collections.abc.Mapping], numpy.ndarray] = <function _boundary_encoding_name_as_one_hot>)Union[torch_geometric_temporal.signal.static_graph_temporal_signal.StaticGraphTemporalSignal, torch_geometric_temporal.signal.dynamic_graph_temporal_signal.DynamicGraphTemporalSignal]

Reads an OpenFOAM case as a PyTorch Geometric graph.

Parameters
  • case_path (str) – Path to the folder containg an OpenFOAM case

  • field_names (Iterable[str]) – List of field names extracted from the case

  • read_boundaries (bool, optional) – Flag for reading boundary patch faces as graph nodes. Also adds a binary mask to the graph for those faces. Defaults to True.

  • times (Iterable[float], optional) – List of times to be read. Defaults to None, which reads all. Overrides ‘times_indices’.

  • times_indices (Iterable[Union[slice, int]], optional) – List of time indices to be read. Defaults to None, which reads all.

Raises

ValueError – no times selected.

Returns

PyTorch Geometric Temporal data iterator. Fields are stored as extra attributes, with the same name as in the case.

Return type

Union[StaticGraphTemporalSignal, DynamicGraphTemporalSignal]

Module contents

foam_graph.utils.read_foam(case_path: str, field_names: Iterable[str], read_boundaries: bool = True, times: Optional[Iterable[float]] = None, times_indices: Optional[Iterable[Union[slice, int]]] = None, boundary_encoding: Callable[[Optional[str], collections.abc.Mapping], numpy.ndarray] = <function _boundary_encoding_name_as_one_hot>)Union[torch_geometric_temporal.signal.static_graph_temporal_signal.StaticGraphTemporalSignal, torch_geometric_temporal.signal.dynamic_graph_temporal_signal.DynamicGraphTemporalSignal]

Reads an OpenFOAM case as a PyTorch Geometric graph.

Parameters
  • case_path (str) – Path to the folder containg an OpenFOAM case

  • field_names (Iterable[str]) – List of field names extracted from the case

  • read_boundaries (bool, optional) – Flag for reading boundary patch faces as graph nodes. Also adds a binary mask to the graph for those faces. Defaults to True.

  • times (Iterable[float], optional) – List of times to be read. Defaults to None, which reads all. Overrides ‘times_indices’.

  • times_indices (Iterable[Union[slice, int]], optional) – List of time indices to be read. Defaults to None, which reads all.

Raises

ValueError – no times selected.

Returns

PyTorch Geometric Temporal data iterator. Fields are stored as extra attributes, with the same name as in the case.

Return type

Union[StaticGraphTemporalSignal, DynamicGraphTemporalSignal]

foam_graph.utils.write_foam(case_name: str, time_out: float, data_out: torch_geometric.data.data.Data, data_names: Iterable[str], fields_base: Iterable[str], fields_out: Iterable[str], time_base: float = 0)None

Writes attributes in a graph as OpenFOAM fields, based on templates.

Parameters
  • case_name (str) – Path to the folder containg an OpenFOAM case.

  • time_out (float) – Time where fields will be saved.

  • data_out (Data) – Graph to be saved.

  • data_names (Iterable[str]) – Attributes selected.

  • fields_base (Iterable[str]) – Names of the template fields.

  • fields_out (Iterable[str]) – Names of the output fields.

  • time_base (float, optional) – Time where template fields are located. Defaults to 0.