Skip to main content

flowTorch logo

flowTorch

status

flowTorch - a Python library for analysis and reduced order modeling of fluid flows

The development of flowTorch is primarily financed by the German Research Foundation (DFG) within the research program FOR 2895 unsteady flow and interaction phenomena at high speed stall conditions with the primary goal to investigate flow conditions that lead to buffeting at airfoils in the transonic flow regime.

https://user-images.githubusercontent.com/8482575/120886182-f2b78800-c5ec-11eb-9b93-efb9a139c431.mp4

The animation shows the shock buffet on a NACA-0012 airfoil at $Re=10^7$, $Ma=0.75$, and $\alpha=4^\circ$ angle of attack. The simulation was conducted with OpenFOAM; follow this link for more information about the setup.

Why flowTorch?

The flowTorch project was started to make the analysis and modeling of fluid data easy and accessible to everyone. The library design intends to strike a balance between usability and flexibility. Instead of a monolithic, black-box analysis tool, the library offers modular components that allow assembling custom analysis and modeling workflows with ease. flowTorch helps to fuse data from a wide range of file formats typical for fluid flow data, for example, to compare experimental and simulation data. The available analysis and modeling tools are rigorously tested and demonstrated on a variety of different fluid flow datasets. Moreover, one can significantly accelerate the entire process of accessing, cleaning, analyzing, and modeling fluid flow data by starting with one of the pipelines available in the flowTorch documentation.

To get a first impression of what working with flowTorch looks like, the code snippet below shows part of a pipeline for performing a dynamic mode decomposition (DMD) of a transient OpenFOAM simulation.

import torch as pt
from flowtorch import DATASETS
from flowtorch.data import FOAMDataloader, mask_box
from flowtorch.analysis.dmd import DMD

path = DATASETS["of_cylinder2D_binary"]
loader = FOAMDataloader(path)

# select a subset of the available snapshots
times = loader.write_times
window_times = [time for time in times if float(time) >= 4.0]

# load vertices, discard z-coordinate, and create a mask
vertices = loader.vertices[:, :2]
mask = mask_box(vertices, lower=[0.1, -1], upper=[0.75, 1])

# assemble the data matrix
data_matrix = pt.zeros((mask.sum().item(), len(window_times)), dtype=pt.float32)
for i, time in enumerate(window_times):
    # load the vorticity vector field, take the z-component [:, 2], and apply the mask
    data_matrix[:, i] = pt.masked_select(loader.load_snapshot("vorticity", time)[:, 2], mask)

# perform DMD
dmd = DMD(data_matrix, rank=19)
# analyze dmd.modes or dmd.eigvals
# ...

Currently, the following sub-packages are under active development. Note that some components are not yet available in the public release because further developments and testing are required:

package content
flowtorch.data data loading, domain reduction (masked selection), outlier removal
flowtorch.analysis algorithms for dimensionality reduction and modal analysis (e.g., SVD, DMD, MSSA)
flowtorch.rom reduced-order modeling (CNM)

flowTorch uses the PyTorch library as a backend for data structures, data types, and linear algebra operations on CPU and GPU. Some cool features of flowTorch include:

  • data accessors return PyTorch tensors, which can be used directly within your favorite machine learning library, e.g., PyTorch, scikit-learn, or TensorFlow
  • most algorithms run on CPU as well as on GPU
  • mixed-precision operations (single/double); switching to single precision makes your life significantly easier when dealing with large datasets
  • user-friendly Python library that integrates easily with popular tools and libraries like Jupyterlab, Matplotlib, Pandas, or Numpy
  • a rich tutorial collection to help you get started
  • interfaces to common data formats like OpenFOAM, VTK (for Flexi and SU2), TAU, iPSP, CSV (for DaVis PIV data and raw OpenFOAM output)

flowTorch can also be used easily in combination with existing Python packages for analysis and reduced-order modeling thanks to the interoperability between PyTorch and NumPy. Great examples are (by no means a comprehensive list):

  • PyDMD - Python dynamic mode decomposition
  • PySINDy - sparse identification of nonlinear dynamical systems from data
  • PyKoopman - data-driven approximations of the Koopman operator

Getting started

Install the latest stable release from PyPI:

pip install flowtorch-fluid

# to uninstall flowTorch, run
pip uninstall flowtorch-fluid

The default installation includes all dependencies required by flowtorch.analysis except for the optional iPSP explorer. Install additional functionality with an optional extra:

# data loaders, reduced-order models, or the iPSP explorer
pip install "flowtorch-fluid[data]"
pip install "flowtorch-fluid[rom]"
pip install "flowtorch-fluid[psp]"

# all optional functionality
pip install "flowtorch-fluid[all]"

Extras can be combined, for example pip install "flowtorch-fluid[data,rom]".

The PyPI distribution is named flowtorch-fluid, while the Python package and imports remain flowtorch.

To install the latest development version directly from GitHub, run:

pip install "flowtorch-fluid[all] @ git+https://github.com/AndreWeiner/flowtorch.git"

Alternatively, clone the repository:

git clone git@github.com:AndreWeiner/flowtorch.git
cd flowtorch

and install it in editable mode with the desired optional dependencies:

pip install -e ".[all]"

Installing all flowTorch dependencies requires significant disk space. Replace all with data, rom, or psp when only part of the optional functionality is needed.

To get an overview of what flowTorch can do for you, have a look at the online documentation. The examples presented in the online documentation are also contained in this repository. In fact, the documentation is a static version of several Jupyter notebooks with end-to-end analyses. If you are interested in an interactive version of one particular example, navigate to ./docs/source/notebooks and run jupyter lab. Note that to execute some of the notebooks, the corresponding datasets are required. The datasets can be downloaded here (~2.6GB). If the data are only required for unit testing, a reduced dataset may be downloaded here (~411MB). Download the data into a directory of your choice and navigate into that directory. To extract the archive, run:

# full dataset
tar xzf datasets_29_10_2021.tar.gz
# reduced dataset
tar xzf datasets_minimal_29_10_2021.tar.gz

To tell flowTorch where the datasets are located, define the FLOWTORCH_DATASETS environment variable:

# add export statement to bashrc; assumes that the extracted 'datasets' or 'datasets_minimal'
# folder is located in the current directory
# full dataset
echo "export FLOWTORCH_DATASETS=\"$(pwd)/datasets/\"" >> ~/.bashrc
# reduced dataset
echo "export FLOWTORCH_DATASETS=\"$(pwd)/datasets_minimal/\"" >> ~/.bashrc
# reload bashrc
. ~/.bashrc

Installing ParaView

Note: the following installation of ParaView is only necessary if the TecplotDataloader is needed.

flowTorch uses the ParaView Python module for accessing Tecplot data. When installing ParaView, special attention must be paid to the installed Python and VTK versions. Therefore, the following manual installation is recommended instead of using a standard package installation of ParaView.

  1. Determine the version of Python:
python3 --version
# example output
Python 3.8.10
  1. Download the ParaView binaries according to your Python version from here. Note that you may have to use an older version of ParaView to match your Python version.
  2. Install the ParaView binaries, e.g., as follows:
# optional: remove old package installation if available
sudo apt remove paraview
# replace the archive's name if needed in the commands below
sudo mv ParaView-5.9.1-MPI-Linux-Python3.8-64bit.tar.gz /opt/
cd /opt
sudo tar xf ParaView-5.9.1-MPI-Linux-Python3.8-64bit.tar.gz
sudo rm ParaView-5.9.1-MPI-Linux-Python3.8-64bit.tar.gz
cd ParaView-5.9.1-MPI-Linux-Python3.8-64bit/
# add path to ParaView binary and Python modules
echo export PATH="\$PATH:$(pwd)/bin" >> ~/.bashrc
echo export PYTHONPATH="\$PYTHONPATH:$(pwd)/lib/python3.8/site-packages" >> ~/.bashrc

In case of version conflicts between Python packages coming with ParaView and local versions of these packages, the following options exist:

  1. go to your ParaView installation and manually delete or rename the affected packages; the packages are located at /path/to/ParaView/lib/python3.8/site-packages
  2. use pvpython, a modified Python interpreter shipped with ParaView and add a virtual environment containing flowTorch but not the conflicting packages (see Using pvpython and virtualenv)

Development

Documentation

Build the flowTorch documentation in an isolated tox environment:

tox -e docs

Tox installs Sphinx and the documentation dependencies automatically. The generated HTML documentation is written to docs/build/html; open docs/build/html/index.html in a browser to view it. The build treats Sphinx warnings as errors so that documentation problems are caught locally.

Packaging

Build the source distribution and wheel and validate their PyPI metadata with:

tox -e package

The generated artifacts are written to dist/. The PyPI distribution is named flowtorch-fluid, while the Python import package remains flowtorch.

Unit testing

The test suite is located in the top-level tests directory. To install the development testing tools, run:

pip install -r requirements-dev.txt

To run the default test suite with the active Python interpreter, execute:

pytest

Tests that require the flowTorch datasets are marked as integration tests and are skipped unless the datasets are downloaded and referenced as described in the previous section. To run only tests that do not require external datasets, execute:

pytest -m "not integration"

You can also execute all tests for one test group, e.g., data:

pytest tests/data

or run individual test modules, e.g.,

pytest tests/data/test_foam_dataloader.py

To run the dataset-free tests with multiple Python versions, use tox:

tox

The default tox configuration runs py310, py312, and py314 environments and skips Python versions that are not installed locally. You can run a single environment with:

tox -e py312

Additional pytest arguments can be passed after --, for example:

tox -e py312 -- tests/data/test_utils.py

To run dataset-dependent integration tests through tox, make sure FLOWTORCH_DATASETS is set and pass the marker explicitly:

tox -e py312 -- -m integration

Code formatting

Python code is formatted with Black using its default line length of 88 characters. Tox installs the pinned Black version in an isolated environment, so no separate Black installation is required. Format the package and tests with:

tox -e format

To format only specific files or directories, pass them after --, for example:

tox -e format -- flowtorch/analysis tests/analysis

Check formatting without changing any files with:

tox -e format-check

Type checking

Python type annotations are checked with mypy. Tox installs the pinned mypy version in an isolated environment, so no separate installation is required. Check the flowtorch package with:

tox -e type-check

To check only specific files or directories, pass them after --, for example:

tox -e type-check -- flowtorch/analysis/svd.py

The shared type-checking options are defined in mypy.ini.

Getting help

If you encounter any issues using flowTorch or if you have any questions regarding current and future development plans, please use the repository's issue tracker. Consider the following steps before and when opening a new issue:

  1. Have you searched for similar issues that may have been already reported? The issue tracker has a filter function to search for keywords in open issues.
  2. Click on the green New issue button in the upper right corner and describe your problem in as much detail as possible. The issue should state what the problem is, what the expected behavior should be, and, maybe, suggest a solution. Note that you can also attach files or images to the issue.
  3. Select a suitable label from the drop-down menu called Labels.
  4. Click on the green Submit new issue button and wait for a reply.

Reference

If flowTorch aids your work, you may support the project by referencing the following article:

@article{Weiner2021,
doi = {10.21105/joss.03860},
url = {https://doi.org/10.21105/joss.03860},
year = {2021},
publisher = {The Open Journal},
volume = {6},
number = {68},
pages = {3860},
author = {Andre Weiner and Richard Semaan},
title = {flowTorch - a Python library for analysis and reduced-order modeling of fluid flows},
journal = {Journal of Open Source Software}
} 

For a list of scientific works relying on flowTorch, refer to this list.

License

flowTorch is GPLv3-licensed; refer to the LICENSE file for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flowtorch_fluid-1.3.0.tar.gz (106.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flowtorch_fluid-1.3.0-py3-none-any.whl (124.2 kB view details)

Uploaded Python 3

File details

Details for the file flowtorch_fluid-1.3.0.tar.gz.

File metadata

  • Download URL: flowtorch_fluid-1.3.0.tar.gz
  • Upload date:
  • Size: 106.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for flowtorch_fluid-1.3.0.tar.gz
Algorithm Hash digest
SHA256 162f2a56f4535e60867e7a0ae4fc1581ca6a2fcc960af879111fe369cb611cd4
MD5 b59b7db66ab6c73e0939f69249ff7c91
BLAKE2b-256 d23901134a8afe0d18b6ef5408a937a2896d82c5eeb0ecf11fe00b80cd1cc9a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for flowtorch_fluid-1.3.0.tar.gz:

Publisher: publish.yml on AndreWeiner/flowtorch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flowtorch_fluid-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: flowtorch_fluid-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 124.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for flowtorch_fluid-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc0964b10da58cf694b2b6ef5f678a3de205d413da54363944c4b363de5bb15
MD5 2fd032480f7e27ae3c32ebfcf7bbbce8
BLAKE2b-256 f43670e4dd49e447c54aaed385f3c72dce05db018e65bd2dfaef4b56dac6dc11

See more details on using hashes here.

Provenance

The following attestation bundles were made for flowtorch_fluid-1.3.0-py3-none-any.whl:

Publisher: publish.yml on AndreWeiner/flowtorch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page