def test_specify_precon(self):

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

        sub1 = model.add_subsystem('sub1', om.Group())
        sub1.add_subsystem('q1', QuadraticComp())
        sub1.add_subsystem('z1', om.ExecComp('y = -6.0 + .01 * x'))
        sub2 = model.add_subsystem('sub2', om.Group())
        sub2.add_subsystem('q2', QuadraticComp())
        sub2.add_subsystem('z2', om.ExecComp('y = -6.0 + .01 * x'))

        model.connect('sub1.q1.x', 'sub1.z1.x')
        model.connect('sub1.z1.y', 'sub2.q2.c')
        model.connect('sub2.q2.x', 'sub2.z2.x')
        model.connect('sub2.z2.y', 'sub1.q1.c')

        model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
        model.linear_solver = om.ScipyKrylov()

        prob.setup()

        model.sub1.linear_solver = om.DirectSolver()
        model.sub2.linear_solver = om.DirectSolver()

        model.linear_solver.precon = om.LinearBlockGS()

        prob.set_solver_print(level=2)
        prob.run_model()

        assert_near_equal(prob.get_val('sub1.q1.x'), 1.996, .0001)
        assert_near_equal(prob.get_val('sub2.q2.x'), 1.996, .0001)
示例#2
0
    def test_check_partials_for_docs(self):

        p = om.Problem()

        p.model.add_subsystem('quad', QuadraticComp())

        p.setup()

        p.check_partials(compact_print=True)
示例#3
0
    def test_check_partials_for_docs(self):

        from openmdao.api import Problem
        from openmdao.test_suite.components.quad_implicit import QuadraticComp

        p = Problem()

        p.model.add_subsystem('quad', QuadraticComp())

        p.setup()

        p.check_partials(compact_print=True)
示例#4
0
    def test_specify_precon(self):
        import numpy as np

        from openmdao.api import Problem, Group, ScipyKrylov, NewtonSolver, LinearBlockGS, \
             DirectSolver, ExecComp, PETScKrylov

        from openmdao.test_suite.components.quad_implicit import QuadraticComp

        prob = Problem()
        model = prob.model

        sub1 = model.add_subsystem('sub1', Group())
        sub1.add_subsystem('q1', QuadraticComp())
        sub1.add_subsystem('z1', ExecComp('y = -6.0 + .01 * x'))
        sub2 = model.add_subsystem('sub2', Group())
        sub2.add_subsystem('q2', QuadraticComp())
        sub2.add_subsystem('z2', ExecComp('y = -6.0 + .01 * x'))

        model.connect('sub1.q1.x', 'sub1.z1.x')
        model.connect('sub1.z1.y', 'sub2.q2.c')
        model.connect('sub2.q2.x', 'sub2.z2.x')
        model.connect('sub2.z2.y', 'sub1.q1.c')

        model.nonlinear_solver = NewtonSolver()
        model.linear_solver = ScipyKrylov()

        prob.setup()

        model.sub1.linear_solver = DirectSolver()
        model.sub2.linear_solver = DirectSolver()

        model.linear_solver.precon = LinearBlockGS()

        prob.set_solver_print(level=2)
        prob.run_model()

        assert_rel_error(self, prob['sub1.q1.x'], 1.996, .0001)
        assert_rel_error(self, prob['sub2.q2.x'], 1.996, .0001)
示例#5
0
    def test_specify_precon(self):
        import numpy as np

        import openmdao.api as om
        from openmdao.test_suite.components.quad_implicit import QuadraticComp

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

        sub1 = model.add_subsystem('sub1', om.Group())
        sub1.add_subsystem('q1', QuadraticComp())
        sub1.add_subsystem('z1', om.ExecComp('y = -6.0 + .01 * x'))
        sub2 = model.add_subsystem('sub2', om.Group())
        sub2.add_subsystem('q2', QuadraticComp())
        sub2.add_subsystem('z2', om.ExecComp('y = -6.0 + .01 * x'))

        model.connect('sub1.q1.x', 'sub1.z1.x')
        model.connect('sub1.z1.y', 'sub2.q2.c')
        model.connect('sub2.q2.x', 'sub2.z2.x')
        model.connect('sub2.z2.y', 'sub1.q1.c')

        model.nonlinear_solver = om.NewtonSolver(solve_subsystems=False)
        model.linear_solver = om.ScipyKrylov()

        prob.setup()

        model.sub1.linear_solver = om.DirectSolver()
        model.sub2.linear_solver = om.DirectSolver()

        model.linear_solver.precon = om.LinearBlockGS()

        prob.set_solver_print(level=2)
        prob.run_model()

        assert_near_equal(prob['sub1.q1.x'], 1.996, .0001)
        assert_near_equal(prob['sub2.q2.x'], 1.996, .0001)
示例#6
0
    def test_check_partials(self):
        p = Problem()

        p.model.add_subsystem('quad', QuadraticComp())

        p.setup()

        check = p.check_partials(out_stream=None)

        for out_name, of in check.items():
            for i_name, wrt in of.items():
                J_fwd = wrt['J_fwd']
                J_fd = wrt['J_fd']
                if J_fd > 1e-5:
                    err = np.abs(J_fwd - J_fd) / J_fd
                else:
                    err = np.abs(J_fwd - J_fd)
                self.assertLess(err, 1e-4)