fastoad.openmdao.variables.variable module
Class for managing an OpenMDAO variable.
- class fastoad.openmdao.variables.variable.Variable(name: str, *, init_metadata: bool = True, **kwargs)[source]
Bases:
HashableA class for storing data of OpenMDAO variables.
Instantiation is expected to be done through keyword arguments only.
Beside the mandatory parameter ‘name, kwargs is expected to have keys ‘value’, ‘units’ and ‘desc’, that are accessible respectively through properties
name(),value(),units()anddescription().Other keys are possible. They match the definition of OpenMDAO’s method
Component.add_output()described here.These keys can be listed with class method
get_openmdao_keys(). Any other key in kwargs will be silently ignored.Special behaviour:
description()will return the content of kwargs[‘desc’] unless these 2 conditions are met:kwargs[‘desc’] is None or ‘desc’ key is missing
a description exists in FAST-OAD internal data for the variable name
Then, the internal description will be returned by
description()- Parameters:
name – the name of the variable
init_metadata – if True, applies default values for metadata keys not provided in kwargs
kwargs – the OpenMDAO metadata of the variable, as keyword arguments
- name
Name of the variable
- get_val(new_units: str | None = None) float | ndarray[source]
Returns the variable value converted in the new_units. One dimensional lists and np.array are scalarized.
Note that this method should not be confused with OpenMDAO’s problem.get_val(). While they have similar behavior, this method applies to a Variable instance rather than to a Problem instance.
- Parameters:
new_units – units to convert the value to. If None, the value will be returned with its original units.
- Returns:
the variable value, converted to new_units if specified.
- update_missing_metadata(source_variable: Variable)[source]
Add metadata from source_variable to this variable, but only for keys that don’t already exist.
This is used to fill in missing metadata while preserving existing values.
- Parameters:
source_variable – Source for additional metadata
- classmethod read_variable_descriptions(file_parent: str | PathLike, *, update_existing: bool = True)[source]
Reads variable descriptions in indicated folder or package, if it contains some.
The file variable_descriptions.txt is looked for. Nothing is done if it is not found (no error raised also).
Each line of the file should be formatted like:
my:variable||The description of my:variable, as long as needed, but on one line.
- Parameters:
file_parent – the folder path or the package name that should contain the file
update_existing – if True, previous descriptions will be updated. if False, previous descriptions will be erased.
- classmethod update_variable_descriptions(variable_descriptions: Mapping[str, str] | Iterable[tuple[str, str]])[source]
Updates description of variables.
- Parameters:
variable_descriptions – dict-like object with variable names as keys and descriptions as values
- property value
value of the variable
- property val
value of the variable (alias of property “value”)
- property units
units associated to value (or None if not found)
- property description
description of the variable (or None if not found)
- property desc
description of the variable (or None if not found) (alias of property “description”)
- property is_input
I/O status of the variable.
True if variable is a problem input
False if it is an output
None if information not found