def test_fan_out_serial_sets(self): prob = Problem(impl=impl) prob.root = FanOutGrouped() prob.root.ln_solver = LinearGaussSeidel() prob.root.sub.ln_solver = LinearGaussSeidel() # Parallel Groups prob.driver.add_param('p.x') prob.driver.add_constraint('c2.y') prob.driver.add_constraint('c3.y') prob.setup(check=False) prob.run() unknown_list = ['c2.y', 'c3.y'] param_list = ['p.x'] J = prob.calc_gradient(param_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6) J = prob.calc_gradient(param_list, unknown_list, mode='rev', return_format='dict') assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
def test_fan_out_grouped_GS_GS(self): prob = Problem() prob.root = FanOutGrouped() prob.root.ln_solver = LinearGaussSeidel() prob.root.sub.ln_solver = LinearGaussSeidel() prob.setup(check=False) prob.run() indep_list = ['p.x'] unknown_list = ['sub.comp2.y', "sub.comp3.y"] J = prob.calc_gradient(indep_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6) J = prob.calc_gradient(indep_list, unknown_list, mode='rev', return_format='dict') assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6)
def test_fan_out_serial_sets_fwd(self): prob = Problem(impl=impl) prob.root = FanOutGrouped() prob.root.ln_solver = LinearGaussSeidel() prob.root.sub.ln_solver = LinearGaussSeidel() prob.root.ln_solver.options['mode'] = 'fwd' prob.root.sub.ln_solver.options['mode'] = 'fwd' prob.driver.add_desvar('p.x') prob.driver.add_constraint('c2.y', upper=0.0) prob.driver.add_constraint('c3.y', upper=0.0) prob.setup(check=False) prob.run() unknown_list = ['c2.y', 'c3.y'] indep_list = ['p.x'] J = prob.calc_gradient(indep_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
def test_fan_out_parallel_sets_fwd(self): prob = Problem(impl=impl) prob.root = FanOutGrouped() prob.root.ln_solver = LinearGaussSeidel() prob.root.sub.ln_solver = LinearGaussSeidel() prob.root.ln_solver.options['mode'] = 'fwd' prob.root.sub.ln_solver.options['mode'] = 'fwd' prob.driver.add_desvar('p.x') prob.driver.add_constraint('c2.y', upper=0.0) prob.driver.add_constraint('c3.y', upper=0.0) prob.driver.parallel_derivs(['c2.y', 'c3.y']) # ignored in fwd if MPI: expected = [('c2.y', 'c3.y')] else: expected = [('c2.y', ), ('c3.y', )] self.assertEqual(prob.driver.outputs_of_interest(), expected) prob.setup(check=False) prob.run() unknown_list = ['c2.y', 'c3.y'] indep_list = ['p.x'] J = prob.calc_gradient(indep_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
def test_fan_out_grouped(self): prob = Problem() prob.root = FanOutGrouped() prob.root.ln_solver = DirectSolver() prob.root.ln_solver.options['jacobian_method'] = 'assemble' prob.setup(check=False) prob.run() indep_list = ['p.x'] unknown_list = ['sub.comp2.y', "sub.comp3.y"] J = prob.calc_gradient(indep_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6) J = prob.calc_gradient(indep_list, unknown_list, mode='rev', return_format='dict') assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6)
def test_fan_out_parallel_sets(self): prob = Problem(impl=impl) prob.root = FanOutGrouped() prob.root.ln_solver = LinearGaussSeidel() prob.root.sub.ln_solver = LinearGaussSeidel() # need to set mode to rev before setup. Otherwise the sub-vectors # for the parallel set vars won't get allocated. prob.root.ln_solver.options['mode'] = 'rev' prob.root.sub.ln_solver.options['mode'] = 'rev' # Parallel Groups prob.driver.add_param('p.x') prob.driver.add_constraint('c2.y') prob.driver.add_constraint('c3.y') prob.driver.parallel_derivs(['c2.y', 'c3.y']) self.assertEqual(prob.driver.outputs_of_interest(), [('c2.y', 'c3.y')]) prob.setup(check=False) prob.run() unknown_list = ['c2.y', 'c3.y'] param_list = ['p.x'] J = prob.calc_gradient(param_list, unknown_list, mode='rev', return_format='dict') assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6) J = prob.calc_gradient(param_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['c2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['c3.y']['p.x'][0][0], 15.0, 1e-6)
def test_fan_out_grouped(self): prob = Problem() prob.root = FanOutGrouped() prob.root.ln_solver = ExplicitSolver() prob.setup(check=False) prob.run() param_list = ['p.x'] unknown_list = ['sub.comp2.y', "sub.comp3.y"] J = prob.calc_gradient(param_list, unknown_list, mode='fwd', return_format='dict') assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6) J = prob.calc_gradient(param_list, unknown_list, mode='rev', return_format='dict') assert_rel_error(self, J['sub.comp2.y']['p.x'][0][0], -6.0, 1e-6) assert_rel_error(self, J['sub.comp3.y']['p.x'][0][0], 15.0, 1e-6)