コード例 #1
0
    def test_globaljac_err(self):
        prob = Problem()
        model = prob.model = Group()
        model.add_subsystem('x_param', IndepVarComp('length', 3.0),
                            promotes=['length'])
        model.add_subsystem('mycomp', TestExplCompSimpleDense(),
                            promotes=['length', 'width', 'area'])

        model.linear_solver = LinearBlockJac()
        prob.set_solver_print(level=0)

        prob.model.jacobian = AssembledJacobian()
        prob.setup(check=False, mode='fwd')

        prob['width'] = 2.0
        prob.run_model()

        of = ['area']
        wrt = ['length']

        with self.assertRaises(RuntimeError) as context:
            prob.compute_totals(of=of, wrt=wrt, return_format='flat_dict')

            self.assertEqual(str(context.exception),
                             "A block linear solver 'LN: LNBJ' is being used with"
                             " an AssembledJacobian in system ''")
コード例 #2
0
ファイル: test_scaling.py プロジェクト: hwangjt/blue
    def test_newton_resid_scaling(self):
        class SimpleComp(ImplicitComponent):
            def setup(self):
                self.add_input('x', val=6.0)
                self.add_output('y', val=1.0, ref=100.0, res_ref=10.1)

                self.declare_partials('*', '*')

            def apply_nonlinear(self, inputs, outputs, residuals):
                residuals['y'] = 3.0 * outputs['y'] - inputs['x']

            def linearize(self, inputs, outputs, jacobian):

                jacobian['y', 'x'] = -1.0
                jacobian['y', 'y'] = 3.0

        prob = Problem()
        model = prob.model = Group()

        model.add_subsystem('p1', IndepVarComp('x', 6.0))
        model.add_subsystem('comp', SimpleComp())

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

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

        prob.setup(check=False)
        prob.run_model()

        assert_rel_error(self, prob['comp.y'], 2.0)

        # Now, let's try with an AssembledJacobian.

        prob = Problem()
        model = prob.model = Group()

        model.add_subsystem('p1', IndepVarComp('x', 6.0))
        model.add_subsystem('comp', SimpleComp())

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

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

        model.jacobian = AssembledJacobian()

        prob.setup(check=False)
        prob.run_model()

        assert_rel_error(self, prob['comp.y'], 2.0)
コード例 #3
0
    def test_error_under_assembled_jac(self):
        prob = Problem()
        model = prob.model = Group()
        model.add_subsystem('p', IndepVarComp('a', 5.0))
        comp = model.add_subsystem('comp', SimpleImp())
        model.connect('p.a', 'comp.a')

        comp.linear_solver = self.linear_solver_class()

        prob.model.jacobian = AssembledJacobian()
        prob.setup(check=False, mode='fwd')

        with self.assertRaises(RuntimeError) as context:
            prob.compute_totals(of=['comp.x'], wrt=['p.a'])

        self.assertEqual(str(context.exception),
                         "A block linear solver 'LN: LNBGS' is being used with"
                         " an AssembledJacobian in system 'comp'")