dafi.random_field.foam¶
OpenFOAM I/O.
These functions are accesible from dafi.random_field.foam.
- dafi.random_field.foam_utilities.foam_header_info(name, foamclass, location=None, isfield=True)[source]¶
Write the info part of the OpenFOAM file header.
Used by
write_field_file().- Parameters:
name (str) – Field name (e.g. ‘p’).
foamclass (str) – OpenFOAM class (e.g. ‘scalar’).
location (str) – File location (optional).
- Returns:
header – OpenFOAM file header info.
- Return type:
str
- dafi.random_field.foam_utilities.foam_header_logo(foam_version, website)[source]¶
Write the logo part of the OpenFOAM file header.
Used by
write_field_file().- Parameters:
foam_version (str) – OpenFOAM version to write in the header.
website (str) – OpenFOAM website to write in the header.
- Returns:
header – OpenFOAM file header logo.
- Return type:
str
- dafi.random_field.foam_utilities.foam_sep()[source]¶
Write a separation comment line.
Used by
write_field_file().- Returns:
sep – Separation comment string
- Return type:
str
- dafi.random_field.foam_utilities.get_cell_centres(foam_case='.', group='internalField', keep_file=False, foam_rc=None)[source]¶
Get the coordinates of cell centers in an OpenFOAM case.
Requires OpenFOAM to be sourced.
- Parameters:
foam_case (str) – Name (path) of OF case directory.
keep_file (bool) – Whether to keep the file (C) generated by the OpenFOAM post-processing utility.
foam_rc (str) – File for sourcing OpenFOAM.
- Returns:
coords – Cell center coordinates (x, y, z). dtype=float, ndim=2, shape=(ncells, 3)
- Return type:
ndarray
- dafi.random_field.foam_utilities.get_cell_volumes(foam_case='.', keep_file=False, foam_rc=None)[source]¶
Get the volume of each cell in an OpenFOAM case.
Requires OpenFOAM to be sourced.
- Parameters:
foam_case (str) – Name (path) of OF case directory.
keep_file (bool) – Whether to keep the file (V) generated by the OpenFOAM post-processing utility.
foam_rc (str) – File for sourcing OpenFOAM.
- Returns:
vol – Cell volumes. dtype=float, ndim=1, shape=(ncells)
- Return type:
ndarray
- dafi.random_field.foam_utilities.get_neighbors(foam_case='.')[source]¶
Get the neighbors of each cell (connectivity).
- Parameters:
foam_case (str) – Name (path) of OF case directory.
- Returns:
connectivity – The keys are cell’s index and the values are a list of indices for the cells that neighbor it.
- Return type:
dictionary
- dafi.random_field.foam_utilities.get_number_cells(foam_case='.', foam_rc=None)[source]¶
Get the number of cells in an OpenFOAM case.
Requires OpenFOAM to be sourced, since it calls the
checkMeshutility.- Parameters:
foam_case (str) – Name (path) of OF case directory.
foam_rc (str) – File for sourcing OpenFOAM.
- Returns:
ncells – Number of cells.
- Return type:
int
- dafi.random_field.foam_utilities.read_cell_centres(file='C', group='internalField')[source]¶
Read an OpenFOAM mesh coordinate file.
See
read_field()for more information.
- dafi.random_field.foam_utilities.read_cell_volumes(file='V')[source]¶
Read an OpenFOAM mesh volume file.
See
read_field()for more information.
- dafi.random_field.foam_utilities.read_field(file, ndim, group='internalField')[source]¶
Read the field values from an OpenFOAM field file.
Can read either the internal field or a specified boundary.
- Parameters:
file (str) – Name of OpenFOAM field file.
ndim (int) – Field dimension (e.g. 1 for scalar field).
group (str) – Name of the group to read: ‘internalField’ or name of specific boundary.
- Returns:
data – Field values on specified group. dtype=float, ndim=2, shape=(ncells, ndim)
- Return type:
ndarray
- dafi.random_field.foam_utilities.read_field_file(file)[source]¶
Read a complete OpenFOAM field file.
This includes header information not just the field values. The output can be directly used to write the file again, e.g.
>>> content = read_field_file(file) >>> write_field_file(**content).
- Parameters:
file (str) – Name (path) of OpenFOAM field file.
- Returns:
info – The contents of the file organized with the same structure as the inputs to the
write_field_file()method. Seewrite_field_file()for more information.- Return type:
dictionary
- dafi.random_field.foam_utilities.read_header(file)[source]¶
Read the information in an OpenFOAM file header.
- Parameters:
file (str) – Name (path) of OpenFOAM file.
- Returns:
info – The information in the file header.
- Return type:
dictionary
- dafi.random_field.foam_utilities.read_scalar_field(file, group='internalField')[source]¶
Read an OpenFOAM scalar field file.
See
read_field()for more information.
- dafi.random_field.foam_utilities.read_symmTensor_field(file, group='internalField')[source]¶
Read an OpenFOAM symmTensor field file.
See
read_field()for more information.
- dafi.random_field.foam_utilities.read_tensor_field(file, group='internalField')[source]¶
Read an OpenFOAM tensor field file.
See
read_field()for more information.
- dafi.random_field.foam_utilities.read_vector_field(file, group='internalField')[source]¶
Read an OpenFOAM vector field file.
See
read_field()for more information.
- dafi.random_field.foam_utilities.write(version, fieldname, internal_field, boundaries, location=None, file=None)[source]¶
Write an OpenFOAM field file for one of the pre-specified fields.
The implemented fields are: ‘p’, ‘k’, ‘epsilon’, ‘omega’, ‘nut’, ‘Cx’, ‘Cy’, ‘Cz’, ‘V’, ‘U’, ‘C’, ‘Tau’, ‘grad(U)’. This calls
write_field_file()but requires less information.- Parameters:
version (str) – OpenFOAM version. Must be length 1 (e.g. ‘7’) or 4 (e.g. ‘1912’).
fieldname (str) – One of the pre-defined fields.
internal_field (dictionary) – See
write_field_file().boundaries (list) – See
write_field_file().location (str) – See
write_field_file().file (str) – See
write_field_file().
- dafi.random_field.foam_utilities.write_Tau(version, internal, boundaries, location=None, file=None)[source]¶
Write a Reynolds stress field file.
See
write()for more information.
- dafi.random_field.foam_utilities.write_U(version, internal, boundaries, location=None, file=None)[source]¶
Write a velocity field file.
See
write()for more information.
- dafi.random_field.foam_utilities.write_controlDict(content, foam_version, website, ofcase=None)[source]¶
- Parameters:
content (dict) – Content of controlDict.
foam_version (str) – OpenFOAM version to write in the header.
website (str) – OpenFOAM website to write in the header.
ofcase (str) – OpenFOAM directory. File will be written to <ofcase>/system/controlDict. If None file will be written in current directory.
- Returns:
file_loc (str) – Location (absolute path) of file written.
file_content (str) – Content written to file.
- dafi.random_field.foam_utilities.write_epsilon(version, internal, boundaries, location=None, file=None)[source]¶
Write a TKE dissipation rate field file.
See
write()for more information.
- dafi.random_field.foam_utilities.write_field_file(name, foam_class, dimensions, internal_field, boundaries, foam_version, website, location=None, file=None)[source]¶
Write an OpenFOAM field file.
- Parameters:
name (str) – Field name (e.g. ‘p’).
foam_class (str) – OpenFOAM class (e.g. ‘scalar’).
dimensions (str or list) – Field dimensions in SI units using OpenFOAM convention (e.g. ‘[0 2 -2 0 0 0 0]’). Alternatively can be a list of 7 or 3 integers. If three (MLT) zeros will be appended at the end, i.e. [M L T 0 0 0 0].
internal_field (dictionary) – Dictionary containing internal field information. See note below for more information.
boundaries (list) – List containing one dictionary per boundary. Each dictionary contains the required information on that boundary. See note below for more information.
foam_version (str) – OpenFOAM version to write in the header.
website (str) – OpenFOAM website to write in the header.
location (str) – File location (optional).
file (str) – File name (path) where to write field. If ‘None’ will write in current directory using the field name as the file name.
- Returns:
file_loc (str) – Location (absolute path) of file written.
file_content (str) – Content written to file.
Note
- internal_field
The
internal_fielddictionary must have the following entries:- uniform - bool
Whether the internal field has uniform or nonuniform value.
- value - float or ndarray
The uniform or nonuniform values of the internal field.
- boundaries
Each boundary dictionary in the
boundarieslist must have the following entries:- name - str
Boundary name.
- type - str
Boundary type.
- value - dict (optional)
Dictionary with same entries as the ‘internal_field’ dictionary.
- dafi.random_field.foam_utilities.write_k(version, internal, boundaries, location=None, file=None)[source]¶
Write a turbulent kinetic energy (TKE) field file.
See
write()for more information.
- dafi.random_field.foam_utilities.write_nut(version, internal, boundaries, location=None, file=None)[source]¶
Write an eddy viscosity field file.
See
write()for more information.