Exemple #1
0
    def test_specify_subgroup_solvers(self):
        from openmdao.api import Problem, NewtonSolver, ScipyIterativeSolver, DirectSolver, NonlinearBlockGS, LinearBlockGS
        from openmdao.test_suite.components.double_sellar import DoubleSellar

        prob = Problem()
        model = prob.model = DoubleSellar()

        # each SubSellar group converges itself
        g1 = model.get_subsystem('g1')
        g1.nonlinear_solver = NewtonSolver()
        g1.linear_solver = DirectSolver()  # used for derivatives

        g2 = model.get_subsystem('g2')
        g2.nonlinear_solver = NewtonSolver()
        g2.linear_solver = DirectSolver()

        # Converge the outer loop with Gauss Seidel, with a looser tolerance.
        model.nonlinear_solver = NonlinearBlockGS()
        model.nonlinear_solver.options['rtol'] = 1.0e-5
        model.linear_solver = ScipyIterativeSolver()
        model.linear_solver.precon = LinearBlockGS()

        prob.setup()
        prob.run_model()

        assert_rel_error(self, prob['g1.y1'], 0.64, .00001)
        assert_rel_error(self, prob['g1.y2'], 0.80, .00001)
        assert_rel_error(self, prob['g2.y1'], 0.64, .00001)
        assert_rel_error(self, prob['g2.y2'], 0.80, .00001)
Exemple #2
0
    def setup(self):
        self.add_subsystem('px', IndepVarComp('x', 1.0), promotes=['x'])
        self.add_subsystem('pz',
                           IndepVarComp('z', np.array([5.0, 2.0])),
                           promotes=['z'])

        cycle = self.add_subsystem('cycle',
                                   Group(),
                                   promotes=['x', 'z', 'y1', 'y2'])
        cycle.add_subsystem('d1',
                            SellarDis1(),
                            promotes=['x', 'z', 'y1', 'y2'])
        cycle.add_subsystem('d2', SellarDis2(), promotes=['z', 'y1', 'y2'])

        self.add_subsystem('obj_cmp',
                           ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                                    z=np.array([0.0, 0.0]),
                                    x=0.0),
                           promotes=['x', 'z', 'y1', 'y2', 'obj'])

        self.add_subsystem('con_cmp1',
                           ExecComp('con1 = 3.16 - y1'),
                           promotes=['con1', 'y1'])
        self.add_subsystem('con_cmp2',
                           ExecComp('con2 = y2 - 24.0'),
                           promotes=['con2', 'y2'])

        self.nonlinear_solver = NonlinearBlockGS()

        self.nonlinear_solver = self.options['nonlinear_solver']
        if self.options['nl_atol']:
            self.nonlinear_solver.options['atol'] = self.options['nl_atol']
        if self.options['nl_maxiter']:
            self.nonlinear_solver.options['maxiter'] = self.options[
                'nl_maxiter']
Exemple #3
0
    def test_test_promoted_connections_nlbgs_solver(self):
        p = Problem()

        p.model = model = Group()
        model.linear_solver = DirectSolver()
        model.nonlinear_solver = NonlinearBlockGS()
        model.nonlinear_solver.options['reraise_child_analysiserror'] = True
        model.add_subsystem('c1',
                            IndepVarComp('x', 1.0),
                            promotes_outputs=['x'])
        model.add_subsystem('c2',
                            ReconfComp1(),
                            promotes_inputs=['x'],
                            promotes_outputs=['y'])
        model.add_subsystem('c3',
                            ReconfComp2(),
                            promotes_inputs=['y'],
                            promotes_outputs=['f'])
        p.setup()
        p['x'] = 3.

        # First run the model once; counter = 1, size of y = 1
        p.run_model()
        self.assertEqual(len(p['y']), 1)

        # Run the model again, which will trigger reconfiguration; counter = 2, size of y = 2
        p.run_model()
        self.assertEqual(len(p['y']), 2)
        assert_rel_error(self, p['y'], [6., 6.])
    def test_reconf_comp_connections_nlbgs_solver(self):
        p = Problem()

        p.model = model = Group()
        model.linear_solver = DirectSolver()
        model.nonlinear_solver = NonlinearBlockGS()
        model.add_subsystem('c1',
                            IndepVarComp('x', 1.0),
                            promotes_outputs=['x'])
        model.add_subsystem('c2', ReconfComp1(), promotes_inputs=['x'])
        model.add_subsystem('c3', ReconfComp2(), promotes_outputs=['f'])
        model.connect('c2.y', 'c3.y')
        p.setup()
        p['x'] = 3.

        # First run the model once; counter = 1, size of y = 1
        p.run_model()

        self.assertEqual(len(p['c2.y']), 1)
        self.assertEqual(len(p['c3.y']), 1)
        # Run the model again, which will trigger reconfiguration; counter = 2, size of y = 2
        p.run_model()

        self.assertEqual(len(p['c2.y']), 2)
        self.assertEqual(len(p['c3.y']), 2)
        assert_near_equal(p['c3.y'], [6., 6.])
Exemple #5
0
 def initialize(self):
     self.options.declare('nonlinear_solver', default=NonlinearBlockGS(),
                          desc='Nonlinear solver for Sellar MDA')
     self.options.declare('nl_atol', default=None,
                          desc='User-specified atol for nonlinear solver.')
     self.options.declare('nl_maxiter', default=None,
                          desc='Iteration limit for nonlinear solver.')
     self.options.declare('linear_solver', default=ScipyKrylov(),
                          desc='Linear solver')
     self.options.declare('ln_atol', default=None,
                          desc='User-specified atol for linear solver.')
     self.options.declare('ln_maxiter', default=None,
                          desc='Iteration limit for linear solver.')
Exemple #6
0
    def setup(self):
        self.add_subsystem('px', IndepVarComp('x', 1.0))
        self.add_subsystem('pz', IndepVarComp('z', np.array([5.0, 2.0])))

        self.add_subsystem('d1', SellarDis1withDerivatives())
        self.add_subsystem('d2', SellarDis2withDerivatives())

        self.add_subsystem('obj_cmp', ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                           z=np.array([0.0, 0.0]), x=0.0))

        self.add_subsystem('con_cmp1', ExecComp('con1 = 3.16 - y1'))
        self.add_subsystem('con_cmp2', ExecComp('con2 = y2 - 24.0'))

        self.connect('px.x', ['d1.x', 'obj_cmp.x'])
        self.connect('pz.z', ['d1.z', 'd2.z', 'obj_cmp.z'])
        self.connect('d1.y1', ['d2.y1', 'obj_cmp.y1', 'con_cmp1.y1'])
        self.connect('d2.y2', ['d1.y2', 'obj_cmp.y2', 'con_cmp2.y2'])

        self.nonlinear_solver = NonlinearBlockGS()
        self.linear_solver = ScipyKrylov()
Exemple #7
0
 def configure(self):
     self.mda.linear_solver = ScipyKrylov()
     self.mda.nonlinear_solver = NonlinearBlockGS()
Exemple #8
0
 def configure(self):
     self.mda.linear_solver = ScipyIterativeSolver()
     self.mda.nonlinear_solver = NonlinearBlockGS()