caelus.io – CML Input File Manipulation¶
Caelus/OpenFOAM Input File Interface¶
- class caelus.io.dictfile.BlockMeshDict(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
constant/polyMesh/blockMeshDict interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property blocks¶
- property boundary¶
- property convertToMeters¶
- property edges¶
- property mergePatchPairs¶
- property vertices¶
- class caelus.io.dictfile.ChangeDictionaryDict(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
system/changeDictionaryDict interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property dictionaryReplacement¶
- class caelus.io.dictfile.CmlControls(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
cmlControls interface
- Parameters:
filename (path) – Path to the input file
- class caelus.io.dictfile.ControlDict(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
system/controlDict interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property adjustTimeStep¶
- property application¶
- property deltaT¶
- property endTime¶
- property functions¶
function object definitions in controlDict
- property graphFormat¶
- property maxCo¶
- property purgeWrite¶
- property runTimeModifiable¶
- property startFrom¶
- property startTime¶
- property stopAt¶
- property timeFormat¶
- property timePrecision¶
- property writeCompression¶
- property writeControl¶
- property writeFormat¶
- property writeInterval¶
- property writePrecision¶
- class caelus.io.dictfile.DecomposeParDict(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
system/decomposeParDict interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property method¶
- property numberOfSubdomains¶
- class caelus.io.dictfile.DictFile(filename=None, populate_defaults=True)[source]¶
Bases:
object
Caelus/OpenFOAM input file reader/writer
The default constructor does not read a file, but instead creates a new input file object. If a property list is provided, this is used to initialize the default entries. To read an existing file, the use of
DictFile.read_if_present()
method is recommended.- Parameters:
filename (path) – Path to the input file
- classmethod load(filename=None, debug=False)[source]¶
Load a Caelus input file from disk
- Parameters:
filename (path) – Path to the input files
debug (bool) – Turn on detailed errors
- classmethod read_if_present(casedir=None, filename=None, debug=False, populate_defaults=True)[source]¶
Read the file if present, else create object with default values
- Parameters:
casedir (path) – Path to the case directory
filename (path) – Filename to read
debug (bool) – Turn on detailed errors
populate_defaults (bool) – Populate the defaults
- write(casedir=None, filename=None, update_object=True, write_header=True)[source]¶
Write a formatted Caelus input file
- Parameters:
casedir (path) – Path to the case directory
filename (path) – Filename to write
update_object (bool) – Ensure object type is consistent
write_header (bool) – Write header for the file
- property contents¶
Access entries within the Caelus CML dictionary
- data¶
Contents of the file as a dictionary suitable for manipulation
- filename¶
File to read/write data
- header¶
Contents of the FoamFile sub-dictionary in the file
- class caelus.io.dictfile.DictMeta(name, bases, cdict)[source]¶
Bases:
type
Create property methods and add validation for properties.
This metaclass implements the boilerplate code necessary to add getter/setters for various entries found in a Caelus input file. It expects a class variable
_dict_properties
that contains tuples for the various entries in the input file. The tuple can be of two forms:(name, default_value)
(name, default_value, valid_values)
If the default_value is not None, then this value will be used to automatically initialize the particular entry by
create_default_entries()
method. Ifvalid_values
are provided, any attempt to set/modify this value will be checked to ensure that only the allowed values are used.
- class caelus.io.dictfile.FvSchemes(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
system/fvSchemes interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property ddtSchemes¶
- property divSchemes¶
- property fluxRequired¶
- property gradSchemes¶
- property interpolationSchemes¶
- property laplacianSchemes¶
- property snGradSchemes¶
- class caelus.io.dictfile.FvSolution(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
system/fvSolution interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property PIMPLE¶
- property PISO¶
- property SIMPLE¶
- property potentialFlow¶
- property relaxationFactors¶
- property solvers¶
- class caelus.io.dictfile.LESProperties(filename=None, populate_defaults=True)[source]¶
Bases:
TurbModelProps
constant/LESProperties interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()[source]¶
Create the default turbulence model entries
In addition to the default options specified in turbulence properties class, this also triggers the default entries for delta.
- property delta¶
LES delta
- class caelus.io.dictfile.PolyMeshBoundary(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
constant/polyMesh/boundary interface
- Parameters:
filename (path) – Path to the input file
- class caelus.io.dictfile.RASProperties(filename=None, populate_defaults=True)[source]¶
Bases:
TurbModelProps
constant/RASProperties interface
- Parameters:
filename (path) – Path to the input file
- class caelus.io.dictfile.TransportProperties(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
constant/transportProperties interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property transportModel¶
- class caelus.io.dictfile.TurbModelProps(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
Common interface for LES/RAS models
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property coeffs¶
Turbulence model coefficients
This represents the sub-dictionary (e.g., kOmegaSSTCoeffs, SmagorinksyCoeffs) containing the additional parameters necessary for the turbulence model. The accessor automatically populates the right name when generating the dictionary depending on the turbulence model selected.
- property model¶
Turbulence model
Depending on the type (RANS or LES), this is the entry RASModel or LESModel respectively in the RASProperties and LESProperties file. To simplify access, it is simply named model here.
- property printCoeffs¶
- property turbulence¶
- class caelus.io.dictfile.TurbulenceProperties(filename=None, populate_defaults=True)[source]¶
Bases:
DictFile
constant/turbulenceProperties interface
- Parameters:
filename (path) – Path to the input file
- create_default_entries()¶
Create defaults from property list
- property simulationType¶
- caelus.io.dictfile.cml_std_files = {'LESProperties': <class 'caelus.io.dictfile.LESProperties'>, 'RASProperties': <class 'caelus.io.dictfile.RASProperties'>, 'blockMeshDict': <class 'caelus.io.dictfile.BlockMeshDict'>, 'changeDictionaryDict': <class 'caelus.io.dictfile.ChangeDictionaryDict'>, 'cmlControls': <class 'caelus.io.dictfile.CmlControls'>, 'controlDict': <class 'caelus.io.dictfile.ControlDict'>, 'decomposeParDict': <class 'caelus.io.dictfile.DecomposeParDict'>, 'fvSchemes': <class 'caelus.io.dictfile.FvSchemes'>, 'fvSolution': <class 'caelus.io.dictfile.FvSolution'>, 'transportProperties': <class 'caelus.io.dictfile.TransportProperties'>, 'turbulenceProperties': <class 'caelus.io.dictfile.TurbulenceProperties'>}¶
Mapping of standard files known to exist in a case directory
Caelus/OpenFOAM Dictionary Implementation¶
- class caelus.io.caelusdict.CaelusDict[source]¶
Bases:
Struct
Caelus Input File Dictionary
- yaml_decoder¶
alias of
StructYAMLLoader
- yaml_encoder¶
alias of
StructYAMLDumper
Caelus/OpenFOAM Input File Datatypes
- class caelus.io.dtypes.BoundaryList(value)[source]¶
Bases:
FoamType
polyMesh/boundary file
- write_value(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_str='')[source]¶
Write as a Caelus/OpenFOAM entry
This method is called by
DictPrinter
to format the data suitable for writing to a Caelus input file that can be read by the solvers.- Parameters:
fh (file) – A valid file handle
indent_str (str) – Padding for indentation
- class caelus.io.dtypes.CalcDirective(directive, value)[source]¶
Bases:
FoamType
A
#calc
directive entry- Example::
radHalfAngle #calc “degToRad($halfAngle)”;
- class caelus.io.dtypes.CodeStream(value)[source]¶
Bases:
FoamType
A codestream entry
Contains C++ code that can be compiled and executed to determine dictionary parameters.
- class caelus.io.dtypes.DimStr(units)[source]¶
Bases:
FoamType
String dimensions
- write_value(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_str='')[source]¶
Write as a Caelus/OpenFOAM entry
This method is called by
DictPrinter
to format the data suitable for writing to a Caelus input file that can be read by the solvers.- Parameters:
fh (file) – A valid file handle
indent_str (str) – Padding for indentation
- class caelus.io.dtypes.DimValue(name, dims, value)[source]¶
Bases:
FoamType
A dimensioned value
A dimensioned value contains three parts: the name, units, and the value. Units are of type
Dimension
and value can be a scalar, vector, tensor or a symmetric tensor.
- class caelus.io.dtypes.Dimension(units=None, **kwargs)[source]¶
Bases:
FoamType
Caelus dimensional units
Represents the units of a dimensional quantity as an array of seven integers that represent the powers of the fundamental units: mass, length, time, temperature, quantity, current, and luminous intensity.
Provide an array of individual units as keyword arguments
- Parameters:
units (list) – A list of 5 or 7 entries
- class caelus.io.dtypes.Directive(directive, value)[source]¶
Bases:
FoamType
A Caelus directive type
Directives are keyword-less entries that indicate certain processing actions and begin with a hash (
#
) symbol. For example, the#includeEtc
directive that can be used to include files fromfoamEtc
directory.- write_value(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_str='', nested=False)[source]¶
Write out the dimensional value
- directive¶
Type of directive (str)
- value¶
Value of the directive (e.g., file to be included)
- class caelus.io.dtypes.EvalDirective(directive, value)[source]¶
Bases:
FoamType
A
#eval
directive entryExamples
timeStart #eval #{ 0.1 * ${/endTime} #}; r0CosT #eval{ $r0*cos(degToRad($t )) };
- write_value(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_str='')[source]¶
Write as a Caelus/OpenFOAM entry
This method is called by
DictPrinter
to format the data suitable for writing to a Caelus input file that can be read by the solvers.- Parameters:
fh (file) – A valid file handle
indent_str (str) – Padding for indentation
- class caelus.io.dtypes.Field(ftype, value)[source]¶
Bases:
FoamType
A field declaration
This class represents both uniform and non-uniform fields. The attribute
ftype
indicates the type of field and thevalue
contains the value for the given field. Uniform fields can be scalar, vector, tensor, or symmetric tensors. Non-uniform fields are typically aListTemplate
entity.- write_nonuniform(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Write a non-uniform field
- class caelus.io.dtypes.FoamType[source]¶
Bases:
object
Base class for a FOAM type
- abstract write_value(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_str='')[source]¶
Write as a Caelus/OpenFOAM entry
This method is called by
DictPrinter
to format the data suitable for writing to a Caelus input file that can be read by the solvers.- Parameters:
fh (file) – A valid file handle
indent_str (str) – Padding for indentation
- class caelus.io.dtypes.MacroSubstitution(value, semi=True)[source]¶
Bases:
FoamType
Macro substition without keyword
- class caelus.io.dtypes.MultipleValues(value)[source]¶
Bases:
FoamType
Multiple values for single keyword
- Example::
laplacian(nuEff,U) Gauss linear corrected;
Here “Gauss linear corrected” is stored as an instance of this class to disambiguate between multi-valued entries and plain lists.
- write_value(fh=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_str='')[source]¶
Write as a Caelus/OpenFOAM entry
This method is called by
DictPrinter
to format the data suitable for writing to a Caelus input file that can be read by the solvers.- Parameters:
fh (file) – A valid file handle
indent_str (str) – Padding for indentation
Caelus Input File Pretty-printer¶
- class caelus.io.printer.DictPrinter(buf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, tab_width=4)[source]¶
Bases:
object
Caelus Input File Pretty-printer
Given a CaelusDict instance, this class will emit formatted data suitable for use with Caelus solvers
- Parameters:
buf (file handle) – A valid buffer to output to
tab_width (int) – Indentation width
- write_dict(value)[source]¶
Pretty-print a Caelus dictionary type
- Parameters:
value (Mapping) – A valid python dict-like instance
- write_dict_item(key, value, nested=False)[source]¶
Pretty-print a dictionary entry
- Parameters:
key (str) – Keyword for the parameter
value (object) – Value for the keyword
nested (bool) – Flag indicating whether the entries are nested
- write_list(value, recursive=False)[source]¶
Pretty-print a list entry
Lists are mixed-type data entries. Empty lists and short string lists are printed flat in the same line. All other lists have their entries printed on new lines.
- Parameters:
value (list) – A list entry
recursive (bool) – Flag indicating whether this list is part of another list or dict
- write_ndarray(value, recursive=False)[source]¶
Pretty-print a numeric list
- Parameters:
value (np.ndarray) – Array object
recursive (bool) – Flag indicating whether it is part of a list or dict
- write_value(value, recursive=False, indented=False)[source]¶
Pretty-print an RHS entry based on its type
- Parameters:
value (object) – Value to be printed
recursive (bool) – Flag indicating whether the value is part of a dictionary or a list
indented (bool) – Flag indicating whether value must be indented
- keyword_fmt = '%-20s'¶
Default width for keywords
- class caelus.io.printer.Indenter(tab_width=4)[source]¶
Bases:
object
An indentation utility for use with DictPrinter
- Parameters:
tab_width (int) – Default indentation width
- curr_indent¶
Current indentation column
- property indent_str¶
Return an indentation string
- tab_width¶
Identation width
- caelus.io.printer.foam_writer(filename, header=None)[source]¶
Caelus/OpenFOAM file writer
- Parameters:
header (CaelusDict) – The FoamFile entries
- Yields:
printer (DictPrinter) – A dictionary printer for printing data