def test_basic_fd_comps(self): prob = Problem() prob.model = Group() prob.model.add_subsystem('px1', IndepVarComp('x1', 100.0), promotes=['x1']) prob.model.add_subsystem('src', SrcCompFD()) prob.model.add_subsystem('tgtF', TgtCompFFD()) prob.model.add_subsystem('tgtC', TgtCompCFD()) prob.model.add_subsystem('tgtK', TgtCompKFD()) prob.model.connect('x1', 'src.x1') prob.model.connect('src.x2', 'tgtF.x2') prob.model.connect('src.x2', 'tgtC.x2') prob.model.connect('src.x2', 'tgtK.x2') prob.setup(check=False) prob.run_model() assert_rel_error(self, prob['src.x2'], 100.0, 1e-6) assert_rel_error(self, prob['tgtF.x3'], 212.0, 1e-6) assert_rel_error(self, prob['tgtC.x3'], 100.0, 1e-6) assert_rel_error(self, prob['tgtK.x3'], 373.15, 1e-6) indep_list = ['x1'] unknown_list = ['tgtF.x3', 'tgtC.x3', 'tgtK.x3'] J = prob.compute_totals(of=unknown_list, wrt=indep_list, return_format='dict') assert_rel_error(self, J['tgtF.x3']['x1'][0][0], 1.8, 1e-6) assert_rel_error(self, J['tgtC.x3']['x1'][0][0], 1.0, 1e-6) assert_rel_error(self, J['tgtK.x3']['x1'][0][0], 1.0, 1e-6) prob.setup(check=False, mode='rev') prob.run_model() J = prob.compute_totals(of=unknown_list, wrt=indep_list, return_format='dict') assert_rel_error(self, J['tgtF.x3']['x1'][0][0], 1.8, 1e-6) assert_rel_error(self, J['tgtC.x3']['x1'][0][0], 1.0, 1e-6) assert_rel_error(self, J['tgtK.x3']['x1'][0][0], 1.0, 1e-6) prob.model.approx_totals(method='fd') prob.setup(check=False, mode='rev') prob.run_model() J = prob.compute_totals(of=unknown_list, wrt=indep_list, return_format='dict') assert_rel_error(self, J['tgtF.x3']['x1'][0][0], 1.8, 1e-6) assert_rel_error(self, J['tgtC.x3']['x1'][0][0], 1.0, 1e-6) assert_rel_error(self, J['tgtK.x3']['x1'][0][0], 1.0, 1e-6) # Make sure check partials handles conversion data = prob.check_partials() for key1, val1 in iteritems(data): for key2, val2 in iteritems(val1): assert_rel_error(self, val2['abs error'][0], 0.0, 1e-6) assert_rel_error(self, val2['abs error'][1], 0.0, 1e-6) assert_rel_error(self, val2['abs error'][2], 0.0, 1e-6) assert_rel_error(self, val2['rel error'][0], 0.0, 1e-6) assert_rel_error(self, val2['rel error'][1], 0.0, 1e-6) assert_rel_error(self, val2['rel error'][2], 0.0, 1e-6)
def test_basic_fd_comps(self): prob = om.Problem() prob.model.add_subsystem('px1', om.IndepVarComp('x1', 100.0), promotes=['x1']) prob.model.add_subsystem('src', SrcCompFD()) prob.model.add_subsystem('tgtF', TgtCompFFD()) prob.model.add_subsystem('tgtC', TgtCompCFD()) prob.model.add_subsystem('tgtK', TgtCompKFD()) prob.model.connect('x1', 'src.x1') prob.model.connect('src.x2', 'tgtF.x2') prob.model.connect('src.x2', 'tgtC.x2') prob.model.connect('src.x2', 'tgtK.x2') prob.setup() prob.run_model() assert_near_equal(prob['src.x2'], 100.0, 1e-6) assert_near_equal(prob['tgtF.x3'], 212.0, 1e-6) assert_near_equal(prob['tgtC.x3'], 100.0, 1e-6) assert_near_equal(prob['tgtK.x3'], 373.15, 1e-6) indep_list = ['x1'] unknown_list = ['tgtF.x3', 'tgtC.x3', 'tgtK.x3'] J = prob.compute_totals(of=unknown_list, wrt=indep_list, return_format='dict') assert_near_equal(J['tgtF.x3']['x1'][0][0], 1.8, 1e-6) assert_near_equal(J['tgtC.x3']['x1'][0][0], 1.0, 1e-6) assert_near_equal(J['tgtK.x3']['x1'][0][0], 1.0, 1e-6) prob.setup(check=False, mode='rev') prob.run_model() J = prob.compute_totals(of=unknown_list, wrt=indep_list, return_format='dict') assert_near_equal(J['tgtF.x3']['x1'][0][0], 1.8, 1e-6) assert_near_equal(J['tgtC.x3']['x1'][0][0], 1.0, 1e-6) assert_near_equal(J['tgtK.x3']['x1'][0][0], 1.0, 1e-6) prob.model.approx_totals(method='fd') prob.setup(check=False, mode='rev') prob.run_model() J = prob.compute_totals(of=unknown_list, wrt=indep_list, return_format='dict') assert_near_equal(J['tgtF.x3']['x1'][0][0], 1.8, 1e-6) assert_near_equal(J['tgtC.x3']['x1'][0][0], 1.0, 1e-6) assert_near_equal(J['tgtK.x3']['x1'][0][0], 1.0, 1e-6) # Make sure check partials handles conversion data = prob.check_partials(out_stream=None, step=1.1e-6) # Need to make step different # than for compute, otherwise get error for key1, val1 in data.items(): for key2, val2 in val1.items(): assert_near_equal(val2['abs error'][0], 0.0, 1e-6) assert_near_equal(val2['rel error'][0], 0.0, 1e-6)