DirectSolver#
DirectSolver is a linear solver that assembles the system Jacobian and solves the linear system with LU factorization and back substitution. It can handle any system topology. Since it assembles a global Jacobian for all of its subsystems, any linear solver that is assigned in any of its subsystems does not participate in this calculation (though they may be used in other ways such as in subsystem Newton solves.)
Here we calculate the total derivatives of the Sellar system objective with respect to the design variable ‘z’.
SellarDerivatives
class definition
class SellarDerivatives(om.Group):
"""
Group containing the Sellar MDA. This version uses the disciplines with derivatives.
"""
def setup(self):
self.add_subsystem('d1', SellarDis1withDerivatives(), promotes=['x', 'z', 'y1', 'y2'])
self.add_subsystem('d2', SellarDis2withDerivatives(), promotes=['z', 'y1', 'y2'])
self.add_subsystem('obj_cmp', om.ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)', obj=0.0,
x=0.0, z=np.array([0.0, 0.0]), y1=0.0, y2=0.0),
promotes=['obj', 'x', 'z', 'y1', 'y2'])
self.add_subsystem('con_cmp1', om.ExecComp('con1 = 3.16 - y1', con1=0.0, y1=0.0),
promotes=['con1', 'y1'])
self.add_subsystem('con_cmp2', om.ExecComp('con2 = y2 - 24.0', con2=0.0, y2=0.0),
promotes=['con2', 'y2'])
self.set_input_defaults('x', 1.0)
self.set_input_defaults('z', np.array([5.0, 2.0]))
import openmdao.api as om
from openmdao.test_suite.components.sellar_feature import SellarDerivatives
prob = om.Problem()
model = prob.model = SellarDerivatives()
model.nonlinear_solver=om.NonlinearBlockGS()
model.linear_solver = om.DirectSolver()
prob.setup()
prob.run_model()
wrt = ['z']
of = ['obj']
J = prob.compute_totals(of=of, wrt=wrt, return_format='flat_dict')
print(J['obj', 'z'][0][0])
print(J['obj', 'z'][0][1])
NL: NLBGS Converged in 8 iterations
9.610010556989947
1.784485335631365
DirectSolver Options#
Option | Default | Acceptable Values | Acceptable Types | Description |
---|---|---|---|---|
assemble_jac | True | [True, False] | ['bool'] | Activates use of assembled jacobian by this solver. |
err_on_singular | True | [True, False] | ['bool'] | Raise an error if LU decomposition is singular. |
iprint | 1 | N/A | ['int'] | whether to print output |
rhs_checking | False | N/A | ['bool', 'dict'] | If True, check RHS vs. cache and/or zero to avoid some solves.Can also be set to a dict of options for the LinearRHSChecker to allow finer control over it. Allowed options are: ('check_zero', 'rtol', 'atol', 'max_cache_entries', 'collect_stats', 'auto', 'verbose') |
DirectSolver Constructor#
The call signature for the DirectSolver
constructor is:
- DirectSolver.__init__(**kwargs)[source]
Declare the solver options.