ofreader

A python library to read OpenFOAM files for post-processing.

https://github.com/itv-stuttgart/ofreader

Science Score: 52.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
    Organization itv-stuttgart has institutional domain (www.irst.uni-stuttgart.de)
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.7%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A python library to read OpenFOAM files for post-processing.

Basic Info
  • Host: GitHub
  • Owner: ITV-Stuttgart
  • License: gpl-3.0
  • Language: C++
  • Default Branch: main
  • Size: 923 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created 10 months ago · Last pushed 9 months ago
Metadata Files
Readme License Citation

README.md

ofReader - Python Library for OpenFOAM

Python functions to read OpenFOAM data for post processing.

Installation

Starting with version 4.0 the project uses the TOML file for project builds.

  1. Make sure you have the required packages installed: bash pip install --upgrade pip setuptools wheel
  2. Use pip install . to install the ofReader package.

Usage

After installing the python library import it with

```python from ofReader import sampleLineReader

Load data from a sample line

data = sampleLineReader('../postProcessing/sample/linealpha.liquidkrhosigma.csv')

Access data sets by name of the field, e.g.:

data['x'] => for position

data['alpha.liquid'] => for the liquid.alpha field

data['k'] => for the turb. kin. energy

```

Load OpenFOAM Fields and Mesh

The OpenFOAM fields can be read with ```python from ofReader.ofFileReader import readOpenFOAMFile

E.g. read the velocity field of time step 0.005s

pathToFile = '0.005/U' eulerianData = readOpenFOAMFile(pathToFile)

To load a decomposed OpenFOAM file use

velocity = readOpenFOAMFile('/path/to/case',fileName='U', time=0.05, decomposed=True)

This also works for Lagrangian data

pathToLagrangianData = '0.005/lagrangian/cloudName/pos' lagrangianData = readOpenFOAMFile(pathToFile) ```

For the Eulerian fields the position of the entries is stored in the fvMesh object. Therefore, an fvMesh python class is provided which can read the mesh and provides an interface for the cells: ```python from ofReader.fvMesh import fvMesh mesh = fvMesh(pathToCase)

Get cell center points as list of arrays

center = mesh.centers() ```

[!TIP] However, the class is very slow and time consuming, if only the position of the cells is of interest use the built in postProcess -func writeCellCentres function of OpenFOAM.

Write OpenFOAM File

To write a data block as an OpenFOAM file, a file header and boundaries have to be defined.

```python

First create an OpenFOAM file header

ofFileFormat header

Store a scalar field

header.type = "scalar"

Create a list of boundaries

Currently still WIP, best to use empty

ofBoundaryData boundary boundary.addPatch('inlet','empty')

dimensions of the field in OpenFOAM format

fieldDimensions = [0,0,0,0,0,0,0]

Write OpenFOAM file

writeOpenFOAMFile('Path/to/file', header, dataBlock, boundary, fieldDimensions) ```

Sample Particle Data to Plane

In Lagrangian simulations, a common use case is to map particle data onto a plane — particularly useful for circumferential or axisymmetric setups. For this purpose, the MapParticleToPlane class is provided.

This class allows you to:

  • Define an arbitrary sampling plane via a point and normal vector.
  • Project particle data (e.g., position, velocity, diameter) onto that plane.
  • Export the sampled data for visualization or further analysis.

Basic Usage

```python from ofReader.mapParticleToPlane import MapParticleToPlane

mapper = MapParticleToPlane( pathtocase="path/to/case", time="latestTime", planeorigin=[0.0, 0.0, 0.0], planenormal=[0.0, 0.0, 1.0] )

sampled_data = mapper.sample() ```

The returned sampled_data is a dictionary containing the projected particle properties.

[!NOTE] This class is particularly useful for post-processing particle-laden flows simulated with OpenFOAM.

Tests

Install the python tests with: bash pip install .[test] Run the tests with: bash pytest

Owner

  • Name: Institute for Reactive Flows
  • Login: ITV-Stuttgart
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it using the metadata below."
title: "ofReader: A Python Tool for Post-Processing Lagrangian Particle Data from OpenFOAM"
authors:
  - given-names: Jan Wilhelm
    family-names: Gärtner
    email: jan-wilhelm.gaertner@irst.uni-stuttgart.de
    affiliation: University of Stuttgart
    orcid: https://orcid.org/0000-0002-1718-7735
date-released: 2025-05-14
version: 0.1.0
repository-code: https://github.com/ITV-Stuttgart/ofReader
license: GPLv3
keywords:
  - OpenFOAM
  - Lagrangian
  - Particle tracking
  - Python
  - CFD


GitHub Events

Total
  • Watch event: 2
  • Push event: 3
  • Create event: 2
Last Year
  • Watch event: 2
  • Push event: 3
  • Create event: 2

Dependencies

setup.py pypi
  • numpy *
  • pyvista *
  • scipy *
  • tqdm *