foampy package

Submodules

foampy.case module

Module to contain Case object.

class foampy.case.Case(casedir=’./’)[source]

Bases: object

Object to represent an entire OpenFOAM case.

This should contain a list of dictionaries, some mandatory, some optional.

read()[source]

Read all dictionaries present.

foampy.core module

Core functionality for foamPy.

foampy.core.clean(leave_mesh=False, remove_zero=False, extra=[])[source]

Clean case.

foampy.core.gen_dynmeshdict(U, R, meantsr, cellzone=’AMIsurface’, rpm_fluc=3.7, npoints=400, axis=’(0 0 1)’, direction=1)[source]

Generates a dynamicMeshDict for a given U, R, meantsr, and an optional rpm fluctuation amplitude. Phase is fixed.

foampy.core.gen_stripped_lines(fpath)[source]
foampy.core.get_deltat(casedir=’./’)[source]

Get run deltaT.

foampy.core.get_endtime()[source]

Get run endTime.

foampy.core.get_max_courant_no()[source]
foampy.core.get_n_processors(casedir=’./’, dictpath=’system/decomposeParDict’)[source]

Read number of processors from decomposeParDict.

foampy.core.get_ncells(casedir=’./’, logname=’log.checkMesh’, keyword=’cells’, autogen=True)[source]
foampy.core.get_solver_times(casedir=’./’, solver=None, log_fpath=None, window=400)[source]

Read last N lines from file solver log and return t (current Time), deltaT, and clockTime.

foampy.core.load_all_torque_drag(casedir=”, torque_axis=’z’, drag_axis=’x’)[source]
foampy.core.load_forces(casedir=’./’, object_name=’forces’, start_time=0)[source]

Load forces and moments as a pandas DataFrame.

foampy.core.load_probes_data(casedir=’./’, object_name=’probes’, start_time=0, field_name=’U’)[source]

Load probes data as pandas DataFrame.

foampy.core.load_sample_xy(casedir=’./’, profile=’U’)[source]

Import text data created with the OpenFOAM sample utility.

foampy.core.load_set(casedir=’./’, name=’profile’, quantity=’U’, fmt=’xy’, axis=’xyz’)[source]

Import text data created with the OpenFOAM sample utility.

foampy.core.load_theta_omega(casedir=”, t_interp=[], theta_units=’degrees’)[source]

Import omega from dynamicMeshDict table. Returns t, theta, omega (rad/s) where theta is calculated using the trapezoidal rule.

t_interp is a keyword argument for an array over which omega and theta will be interpolated.

foampy.core.load_torque_drag(casedir=”, folder=‘0’, filename=None, torque_axis=’z’, drag_axis=’x’)[source]

Loads time, z-axis torque, and streamwise force from specified forces folder. Case name can be left empty if running within a case folder.

foampy.core.monitor_progress()[source]

Monitor solver progress.

foampy.core.read_case()[source]

Will eventually read all case dicts and put in a hierarchy of dicts.

foampy.core.read_dict(dictname=None, dictpath=None, casedir=’./’)[source]

Read an OpenFOAM dict into a Python dict. Right now this is quite crude, but gets the job done decently for 1 word parameters.

foampy.core.read_log_end(logname, nlines=20)[source]

Read last lines from log and return as a list.

foampy.core.run(appname, tee=False, logname=None, parallel=False, nproc=None, args=[], overwrite=False, append=False)[source]

Run an application.

foampy.core.run_parallel(appname, **kwargs)[source]

Run application in parallel.

foampy.core.summary(casedir=’./’, **extra_params)[source]

Summarize a case and return as a pandas Series.

casedir : str
Case directory to be summarized.
extra_params : dict
Key/value pairs for keywords and the functions that return their respective values.

foampy.dictionaries module

Functions for reading and writing dictionaries.

foampy.dictionaries.build_header(dictobject=”, version=‘2.3.x’, fileclass=’dictionary’, incl_foamfile=True)[source]

Creates the header for an OpenFOAM dictionary. Inputs are the object and version.

foampy.dictionaries.read_single_line_value(dictname=None, dictpath=None, keyword=”, dtype=<class ‘float’>, casedir=’./’)[source]

Read value from a dictionary that appears on a single line.

foampy.dictionaries.read_text(dictpath, keyword)[source]
foampy.dictionaries.replace_value(dictpath, keyword, newvalue)[source]

Replace a value in a dictionary.

foampy.foil module

Module for working with foil data.

class foampy.foil.FoilData[source]

Bases: object

Object that represents a foil characteristic database.

mirror()[source]

Mirror positive coefficients about zero degrees angle of attack.

read(fpath, startline=None, stopline=None, comments=False)[source]

Reads foil data from file. Format is detected automatically, but column order is not.

write(fpath)[source]

Write foil data to file in OpenFOAM format.

foampy.foil.mirror_foildata(inpath, outpath)[source]

Mirror positive data in file about zero angle of attack.

foampy.foil.reformat_foildata(input_path, output_path, startline=None, stopline=None)[source]

Reformat foil data file into a list of 4-element OpenFOAM lists.

foampy.gui module

foampy.templates module

Code related to templating.

foampy.templates.fill_template(src, dest=None, **params)[source]

Fill a template file based on given parameters using new style Python string formatting.

foampy.templates.gen_from_template_dir(fpath_out, template_dir=’templates’, fname_out=None, **params)[source]

Generate a file from a template with the same relative path inside template_dir.

foampy.templates.make_template(fpath, template_dir=’templates’, keywords=[], git=True, delete=True)[source]

Convert an OpenFOAM dictionary to a template for use with Python’s string formatting.

fpath : str
Path to file to be converted to a template.
template_dir : str
Path to directory in which to store templates.
keywords : list
List of strings to setup as formatted keywords in template.
git : bool
If True, attempt to remove file from Git repo and add to .gitignore file.
foampy.templates.to_snake_case(keyword)[source]

Convert a keyword to snake case.

From https://stackoverflow.com/questions/1175208

foampy.types module

This module contains classes to work with custom OpenFOAM classes, e.g., lists and dictionaries.

class foampy.types.BlockMeshDict(name=’blockMeshDict’, casedir=’./’, subdir=’system’)[source]

Bases: foampy.types.FoamDict

Object to represent a blockMeshDict.

class foampy.types.FoamDict(name=”, casedir=’./’, subdir=’system’, **kwargs)[source]

Bases: collections.OrderedDict

Object that represents an OpenFOAM dictionary.

read()[source]

Parse dictionary.

write()[source]

Write dictionary to file.

class foampy.types.FoamList(list_in=None, dtype=<class ‘float’>)[source]

Bases: list

Class that represents an OpenFOAM list.

class foampy.types.FoamSubDict(name=”, **kwargs)[source]

Bases: collections.OrderedDict

Object to represent a dictionary inside a dictionary.

Module contents