Esempio n. 1
0
    def test_diamond(self):

        prob = Problem()
        prob.model = Diamond()
        prob.setup(check=False, mode='fwd')
        prob.set_solver_print(level=0)
        prob.run_model()

        assert_rel_error(self, prob['c4.y1'], 46.0, 1e-6)
        assert_rel_error(self, prob['c4.y2'], -93.0, 1e-6)

        indep_list = ['iv.x']
        unknown_list = ['c4.y1', 'c4.y2']

        J = prob.compute_totals(of=unknown_list, wrt=indep_list)
        assert_rel_error(self, J['c4.y1', 'iv.x'][0][0], 25, 1e-6)
        assert_rel_error(self, J['c4.y2', 'iv.x'][0][0], -40.5, 1e-6)

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

        assert_rel_error(self, prob['c4.y1'], 46.0, 1e-6)
        assert_rel_error(self, prob['c4.y2'], -93.0, 1e-6)

        J = prob.compute_totals(of=unknown_list, wrt=indep_list)
        assert_rel_error(self, J['c4.y1', 'iv.x'][0][0], 25, 1e-6)
        assert_rel_error(self, J['c4.y2', 'iv.x'][0][0], -40.5, 1e-6)
Esempio n. 2
0
    def test_diamond(self, solver, nlsolver):

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

        prob.model.linear_solver = solver()
        prob.model.nonlinear_solver = nlsolver()

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

        assert_near_equal(prob['c4.y1'], 46.0, 1e-6)
        assert_near_equal(prob['c4.y2'], -93.0, 1e-6)

        indep_list = ['iv.x']
        unknown_list = ['c4.y1', 'c4.y2']

        J = prob.compute_totals(of=unknown_list, wrt=indep_list)
        assert_near_equal(J['c4.y1', 'iv.x'][0][0], 25, 1e-6)
        assert_near_equal(J['c4.y2', 'iv.x'][0][0], -40.5, 1e-6)

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

        assert_near_equal(prob['c4.y1'], 46.0, 1e-6)
        assert_near_equal(prob['c4.y2'], -93.0, 1e-6)

        J = prob.compute_totals(of=unknown_list, wrt=indep_list)
        assert_near_equal(J['c4.y1', 'iv.x'][0][0], 25, 1e-6)
        assert_near_equal(J['c4.y2', 'iv.x'][0][0], -40.5, 1e-6)
Esempio n. 3
0
        def test_single_diamond_grouped(self):
            # Test derivatives for grouped diamond topology.

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

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

            wrt = ['iv.x']
            of = ['c4.y1', 'c4.y2']

            J = prob.compute_totals(of=of, wrt=wrt, return_format='flat_dict')
            assert_near_equal(J['c4.y1', 'iv.x'], [[25]], 1e-6)
            assert_near_equal(J['c4.y2', 'iv.x'], [[-40.5]], 1e-6)

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

            J = prob.compute_totals(of=of, wrt=wrt, return_format='flat_dict')
            assert_near_equal(J['c4.y1', 'iv.x'], [[25]], 1e-6)
            assert_near_equal(J['c4.y2', 'iv.x'], [[-40.5]], 1e-6)