butterfly.case module

Butterfly OpenFOAM Case.

class butterfly.case.Case(name, foamfiles, geometries)[source]

Bases: object

Principal class for OpenFOAM Cases.

This class can either be instantiated directly through the __init__ constructor or through the following classmethods:

  1. from_folder: Create a Butterfly case from a case folder
  2. from_bf_geometries: Create a case from Butterfly geometries.
  3. from_wind_tunnel: Create case from wind tunnel.
Notes for beginners:
What is an OpenFOAM case?
As defined by AndRAS Horvath in “OpenFOAM tutorial collection”, a case is the combination of geometry definition (the finite volume mesh), configuration files (called dictionaries in OpenFOAM language), definition of boundary conditions and initial conditions, custom function and results all structured in many files and directories. The 0-directory contains the initial- and boundary-conditions. The (initial) mesh is in constant/polyMesh. Most config files are in system/. Material and turbulence properties are in constant/.
MINFOAMFIles = ('fvSchemes', 'fvSolution', 'controlDict', 'blockMeshDict', 'snappyHexMeshDict')
SUBFOLDERS = ('0', 'constant', 'constant\\polyMesh', 'constant\\triSurface', 'system', 'log')
ToString()[source]

Overwrite .NET ToString method.

add_foam_file(foamfile)[source]

Add a foamfile to the case.

add_foam_files(foamfiles)[source]

Add foamfiles to the Case.

add_refinementRegion(refinementRegion)[source]

Add a refinement region.

add_refinementRegions(refinementRegions)[source]

Add a collections of refinement regions.

blockMesh(args=None, wait=True, overwrite=True)[source]

Run blockMesh.

Parameters:
  • args – Command arguments.
  • wait – Wait until command execution ends.
  • overwrite – Overwrite current content of the folder.
Returns:

namedtuple(success, error, process, logfiles, errorfiles).

calculate_mesh_orthogonality(use_currnt_check_mesh_log=False)[source]

Calculate max and average mesh orthogonality.

If average values is more than 80, try to generate a better mesh. You can use this values to set discretization schemes. try case.setFvSchemes(average_orthogonality)

check_mesh(args=None, wait=True)[source]

Run checkMesh.

Parameters:
  • args – Command arguments.
  • wait – Wait until command execution ends.
Returns:

namedtuple(success, error, process, logfiles, errorfiles).

command(cmd, args=None, decomposeParDict=None, run=True, wait=True)[source]

Run an OpenFOAM command for this case. This method creates a log and err file under logFolder for each command. The output will be logged as {cmd}.log and {cmd}.err. :param cmd: OpenFOAM command. :param args: Command arguments. :param decomposeParDict: Optional input for decomposeParDict to run analysis

in parallel if desired.
Parameters:
  • run – Run the command in shell.
  • wait – Wait until the command is over.
Returns:

If run is True returns a namedtuple for

(success, error, process, logfiles, errorfiles). success: as a boolen. error: None in case of success otherwise the error message as

a string.

process: Popen process. logfiles: List of fullpath to log files. errorfiles: List of fullpath to error files.

else return a namedtuple for

(cmd, logfiles, errorfiles) cmd: command lines. logfiles: A tuple for log files. errorfiles: A tuple for error files.

constant_folder

constant folder fullpath.

copy_snappyHexMesh(folder_number=None, overwrite=True)[source]

Copy the results of snappyHexMesh to constant/polyMesh.

duplicate()[source]

Return a copy of this object.

foam_files

Get all the foam_files.

classmethod from_bf_geometries(name, geometries, blockMeshDict=None, meshing_parameters=None, make2d_parameters=None, convertToMeters=1)[source]

Create a case from Butterfly geometries.

foam_files/dictionaries will be generated based on boundary condition of geometries. fvSolution and fvSchemes will be set to default can can be overwritten once a Solution is created from a Case and a Recipe. You can overwrite them through the recipe.

Parameters:
  • name – Case name as a string with no whitespace.
  • geometries – Collection of bf_geometries. FoamFiles/dictionaries will be generated based on boundary condition of geometries.
  • blockMeshDict – Optional input for blockMeshDict. If blockMeshDict is not provided, it will be calculated from geometries in XY direction and boundary condition for faces will be set to BoundingBoxBoundaryCondition. Use BlockMeshDict to create the blockMeshDict if your case is not aligned to XY direction or you need to assign different boundary condition to geometries.
  • meshing_parameters – Optional input for MeshingParameters.
  • make2d_parameters – Optional input for make2d_parameters to make a 2d case.
classmethod from_folder(path, name=None, convert_from_meters=1)[source]

Create a Butterfly case from a case folder.

Parameters:
  • path – Full path to case folder.
  • name – An optional new name for this case.
  • convert_from_meters – A number to be multiplied to stl file vertices to be converted to the new units if not meters. This value will be the inverse of convertToMeters.
classmethod from_wind_tunnel(wind_tunnel, make2d_parameters=None)[source]

Create case from wind tunnel.

geometries

Butterfly geometries.

get_foam_file_by_name(name)[source]

Get a foamfile by name.

get_foam_files_from_location(location=None)[source]

Get foam_files in a specific location (0, constant, system).

get_result_folders()[source]

Return sorted list of numerical folders.

get_snappyHexMesh_folders()[source]

Return sorted list of numerical folders.

isCase

return True.

is_polyMesh_snappyHexMesh

Check if the mesh in polyMesh folder is snappyHexMesh.

load_mesh()[source]

Return OpenFOAM mesh as a Rhino mesh.

load_points()[source]

Return OpenFOAM mesh as a Rhino mesh.

load_probe_values(field)[source]

Return OpenFOAM probes results for a field.

load_probes(field)[source]

Return OpenFOAM probes locations for a field.

log_folder

log folder fullpath.

polyMesh_folder

polyMesh folder fullpath.

postProcessing_folder

postProcessing folder fullpath.

probes

Get and set Probes.

probes_folder

Fullpath to probes folder.

project_dir

Get project directory.

project_name

Project name.

purge(remove_polyMesh_content=True, remove_snappyHexMesh_folders=True, remove_result_folders=False, remove_postProcessing_folder=False)[source]

Purge case folder.

refinementRegions

Get refinement regions.

remove_polyMesh_content()[source]

Remove files inside polyMesh folder.

remove_postProcessing_folder()[source]

Remove post postProcessing folder.

remove_processor_folders()[source]

Remove processor folders for parallel runs.

remove_result_folders()[source]

Remove results folder.

remove_snappyHexMesh_folders()[source]

Remove snappyHexMesh numerical folders.

Use this to clean the folder.

rename_snappyHexMesh_folders(add=True)[source]

Rename snappyHexMesh numerical folders to name.org and vice versa.

Parameters:add – Set to True to add .org at the end of the file. Set to False to rename them back to the original naming.
sample(name, points, field, wait=True)[source]

Sample the results for a certain field.

Parameters:
  • name – A unique name for this sample.
  • points – List of points as (x, y, z).
  • fields – List of fields (e.g. U, p).
  • args – Command arguments.
  • wait – Wait until command execution ends.
Returns:

namedtuple(probes, values).

save(overwrite=False, minimum=True)[source]

Save case to folder.

Parameters:
  • overwrite – If True all the current content will be overwritten (default: False).
  • minimum – Write minimum necessary files for case. These files will be enough for meshing the case but not running any commands. Files are (‘fvSchemes’, ‘fvSolution’, ‘controlDict’, ‘blockMeshDict’,’snappyHexMeshDict’). Rest of the files will be created from a Solution.
snappyHexMesh(args=None, wait=True)[source]

Run snappyHexMesh.

Parameters:
  • args – Command arguments.
  • wait – Wait until command execution ends.
Returns:

namedtuple(success, error, process, logfiles, errorfiles).

surfaceFeatureExtract(args=None, wait=True)[source]

Run surfaceFeatureExtract command.

Parameters:
  • args – Command arguments.
  • wait – Wait until command execution ends.
Returns:

namedtuple(success, error, process, logfiles, errorfiles).

system_folder

system folder fullpath.

triSurface_folder

triSurface folder fullpath.

update_bc_in_zero_folder()[source]

Update boundary conditions in files in 0 folder.

Call this method if you have made any changes to boundary condition of any of the geometries after initiating the class.

working_dir

Change default working directory.

Do not change the working dir if you are using OpenFOAM for Windows to run the analysis.

zero_folder

Folder 0 fullpath.