Skip to main content

CaseFOAM - An OpenFOAM case manipulatior and creator.

This module is a addition to PyFoam and can automatically setup OpenFOAM cases with varying conditions.

Getting started

Installing CaseFOAM

In order to use the Python module you need the PyFoam package.

install the package after cloning the repository with:

  $ pip install .

or via pypi by executing:
$ pip install casefoam

User’s Guide

For a full documentation change into doc and build the documentation for example as html.

$ cd doc/
$ make html
$ firefox build/html/index.html

Example

CaseFoam offers two main features: the easy generation of parameter studies and the analysis of these. In the example, we want to change the intial height of the column and perform a grid study for the damBreak test case:

doc/media/damBreak.gif

parameter studies

The first step is the generation of the cases. We want to generate three column heights where each case has three grids with a differnt cell size.

cat genCases.py:

import casefoam

baseCase = 'damBreak'
caseStructure = [['height_02', 'height_03', 'height_04'],
                ['grid1', 'grid2', 'grid3']
                ]

def update_grid(a,b,c,d,e):
    return {
        'system/blockMeshDict': {'#!stringManipulation': {'varA': '%s' %a,
                                                          'varB': '%s' %b,
                                                          'varC': '%s' %c,
                                                          'varD': '%s' %d,
                                                          'varE': '%s' %e
                                                          }
                                }
    }

def update_height(height):
    return {
        'system/setFieldsDict': {'#!stringManipulation':
                                {'var_height': '%s' %height}}
    }

caseData = {
    'height_02': update_height(0.2),
    'height_03': update_height(0.3),
    'height_04': update_height(0.4),
    'grid1': update_grid(23,8,19,42,4),
    'grid2': update_grid(23*2,8*2,19*2,42*2,4*2),
    'grid3': update_grid(23*3,8*3,19*3,42*3,4*3)
}

# generate cases
casefoam.mkCases(baseCase, caseStructure, caseData, hierarchy='tree',writeDir='Cases')

There a three different options how the cases can be manipulated:

  • replacing a string inside the specified files

  • executing a bash script

  • by specifying a dictionary

for details please see the user manual.

The script is executed by:

python genCases.py

This will the generate the following structure:

doc/media/caseStructure.png

The cases can be started by running the newly created Allrun script

./Allrun

postProcessing

Three functions are avaiable for the postProcessing:

  • time_series

  • positional_field

  • posField_to_timeSeries

For the damBreak test case we want to plot the freesurface position at a given time. For that, we use the positional_field function and get a pandas dataframe which we plot with holoviews

import casefoam
import matplotlib.pyplot as plt
import pandas as pd
import holoviews as hv
hv.extension('bokeh')

caseStructure = [['height_02', 'height_03', 'height_04'],
                ['grid1', 'grid2', 'grid3']]
baseCase = 'Cases'
surfaceDir = 'freeSurface'
surface = casefoam.positional_field(surfaceDir,'U_freeSurface.raw',0.3,caseStructure,baseCase)
surface.columns = ['x','y','z','Ux','Uy','Uz','col_height','res']
surface_ds = hv.Dataset(surface, [ 'col_height','res'], ['x','y','z','Ux','Uy','Uz'])

holoviews is optimized for the use for the jupyter notebooks. The %%opts arguments are used to modify the layout of the plot. holoviews renders an interactive plot which can be exported as html:

%%opts Scatter [width=600,height=600,title='freeSurface at 0.3s',tools=['hover']]
%%opts (muted_alpha=0.0)
surface_ds.to(hv.Scatter,'x','y').overlay('res')
doc/media/freeSurface.gif

version 0.0.1

0.0.1 (2021-04-14)

  • First release on PyPI.

version 0.0.2

0.0.2 (2021-04-14)

  • First release on PyPI.

version 0.0.3

0.0.3 (2021-04-14)

  • First release on PyPI.

version 0.0.4

0.0.4 (2021-04-14)

  • First release on PyPI.

version 0.1.0

0.1.0 (2022-02-16)

  • added CI

  • replaced append with concat

version 0.1.1

0.1.1 (2022-05-18)

  • new Function: of_cases finds all OpenFOAM cases in folder

version 0.2.0

0.2.0 (2022-05-18)

  • new Function: profiling allows to load profiling data from OpenFOAM

add profiling to system controlDict:
profiling
{
    active      true;
    cpuInfo     false;
    memInfo     false;
    sysInfo     false;
}
prof = casefoam.profiling(time=0,processorDir="", caseStructure=caseStructure,baseCase=baseCase)

Metadata

Release files for casefoam 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for casefoam 0.2.0
File Size Uploaded
casefoam-0.2.0.tar.gz 1.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for casefoam 0.2.0
File Interpreter ABI Platform
casefoam-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / casefoam-0.2.0.tar.gz

Download URL casefoam-0.2.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
f86818f3a40726173ee430d71144d16683945224438d3462f691328ba70610a6
BLAKE2b-256 checksum
How to use checksums
22605b3046afe6e6d4c107c30c2874162e121b144f553386a1ed14f14d631da6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / casefoam-0.2.0-py3-none-any.whl

Download URL casefoam-0.2.0-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbfe202d8cc8b33c7e74ac20769dbf3bc6b7355abf4e8ac4ae973fdb4633b166
BLAKE2b-256 checksum
How to use checksums
09c0a9d30ed78c798e1c148930991054479abb5b2a1ee402065720212e6169e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page