def test_outputs(self): surfaces = get_default_surfaces() group = Group() comp = VLMGeometry(surface=surfaces[0]) indep_var_comp = IndepVarComp() indep_var_comp.add_output('def_mesh', val=surfaces[0]['mesh'], units='m') group.add_subsystem('geom', comp, promotes=['*']) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) prob = Problem() prob.model.add_subsystem('group', group, promotes=['*']) prob.setup() prob.run_model() assert_rel_error(self, prob['widths'], np.array([11.95624787, 11.90425878, 11.44086572]), 1e-6) assert_rel_error(self, prob['cos_sweep'], np.array([9.7938336, 9.79384207, 9.79385053]), 1e-6) assert_rel_error(self, prob['S_ref'], np.array([415.02211208]), 1e-6) assert_rel_error(self, prob['chords'], np.array([2.72796, 5.1252628, 7.8891638, 13.6189974]), 1e-6) assert_rel_error(self, prob['lengths'], np.array([2.72796, 5.1252628, 7.8891638, 13.6189974]), 1e-6)
def test_simple_values(self): surface = get_default_surfaces()[0] surface['n_point_masses'] = 1 comp = ComputeThrustLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]]) engine_thrusts = np.array([[1/9.8]]) point_mass_locations = np.array([[.55012, 0.1, 0.]]) indep_var_comp.add_output('nodes', val=nodesval, units='m') indep_var_comp.add_output('engine_thrusts', val=engine_thrusts, units='N') indep_var_comp.add_output('point_mass_locations', val=point_mass_locations, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('compute_point_mass_loads', comp, promotes=['*']) prob = run_test(self, group, complex_flag=True, step=1e-8, atol=1e-5, compact_print=True) truth_array = np.array([0, 0, -1., 0., 0.55012, 0.]) assert_rel_error(self, prob['comp.loads_from_thrusts'][0, :], truth_array, 1e-6)
def test_1(self): surface = get_default_surfaces()[0] surface['struct_weight_relief'] = True comp = TotalLoads(surface=surface) run_test(self, comp, complex_flag=True)
def test(self): surface = get_default_surfaces()[0] ny = surface['mesh'].shape[1] comp = FEM(surface=surface) run_test(self, comp)
def test(self): surfaces = get_default_surfaces() group = om.Group() comp = SolveMatrix(surfaces=surfaces) indep_var_comp = om.IndepVarComp() system_size = 0 for surface in surfaces: nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] system_size += (nx - 1) * (ny - 1) indep_var_comp.add_output('rhs', val=np.ones((system_size)), units='m/s') indep_var_comp.add_output('mtx', val=np.identity((system_size)), units='1/m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('solve_matrix', comp, promotes=['*']) run_test(self, group)
def test(self): surface = get_default_surfaces()[0] group = Group() comp = VonMisesTube(surface=surface) indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] # define the spar with y out the wing nodes = np.zeros((ny, 3)) nodes[:,0] = np.linspace(0,0.01,ny) nodes[:,1] = np.linspace(0,1,ny) radius = 0.01*np.ones((ny - 1)) disp = np.zeros((ny, 6)) for i in range(6): disp[:,i] = np.linspace(0,0.001,ny) indep_var_comp.add_output('nodes', val=nodes, units='m') indep_var_comp.add_output('radius', val=radius, units='m') indep_var_comp.add_output('disp', val=disp, units='m') group.add_subsystem('vm_comp', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.nodes', 'vm_comp.nodes') group.connect('indep_var_comp.radius', 'vm_comp.radius') group.connect('indep_var_comp.disp', 'vm_comp.disp') run_test(self, group, complex_flag=True, compact_print=True, method='cs', step=1e-40, atol=2e-4, rtol=1e-8)
def test_2(self): surface = get_default_surfaces()[0] surface['distributed_fuel_weight'] = True comp = TotalLoads(surface=surface) run_test(self, comp, complex_flag=True)
def test_structural_weight_loads(self): surface = get_default_surfaces()[0] comp = StructureWeightLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] #carefully chosen "random" values that give non-uniform derivatives outputs that are good for testing nodesval = np.array( [[1., 2., 4.], [20., 22., 7.], [8., 17., 14.], [13., 14., 16.]], dtype=complex) element_weights_val = np.arange(ny - 1) + 1 indep_var_comp.add_output('nodes', val=nodesval, units='m') indep_var_comp.add_output('element_weights', val=element_weights_val, units='N') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('load', comp, promotes=['*']) p = run_test(self, group, complex_flag=True, compact_print=True)
def test_simple_values(self): surface = get_default_surfaces()[0] surface['n_point_masses'] = 1 comp = ComputePointMassLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]]) point_masses = np.array([[1/9.8]]) point_mass_locations = np.array([[.55012, 0.1, 0.]]) indep_var_comp.add_output('nodes', val=nodesval, units='m') indep_var_comp.add_output('point_masses', val=point_masses, units='kg') indep_var_comp.add_output('point_mass_locations', val=point_mass_locations, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('compute_point_mass_loads', comp, promotes=['*']) prob = run_test(self, group, complex_flag=True, step=1e-8, atol=1e-5, compact_print=True) truth_array = np.array([0, 0, -1., 0., 0.55012, 0.]) assert_rel_error(self, prob['comp.loads_from_point_masses'][0, :], truth_array, 1e-6)
def test(self): surface = get_default_surfaces()[0] surface['t_over_c_cp'] = np.array([0.1, 0.15, 0.2]) ny = surface['num_y'] nx = surface['num_x'] n_cp = len(surface['t_over_c_cp']) group = Group() indep_var_comp = IndepVarComp() indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp']) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('t_over_c_bsp', BsplinesComp(in_name='t_over_c_cp', out_name='t_over_c', num_control_points=n_cp, num_points=int(ny - 1), bspline_order=min(n_cp, 4), distribution='uniform'), promotes_inputs=['t_over_c_cp'], promotes_outputs=['t_over_c']) comp = ViscousDrag(surface=surface, with_viscous=True) group.add_subsystem('viscousdrag', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test_derivs(self): surface = get_default_surfaces()[0] surface['n_point_masses'] = 2 comp = ComputePointMassLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]]) point_masses = np.array([[2., 1.]]) point_mass_locations = np.array([[2.1, 0.1, 0.2], [3.2, 1.2, 0.3]]) indep_var_comp.add_output('nodes', val=nodesval, units='m') indep_var_comp.add_output('point_masses', val=point_masses, units='kg') indep_var_comp.add_output('point_mass_locations', val=point_mass_locations, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('compute_point_mass_loads', comp, promotes=['*']) prob = run_test(self, group, complex_flag=True, step=1e-8, atol=1e-5, compact_print=True)
def test_structural_weight_loads(self): surface = get_default_surfaces()[0] comp = StructureWeightLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] #carefully chosen "random" values that give non-uniform derivatives outputs that are good for testing nodesval = np.array([[1., 2., 4.], [20., 22., 7.], [8., 17., 14.], [13., 14., 16.]],dtype=complex) element_weights_val = np.arange(ny-1)+1 indep_var_comp.add_output('nodes', val=nodesval,units='m') indep_var_comp.add_output('element_weights', val=element_weights_val,units='N') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('load', comp, promotes=['*']) p = run_test(self, group, complex_flag=True, compact_print=True)
def test(self): surface = get_default_surfaces()[0] group = Group() comp = VonMisesTube(surface=surface) indep_var_comp = IndepVarComp() ny = surface['num_y'] # define the spar with y out the wing nodes = np.zeros((ny, 3)) nodes[:,1] = np.linspace(0,1,ny) radius = 0.01*np.ones((ny - 1)) disp = np.zeros((ny, 6)) for i in range(6): disp[:,i] = np.linspace(0,0.001,ny) indep_var_comp.add_output('nodes', val=nodes, units='m') indep_var_comp.add_output('radius', val=radius, units='m') indep_var_comp.add_output('disp', val=disp, units='m') group.add_subsystem('vm_comp', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.nodes', 'vm_comp.nodes') group.connect('indep_var_comp.radius', 'vm_comp.radius') group.connect('indep_var_comp.disp', 'vm_comp.disp') run_test(self, group)
def test_detailed(self): """ This is a longer version of the previous method, with plotting. """ # Load in default lifting surfaces to setup the comparison surfaces = get_default_surfaces() # Instantiate an OpenMDAO problem and add the component we want to test # as asubsystem, giving that component a default lifting surface prob = om.Problem() prob.model.add_subsystem('tube', SectionPropertiesTube(surface=surfaces[0])) # Set up the problem and ensure it uses complex arrays so we can check # the derivatives using complex step prob.setup(force_alloc_complex=True) # Actually run the model, which is just a component in this case, then # check the derivatives and store the results in the `check` dict prob.run_model() check = prob.check_partials(compact_print=False) # Loop through this `check` dictionary and visualize the approximated # and computed derivatives for key, subjac in iteritems(check[list(check.keys())[0]]): print() print(key) view_mat(subjac['J_fd'],subjac['J_fwd'],key) # Loop through the `check` dictionary and perform assert that the # approximated deriv must be very close to the computed deriv for key, subjac in iteritems(check[list(check.keys())[0]]): if subjac['magnitude'].fd > 1e-6: assert_almost_equal( subjac['rel error'].forward, 0., err_msg='deriv of %s wrt %s' % key) assert_almost_equal( subjac['rel error'].reverse, 0., err_msg='deriv of %s wrt %s' % key)
def test(self): surface = get_default_surfaces()[0] surface['t_over_c_cp'] = np.array([0.1, 0.15, 0.2]) nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] n_cp = len(surface['t_over_c_cp']) group = om.Group() indep_var_comp = om.IndepVarComp() indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp']) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) x_interp = np.linspace(0., 1., int(ny - 1)) comp = group.add_subsystem('t_over_c_bsp', om.SplineComp( method='bsplines', x_interp_val=x_interp, num_cp=n_cp, interp_options={'order': min(n_cp, 4)}), promotes_inputs=['t_over_c_cp'], promotes_outputs=['t_over_c']) comp.add_spline(y_cp_name='t_over_c_cp', y_interp_name='t_over_c', y_cp_val=np.zeros(n_cp)) comp = ViscousDrag(surface=surface, with_viscous=True) group.add_subsystem('viscousdrag', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test_quick(self): """ Short pre-setup test to compare component derivs. """ surfaces = get_default_surfaces() comp = SectionPropertiesTube(surface=surfaces[0]) run_test(self, comp, complex_flag=True)
def test(self): surface = get_default_surfaces()[0] surface['with_wave'] = True surface['t_over_c_cp'] = np.array([0.15, 0.21, 0.03, 0.05]) nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] n_cp = len(surface['t_over_c_cp']) group = om.Group() indep_var_comp = om.IndepVarComp() indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp']) indep_var_comp.add_output('Mach_number', val=.95) indep_var_comp.add_output('CL', val=0.7) indep_var_comp.add_output('widths', val = np.array([12.14757848, 11.91832712, 11.43730892]),units='m') indep_var_comp.add_output('cos_sweep', val = np.array([10.01555924, 9.80832351, 9.79003729]),units='m') indep_var_comp.add_output('chords', val = np.array([ 2.72835132, 5.12528179, 7.88916016, 13.6189974]),units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) x_interp = np.linspace(0., 1., int(ny-1)) comp = group.add_subsystem('t_over_c_bsp', om.SplineComp( method='bsplines', x_interp_val=x_interp, num_cp=n_cp, interp_options={'order' : min(n_cp, 4)}), promotes_inputs=['t_over_c_cp'], promotes_outputs=['t_over_c']) comp.add_spline(y_cp_name='t_over_c_cp', y_interp_name='t_over_c') comp = WaveDrag(surface=surface) group.add_subsystem('wavedrag', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test(self): surfaces = get_default_surfaces() group = Group() comp = Forces(surfaces=surfaces) indep_var_comp = IndepVarComp() indep_var_comp.add_output('wing_widths', val=np.ones((surfaces[0]['num_y'] - 1)), units='m') indep_var_comp.add_output('tail_widths', val=np.ones((surfaces[1]['num_y'] - 1)), units='m') indep_var_comp.add_output('M', val=.3) group.add_subsystem('indep_var_comp', indep_var_comp) group.add_subsystem('forces', comp) group.connect('indep_var_comp.wing_widths', 'forces.wing_widths') group.connect('indep_var_comp.tail_widths', 'forces.tail_widths') group.connect('indep_var_comp.M', 'forces.M') run_test(self, group)
def test_detailed(self): """ This is a longer version of the previous method, with plotting. """ # Load in default lifting surfaces to setup the comparison surfaces = get_default_surfaces() # Instantiate an OpenMDAO problem and add the component we want to test # as asubsystem, giving that component a default lifting surface prob = Problem() prob.model.add_subsystem('tube', SectionPropertiesTube(surface=surfaces[0])) # Set up the problem and ensure it uses complex arrays so we can check # the derivatives using complex step prob.setup(force_alloc_complex=True) # Actually run the model, which is just a component in this case, then # check the derivatives and store the results in the `check` dict prob.run_model() check = prob.check_partials(compact_print=False) # Loop through this `check` dictionary and visualize the approximated # and computed derivatives for key, subjac in iteritems(check[list(check.keys())[0]]): print() print(key) view_mat(subjac['J_fd'],subjac['J_fwd'],key) # Loop through the `check` dictionary and perform assert that the # approximated deriv must be very close to the computed deriv for key, subjac in iteritems(check[list(check.keys())[0]]): if subjac['magnitude'].fd > 1e-6: assert_almost_equal( subjac['rel error'].forward, 0., err_msg='deriv of %s wrt %s' % key) assert_almost_equal( subjac['rel error'].reverse, 0., err_msg='deriv of %s wrt %s' % key)
def test_derivs(self): surface = get_default_surfaces()[0] surface['n_point_masses'] = 2 comp = ComputePointMassLoads(surface=surface) group = om.Group() indep_var_comp = om.IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]]) point_masses = np.array([[2., 1.]]) point_mass_locations = np.array([[2.1, 0.1, 0.2], [3.2, 1.2, 0.3]]) indep_var_comp.add_output('nodes', val=nodesval, units='m') indep_var_comp.add_output('point_masses', val=point_masses, units='kg') indep_var_comp.add_output('point_mass_locations', val=point_mass_locations, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('compute_point_mass_loads', comp, promotes=['*']) prob = run_test(self, group, complex_flag=True, step=1e-8, atol=1e-5, compact_print=True)
def test(self): surface = get_default_surfaces()[0] surface['with_wave'] = True surface['t_over_c_cp'] = np.array([0.15, 0.21, 0.03, 0.05]) nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] n_cp = len(surface['t_over_c_cp']) group = Group() indep_var_comp = IndepVarComp() indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp']) indep_var_comp.add_output('Mach_number', val=.95) indep_var_comp.add_output('CL', val=0.7) indep_var_comp.add_output('widths', val = np.array([12.14757848, 11.91832712, 11.43730892]),units='m') indep_var_comp.add_output('cos_sweep', val = np.array([10.01555924, 9.80832351, 9.79003729]),units='m') indep_var_comp.add_output('chords', val = np.array([ 2.72835132, 5.12528179, 7.88916016, 13.6189974]),units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('t_over_c_bsp', BsplinesComp( in_name='t_over_c_cp', out_name='t_over_c', num_control_points=n_cp, num_points=int(ny-1), bspline_order=min(n_cp, 4), distribution='uniform'), promotes_inputs=['t_over_c_cp'], promotes_outputs=['t_over_c']) comp = WaveDrag(surface=surface) group.add_subsystem('wavedrag', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test(self): surfaces = get_default_surfaces() group = Group() comp = Forces(surfaces=surfaces) indep_var_comp = IndepVarComp() indep_var_comp.add_output('wing_widths', val=np.ones((surfaces[0]['num_y'] - 1)), units='m') indep_var_comp.add_output('tail_widths', val=np.ones((surfaces[1]['num_y'] - 1)), units='m') indep_var_comp.add_output('wing_def_mesh', val=surfaces[0]['mesh'], units='m') indep_var_comp.add_output('tail_def_mesh', val=surfaces[1]['mesh'], units='m') indep_var_comp.add_output('M', val=.3) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('forces', comp, promotes=['*']) run_test(self, group)
def test(self): surfaces = get_default_surfaces() comp = EvalVelMtx(surfaces=surfaces, num_eval_points=2, eval_name='test_name') run_test(self, comp)
def test(self): surfaces = get_default_surfaces() comp = GetVectors(surfaces=surfaces, num_eval_points=10, eval_name='test_name') run_test(self, comp)
def test(self): surfaces = get_default_surfaces() comp = EvalVelocities(surfaces=surfaces, eval_name='TestEval', num_eval_points=11) run_test(self, comp)
def test(self): surface = get_default_surfaces()[0] # turn down some of these properties, so the absolute deriv error isn't magnified surface['E'] = 7 surface['G'] = 3 surface['yield'] = .02 comp = FailureKS(surface=surface) run_test(self, comp, complex_flag=True, step=1e-40, method='cs', compact_print=False)
def test(self): surface = get_default_surfaces()[0] surface['data_x_upper'] = np.array([0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6], dtype = 'complex128') surface['data_x_lower'] = np.array([0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6], dtype = 'complex128') surface['data_y_upper'] = np.array([ 0.0447, 0.046, 0.0472, 0.0484, 0.0495, 0.0505, 0.0514, 0.0523, 0.0531, 0.0538, 0.0545, 0.0551, 0.0557, 0.0563, 0.0568, 0.0573, 0.0577, 0.0581, 0.0585, 0.0588, 0.0591, 0.0593, 0.0595, 0.0597, 0.0599, 0.06, 0.0601, 0.0602, 0.0602, 0.0602, 0.0602, 0.0602, 0.0601, 0.06, 0.0599, 0.0598, 0.0596, 0.0594, 0.0592, 0.0589, 0.0586, 0.0583, 0.058, 0.0576, 0.0572, 0.0568, 0.0563, 0.0558, 0.0553, 0.0547, 0.0541], dtype = 'complex128') surface['data_y_lower'] = np.array([-0.0447, -0.046, -0.0473, -0.0485, -0.0496, -0.0506, -0.0515, -0.0524, -0.0532, -0.054, -0.0547, -0.0554, -0.056, -0.0565, -0.057, -0.0575, -0.0579, -0.0583, -0.0586, -0.0589, -0.0592, -0.0594, -0.0595, -0.0596, -0.0597, -0.0598, -0.0598, -0.0598, -0.0598, -0.0597, -0.0596, -0.0594, -0.0592, -0.0589, -0.0586, -0.0582, -0.0578, -0.0573, -0.0567, -0.0561, -0.0554, -0.0546, -0.0538, -0.0529, -0.0519, -0.0509, -0.0497, -0.0485, -0.0472, -0.0458, -0.0444], dtype = 'complex128') surface['original_wingbox_airfoil_t_over_c'] = 0.1 comp = SectionPropertiesWingbox(surface=surface) run_test(self, comp, complex_flag=True)
def test(self): """ This is for checking the partials. """ surface = get_default_surfaces()[0] # turn down some of these properties, so the absolute deriv error isn't magnified surface['E'] = 7 surface['G'] = 3 surface['yield'] = .02 surface['data_x_upper'] = np.array([ 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ], dtype='complex128') surface['data_x_lower'] = np.array([ 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ], dtype='complex128') surface['data_y_upper'] = np.array([ 0.0447, 0.046, 0.0472, 0.0484, 0.0495, 0.0505, 0.0514, 0.0523, 0.0531, 0.0538, 0.0545, 0.0551, 0.0557, 0.0563, 0.0568, 0.0573, 0.0577, 0.0581, 0.0585, 0.0588, 0.0591, 0.0593, 0.0595, 0.0597, 0.0599, 0.06, 0.0601, 0.0602, 0.0602, 0.0602, 0.0602, 0.0602, 0.0601, 0.06, 0.0599, 0.0598, 0.0596, 0.0594, 0.0592, 0.0589, 0.0586, 0.0583, 0.058, 0.0576, 0.0572, 0.0568, 0.0563, 0.0558, 0.0553, 0.0547, 0.0541 ], dtype='complex128') surface['data_y_lower'] = np.array([ -0.0447, -0.046, -0.0473, -0.0485, -0.0496, -0.0506, -0.0515, -0.0524, -0.0532, -0.054, -0.0547, -0.0554, -0.056, -0.0565, -0.057, -0.0575, -0.0579, -0.0583, -0.0586, -0.0589, -0.0592, -0.0594, -0.0595, -0.0596, -0.0597, -0.0598, -0.0598, -0.0598, -0.0598, -0.0597, -0.0596, -0.0594, -0.0592, -0.0589, -0.0586, -0.0582, -0.0578, -0.0573, -0.0567, -0.0561, -0.0554, -0.0546, -0.0538, -0.0529, -0.0519, -0.0509, -0.0497, -0.0485, -0.0472, -0.0458, -0.0444 ], dtype='complex128') surface['original_wingbox_airfoil_t_over_c'] = 0.1 comp = SectionPropertiesWingbox(surface=surface) run_test(self, comp, complex_flag=True, method='cs', step=1e-40)
def test(self): surface = get_default_surfaces()[0] # turn down some of these properties, so the absolute deriv error isn't magnified surface['E'] = 7 surface['G'] = 3 surface['yield'] = .02 comp = FailureExact(surface=surface) run_test(self, comp)
def test(self): surface = get_default_surfaces()[0] ny = surface['mesh'].shape[1] group = om.Group() ivc = om.IndepVarComp() ivc.add_output('nodes', val=np.random.random_sample((ny, 3))) comp = Weight(surface=surface) group.add_subsystem('ivc', ivc, promotes=['*']) group.add_subsystem('comp', comp, promotes=['*']) run_test(self, group, compact_print=False, complex_flag=True)
def test(self): surface = get_default_surfaces()[0] ny = surface['num_y'] group = Group() ivc = IndepVarComp() ivc.add_output('nodes', val=np.random.random_sample((ny, 3))) comp = Weight(surface=surface) group.add_subsystem('ivc', ivc, promotes=['*']) group.add_subsystem('comp', comp, promotes=['*']) run_test(self, group)
def test(self): surface = get_default_surfaces()[0] ny = surface['mesh'].shape[1] group = Group() ivc = IndepVarComp() ivc.add_output('nodes', val=np.random.random_sample((ny, 3))) comp = Weight(surface=surface) group.add_subsystem('ivc', ivc, promotes=['*']) group.add_subsystem('comp', comp, promotes=['*']) run_test(self, group, compact_print=False, complex_flag=True)
def test_rotation_option_derivatives(self): surfaces = get_default_surfaces() comp = ConvertVelocity(surfaces=surfaces, rotational=True) prob = om.Problem() prob.model.add_subsystem('comp', comp) prob.setup(force_alloc_complex=True) prob['comp.rotational_velocities'] = np.random.random(prob['comp.rotational_velocities'].shape) prob['comp.beta'] = 15.0 prob.run_model() check = prob.check_partials(compact_print=True, method='cs', step=1e-40) assert_check_partials(check)
def test(self): surfaces = get_default_surfaces() group = Group() comp = VLMGeometry(surface=surfaces[0]) indep_var_comp = IndepVarComp() indep_var_comp.add_output('def_mesh', val=surfaces[0]['mesh'], units='m') group.add_subsystem('geom', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.def_mesh', 'geom.def_mesh') run_test(self, group)
def test(self): surfaces = get_default_surfaces() group = Group() comp = RadiusComp(surface=surfaces[0]) indep_var_comp = IndepVarComp() indep_var_comp.add_output('mesh', val=surfaces[0]['mesh'], units='m') group.add_subsystem('radius', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.mesh', 'radius.mesh') run_test(self, group)
def test2(self): surfaces = get_default_surfaces() group = Group() comp = MomentCoefficient(surfaces=surfaces) indep_var_comp = IndepVarComp() indep_var_comp.add_output('S_ref_total', val=1e4, units='m**2') group.add_subsystem('moment_calc', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.S_ref_total', 'moment_calc.S_ref_total') run_test(self, group)
def test_assembled_jac(self): surfaces = get_default_surfaces() comp = EvalVelMtx(surfaces=surfaces, num_eval_points=2, eval_name='test_name') prob = om.Problem() prob.model.add_subsystem('comp', comp) prob.model.linear_solver = om.DirectSolver(assemble_jac=True) prob.model.options['assembled_jac_type'] = 'csc' prob.setup(force_alloc_complex=True) prob.run_model() data = prob.check_partials(compact_print=True, out_stream=None, method='cs', step=1e-40) assert_check_partials(data, atol=1e20, rtol=1e-6)
def test(self): surfaces = get_default_surfaces() group = om.Group() comp = VLMGeometry(surface=surfaces[0]) indep_var_comp = om.IndepVarComp() indep_var_comp.add_output('def_mesh', val=surfaces[0]['mesh'], units='m') group.add_subsystem('geom', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.def_mesh', 'geom.def_mesh') run_test(self, group)
def test(self): surface = get_default_surfaces()[0] comp = ComputeTransformationMatrix(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] disp = np.random.random_sample((ny, 6)) * 100. indep_var_comp.add_output('disp', val=disp, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('trans_mtx', comp, promotes=['*']) run_test(self, group, complex_flag=True, method='cs')
def test_assembled_jac(self): surfaces = get_default_surfaces() comp = EvalVelMtx(surfaces=surfaces, num_eval_points=2, eval_name='test_name') prob = Problem() prob.model.add_subsystem('comp', comp) from openmdao.api import DirectSolver prob.model.linear_solver = DirectSolver(assemble_jac=True) prob.model.options['assembled_jac_type'] = 'csc' prob.setup(force_alloc_complex=True) prob.run_model() data = prob.check_partials(compact_print=True, out_stream=None, method='cs', step=1e-40) assert_check_partials(data, atol=1e20, rtol=1e-6)
def test(self): surface = get_default_surfaces()[0] group = Group() comp = LoadTransfer(surface=surface) indep_var_comp = IndepVarComp() nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] indep_var_comp.add_output('def_mesh', val=np.random.random((nx, ny, 3)), units='m') indep_var_comp.add_output('sec_forces', val=np.random.random((nx-1, ny-1, 3)), units='N') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('load_transfer', comp, promotes=['*']) run_test(self, group, complex_flag=True, compact_print=False)
def test(self): surface = get_default_surfaces()[0] comp = DisplacementTransfer(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] mesh = surface['mesh'] indep_var_comp.add_output('mesh', val=mesh, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('load', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test(self): surfaces = get_default_surfaces() group = Group() comp = RadiusComp(surface=surfaces[0]) ny = surfaces[0]['mesh'].shape[1] indep_var_comp = IndepVarComp() indep_var_comp.add_output('mesh', val=surfaces[0]['mesh'], units='m') indep_var_comp.add_output('t_over_c', val=np.linspace(0.1,0.5,num=ny-1)) group.add_subsystem('radius', comp) group.add_subsystem('indep_var_comp', indep_var_comp) group.connect('indep_var_comp.mesh', 'radius.mesh') group.connect('indep_var_comp.t_over_c', 'radius.t_over_c') run_test(self, group)
def test(self): surface = get_default_surfaces()[0] group = Group() comp = StructuralCG(surface=surface) indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] indep_var_comp.add_output('nodes', val=np.random.random((ny, 3)), units='m') indep_var_comp.add_output('structural_weight', val=1., units='N') indep_var_comp.add_output('element_weights', val=np.ones((ny-1)), units='N') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('structural_cg', comp, promotes=['*']) run_test(self, group, complex_flag=True, compact_print=False)
def test(self): """ This is for checking the partials. """ surface = get_default_surfaces()[0] # turn down some of these properties, so the absolute deriv error isn't magnified surface['E'] = 7 surface['G'] = 3 surface['yield'] = .02 surface['data_x_upper'] = np.array([0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6], dtype = 'complex128') surface['data_x_lower'] = np.array([0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6], dtype = 'complex128') surface['data_y_upper'] = np.array([ 0.0447, 0.046, 0.0472, 0.0484, 0.0495, 0.0505, 0.0514, 0.0523, 0.0531, 0.0538, 0.0545, 0.0551, 0.0557, 0.0563, 0.0568, 0.0573, 0.0577, 0.0581, 0.0585, 0.0588, 0.0591, 0.0593, 0.0595, 0.0597, 0.0599, 0.06, 0.0601, 0.0602, 0.0602, 0.0602, 0.0602, 0.0602, 0.0601, 0.06, 0.0599, 0.0598, 0.0596, 0.0594, 0.0592, 0.0589, 0.0586, 0.0583, 0.058, 0.0576, 0.0572, 0.0568, 0.0563, 0.0558, 0.0553, 0.0547, 0.0541], dtype = 'complex128') surface['data_y_lower'] = np.array([-0.0447, -0.046, -0.0473, -0.0485, -0.0496, -0.0506, -0.0515, -0.0524, -0.0532, -0.054, -0.0547, -0.0554, -0.056, -0.0565, -0.057, -0.0575, -0.0579, -0.0583, -0.0586, -0.0589, -0.0592, -0.0594, -0.0595, -0.0596, -0.0597, -0.0598, -0.0598, -0.0598, -0.0598, -0.0597, -0.0596, -0.0594, -0.0592, -0.0589, -0.0586, -0.0582, -0.0578, -0.0573, -0.0567, -0.0561, -0.0554, -0.0546, -0.0538, -0.0529, -0.0519, -0.0509, -0.0497, -0.0485, -0.0472, -0.0458, -0.0444], dtype = 'complex128') surface['original_wingbox_airfoil_t_over_c'] = 0.1 comp = SectionPropertiesWingbox(surface=surface) run_test(self, comp, complex_flag=True, method='cs', step=1e-40)
def test(self): surface = get_default_surfaces()[0] # turn down some of these properties, so the absolute deriv error isn't magnified surface['E'] = 7 surface['G'] = 3 surface['yield'] = .02 surface['strength_factor_for_upper_skin'] = 1.0 comp = VonMisesWingbox(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]]) indep_var_comp.add_output('nodes', val=nodesval) indep_var_comp.add_output('disp', val=np.ones((ny, 6))) indep_var_comp.add_output('Qz', val=np.ones((ny - 1))) indep_var_comp.add_output('Iz', val=np.ones((ny - 1))) indep_var_comp.add_output('J', val=np.ones((ny - 1))) indep_var_comp.add_output('A_enc', val=np.ones((ny - 1))) indep_var_comp.add_output('spar_thickness', val=np.ones((ny - 1))) indep_var_comp.add_output('skin_thickness', val=np.ones((ny - 1))) indep_var_comp.add_output('htop', val=np.ones((ny - 1))) indep_var_comp.add_output('hbottom', val=np.ones((ny - 1))) indep_var_comp.add_output('hfront', val=np.ones((ny - 1))) indep_var_comp.add_output('hrear', val=np.ones((ny - 1))) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('vonmises_wingbox', comp, promotes=['*']) run_test(self, group, complex_flag=True, step=1e-8, atol=2e-5, compact_print=True)
def test_0(self): surface = get_default_surfaces()[0] comp = FuelLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]], dtype=complex) indep_var_comp.add_output('nodes', val=nodesval) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('load', comp, promotes=['*']) run_test(self, group, complex_flag=True, atol=1e-2, rtol=1e-6)
def test(self): surface = get_default_surfaces()[0] surface['data_x_upper'] = np.array([0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6], dtype = 'complex128') surface['data_x_lower'] = np.array([0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6], dtype = 'complex128') surface['data_y_upper'] = np.array([ 0.0447, 0.046, 0.0472, 0.0484, 0.0495, 0.0505, 0.0514, 0.0523, 0.0531, 0.0538, 0.0545, 0.0551, 0.0557, 0.0563, 0.0568, 0.0573, 0.0577, 0.0581, 0.0585, 0.0588, 0.0591, 0.0593, 0.0595, 0.0597, 0.0599, 0.06, 0.0601, 0.0602, 0.0602, 0.0602, 0.0602, 0.0602, 0.0601, 0.06, 0.0599, 0.0598, 0.0596, 0.0594, 0.0592, 0.0589, 0.0586, 0.0583, 0.058, 0.0576, 0.0572, 0.0568, 0.0563, 0.0558, 0.0553, 0.0547, 0.0541], dtype = 'complex128') surface['data_y_lower'] = np.array([-0.0447, -0.046, -0.0473, -0.0485, -0.0496, -0.0506, -0.0515, -0.0524, -0.0532, -0.054, -0.0547, -0.0554, -0.056, -0.0565, -0.057, -0.0575, -0.0579, -0.0583, -0.0586, -0.0589, -0.0592, -0.0594, -0.0595, -0.0596, -0.0597, -0.0598, -0.0598, -0.0598, -0.0598, -0.0597, -0.0596, -0.0594, -0.0592, -0.0589, -0.0586, -0.0582, -0.0578, -0.0573, -0.0567, -0.0561, -0.0554, -0.0546, -0.0538, -0.0529, -0.0519, -0.0509, -0.0497, -0.0485, -0.0472, -0.0458, -0.0444], dtype = 'complex128') comp = WingboxGeometry(surface=surface) group = Group() indep_var_comp = IndepVarComp() indep_var_comp.add_output('mesh', val=surface['mesh']) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('wingbox_geometry', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test(self): surfaces = get_default_surfaces() group = Group() comp = SolveMatrix(surfaces=surfaces) indep_var_comp = IndepVarComp() system_size = 0 for surface in surfaces: nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] system_size += (nx - 1) * (ny - 1) indep_var_comp.add_output('rhs', val=np.ones((system_size)), units='m/s') indep_var_comp.add_output('mtx', val=np.identity((system_size)), units='1/m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('solve_matrix', comp, promotes=['*']) run_test(self, group)
def test(self): surface = get_default_surfaces()[0] surface['t_over_c_cp'] = np.array([0.1, 0.15, 0.2]) nx = surface['mesh'].shape[0] ny = surface['mesh'].shape[1] n_cp = len(surface['t_over_c_cp']) group = Group() indep_var_comp = IndepVarComp() indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp']) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('t_over_c_bsp', BsplinesComp( in_name='t_over_c_cp', out_name='t_over_c', num_control_points=n_cp, num_points=int(ny-1), bspline_order=min(n_cp, 4), distribution='uniform'), promotes_inputs=['t_over_c_cp'], promotes_outputs=['t_over_c']) comp = ViscousDrag(surface=surface, with_viscous=True) group.add_subsystem('viscousdrag', comp, promotes=['*']) run_test(self, group, complex_flag=True)
def test_no_derivs(self): surface = get_default_surfaces()[0] surface['n_point_masses'] = 1 comp = ComputeThrustLoads(surface=surface) group = Group() indep_var_comp = IndepVarComp() ny = surface['mesh'].shape[1] nodesval = np.array([[0., 0., 0.], [0., 1., 0.], [0., 2., 0.], [0., 3., 0.]]) engine_thrusts = np.array([[10.]]) point_mass_locations = np.array([[0., 0.1, -0.5]]) indep_var_comp.add_output('nodes', val=nodesval, units='m') indep_var_comp.add_output('engine_thrusts', val=engine_thrusts, units='N') indep_var_comp.add_output('point_mass_locations', val=point_mass_locations, units='m') group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) group.add_subsystem('compute_point_mass_loads', comp, promotes=['*']) prob = Problem(model=group) prob.setup() prob.run_model() truth_array = np.array([-10., 0, 0., 0., 5., 1.]) assert_rel_error(self, prob['loads_from_thrusts'][0, :], truth_array, 1e-6)
def test_outputs(self): surfaces = get_default_surfaces() group = Group() comp = VLMGeometry(surface=surfaces[0]) indep_var_comp = IndepVarComp() indep_var_comp.add_output('def_mesh', val=surfaces[0]['mesh'], units='m') group.add_subsystem('geom', comp, promotes=['*']) group.add_subsystem('indep_var_comp', indep_var_comp, promotes=['*']) prob = Problem() prob.model.add_subsystem('group', group, promotes=['*']) prob.setup() prob.run_model() assert_rel_error(self, prob['widths'] , np.array([11.95624787, 11.90425878, 11.44086572]), 1e-6) assert_rel_error(self, prob['cos_sweep'] , np.array([9.7938336, 9.79384207, 9.79385053]), 1e-6) assert_rel_error(self, prob['S_ref'] , np.array([ 415.02211208]), 1e-6) assert_rel_error(self, prob['chords'] , np.array([ 2.72796, 5.1252628, 7.8891638, 13.6189974]), 1e-6) assert_rel_error(self, prob['lengths'] , np.array([ 2.72796, 5.1252628, 7.8891638, 13.6189974]), 1e-6)
def test(self): surface = get_default_surfaces()[0] comp = CreateRHS(surface=surface) run_test(self, comp)
def test(self): surfaces = get_default_surfaces() comp = VLMMtxRHSComp(surfaces=surfaces) run_test(self, comp)