Module storing the public interface to generate OpenFoam cases from LCL
simulations and aperture maps.
Written By: Matthew Stadelman
Date Written: 2016/03/22
Last Modifed: 2016/08/08

class apmapflow.openfoam.OpenFoamDict(name, values=None)[source]

Class used to build the dictionary style OpenFoam input blocks

class apmapflow.openfoam.OpenFoamList(name, values=None)[source]

Class used to build the output lists used in blockMeshDict.

class apmapflow.openfoam.OpenFoamFile(*args, **kwargs)[source]

Class used to build OpenFoam input files

write_foam_file(path='.', create_dirs=True, overwrite=False)[source]

Writes out the foam file, adding proper location directory if create_dirs is True

class apmapflow.openfoam.BlockMeshDict(field, avg_fact=1.0, mesh_params=None, offset_field=None)[source]

This is a special subclass of OpenFoamFile used to generate and output a blockMeshDict for OpenFoam


Populates keys on itself based on geometry data to output a mesh file


Generates a simple mesh including all cells in the data map

generate_threshold_mesh(min_value=0.0, max_value=1000000000.0)[source]

Generates a mesh excluding all blocks below the min_value arg. Regions that are isolated by the thresholding are also automatically removed.

set_boundary_patches(boundary_blocks, reset=False)[source]

Sets up boundary patches based on the dictionary passed in. Overlapping declarations are overwritten by the last patch to use that face. The boundary blocks dictionary contains a dictionary entry for each patch name.

  • boundary_blocks dictionary has the format of:
    {patch_name: {

    <side>: [ block-list ], <side>: [ block-list ], ...

    } where <side> is left, right, bottom, top, front or back and block list is a list of blocks to add that patch to the side of.

  • reset - boolean : if True then the face labels dictionary

    and _faces array are re-initialized to default values

write_foam_file(path='.', create_dirs=True, overwrite=False)[source]

Writes a full blockMeshDict file based on stored geometry data

write_mesh_file(path='.', create_dirs=True, overwrite=False)[source]

Passes args off to write_foam_file

write_symmetry_plane(path='.', create_dirs=True, overwrite=False)[source]

Exports the +Y half of the mesh flattening out everything below 0 on the Y axis

class apmapflow.openfoam.OpenFoamExport(field=None, avg_fact=1.0, mesh_params=None)[source]

A class to handle generation and exporting of OpenFoam files

generate_block_mesh_dict(field, avg_fact=1.0, mesh_params=None)[source]

Passes arguments off to BlockMeshDict init method.


Generates, reads and adds OpenFoam files to the export to provide a centralized location to perform modifications and write files. Any number of ‘file’ arguments may be passed into this function but they are required to have one of the following three forms:

  1. An already existing OpenFoamFile instances
  2. A string representing the path to a valid OpenFoamFile
  3. An iterable acceptable to the dictionary constructor with at
    minimum 2 keys: location and object; ‘class’ is an optional key. Those 2/3 keys are removed and the rest of the iterable is passed along to the OpenFoamFile __init__ method as the ‘values’ keyword.

Files are stored on the export object in a dictionary attribute called ‘foam_files’. Keys in this dictionary have the format of ‘’. Where ‘name’ is ‘name’ attribute on the OpenFoamFile.

write_foam_files(path='.', overwrite=False)[source]

Writes the files generated by ‘generate_foam_files’ to their associated directories on the supplied path. If a directory doesn’t exist then it is created

write_mesh_file(path='.', create_dirs=True, overwrite=False)[source]

Passes arguments off to the BlockMeshDict method

write_symmetry_plane(path='.', create_dirs=True, overwrite=False)[source]

Passes arguments off to the BlockMeshDict method

class apmapflow.openfoam.ParallelMeshGen(field, system_dir, nprocs=4, **kwargs)[source]

Handles creation of a large mesh in parallel utilizing the OpenFoam utilties mergeMesh and stitchMesh.

generate_mesh(mesh_type='simple', path='.', ndivs=8, **kwargs)[source]

Generates multiple mesh types and outputs them to a specific path. Valid mesh_types are: simple, threshold and symmetry. Additional kwargs need to be supplied for the given mesh type if it needs additional keywords.