Modifying Solver Options#

In OpenMDAO, implicit outputs can have bounds and scaling attached to them. These are defined when add_output is called on an implicit component.

In complex models, this means that a user may need to tweak bounds and scaling in multiple files. The bounds and scaling of a variable may be dependent upon the application of the model. These bounds may need to be adjusted in a file that is generally outside of the expertise of the user.

OpenMDAO provides a method System.set_output_solver_options that allows users to set bounds throughout their model from a single script or notebook.

System.set_output_solver_options(name, lower=UNDEFINED, upper=UNDEFINED, ref=UNDEFINED, ref0=UNDEFINED, res_ref=UNDEFINED)[source]

Set solver output options.

Allows the user to set output solver options after the output has been defined and metadata set using the add_ouput method.

Parameters:
namestr

Name of the variable in this system’s namespace.

lowerfloat or list or tuple or ndarray 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.

upperfloat or list or tuple or ndarray or 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.

reffloat

Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 1. Default is 1.

ref0float

Scaling parameter. The value in the user-defined units of this output variable when the scaled value is 0. Default is 0.

res_reffloat

Scaling parameter. The value in the user-defined res_units of this output’s residual when the scaled value is 1. Default is None, which means residual scaling matches output scaling.

Example of Setting Solver Output Options#

Here is an example of how to make use of the System.set_output_solver_options method.

# Implicit component in which bounds and scaling are set on outputs
import openmdao.api as om

class ScalingExample3(om.ImplicitComponent):

    def setup(self):
        self.add_input('x1', val=100.0)
        self.add_input('x2', val=5000.0)
        self.add_output('y1', val=200., ref=1e2, res_ref=1e5, ref0=1.0, lower=2., upper=3)
        self.add_output('y2', val=6000., ref=1e3, res_ref=1e-5)

    def apply_nonlinear(self, inputs, outputs, residuals):
        x1 = inputs['x1']
        x2 = inputs['x2']
        y1 = outputs['y1']
        y2 = outputs['y2']

        residuals['y1'] = 1e5 * (x1 - y1) / y1
        residuals['y2'] = 1e-5 * (x2 - y2) / y2
# Script that makes use of this implicit component
prob = om.Problem()

# ScalingExample3 sets values for ref, res_ref, ref0, lower, and upper
comp = prob.model.add_subsystem('comp', ScalingExample3())

prob.setup() 
prob.run_model() # Run model with the bounds and scaling set in the component
# Now override a value from this cell (could also be from a separate script) and re-run the model
prob.model.set_output_solver_options(name='comp.y1',ref=1e3)
prob.setup() 
prob.run_model()