butterfly package¶
Submodules¶
butterfly.RASProperties module¶
RASProperties class.
Use turbulenceProperties from Version 3.0+
-
class
butterfly.RASProperties.
RASProperties
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Finite Volume Solution class.
-
RASModel
¶ RAS model.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
printCoeffs
¶ is printCoeffs on/off.
-
turbulence
¶ is turbulence on/off.
-
butterfly.T module¶
T[emperature] class.
-
class
butterfly.T.
T
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
T (temperature) class.
butterfly.U module¶
U class.
-
class
butterfly.U.
U
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
U (Speed) class.
butterfly.alphat module¶
alphat class.
-
class
butterfly.alphat.
Alphat
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
alphat class.
-
dimensions
¶ Return dimensions.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
internalField
¶ Return internalField.
-
butterfly.blockMeshDict module¶
BlockMeshDict class.
-
class
butterfly.blockMeshDict.
BlockMeshDict
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
BlockMeshDict.
-
back_face_indices
¶ Get indecies for back face.
-
back_face_vertices
¶ Get vertices for back face.
-
bottom_face_indices
¶ Get indecies for bottom face.
-
bottom_face_vertices
¶ Get vertices for bottom face.
-
boundary
¶ Get boundaries and a dictionary.
-
center
¶ Get center of the block.
-
convertToMeters
¶ Get convertToMeters.
-
expand_by_cells_count
(x_count, y_count, z_count, renumber_division=True)[source]¶ Expand blockMeshDict boundingbox for n cells from all sides.
This method will increase the number of divisions by 2 to keep the size of the cells unchanged unless renumber_division is set to False. Use a negative count to shrink the bounding box.
-
expand_uniform_by_cells_count
(count, renumber_division=True)[source]¶ Expand blockMeshDict boundingbox for n cells from all sides.
This method will increase the number of divisions by 2 to keep the size of the cells unchanged unless renumber_division is set to False. Use a negative count to shrink the bounding box.
-
classmethod
from_bf_block_geometries
(bf_block_geometries, convertToMeters=1, n_div_xyz=None, grading=None, x_axis=None)[source]¶ Create BlockMeshDict from bf_block_geometries.
Parameters: - bf_block_geometries – A collection of boundary surfaces for bounding box.
- convertToMeters – Scaling factor for the vertex coordinates.
- n_div_xyz – Number of divisions in (x, y, z) as a tuple (default: 5, 5, 5).
- grading – A simpleGrading (default: simpleGrading(1, 1, 1)).
- x_axis – An optional tuple that indicates the x_axis direction (default: (1, 0)).
-
classmethod
from_file
(filepah, convertToMeters=1)[source]¶ Create a blockMeshDict from file.
Parameters: - filepah – Full path to blockMeshDict.
- converToMeters – converToMeters for the new document. This values will be used to update the vertices to the new units. Default is 1 which means blockMeshDict will be converted to meters.
-
classmethod
from_min_max
(min_pt, max_pt, convertToMeters=1, n_div_xyz=None, grading=None, x_axis=None)[source]¶ Create BlockMeshDict from minimum and maximum point.
Parameters: - min_pt – Minimum point of bounding box as (x, y, z).
- max_pt – Maximum point of bounding box as (x, y, z).
- convertToMeters – Scaling factor for the vertex coordinates.
- n_div_xyz – Number of divisions in (x, y, z) as a tuple (default: 5, 5, 5).
- grading – A simpleGrading (default: simpleGrading(1, 1, 1)).
- x_axis – An optional tuple that indicates the x_axis direction (default: (1, 0)).
-
classmethod
from_origin_and_size
(origin, width, length, height, convertToMeters=1, n_div_xyz=None, grading=None, x_axis=None)[source]¶ Create BlockMeshDict from bf_block_geometries.
Parameters: - origin – Minimum point of bounding box as (x, y, z).
- width – Width in x direction.
- length – Length in y direction.
- height – Height in y direction.
- convertToMeters – Scaling factor for the vertex coordinates.
- n_div_xyz – Number of divisions in (x, y, z) as a tuple (default: 5, 5, 5).
- grading – A simpleGrading (default: simpleGrading(1, 1, 1)).
- x_axis – An optional tuple that indicates the x_axis direction (default: (1, 0)).
-
classmethod
from_vertices
(vertices, convertToMeters=1, n_div_xyz=None, grading=None, x_axis=None)[source]¶ Create BlockMeshDict from vertices.
Parameters: - vertices – 8 vertices to define the bounding box.
- convertToMeters – Scaling factor for the vertex coordinates.
- n_div_xyz – Number of divisions in (x, y, z) as a tuple (default: 5, 5, 5).
- grading – A simpleGrading (default: simpleGrading(1, 1, 1)).
- x_axis – An optional tuple that indicates the x_axis direction (default: (1, 0)).
-
front_face_indices
¶ Get indecies for front face.
-
front_face_vertices
¶ Get vertices for front face.
-
geometry
¶ A tuple of bf_geometries for BoundingBox faces.
-
get_face_indices
(face_index)[source]¶ Update boundary to empty for one of the faces.
Parameters: face_index – 0 - front, 1 - back, 2 - bottom, 3 - top, 4 - right, 5 - left.
-
get_face_vertices
(face_index)[source]¶ Update boundary to empty for one of the faces.
Parameters: face_index – 0 - front, 1 - back, 2 - bottom, 3 - top, 4 - right, 5 - left.
-
grading
¶ A simpleGrading (default – simpleGrading(1, 1, 1)).
-
height
¶ Length of block in Z direction.
-
is2d_in_x_direction
¶ Return True if the case is 2d in X direction.
-
is2d_in_y_direction
¶ Return True if the case is 2d in Y direction.
-
is2d_in_z_direction
¶ Return True if the case is 2d in Z direction.
-
left_face_indices
¶ Get indecies for left face.
-
left_face_vertices
¶ Get vertices for left face.
-
length
¶ Length of block in Y direction.
-
make2d
(plane_origin, plane_normal, width=0.1)[source]¶ Make the blockMeshDict two dimensional.
Parameters: - plane_origin – Plane origin as (x, y, z).
- plane_normal – Plane normal as (x, y, z).
- width – width of 2d blockMeshDict (default: 01).
-
max_pt
¶ Return maximum pt x, y, z in this block.
-
min_pt
¶ Return minimum pt x, y, z in this block.
-
min_z
¶ Return minimum Z value of vertices in this block.
-
n_div_xyz
¶ Number of divisions in (x, y, z) as a tuple (default – 5, 5, 5).
-
right_face_indices
¶ Get indecies for right face.
-
right_face_vertices
¶ Get vertices for right face.
-
top_face_indices
¶ Get indecies for top face.
-
top_face_vertices
¶ Get vertices for top face.
-
vertices
¶ Get the sorted list of vertices.
-
vertices_order
¶ Get order of vertices in blocks.
-
width
¶ Length of block in X direction.
-
x_axis
¶ X axis as a tuple.
-
y_axis
¶ Y axis.
-
z_axis
¶ Z axis.
-
butterfly.boundarycondition module¶
Collection of OpenFOAM boundary conditions (e.g. wall, inlet, outlet).
-
class
butterfly.boundarycondition.
BoundaryCondition
(bc_type='patch', T=None, U=None, p=None, k=None, epsilon=None, nut=None, alphat=None, p_rgh=None)[source]¶ Bases:
object
Boundary condition base class.
-
T
¶ T boundary condition.
-
U
¶ U boundary condition.
-
alphat
¶ alphat boundary condition.
-
epsilon
¶ epsilon boundary condition.
-
k
¶ k boundary condition.
-
nut
¶ nut boundary condition.
-
p
¶ p boundary condition.
-
p_rgh
¶ p_rgh boundary condition.
-
-
class
butterfly.boundarycondition.
BoundingBoxBoundaryCondition
[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Bounding box boundary condition for bounding box geometry.
It returns a boundary condition of ZeroGradient for all the inputs.
-
class
butterfly.boundarycondition.
EmptyBoundaryCondition
[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Empty boundary condition.
It returns a boundary condition of Empty for all the inputs.
-
class
butterfly.boundarycondition.
FixedInletBoundaryCondition
(T=None, U=None, p=None, k=None, epsilon=None, nut=None, alphat=None, p_rgh=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Inlet boundary condition base class.
-
T
¶ Optional input for Temperature.
-
U
¶ Air velocity as fixed value (x, y, z).
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
FixedOutletBoundaryCondition
(T=None, U=None, p=None, k=None, epsilon=None, nut=None, alphat=None, p_rgh=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Outlet boundary condition base class.
-
pressure
¶ Pressure as a float (default: 0)
-
T
¶ Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
IndoorWallBoundaryCondition
(T=None, U=None, p=None, k=None, epsilon=None, nut=None, alphat=None, p_rgh=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Wall boundary condition base class.
-
T
¶ Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
WindTunnelGroundBoundaryCondition
(ABLConditions, T=None, U=None, p=None, k=None, epsilon=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Wind tunnel ground boundary condition.
-
T
¶ Optional input for Temperature.
-
T
Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
WindTunnelInletBoundaryCondition
(ABLConditions, T=None, p=None, nut=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Wind tunnel atmBoundaryLayerInletVelocity boundary condition.
-
T
¶ Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
WindTunnelOutletBoundaryCondition
(T=None, U=None, p=None, k=None, epsilon=None, nut=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Outlet boundary condition for wind tunnel.
-
pressure
¶ Pressure as a float (default: 0)
-
T
¶ Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
WindTunnelTopAndSidesBoundaryCondition
(T=None, U=None, p=None, k=None, epsilon=None, nut=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Outlet boundary condition for top and sides of wind tunnel.
-
pressure
¶ Pressure as a float (default: 0)
-
T
¶ Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
-
class
butterfly.boundarycondition.
WindTunnelWallBoundaryCondition
(T=None, U=None, p=None, k=None, epsilon=None, nut=None)[source]¶ Bases:
butterfly.boundarycondition.BoundaryCondition
Wall boundary condition for wall geometrys inside wind tunnel.
-
T
¶ Optional input for Temperature.
-
T
Optional input for Temperature.
-
U
¶ OpenFOAM value for U.
-
p
¶ OpenFOAM value for p.
-
k
¶ OpenFOAM value for k.
-
epsilon
¶ OpenFOAM value for epsilon.
-
nut
¶ OpenFOAM value for nut.
-
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:
- from_folder: Create a Butterfly case from a case folder
- from_bf_geometries: Create a case from Butterfly geometries.
- 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')¶
-
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.
-
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_files_from_location
(location=None)[source]¶ Get foam_files in a specific location (0, constant, system).
-
isCase
¶ return True.
-
is_polyMesh_snappyHexMesh
¶ Check if the mesh in polyMesh folder is snappyHexMesh.
-
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_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.
butterfly.conditions module¶
ABL Conditions and initialConditions class.
-
class
butterfly.conditions.
ABLConditions
(values=None)[source]¶ Bases:
butterfly.foamfile.Condition
ABL Conditions.
-
Uref
¶ Get flow speed as a float.
-
Zref
¶ Get reference z value for input wind speed- usually 10 meters
-
flowDir
¶ Get flow dir as tuple (x, y, z).
-
flow_speed
¶ Get flow speed as a float.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
z0
¶ roughness - default is set to 1 for urban environment
-
zDir
¶ z direction. (0 0 1) for wind tunnel
-
zGround
¶ Min z value of the bounding box (default – uniform 0)
-
-
class
butterfly.conditions.
InitialConditions
(values=None, Uref=0, Zref=10, z0=1, cm=0.09, k=0.41)[source]¶ Bases:
butterfly.foamfile.Condition
Initial conditions.
-
Uref
¶ Input velocity in m/s.
-
Zref
¶ Input height reference for input velocity in meters.
-
calculate_k_epsilon
(init=False)[source]¶ Calculate turbulentKE and turbulentEpsilon.
Parameters: init – True if the method is called when the class is initiated (default: False).
-
cm
¶ default: 0.09
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
k
¶ default: 0.41
-
z0
¶ Roughness.
-
butterfly.controlDict module¶
BlockMeshDict class.
-
class
butterfly.controlDict.
ControlDict
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Control dict class.
-
application
¶ Set solver application.
(default: simpleFoam)
-
endTime
¶ Set end timestep (default – 1000).
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
functions
¶ Function objects.
-
include
¶ Get if any file is included in controlDict.
-
purgeWrite
¶ Set the number of results folders to be kept (default – 0).
-
startTime
¶ Set start timestep (default – 0).
-
writeCompression
¶ Write results as .zip files.
Set to True to compress the results before writing to your machine (default: False)
-
writeInterval
¶ Set the number of intervals for writing the results (default – 100).
-
butterfly.decomposeParDict module¶
decomposeParDict class.
Decompose parameters for parallel runs.
-
class
butterfly.decomposeParDict.
DecomposeParDict
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
DecomposeParDict class.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
numberOfSubdomains
¶ Get number of total subdomains.
-
classmethod
butterfly.epsilon module¶
epsilon class.
-
class
butterfly.epsilon.
Epsilon
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
epsilon class.
-
dimensions
¶ Return dimensions.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
internalField
¶ Return internalField.
-
butterfly.exception module¶
Butterfly exceptions.
butterfly.fields module¶
OpenFOAM field values.
-
class
butterfly.fields.
AlphatJayatillekeWallFunction
(value, is_uniform=True, Prt=None)[source]¶ Bases:
butterfly.fields.FixedValue
alphatJayatillekeWallFunction.
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
AtmBoundary
(Uref, Zref, z0, flowDir, zDir='(0 0 1)', zGround=0, from_values=True)[source]¶ Bases:
butterfly.fields.Field
OpenFOAM AtmBoundaryLayerInletVelocity.
-
uref
¶ Flow velocity as a float number.
-
Zref
¶ Reference z value for flow velocity as a float number.
-
z0
¶ Roughness (e.g. uniform 1).
-
flowDir
¶ Velocity vector as a tuple.
-
zDir
¶ Z direction (default:(0 0 1)).
-
zGround
¶ Min z value of the bounding box (default: 0).
-
from_values
¶ True.
-
classmethod
from_ABLConditions
(ABLConditions, value=None)[source]¶ Init class from a condition file.
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
AtmBoundaryLayerInletEpsilon
(Uref, Zref, z0, flowDir, zDir='(0 0 1)', zGround=0, from_values=True)[source]¶ Bases:
butterfly.fields.AtmBoundary
AtmBoundaryLayerInletEpsilon.
-
class
butterfly.fields.
AtmBoundaryLayerInletK
(Uref, Zref, z0, flowDir, zDir='(0 0 1)', zGround=0, from_values=True)[source]¶ Bases:
butterfly.fields.AtmBoundary
AtmBoundaryLayerInletK.
-
class
butterfly.fields.
AtmBoundaryLayerInletVelocity
(Uref, Zref, z0, flowDir, zDir='(0 0 1)', zGround=0, from_values=True)[source]¶ Bases:
butterfly.fields.AtmBoundary
AtmBoundaryLayerInletVelocity.
-
class
butterfly.fields.
Calculated
(value=None, is_unifrom=True)[source]¶ Bases:
butterfly.fields.Field
OpenFOAM calculated value.
Parameters: - value – value.
- is_unifrom – A boolean that indicates if the values is uniform.
-
value_dict
¶ Get fields as a dictionary.
-
class
butterfly.fields.
Empty
[source]¶ Bases:
butterfly.fields.Field
Empty boundary condition.
-
class
butterfly.fields.
EpsilonWallFunction
(value, cmu=None, kappa=None, E=None, is_unifrom=True)[source]¶ Bases:
butterfly.fields.WallFunction
EpsilonWallFunction.
Parameters: - value –
- cmu – (default: None)
- kappa – (default: None)
- E – (default: None)
-
value_dict
¶ Get fields as a dictionary.
-
class
butterfly.fields.
Field
[source]¶ Bases:
object
OpenFOAM field values base class.
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
FixedFluxPressure
(value, is_uniform=True, rho=None)[source]¶ Bases:
butterfly.fields.FixedValue
FixedFluxPressure.
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
FixedValue
(value, is_unifrom=True)[source]¶ Bases:
butterfly.fields.Field
OpenFOAM fixed value.
Parameters: - value – value.
- is_unifrom – A boolean that indicates if the values is uniform.
-
value_dict
¶ Get fields as a dictionary.
-
class
butterfly.fields.
FlowRateInletVelocity
(volumetricFlowRate, value, is_uniform=True)[source]¶ Bases:
butterfly.fields.FixedValue
FlowRateInletVelocity.
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
InletOutlet
(inletValue, value)[source]¶ Bases:
butterfly.fields.Field
OpenFOAM InletOutlet value.
http://www.cfd-online.com/Forums/openfoam-solving/60337-questions-about -inletoutlet-outletinlet-boundary-conditions.html
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
KqRWallFunction
(value, is_unifrom=True)[source]¶ Bases:
butterfly.fields.WallFunction
KqRWallFunction.
-
class
butterfly.fields.
NutkAtmRoughWallFunction
(Uref, Zref, z0, flowDir, zDir='(0 0 1)', zGround=0, from_values=True)[source]¶ Bases:
butterfly.fields.AtmBoundary
NutkAtmRoughWallFunction.
-
class
butterfly.fields.
NutkWallFunction
(value, cmu=None, kappa=None, E=None, is_unifrom=True)[source]¶ Bases:
butterfly.fields.EpsilonWallFunction
NutkWallFunction.
-
class
butterfly.fields.
OutletInlet
(outletValue, value)[source]¶ Bases:
butterfly.fields.Field
OpenFOAM OutletInlet value.
http://www.cfd-online.com/Forums/openfoam-solving/60337-questions-about -inletoutlet-outletinlet-boundary-conditions.html
-
value_dict
¶ Get fields as a dictionary.
-
-
class
butterfly.fields.
PressureInletOutletVelocity
(value, is_unifrom=True)[source]¶ Bases:
butterfly.fields.FixedValue
PressureInletOutletVelocity.
-
class
butterfly.fields.
Slip
[source]¶ Bases:
butterfly.fields.Field
Slip boundary condition.
-
class
butterfly.fields.
WallFunction
(value, is_unifrom=True)[source]¶ Bases:
butterfly.fields.FixedValue
WallFunction.
-
class
butterfly.fields.
ZeroGradient
[source]¶ Bases:
butterfly.fields.Field
ZeroGradient boundary condition.
butterfly.foamfile module¶
Foam File Class.
-
class
butterfly.foamfile.
Condition
(name, cls, location=None, file_format='ascii', default_values=None, values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
OpenFOAM conditions object.
Use this class to create conditions such as initialConditions and ABLConditions. Conditions don’t have OpenFOAM header. It’s only values.
-
class
butterfly.foamfile.
FoamFile
(name, cls, location=None, file_format='ascii', default_values=None, values=None)[source]¶ Bases:
object
FoamFile base class for OpenFOAM dictionaries.
Read (http://cfd.direct/openfoam/user-guide/basic-file-format/) for more information about FoamFile
-
name
¶ Filename (e.g. controlDict)
-
cls
¶ OpenFOAM class constructed from the data file concerned. Typically dictionary or a field, e.g. volVectorField
-
location
¶ Folder name (0, constant or system)
-
file_format
¶ File format (ascii / binary) (default: ascii)
-
classmethod
from_file
(filepath, location=None)[source]¶ Create a FoamFile from a file.
Parameters: - filepath – Full file path to dictionary.
- location – Optional folder name for location (0, constant or system)
-
get_value_by_parameter
(parameter)[source]¶ Get values for a given parameter by parameter name.
Parameters: parameter – Name of a parameter as a string.
-
isFoamFile
¶ Return True for FoamFile.
-
is_constant_file
¶ Check if the file location is ‘constant’ folder.
-
is_system_file
¶ Check if the file location is ‘system’ folder.
-
is_zero_file
¶ Check if the file location is folder 0.
-
parameters
¶ Get list of parameters.
-
save
(project_folder, sub_folder=None, overwrite=True)[source]¶ Save to file.
Parameters: - project_folder – Path to project folder as a string.
- sub_folder – Optional input for sub_folder (default: self.location).
-
set_value_by_parameter
(parameter, value)[source]¶ Set value for a parameter.
Parameters: - parameter – Name of a parameter as a string.
- value – Parameter value as a string.
-
update_values
(v, replace=False, mute=False)[source]¶ Update current values from dictionary v.
if key is not available in current values it will be added, if the key already exists it will be updated.
Returns: True is the dictionary is updated.
-
values
¶ Return values as a dictionary.
-
-
class
butterfly.foamfile.
FoamFileZeroFolder
(name, cls, location=None, file_format='ascii', default_values=None, values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
FoamFiles under 0 folder.
The main difference between FoamFileZeroFolder and FoamFile is that FoamFileZeroFolder has a method to set boundary fields based on input geometry (e.g. Butterfly objects).
butterfly.functions module¶
A cllection of OpenFOAM functions such as Probes.
-
class
butterfly.functions.
Function
(name, cls, location=None, file_format='ascii', default_values=None, values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
OpenFOAM function object.
Use this class to create conditions function objects. Functions don’t have OpenFOAM header and OpenFOAM FoamFile. It’s only values.
-
class
butterfly.functions.
Probes
(values=None)[source]¶ Bases:
butterfly.functions.Function
Probes function.
-
fields
¶ Get and set probes fields from list of tuples.
-
filename
¶ Get Probes filename.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
probeLocations
¶ Get and set probe locations from list of tuples.
-
probes_count
¶ Get number of probes.
-
writeInterval
¶ Set the number of intervals for writing the results (default – 100).
-
butterfly.fvSchemes module¶
Finite Volume Schemes class.
-
class
butterfly.fvSchemes.
FvSchemes
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Finite Volume Schemes class.
-
divSchemesCollector
= {0: '// first order\ndivSchemes\n{\n default none;\n div(phi,epsilon) bounded Gauss upwind default;\n div(phi,U) bounded Gauss upwind grad(U);\n div((nuEff*dev2(T(grad(U))))) Gauss linear;\n div(phi,k) bounded Gauss upwind grad(k);\n}\n', 1: '// second order\ndivSchemes\n{\n default none;\n div(phi,epsilon) bounded Gauss linearUpwind grad(epsilon);\n div(phi,U) bounded Gauss linearUpwind grad(U);\n div((nuEff*dev2(T(grad(U))))) Gauss linear;\n div(phi,k) bounded Gauss linearUpwind grad(k);\n}'}¶
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
classmethod
from_mesh_orthogonality
(average_orthogonality=45)[source]¶ Init fvSchemes based on mesh orthogonality.
Check pp. 45-50 of this document: http://www.dicat.unige.it/guerrero/oftraining/9tipsandtricks.pdf
-
butterfly.fvSolution module¶
Finite Volume Solution class.
-
class
butterfly.fvSolution.
FvSolution
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Finite Volume Solution class.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
classmethod
from_recipe
(recipe=0)[source]¶ Generate fvSolution for a particular recipe.
Parameters: recipe – 0: incompressible, 1: heat transfer.
-
relaxationFactors
¶ Get and set residual controls.
-
residualControl
¶ Get and set residual controls.
-
classmethod
butterfly.g module¶
g[ravity] class.
butterfly.geometry module¶
BF geometry library.
-
class
butterfly.geometry.
BFBlockGeometry
(name, vertices, face_indices, border_vertices, boundary_condition=None)[source]¶ Bases:
butterfly.geometry.BFGeometry
Butterfly block geometry.
Use this geometry to create geometries for blockMeshDict.
-
name
¶ Name as a string (A-Z a-z 0-9 _).
-
vertices
¶ A flatten list of (x, y, z) for vertices.
-
face_indices
¶ A flatten list of (a, b, c) for indices for each face.
-
boundary_condition
¶ Boundary condition for this geometry.
-
border_vertices
¶ List of lists of (x, y, z) values for each quad face of the geometry.
-
border_vertices
Return list of border vertices.
-
isBFBlockGeometry
¶ Return True for Butterfly block geometries.
-
-
class
butterfly.geometry.
BFGeometry
(name, vertices, face_indices, normals=None, boundary_condition=None, refinementLevels=None, nSurfaceLayers=None)[source]¶ Bases:
butterfly.geometry._BFMesh
Butterfly geometry.
-
name
¶ Name as a string (A-Z a-z 0-9 _).
-
vertices
¶ A flatten list of (x, y, z) for vertices.
-
face_indices
¶ A flatten list of (a, b, c) for indices for each face.
-
normals
¶ A flatten list of (x, y, z) for face normals.
-
boundary_condition
¶ Boundary condition for this geometry.
Usage:
vertices = ((0, 0, 0), (10, 0, 0), (10, 10, 0), (0, 10, 0))
- geo = BFGeometry(name=’square’, vertices=vertices,
- face_indices=((0, 1, 2), (0, 2, 3)), normals=((0, 0, 1), (0, 0, 1)))
print(geo.to_stl(convertToMeters=1))
-
boundary_condition
Boundary condition.
-
isBFGeometry
¶ Return True for Butterfly geometries.
-
nSurfaceLayers
¶ Number of surface layers for snappyHexMeshDict addLayers.
-
refinementLevels
¶ refinementLevels for snappyHexMeshDict as (min, max).
-
-
butterfly.geometry.
bf_geometry_from_stl_block
(stl_block, convert_from_meters=1)[source]¶ Create BFGeometry from an stl block as a string.
-
butterfly.geometry.
bf_geometry_from_stl_file
(filepath, convert_from_meters=1)[source]¶ Return a tuple of BFGeometry from an stl file.
-
butterfly.geometry.
calculate_min_max
(geometry, angle)[source]¶ Calculate maximum and minimum x, y, z for input geometry.
angle: Anticlockwise rotation angle of the new coordinates system.
butterfly.grading module¶
Butterfly grading class for blockMeshDict.
-
class
butterfly.grading.
Grading
(percentage_length=None, percentage_cells=None, expansion_ratio=1)[source]¶ Bases:
object
OpenFOAM grading.
Use this class to create OpenFOAM grading with either a single expansion ration or (percentage_length, percentage_cells, expansion_ratio).
-
percentage_length
¶ Percentage of length of the block.
-
percentage_cells
¶ Percentage of cells to be included in this segment.
-
expansion_ratio
¶ Expansion ration in this segment (default: 1).
-
classmethod
from_expansion_ratio
(expansion_ratio=1)[source]¶ Create a grading with only expansion_ratio.
-
isGrading
¶ Return True.
-
is_valid
¶ Return True if grading is just an expansion_ratio.
-
-
class
butterfly.grading.
MultiGrading
(gradings)[source]¶ Bases:
object
MultiGrading.
- Use this object to create MultiGrading like the example below.
- (0.2 0.3 4) // 20% y-dir, 30% cells, expansion = 4 (0.6 0.4 1) // 60% y-dir, 40% cells, expansion = 1 (0.2 0.3 0.25) // 20% y-dir, 30% cells, expansion = 0.25 (1/4)
Read more at section 5.3.1.3: http://cfd.direct/openfoam/user-guide/blockmesh/
-
gradings
¶ A list of minimum two OpenFOAM Gradings. All the gradings should have percentage_length and percentage_cells values.
-
gradings
Get gradings in this MultiGrading.
-
isGrading
¶ Return True.
-
isMultiGrading
¶ Return True.
-
is_valid
¶ Return True.
-
class
butterfly.grading.
SimpleGrading
(x_grading=1, y_grading=1, z_grading=1)[source]¶ Bases:
object
Block simpleGrading in blockMeshDict.
-
x_grading
¶ Grading for X. The input can be a Grading or a MultiGrading (default: 1).
-
y_grading
¶ Grading for Y. The input can be a Grading or a MultiGrading (default: 1).
-
z_grading
¶ Grading for Z. The input can be a Grading or a MultiGrading (default: 1).
- Usage:
x_grading = Grading.from_expansion_ratio(1) y_grading = Grading.from_expansion_ratio(1) z_grading = MultiGrading(
(Grading(0.2, 0.3, 4), Grading(0.6, 0.4, 1), Grading(0.2, 0.3, 0.25)))
print(simpleGrading(x_grading, y_grading, z_grading))
- >> simpleGrading (
1.0 1.0 (
(0.2 0.3 4.0) (0.6 0.4 1.0) (0.2 0.3 0.25)
-
isSimpleGrading
¶ Return True.
-
butterfly.gradingutil module¶
-
class
butterfly.gradingutil.
GradientProperties
(ln, k, r, n, ds, de)¶ Bases:
tuple
-
de
¶ Alias for field number 5
-
ds
¶ Alias for field number 4
-
k
¶ Alias for field number 1
-
ln
¶ Alias for field number 0
-
n
¶ Alias for field number 3
-
r
¶ Alias for field number 2
-
-
butterfly.gradingutil.
grading_by_ds_ccratio_count
(ds, k, n)[source]¶ Calculate grading properties.
Parameters: - ds – Start cell size
- k – Cell-to-cell expansion (or geometric growth ratio)
- n – Number of cells
Returns: - grading properties as a namedtuple.
ln: Total length k: Cell-to-cell expansion (or geometric growth ratio) r: Total expansion ratio (=bias factor in Ansys Meshing) n: Number of cells ds: Start cell size de: End cell size
-
butterfly.gradingutil.
grading_by_length_de_ccratio
(ln, de, k, min_ds=1)[source]¶ Calculate grading properties.
Parameters: - ln – Total length
- de – End cell size
- k – Cell-to-cell expansion (or geometric growth ratio)
- min_ds – Minimum size for start cell size.
Returns: - grading properties as a namedtuple.
ln: Total length k: Cell-to-cell expansion (or geometric growth ratio) r: Total expansion ratio (=bias factor in Ansys Meshing) n: Number of cells ds: Start cell size de: End cell size
-
butterfly.gradingutil.
grading_by_length_ds_ccratio
(ln, ds, k)[source]¶ Calculate grading properties.
Parameters: - ln – Total length
- ds – Start cell size
- k – Cell-to-cell expansion (or geometric growth ratio)
Returns: - grading properties as a namedtuple.
ln: Total length k: Cell-to-cell expansion (or geometric growth ratio) r: Total expansion ratio (=bias factor in Ansys Meshing) n: Number of cells ds: Start cell size de: End cell size
-
butterfly.gradingutil.
grading_by_length_ds_de
(ln, ds, de)[source]¶ Calculate grading properties.
Parameters: - ln – Total length
- ds – Start cell size
- de – End cell size
Returns: - grading properties as a namedtuple.
ln: Total length k: Cell-to-cell expansion (or geometric growth ratio) r: Total expansion ratio (=bias factor in Ansys Meshing) n: Number of cells ds: Start cell size de: End cell size
-
butterfly.gradingutil.
secant
(f, x0, x1, eps, ds, ln, n)[source]¶ The secant method to solve nonlinear equation to find expansion ratio.
From: http://hplgit.github.io/Programming-for-Computations/pub/p4c/p4c-sphinx-Python/ ._pylight007.html
butterfly.k module¶
k class.
-
class
butterfly.k.
K
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
k class.
butterfly.make2dparameters module¶
Butterfly make2d Parameters.
Parameters to convert a 3d OpenFOAM case to 2d.
butterfly.meshingparameters module¶
Butterfly Meshing Parameters.
Collection of meshing parameters for blockMesh and snappyHexMesh.
-
class
butterfly.meshingparameters.
MeshingParameters
(cell_size_xyz=None, grading=None, locationInMesh=None, globRefineLevel=None)[source]¶ Bases:
object
Meshing parameters.
-
cell_size_xyz
¶ Cell size in (x, y, z) as a tuple (default: length / 5). This value updates number of divisions in blockMeshDict.
-
grading
¶ A simpleGrading (default: simpleGrading(1, 1, 1)). This value updates grading in blockMeshDict.
-
locationInMesh
¶ A tuple for the location of the mesh to be kept. This value updates locationInMesh in snappyHexMeshDict.
-
globRefineLevel
¶ A tuple of (min, max) values for global refinment. This value updates globalRefinementLevel in snappyHexMeshDict.
-
grading
A simpleGrading (default – simpleGrading(1, 1, 1)).
-
isMeshingParameters
¶ Return True.
-
butterfly.nut module¶
nut class.
-
class
butterfly.nut.
Nut
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
Nut class.
butterfly.p module¶
p class.
-
class
butterfly.p.
P
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
P (pressure) class.
butterfly.p_rgh module¶
p_rgh class.
-
class
butterfly.p_rgh.
P_rgh
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFileZeroFolder
p_rgh class.
butterfly.parser module¶
OpenFOAM/c++ dictionary parser.
-
class
butterfly.parser.
CppDictParser
(text)[source]¶ Bases:
object
Parse OpenFOAM dictionary to Python dictionary.
Use values property to get the dictionary.
-
text
¶ OpenFOAM dictionary as a single multiline string.
-
values
¶ Get OpenFOAM dictionary values as a python dictionary.
-
-
class
butterfly.parser.
ResidualParser
(filepath, parse=True)[source]¶ Bases:
object
Paeser for residual values from a log file.
-
filepath
¶ Full file path to .log file.
-
parser
¶ If ture Parser will start parsing the values once initiated.
-
residuals
¶ Get residuals as a dictionary.
-
time_range
¶ Get time range as a tuple.
-
butterfly.recipe module¶
Butterfly recipes.
-
class
butterfly.recipe.
HeatTransfer
(turbulenceProperties=None, fvSolution=None, fvSchemes=None, residualControl=None, relaxationFactors=None, TRef=None)[source]¶ Bases:
butterfly.recipe._SingleCommandRecipe
Recipe for heat transfer.
This recipe excutes buoyantBoussinesqSimpleFoam for the input case.
-
turbulenceProperties
¶ Turbulence properties.
-
fvSolution
¶ Optional input for fvSolution to overwrite default fvSolution.
-
fvSchemes
¶ Optional input for fvSchemes to overwrite default fvSchemes.
-
residualControl
¶ A dictionary of values for residualControl of quantities.
-
relaxationFactors
¶ A list of values for relaxationFactors of quantities.
-
prepare_case
(case, overwrite=False, remove=False)[source]¶ Prepare a case for this recipe.
This method sets up the application in control dict and double checks files under Zero folder for each quantities. It creates, overwrites or removes the files if needed. Solution class calls this method on initialization.
Parameters: - case – A Butterfly case.
- overwrite – Set to True to overwrite current files.
- remove – Set to True to remove extra files in the folder.
-
-
class
butterfly.recipe.
SteadyIncompressible
(turbulenceProperties=None, fvSolution=None, fvSchemes=None, residualControl=None, relaxationFactors=None)[source]¶ Bases:
butterfly.recipe._SingleCommandRecipe
Recipe for Steady Incompressible flows.
This recipe excutes simpleFoam for the input case.
-
turbulenceProperties
¶ Turbulence properties.
-
fvSolution
¶ Optional input for fvSolution to overwrite default fvSolution.
-
fvSchemes
¶ Optional input for fvSchemes to overwrite default fvSchemes.
-
residualControl
¶ A dictionary of values for residualControl of quantities.
-
relaxationFactors
¶ A list of values for relaxationFactors of quantities.
-
butterfly.refinementRegion module¶
Butterfly refinement region.
-
class
butterfly.refinementRegion.
Distance
(levels)[source]¶ Bases:
butterfly.refinementRegion._RefinementMode
Distance refinement mode.
-
levels
¶ A list of (x, y) values for levels. ‘levels’ specifies per distance to the geometry the wanted refinement level.
-
-
class
butterfly.refinementRegion.
Inside
(level)[source]¶ Bases:
butterfly.refinementRegion._RefinementMode
Inside refinement mode.
-
level
¶ Refinement level as an integer. All cells inside the geometry get refined up to the level. The geometry needs to be closed for this to be possible.
-
-
class
butterfly.refinementRegion.
Outside
(level)[source]¶ Bases:
butterfly.refinementRegion.Inside
Outside refinement mode.
-
level
¶ Refinement level as an integer. All cells inside the geometry get refined up to the level. The geometry needs to be closed for this to be possible.
-
-
class
butterfly.refinementRegion.
RefinementRegion
(name, vertices, face_indices, normals, refinement_mode)[source]¶ Bases:
butterfly.geometry._BFMesh
Butterfly refinement region.
-
name
¶ Name as a string (A-Z a-z 0-9 _).
-
vertices
¶ A flatten list of (x, y, z) for vertices.
-
face_indices
¶ A flatten list of (a, b, c) for indices for each face.
-
normals
¶ A flatten list of (x, y, z) for face normals.
-
refinement_mode
¶ Refinement mode (0: inside, 1: outside, 2: distance)
-
isRefinementRegion
¶ Return True for Butterfly refinement region.
-
refinement_mode
Boundary condition.
-
butterfly.runmanager module¶
Runmanager for butterfly.
Run manager is only useful for running OpenFOAM for Windows which runs in a docker container. For linux systems simply use .bash files or libraries such as pyFOAM.
-
class
butterfly.runmanager.
RunManager
(project_name)[source]¶ Bases:
object
RunManager to write and run OpenFOAM commands through batch files.
Run manager is currently only useful for running OpenFOAM for Windows which runs in a docker container. For linux systems simply use .bash files or libraries such as pyFOAM.
-
check_file_contents
(files, mute=False)[source]¶ Check files for content and print them out if any.
Parameters: files – A list of ASCII files. Returns: (hasContent, content) hasContent: A boolean that shows if there is any contents. content: Files content if any
-
command
(cmd, args=None, decomposeParDict=None, include_header=True)[source]¶ Get command line for an OpenFOAM command in parallel or serial.
Parameters: - cmd – An OpenFOAM command.
- args – List of optional arguments for command. e.g. (‘c’, ‘latestTime’)
- decomposeParDict – decomposeParDict for parallel runs (default: None).
- include_header – Include header lines to set up the environment (default: True).
- tee – Include tee in command line.
Returns: (cmd, logfiles, errorfiles)
-
container_id
¶ Container ID.
-
ensure_user_is_admin
()[source]¶ Ensure user is logged in as admin.
If user is not admin raise UserNotAdminError.
-
is_user_admin
¶ Return True if user is admin.
-
pid
¶ Return PID for the latest command.
-
shellinit
= None¶
-
butterfly.sampleDict module¶
sampleDict class.
-
class
butterfly.sampleDict.
SampleDict
(values=None)[source]¶ Bases:
butterfly.foamfile.Condition
Probes function.
-
fields
¶ Get and set probes fields from list of tuples.
-
filename
¶ Get SampleDict filename.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
output_filenames
¶ A tuple of output file names.
-
points
¶ Get and set probe locations from list of tuples.
-
points_count
¶ Get number of probes.
-
butterfly.snappyHexMeshDict module¶
snappyHexMeshDict class.
-
class
butterfly.snappyHexMeshDict.
SnappyHexMeshDict
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Control dict class.
-
addLayers
¶ Set if addLayers should be ran.
-
add_stl_geometry
(file_name)[source]¶ Add stl geometry to snappyHexMeshDict.
Parameters: file_name – Stl file name. This file should be located under /constant/triSurface.
-
castellatedMesh
¶ Set if castellatedMesh should be ran.
-
extractFeaturesRefineLevel
¶ A refinment value for extract feature level.
-
features
¶ Set features for castellatedMeshControls.
-
classmethod
from_bf_geometries
(project_name, geometries, meshing_parameters=None, convertToMeters=1, values=None)[source]¶ Create snappyHexMeshDict from HBGeometries.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
geometries
¶ Butterfly geometries.
-
globRefineLevel
¶ A tuple of (min, max) values for global refinment.
-
is_featureEdgeRefinement_implicit
¶ Return True if implicit feature refinment is used.
-
locationInMesh
¶ A tuple for the location of the volume the should be meshed.
x, y, z values will be multiplied to self.convertToMeters. If the units are not Meters you can set the convertToMeters using self.convertToMeters
-
maxGlobalCells
¶ Number of max global cells for castellatedMeshControls (default – 2000000).
-
nCellsBetweenLevels
¶ Number of cells between levels for castellatedMeshControls (default – 3).
-
project_name
¶ Project name.
-
refinementRegion_mode
(refinementRegion_name)[source]¶ Refinement region mode for a refinement region.
-
refinementRegion_names
¶ List of stl files if any.
-
refinementRegions
¶ Refinement regions.
-
set_featureEdgeRefinement_to_explicit
(file_name, refinement_level=2)[source]¶ Set meshing snap to explicitFeatureSnap.
Parameters: - file_name – eMesh file name.
- refinement_level – extractFeaturesRefineLevel (default: 2)
-
snap
¶ Set if snap should be ran.
-
stl_file_names
¶ List of names for stl files if any.
This method doesn’t return stl files for refinementRegions. You can use self.refinementRegion_names to get the names for refinment regions.
-
butterfly.solution module¶
Butterfly Solution.
-
class
butterfly.solution.
Solution
(case, recipe, decomposeParDict=None, solution_parameter=None, remove_extra_foam_files=False)[source]¶ Bases:
object
Butterfly Solution.
This class creates a solution from a recipe which is ready to run and monitor.
Parameters: - case – A butterfly case.
- recipe – A butterfly recipe.
- decomposeParDict – decomposeParDict for parallel run (default: None).
- solution_parameter – A SolutionParameter (default: None).
- remove_extra_foam_files – set to True if you want butterfly to remove all the extra files in 0 folder once you update the recipe (default: False).
-
case
¶ Case.
-
controlDict
¶ Get controlDict.
-
decomposeParDict
¶ DecomposeParDict.
-
err_files
¶ Get full path to error files.
-
info
¶ Get timestep and residual values as a tuple.
-
is_running
¶ Check if the solution is still running.
-
log
¶ Get the log report.
-
log_files
¶ Get full path to log files.
-
probes
¶ Get probes if any.
-
project_dir
¶ Get project directory.
-
project_name
¶ Get porject name.
-
purge
(remove_polyMesh_content=True, remove_snappyHexMesh_folders=True, remove_result_folders=False, remove_postProcessing_folder=False)[source]¶ Purge solution’s case folder.
-
recipe
¶ Get recipe.
-
remove_extra_foam_files
¶ If True, solution will remove extra files everytime recipe changes.
-
residualControl
¶ Get residualControl values for this solution.
-
residual_fields
¶ Get list of residuals to be watched during the run.
-
residual_file
¶ Return address of the residual file.
-
residual_values
¶ Get timestep and residual values as a tuple.
-
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).
-
timestep
¶ Get latest timestep for this solution.
-
class
butterfly.solution.
SolutionParameter
(of_filename, values, replace=False, time_range=None)[source]¶ Bases:
object
A solution parameter that can be changed during the solution.
Add solution parameter to to solution settings.
-
filename
¶ OpenFOAM filename that the values are belong to (e.g. blockMeshDict, fvSchemes).
-
values
¶ New values as a python dictionary.
-
replace
¶ Set to True if you want the original dictionary to be replaced by new values. Default is False which means the original dictionary will be only updated by new values.
-
time_range
¶ Time range that this SolutioParameter is valid as a tuple (default: (0, 1.0e+100)).
-
filename
Return OpenFOAM file name.
-
classmethod
from_cpp_dictionary
(of_filename, dictionary, replace=False, time_range=None, header=False)[source]¶ Create from an OpenFOAM dictionary in text format.
-
classmethod
from_dictionary_file
(of_filename, filepath, replace=False, time_range=None)[source]¶ Create from an OpenFOAM dictionary file.
-
isSolutionParameter
¶ Return True.
-
time_range
Get time range.
-
values
Return OpenFOAM file name.
-
butterfly.surfaceFeatureExtractDict module¶
Finite Volume Solution class.
-
class
butterfly.surfaceFeatureExtractDict.
SurfaceFeatureExtractDict
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
surfaceFeatureExtractDict class.
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
classmethod
from_stl_file
(file_name, extractionMethod='extractFromSurface', includedAngle=150, geometricTestOnly=True, writeObj=False)[source]¶ Generate fvSolution for a particular recipe.
Parameters: - file_name – stl file name (e.g. project.stl)
- extractionMethod – Indicate how to obtain raw features. extractFromFile or extractFromSurface
- includedAngle – An integer for the max angle between the faces to be considered as two different faces and so the edge between them will be considered as an edge. 0 > selects no edges and 180 > selects all edges (default: 150).
- geometricTestOnly – A Boolean (default: True).
- writeObj – A Boolean to write features to obj format for postprocessing. (default: False)
-
classmethod
butterfly.transportProperties module¶
TransportProperties class.
-
class
butterfly.transportProperties.
TransportProperties
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Transport Properties class.
-
Cp0
¶
-
Pr
¶
-
Prt
¶
-
TRef
¶
-
beta
¶
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
nu
¶
-
transportModel
¶
-
butterfly.turbulenceProperties module¶
turbulenceProperties class.
Use turbulenceProperties for versions prior to 3.0+
-
class
butterfly.turbulenceProperties.
TurbulenceProperties
(values=None)[source]¶ Bases:
butterfly.foamfile.FoamFile
Turbulence Properties class.
-
classmethod
LES
(LESModel='kEqn', delta='cubeRootVol', turbulence=True, printCoeffs=True, LESModel_coeffs=None, delta_coeffs=None)[source]¶ Large eddy simulation (LES) modelling.
Parameters: - LESModel –
Name of LES turbulence model. Incompressible LES turbulence models.
DeardorffDiffStress, Smagorinsky, SpalartAllmarasDDES, SpalartAllmarasDES, SpalartAllmarasIDDES, WALE, dynamicKEqn, dynamicLagrangian, kEqn, kOmegaSSTDES- Compressible LES turbulence models.
- DeardorffDiffStress, Smagorinsky, SpalartAllmarasDDES, SpalartAllmarasDES, SpalartAllmarasIDDES, WALE, dynamicKEqn, dynamicLagrangian, kEqn, kOmegaSSTDES
- delta – Name of delta model.
- turbulence – Boolean switch to turn the solving of turbulence modelling on/off (default: True).
- printCoeffs – Boolean switch to print model coeffs to terminal at simulation start up (default: True).
- LESModel_coeffs – Dictionary of coefficients for the respective LESModel, to override the default coefficients.
- delta_coeffs – Dictionary of coefficients for the delta model.
- LESModel –
-
classmethod
RAS
(RASModel='RNGkEpsilon', turbulence=True, printCoeffs=True, RASModel_coeffs=None)[source]¶ Reynolds-averaged simulation (RAS) turbulence model.
Read more: http://cfd.direct/openfoam/user-guide/turbulence/ Watch this: https://www.youtube.com/watch?v=Eu_4ppppQmw
Parameters: - RASModel –
Name of RAS turbulence model (default: RNGkEpsilon). Incompressible RAS turbulence models:
LRR, LamBremhorstKE, LaunderSharmaKE, LienCubicKE, LienLeschziner, RNGkEpsilon, SSG, ShihQuadraticKE, SpalartAllmaras, kEpsilon, kOmega, kOmegaSSTSAS, kkLOmega, qZeta, realizableKE, v2f- Compressible RAS turbulence models:
- LRR, LaunderSharmaKE, RNGkEpsilon, SSG, SpalartAllmaras, buoyantKEpsilon, kEpsilon, kOmega, kOmegaSSTSAS, realizableKE, v2f
- turbulence – Boolean switch to turn the solving of turbulence modelling on/off (default: True).
- printCoeffs – Boolean switch to print model coeffs to terminal at simulation start up (default: True).
- RASModel_coeffs – Optional dictionary of coefficients for the respective RASModel, to override the default coefficients.
- RASModel –
-
classmethod
from_file
(filepath)[source]¶ Create a FoamFile from a file.
Parameters: filepath – Full file path to dictionary.
-
isTurbulenceProperties
¶ Return True.
-
classmethod
butterfly.utilities module¶
Collection of useful methods.
-
butterfly.utilities.
get_boundary_field_from_geometries
(bf_geometries, field='U')[source]¶ Get data for boundaryField as a dictionary.
Parameters: - bf_geometries – List of Butterfly geometries.
- parameter – One of the fileds as a string (U , p, k , epsilon, nut)
Returns: A dictionary of data that can be passed to snappyHexMeshDict.
-
butterfly.utilities.
get_snappyHexMesh_geometry_feild
(project_name, bf_geometries, meshing_type='triSurfaceMesh', stl_file=None)[source]¶ Get data for Geometry as a dictionary.
Parameters: - project_name – Name of OpenFOAM case.
- bf_geometries – List of Butterfly geometries.
- meshing_type – Meshing type. (Default: triSurfaceMesh)
- stl_file – Name of .stl file if it is different from project_name.stl
Returns: A dictionary of data that can be passed to snappyHexMeshDict.
-
butterfly.utilities.
get_snappyHexMesh_refinement_surfaces
(project_name, bf_geometries, global_levels=None)[source]¶ Get data for MeshRefinementSurfaces as a dictionary.
Parameters: - project_name – Name of OpenFOAM case.
- bf_geometries – List of Butterfly geometries.
- global_levels – Default Min, max level of geometry mesh refinement.
Returns: A dictionary of data that can be passed to snappyHexMeshDict.
-
butterfly.utilities.
get_snappyHexMesh_surface_layers
(bf_geometries)[source]¶ Get data for n_surface_layers as a dictionary.
Parameters: bf_geometries – List of Butterfly geometries. Returns: A dictionary of data that can be passed to snappyHexMeshDict.
-
butterfly.utilities.
load_case_files
(folder, fullpath=False)[source]¶ load openfoam files from a folder.
-
butterfly.utilities.
load_of_boundary_file
(path_to_file)[source]¶ Return Face indecies for boundary faces as a set.
-
butterfly.utilities.
load_of_faces_file
(path_to_file, inner_mesh=True)[source]¶ Return faces indecies as a generator of tuples.
-
butterfly.utilities.
load_of_points_file
(path_to_file)[source]¶ Return points as a generator of tuples.
-
butterfly.utilities.
load_probe_values_from_folder
(probes_folder, field)[source]¶ Return OpenFOAM probe values for a field for the last timestep.
Parameters: field – Probes field (e.g. U, p, T).
-
butterfly.utilities.
load_probes_and_values_from_sample_file
(fp)[source]¶ Load probes and respected values from the results of a sample file.
-
butterfly.utilities.
load_probes_from_postProcessing_file
(probes_folder, field)[source]¶ Return a generator of probes as tuples.
Parameters: - probes_folder – full path to probes folder.
- field – Probes field (e.g. U, p, T).
-
butterfly.utilities.
mkdir
(directory, overwrite=True)[source]¶ Make a directory.
Parameters: - directory – directory as a string.
- overwrite – A boolean to overwrite the folder if already exists.
-
butterfly.utilities.
read_last_line
(filepath, block_size=1024)[source]¶ Read the last line of a file.
Modified from: http://www.manugarg.com/2007/04/tailing-in-python.html :param filepath: path to file :param block_size: data is read in chunks of this size (optional, default=1024)
Raises: IOError if file cannot be processed.
-
butterfly.utilities.
run_batch_file
(filepath, wait=True)[source]¶ run an executable .bat file.
Parameters: wait – Wait for analysis to finish (default: True). Returns: Popen process.
-
butterfly.utilities.
update_dict
(d, u)[source]¶ Update a dictionary witout overwriting the currect values.
source: http://stackoverflow.com/a/3233356/4394669 :param d: original dictionary. :param u: new dictionary.
butterfly.vectormath module¶
Calculate anitclockwise angle between two vectors.
-
butterfly.vectormath.
angle_anitclockwise
(v1, v2)[source]¶ Calculate clockwise angle between two 2D vectors.
butterfly.version module¶
Versions and header.
butterfly.windtunnel module¶
Butterfly wind tunnel.
-
class
butterfly.windtunnel.
TunnelParameters
(windward=3, top=5, side=5, leeward=15)[source]¶ Bases:
object
Wind tunnel parameters.
Each parameter will be multiplied by multiple height.
Parameters: - windward – Multiplier value for windward extension (default: 3).
- top – Multiplier value for top extension (default: 5).
- side – Multiplier value for side extension (default: 5).
- leeward – Multiplier value for leeward extension (default: 15).
-
class
butterfly.windtunnel.
WindTunnel
(name, inlet, outlet, sides, top, ground, test_geomtries, roughness, meshing_parameters=None, Zref=None, convertToMeters=1)[source]¶ Bases:
object
Butterfly WindTunnel.
Parameters: - inlet – Inlet as a butterfly geometry. inlet boundary condition should be ABL (atmBoundaryLayer).
- outlet – Outlet as a butterfly geometry.
- sides – Left and right side geometries as butterfly geometries.
- top – Top face as buttefly geometry.
- ground – Ground face as butterfly geometry.
- test_geomtries – A list of geometries as butterfly geometries that are located within bounding box boundary.
- roughness – z0 (roughness) value. ‘0.0002’ # sea ‘0.005’ # smooth ‘0.03’ # open ‘0.10’ # roughlyOpen ‘0.25’ # rough ‘0.5’ # veryRough ‘1.0’ # closed ‘2.0’ # chaotic
- Zref – Reference height for wind velocity in meters (default: 10).
-
ABLConditionsDict
¶ Get ABLCondition for this wind tunnel as a dictionary.
-
blockMeshDict
¶ Wind tunnel blockMeshDict.
-
bounding_geometries
¶ Return bounding geometries of wind tunnel.
-
calculate_grading
(cell_size=1, expansion_ratio=1.2, wake_offset=2, height_offset=5, z_mode=0)[source]¶ Calculate simpleGrading for this wind tunnel based on best practice.
This method calcutes grading for blockMeshDict based on the size of the wind tunnel and the bounding box of the geometries.
Parameters: - cell_size – Cell size in the area of interest (default: 1).
- expansion_ratio – expansion ratio for the segments outside the area of interest (default: 1.2).
- wake_offset – The length to be added to the end of geometries bounding box to be considerd as part of area of interest (default: 2).
- height_offset – The length to be added to the topic of geometries bounding box to be considerd as part of area of interest (default: 5).
- z_mode – If 0 special treatment will be considerd for the first 2 and 10 meters. The first 2 meters will be graded for each half meter and from 2-10 it will be graded 0.5-1, from 10 to maximum height it will be 1-5 if expansion ration is less than expansion ratio then expansion ratio will be used. After 10 meters normal expansion_ratio will be used. If 1, z direction will be treated similar to x and y (default: 0).
Returns: SimpleGrading, cell_count as (x_count, y_count, z_count)
-
flowDir
¶ Get flow direction for this wind tunnel as a tuple (x, y, z).
-
flow_speed
¶ Get flow speed for this wind tunnel.
-
classmethod
from_geometries_wind_vector_and_parameters
(name, geometries, wind_vector, tunnel_parameters, roughness, meshing_parameters=None, Zref=None, convertToMeters=1)[source]¶ Create a wind_tunnel based on size, wind speed and wind direction.
-
get_internal_dimensions
()[source]¶ Get internal dimensions of wind tunnel.
This method returns three tuples for x, y and z which are (distance_to_geometry_bounding_box, geometry_bounding_box,
distance_after_geometry_bounding_box). This method is useful to get initial values to calculate grading.
-
height
¶ Get width in x direction.
-
length
¶ Get width in x direction.
-
meshing_parameters
¶ Meshing parameters.
-
refinementRegions
¶ Get refinement regions.
-
save
(overwrite=False, minimum=True, make2d_parameters=None)[source]¶ Save wind_tunnel to folder as an OpenFOAM case.
Parameters: overwrite – If True all the current content will be overwritten (default: False). Returns: A butterfly.Case.
-
width
¶ Get width in x direction.
-
zGround
¶ Minimum z value of the bounding box.
butterfly.z0 module¶
Roughness values.
-
class
butterfly.z0.
Z0
[source]¶ Bases:
object
Typical roughness values based on landscape.
-
chaotic
¶ Roughness value for center of large towns.
-
closed
¶ Roughness value for landscape totally and quite regularly covered.
-
open
¶ Roughness value for country with low vegetation.
-
rough
¶ Roughness value for new landscape with scattred obstacles.
-
roughly_open
¶ Roughness value for cultivated area with regular cover of low crops.
-
sea
¶ Roughness value for open sea or lake.
-
smooth
¶ Roughness value for featureless land geometries.
-
very_rough
¶ Roughness value for ‘old’ cultivated landscape.
-