A Python interface for interacting with OpenFOAM
Project description
foamlib provides a simple, modern and ergonomic Python interface for interacting with OpenFOAM.
It offers the following classes:
FoamFile
(andFoamFieldFile
): read-write access to OpenFOAM configuration and field files as if they were Pythondict
s, usingfoamlib
's own parser. Supports both ASCII and binary field formats.FoamCase
: a class for manipulating, executing and accessing the results of OpenFOAM cases.AsyncFoamCase
: variant ofFoamCase
with asynchronous methods for running multiple cases at once.
Get started
Install
Install with pip:
pip install foamlib
Clone a case
import os
from pathlib import Path
from foamlib import FoamCase
pitz_tutorial = FoamCase(Path(os.environ["FOAM_TUTORIALS"]) / "incompressible/simpleFoam/pitzDaily")
my_pitz = pitz_tutorial.clone("myPitz")
Run the case
my_pitz.run()
Access the results
latest_time = my_pitz[-1]
p = latest_time["p"]
U = latest_time["U"]
print(p.internal_field)
print(U.internal_field)
Clean the case
my_pitz.clean()
Edit the controlDict
file
my_pitz.control_dict["writeInterval"] = 10
Run a case asynchronously
import asyncio
from foamlib import AsyncFoamCase
async def run_case():
my_pitz_async = AsyncFoamCase(my_pitz)
await my_pitz_async.run()
asyncio.run(run_case())
Parse a field using the FoamFieldFile
class directly
from foamlib import FoamFieldFile
U = FoamFieldFile(Path(my_pitz) / "0/U")
print(U.internal_field)
Documentation
For more information, check out the documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
foamlib-0.4.4.tar.gz
(29.6 kB
view hashes)
Built Distribution
foamlib-0.4.4-py3-none-any.whl
(32.6 kB
view hashes)