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.list_files(folder, fullpath=False)[source]

list files in a folder.

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

Return list of skipped points as tuples.

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.tail(file_path, lines=20)[source]

Get tail of the file.

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.utilities.write_to_file(full_path, content)[source]

write string content to a file.