caelus.io – CML Input File Manipulation¶
Caelus/OpenFOAM Input File Interface¶
-
class
caelus.io.dictfile.
BlockMeshDict
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
constant/polyMesh/blockMeshDict interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
blocks
¶
-
boundary
¶
-
convertToMeters
¶
-
edges
¶
-
mergePatchPairs
¶
-
vertices
¶
-
-
class
caelus.io.dictfile.
ChangeDictionaryDict
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
system/changeDictionaryDict interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
dictionaryReplacement
¶
-
-
class
caelus.io.dictfile.
CmlControls
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
cmlControls interface
Parameters: filename (path) – Path to the input file
-
class
caelus.io.dictfile.
ControlDict
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
system/controlDict interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
adjustTimeStep
¶
-
application
¶
-
deltaT
¶
-
endTime
¶
-
functions
¶ function object definitions in controlDict
-
graphFormat
¶
-
maxCo
¶
-
purgeWrite
¶
-
runTimeModifiable
¶
-
startFrom
¶
-
startTime
¶
-
stopAt
¶
-
timeFormat
¶
-
timePrecision
¶
-
writeCompression
¶
-
writeControl
¶
-
writeFormat
¶
-
writeInterval
¶
-
writePrecision
¶
-
-
class
caelus.io.dictfile.
DecomposeParDict
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
system/decomposeParDict interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
method
¶
-
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:
-
write
(casedir=None, filename=None, update_object=True, write_header=True)[source]¶ Write a formatted Caelus input file
Parameters:
-
contents
¶ Access entries within the Caelus CML dictionary
-
data
= None¶ Contents of the file as a dictionary suitable for manipulation
-
filename
= None¶ File to read/write data
-
header
= None¶ Contents of the FoamFile sub-dictionary in the file
-
classmethod
-
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:
caelus.io.dictfile.DictFile
system/fvSchemes interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
ddtSchemes
¶
-
divSchemes
¶
-
fluxRequired
¶
-
gradSchemes
¶
-
interpolationSchemes
¶
-
laplacianSchemes
¶
-
snGradSchemes
¶
-
-
class
caelus.io.dictfile.
FvSolution
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
system/fvSolution interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
PIMPLE
¶
-
PISO
¶
-
SIMPLE
¶
-
potentialFlow
¶
-
relaxationFactors
¶
-
solvers
¶
-
-
class
caelus.io.dictfile.
LESProperties
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.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.
-
delta
¶ LES delta
-
-
class
caelus.io.dictfile.
PolyMeshBoundary
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.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:
caelus.io.dictfile.TurbModelProps
constant/RASProperties interface
Parameters: filename (path) – Path to the input file
-
class
caelus.io.dictfile.
TransportProperties
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
constant/transportProperties interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
transportModel
¶
-
-
class
caelus.io.dictfile.
TurbModelProps
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
Common interface for LES/RAS models
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
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.
-
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.
-
printCoeffs
¶
-
turbulence
¶
-
-
class
caelus.io.dictfile.
TurbulenceProperties
(filename=None, populate_defaults=True)[source]¶ Bases:
caelus.io.dictfile.DictFile
constant/turbulenceProperties interface
Parameters: filename (path) – Path to the input file -
create_default_entries
()¶ Create defaults from property list
-
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:
caelus.utils.struct.Struct
Caelus Input File Dictionary
-
yaml_decoder
¶ alias of
caelus.utils.struct.gen_yaml_decoder.<locals>.StructYAMLLoader
-
yaml_encoder
¶ alias of
caelus.utils.struct.gen_yaml_encoder.<locals>.StructYAMLDumper
-
Caelus/OpenFOAM Input File Datatypes
-
class
caelus.io.dtypes.
BoundaryList
(value)[source]¶ Bases:
caelus.io.dtypes.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:
caelus.io.dtypes.FoamType
A
#calc
directive entry- Example::
- radHalfAngle #calc “degToRad($halfAngle)”;
-
class
caelus.io.dtypes.
CodeStream
(value)[source]¶ Bases:
caelus.io.dtypes.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:
caelus.io.dtypes.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:
caelus.io.dtypes.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:
caelus.io.dtypes.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:
caelus.io.dtypes.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='')[source]¶ Write out the dimensional value
-
directive
= None¶ Type of directive (str)
-
value
= None¶ Value of the directive (e.g., file to be included)
-
-
class
caelus.io.dtypes.
EvalDirective
(directive, value)[source]¶ Bases:
caelus.io.dtypes.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:
caelus.io.dtypes.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
-
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.
ListTemplate
(ltype, value)[source]¶ Bases:
caelus.io.dtypes.FoamType
List<T> type entries
-
class
caelus.io.dtypes.
MacroSubstitution
(value, semi=True)[source]¶ Bases:
caelus.io.dtypes.FoamType
Macro substition without keyword
-
class
caelus.io.dtypes.
MultipleValues
(value)[source]¶ Bases:
caelus.io.dtypes.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_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:
-
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:
-
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
= None¶ Current indentation column
-
indent_str
¶ Return an indentation string
-
tab_width
= None¶ 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