Example #1
0
    def test_sellar_mdf_COBYLA(self):

        prob = Problem()
        model = prob.model = SellarDerivativesGrouped()

        prob.driver = ScipyOptimizeDriver()
        prob.driver.options['optimizer'] = 'COBYLA'
        prob.driver.options['tol'] = 1e-9
        prob.driver.options['disp'] = False

        model.add_design_var('z',
                             lower=np.array([-10.0, 0.0]),
                             upper=np.array([10.0, 10.0]))
        model.add_design_var('x', lower=0.0, upper=10.0)
        model.add_objective('obj')
        model.add_constraint('con1', upper=0.0)
        model.add_constraint('con2', upper=0.0)

        prob.setup(check=False, mode='rev')

        failed = prob.run_driver()

        self.assertFalse(
            failed,
            "Optimization failed, result =\n" + str(prob.driver.result))

        assert_rel_error(self, prob['z'][0], 1.9776, 1e-3)
        assert_rel_error(self, prob['z'][1], 0.0, 1e-3)
        assert_rel_error(self, prob['x'], 0.0, 1e-3)
Example #2
0
    def test_sellar_grouped(self):
        # Tests basic Newton solution on Sellar in a subgroup

        prob = om.Problem(model=SellarDerivativesGrouped(nonlinear_solver=om.NewtonSolver(solve_subsystems=False)))

        prob.setup()
        prob.set_solver_print(level=0)
        prob.run_model()

        assert_near_equal(prob.get_val('y1'), 25.58830273, .00001)
        assert_near_equal(prob.get_val('y2'), 12.05848819, .00001)

        # Make sure we aren't iterating like crazy
        self.assertLess(prob.model.nonlinear_solver._iter_count, 8)
Example #3
0
    def test_sellar_grouped(self):
        # Tests basic Newton solution on Sellar in a subgroup

        prob = Problem(model=SellarDerivativesGrouped(nonlinear_solver=NewtonSolver()))

        prob.setup(check=False)
        prob.set_solver_print(level=0)
        prob.run_model()

        assert_rel_error(self, prob['y1'], 25.58830273, .00001)
        assert_rel_error(self, prob['y2'], 12.05848819, .00001)

        # Make sure we aren't iterating like crazy
        self.assertLess(prob.model.nonlinear_solver._iter_count, 8)
Example #4
0
    def test_basic(self):

        prob = Problem()
        model = prob.model = SellarDerivativesGrouped()

        prob.driver = pyOptSparseDriver()
        prob.driver.options['optimizer'] = "SLSQP"

        model.add_design_var('z', lower=np.array([-10.0, 0.0]), upper=np.array([10.0, 10.0]))
        model.add_design_var('x', lower=0.0, upper=10.0)
        model.add_objective('obj')
        model.add_constraint('con1', upper=0.0)
        model.add_constraint('con2', upper=0.0)

        prob.set_solver_print(level=0)

        prob.setup(check=False, mode='rev')
        prob.run_driver()

        assert_rel_error(self, prob['z'][0], 1.9776, 1e-3)
Example #5
0
        def test_sellar_derivs_grouped(self):
            # Test derivatives across a converged Sellar model.

            prob = Problem()
            prob.model = SellarDerivativesGrouped()
            prob.model.linear_solver = self.linear_solver_class()
            prob.set_solver_print(level=0)

            mda = prob.model.get_subsystem('mda')

            prob.setup(check=False, mode='fwd')
            prob.run_model()

            # Just make sure we are at the right answer
            assert_rel_error(self, prob['y1'], 25.58830273, .00001)
            assert_rel_error(self, prob['y2'], 12.05848819, .00001)

            wrt = ['x', 'z']
            of = ['obj', 'con1', 'con2']

            Jbase = {}
            Jbase['con1', 'x'] = [[-0.98061433]]
            Jbase['con1', 'z'] = np.array([[-9.61002285, -0.78449158]])
            Jbase['con2', 'x'] = [[0.09692762]]
            Jbase['con2', 'z'] = np.array([[1.94989079, 1.0775421]])
            Jbase['obj', 'x'] = [[2.98061392]]
            Jbase['obj', 'z'] = np.array([[9.61001155, 1.78448534]])

            J = prob.compute_totals(of=of, wrt=wrt, return_format='flat_dict')
            for key, val in iteritems(Jbase):
                assert_rel_error(self, J[key], val, .00001)

            prob.setup(check=False, mode='rev')
            prob.run_model()

            J = prob.compute_totals(of=of, wrt=wrt, return_format='flat_dict')
            for key, val in iteritems(Jbase):
                assert_rel_error(self, J[key], val, .00001)
Example #6
0
    def test_sellar_mdf(self):

        prob = Problem()
        model = prob.model = SellarDerivativesGrouped()

        prob.driver = pyOptSparseDriver()
        prob.driver.options['optimizer'] = OPTIMIZER
        if OPTIMIZER == 'SNOPT':
            prob.driver.opt_settings['Verify level'] = 3
        prob.driver.options['print_results'] = False

        model.add_design_var('z', lower=np.array([-10.0, 0.0]), upper=np.array([10.0, 10.0]))
        model.add_design_var('x', lower=0.0, upper=10.0)
        model.add_objective('obj')
        model.add_constraint('con1', upper=0.0)
        model.add_constraint('con2', upper=0.0)

        prob.setup(check=False, mode='rev')
        prob.run_driver()

        assert_rel_error(self, prob['z'][0], 1.9776, 1e-3)
        assert_rel_error(self, prob['z'][1], 0.0, 1e-3)
        assert_rel_error(self, prob['x'], 0.0, 1e-3)