Example #1
0
    def test_feature_specification(self):
        import openmdao.api as om
        from openmdao.solvers.linesearch.tests.test_backtracking import CompAtan

        prob = om.Problem()
        model = prob.model

        model.add_subsystem('px', om.IndepVarComp('x', -100.0))
        model.add_subsystem('comp', CompAtan())

        model.connect('px.x', 'comp.x')

        prob.setup()

        # Initial value for the state:
        prob['comp.y'] = 12.0

        # You can change the om.NewtonSolver settings after setup is called
        newton = prob.model.nonlinear_solver = om.NewtonSolver()
        prob.model.linear_solver = om.DirectSolver()
        newton.options['iprint'] = 2
        newton.options['rtol'] = 1e-8
        newton.options['solve_subsystems'] = True

        newton.linesearch = om.BoundsEnforceLS()
        newton.linesearch.options['iprint'] = 2

        prob.run_model()

        assert_rel_error(self, prob['comp.y'], 19.68734033, 1e-6)
Example #2
0
    def test_feature_specification(self):
        import openmdao.api as om
        from openmdao.solvers.linesearch.tests.test_backtracking import CompAtan

        prob = om.Problem()
        model = prob.model

        model.add_subsystem('comp', CompAtan(), promotes_inputs=['x'])

        prob.setup()

        prob.set_val('x', -100.0)

        # Initial value for the state:
        prob.set_val('comp.y', 12.0)

        # You can change the om.NewtonSolver settings after setup is called
        newton = prob.model.nonlinear_solver = om.NewtonSolver()
        prob.model.linear_solver = om.DirectSolver()
        newton.options['iprint'] = 2
        newton.options['rtol'] = 1e-8
        newton.options['solve_subsystems'] = True

        newton.linesearch = om.BoundsEnforceLS()
        newton.linesearch.options['iprint'] = 2

        prob.run_model()

        assert_near_equal(prob.get_val('comp.y'), 19.68734033, 1e-6)