Skip to content

FoamGraph is a Python library for manipulating OpenFOAM cases as graphs.

License

Notifications You must be signed in to change notification settings

gfngoncalves/foam_graph

Repository files navigation

foam_graph_logo


CI codecov Documentation Status

FoamGraph is a Python library for manipulating OpenFOAM cases as graphs.

Installation

FoamGraph requires PyTorch and PyTorch Geometric. It's recommended to check the documentation of these packages for intallation instructions. The following is an example for conda installation:

conda install pytorch torchvision cudatoolkit={CUDA} -c pytorch
conda install pyg -c pyg

where {CUDA} should be replaced by the desired CUDA version.

Use the package manager pip to install FoamGraph.

pip install .

Example

Currently, the package requires that cell centers are written by OpenFOAM. That can be achieved with the following command (requires OpenFOAM):

postProcess -func writeCellCentres

The following example loads a case folder as a graph:

from torch_geometric.data import download_url, extract_tar
from foam_graph.utils.graph_from_foam import read_foam

download_url("https://github.com/gfngoncalves/openfoam_cases/blob/main/damBreak.tar.xz?raw=true", ".")
extract_tar("damBreak.tar.xz", ".", mode="r:xz")

graph = read_foam(
    "damBreak",
    ("alpha.water",),
    read_boundaries=True,
)

The resulting graph is a StaticGraphTemporalSignal object for static meshes, or a DynamicGraphTemporalSignal for dynamic meshes.

The package alo provides some convenience functions for plotting and preprocessing data. As an example, a timestep can be plotted with:

import matplotlib.pyplot as plt
from foam_graph.visualization.graph_plotting import plot_graph

field_name_plot = "alpha.water"
time_idx = 5

fig, ax = plt.subplots(figsize=(5, 5))
plot_graph(graph[time_idx], field_name_plot, ax=ax)

plt.tight_layout()
plt.show()

dam_break

More examples are provided in the examples folder.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

FoamGraph is a Python library for manipulating OpenFOAM cases as graphs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published