namelist_util.py¶
Utilities for reading and writing Fortran namelists.
-
class
openmdao.util.namelist_util.
Namelist
(comp)[source]¶ Bases:
object
Utility to ease the task of constructing a formatted output file.
Args: comp: Component
Component instance who owns this namelist.
-
add_comment
(comment)[source]¶ Add a comment in the namelist.
Args: comment : string
Comment text to be added. Text should include comment character if one is desired. (Note that a comment character isn’t always needed in a Namelist. It seems to figure out whether something is a comment without it.)
-
add_container
(varpath='', skip=None)[source]¶ Add every variable from a given variable tree path to the namelist. For multi-level trees, this should be colon-delimited.
Args: varpath : string
Vartree name, colon-delimited for multi-level trees.
skip : list of str
List of variables to skip printing to the file. No need to include the vartree path in the names.
-
add_group
(name)[source]¶ Add a new group to the namelist. Any variables added after this are added to this new group.
Args: name : string
Group name to be added.
-
add_newvar
(name, value)[source]¶ Add a new variable to the namelist.
Args: name : string
Name of the variable to be added.
value : int, float, string, ndarray, list, bool
Value of the variable to be added.
-
add_var
(name)[source]¶ Add an openmdao variable to the namelist.
Args: varpath : string
Variable name being added. For variable trees, include the colon between each level.
-
find_card
(group, name)[source]¶ Returns the value for a given namelist variable in a given group.
Args: group: string
namelist group name.
name: string
namelist variable name.
-
generate
()[source]¶ Generates the input file. This should be called after all cards and groups are added to the namelist.
-
load_model
(rules=None, ignore=None, single_group=-1)[source]¶ Loads the current deck into an OpenMDAO component.
Args: rules : dict of lists of strings, optional
An optional dictionary of rules can be passed if the component has a hierarchy of variable trees for its input variables. If no rules dictionary is passed,
load_model
will attempt to find each namelist variable in the top level of the model hierarchy.ignore : list of strings, optional
List of variable names that can safely be ignored.
single_group : integer, optional
Group id number to use for processing one single namelist group. Useful if extra processing is needed or if multiple groups have the same name.
Returns: tuple
Returns a tuple containing the following values: (empty_groups, unlisted_groups, unlinked_vars).
These need to be examined after calling
load_model
to make sure you loaded every variable into your model.- empty_groups : ordereddict( integer : string )
Names and ID number of groups that don’t have cards. This includes strings found at the top level that aren’t comments; these need to be processed by your wrapper to determine how the information fits into your component’s variable hierarchy.
- unlisted_groups : ordereddict( integer : string )
This dictionary includes the names and ID number of groups that have variables that couldn’t be loaded because the group wasn’t mentioned in the rules dictionary.
- unlinked_vars : list
List of all variable names that weren’t found in the component.
-
parse_file
()[source]¶ Parses an existing namelist file and creates a deck of cards to hold the data. After this is executed, you need to call the
load_model()
method to extract the variables from this data structure.
-