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.

header()[source]

Return conditions header.

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)

ToString()[source]

Overwrite .NET ToString method.

body()[source]

Return body string.

static convert_bool_value(v=True)[source]

Convert Boolean values to on/off string.

duplicate()[source]

Return a copy of this object.

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.
header()[source]

Return open foam style 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.
to_openfoam()[source]

Return OpenFOAM 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).

classmethod from_bf_geometries(bf_geometries, values=None)[source]

Init class by bf_geometries.

get_boundary_field(name)[source]

Try to get boundaryField value for a geometry by name.

Parameters:name – Geometry name.
Returns:An OpenFOAM field if name is in boundaryFields.
set_boundary_field(bf_geometries)[source]

Set FoamFile boundaryField values from bf_geometries.

Parameters:bf_geometries – List of Butterfly geometries.
butterfly.foamfile.foam_file_from_file(filepath, name=None, header=False)[source]

Load values from foamfile.

Parameters:
  • filepath – Full file path to dictionary.
  • name – An optional name for foamfile to double check.
  • header – Set to True to get FoamFile data.