multiply_divide_comp.py¶
Definition of the Element Multiply Component.
-
class
openconcept.utilities.math.multiply_divide_comp.ElementMultiplyDivideComp(output_name=None, input_names=None, vec_size=1, length=1, val=1.0, scaling_factor=1, divide=None, input_units=None, **kwargs)[source]¶ Bases:
openmdao.core.explicitcomponent.ExplicitComponentCompute a vectorized element-wise multiplication and/or division.
Use the add_equation method to define any number of mult/div relations User defines the names of the input and output variables using add_equation(output_name=’my_output’, input_names=[‘a’,’b’, ‘c’, …], divide=[False,False,True,…])
\[result = (a * b / c ....) * \textrm{scaling factor}\]- where:
- all inputs shape (vec_size, n)
- b is of shape (vec_size, n)
- c is of shape (vec_size, n)
Result is of shape (vec_size, n)
All input vectors must be of the same shape, specified by the options ‘vec_size’ and ‘length’. Use scaling factor -1 for subtraction.
-
_add_systems¶ list – List of equation systems to be initialized with the system.
-
__init__(output_name=None, input_names=None, vec_size=1, length=1, val=1.0, scaling_factor=1, divide=None, input_units=None, **kwargs)[source]¶ Allow user to create an multiplication system with one-liner.
Parameters: - output_name (str) – (required) name of the result variable in this component’s namespace.
- input_names (iterable of str) – (required) names of the input variables for this system
- vec_size (int) – Length of the first dimension of the input and output vectors (i.e number of rows, or vector length for a 1D vector) Default is 1
- length (int) – Length of the second dimension of the input and ouptut vectors (i.e. number of columns) Default is 1 which results in input/output vectors of size (vec_size,)
- scaling_factor (numeric) – Scaling factor to apply to the whole system Default is 1
- divide (iterable of bool or None) – True to use division operator, False to use mult operator Default is None which results in mult of every input Length is same as number of inputs
- val (float or list or tuple or ndarray) – The initial value of the variable being added in user-defined units. Default is 1.0.
- input_units (iterable of str) – Units for each of the input vectors in order. Output units will be dimensionally consistent.
- **kwargs (str) – Any other arguments to pass to the addition system (same as add_output method for ExplicitComponent) Examples include units (str or None), desc (str)
-
initialize()[source]¶ Declare options.
Parameters: complex (Boolean) – Set True to enable complex math (e.g. for complex step verification)
-
add_equation(output_name, input_names, vec_size=1, length=1, val=1.0, res_units=None, desc='', lower=None, upper=None, ref=1.0, ref0=0.0, res_ref=None, var_set=0, scaling_factor=1, divide=None, input_units=None)[source]¶ Add a multiplication relation.
Parameters: - output_name (str) – (required) name of the result variable in this component’s namespace.
- input_names (iterable of str) – (required) names of the input variables for this system
- vec_size (int) – Length of the first dimension of the input and output vectors (i.e number of rows, or vector length for a 1D vector) Default is 1
- length (int) – Length of the second dimension of the input and ouptut vectors (i.e. number of columns) Default is 1 which results in input/output vectors of size (vec_size,)
- scaling_factor (numeric) – Scaling factor to apply to the whole system Default is 1
- divide (iterable of bool or None) – True to use division operator, False to use mult operator Default is None which results in mult of every input Length is same as number of inputs
- val (float or list or tuple or ndarray) – The initial value of the variable being added in user-defined units. Default is 1.0.
- input_units (iterable of str) – Units for each of the input vectors in order. Output units will be dimensionally consistent.
- res_units (str or None) – Units in which the residuals of this output will be given to the user when requested. Default is None, which means it has no units.
- desc (str) – description of the variable.
- lower (float or list or tuple or ndarray or Iterable or None) – lower bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no lower bound. Default is None.
- upper (float or list or tuple or ndarray or or Iterable None) – upper bound(s) in user-defined units. It can be (1) a float, (2) an array_like consistent with the shape arg (if given), or (3) an array_like matching the shape of val, if val is array_like. A value of None means this output has no upper bound. Default is None.
- ref (float or ndarray) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.
- ref0 (float or ndarray) – Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.
- res_ref (float or ndarray) – Scaling parameter. The value in the user-defined res_units of this output’s residual when the scaled value is 1. Default is 1.
- var_set (hashable object) – For advanced users only. ID or color for this variable, relevant for reconfigurability. Default is 0.