def setup(self):
        surface = self.options['surface']
        ny = surface['num_y']

        if 'spar_thickness_cp' in surface.keys(
        ) or 'skin_thickness_cp' in surface.keys():
            # Add independent variables that do not belong to a specific component
            indep_var_comp = IndepVarComp()

            # Add structural components to the surface-specific group
            self.add_subsystem('indep_vars', indep_var_comp, promotes=['*'])

        if 'spar_thickness_cp' in surface.keys():
            n_cp = len(surface['spar_thickness_cp'])
            # Add bspline components for active bspline geometric variables.
            self.add_subsystem('spar_thickness_bsp',
                               BsplinesComp(in_name='spar_thickness_cp',
                                            out_name='spar_thickness',
                                            num_control_points=n_cp,
                                            num_points=int(ny - 1),
                                            bspline_order=min(n_cp, 4),
                                            distribution='uniform'),
                               promotes_inputs=['spar_thickness_cp'],
                               promotes_outputs=['spar_thickness'])
            indep_var_comp.add_output('spar_thickness_cp',
                                      val=surface['spar_thickness_cp'],
                                      units='m')

        if 'skin_thickness_cp' in surface.keys():
            n_cp = len(surface['skin_thickness_cp'])
            # Add bspline components for active bspline geometric variables.
            self.add_subsystem('skin_thickness_bsp',
                               BsplinesComp(in_name='skin_thickness_cp',
                                            out_name='skin_thickness',
                                            num_control_points=n_cp,
                                            num_points=int(ny - 1),
                                            bspline_order=min(n_cp, 4),
                                            distribution='uniform'),
                               promotes_inputs=['skin_thickness_cp'],
                               promotes_outputs=['skin_thickness'])
            indep_var_comp.add_output('skin_thickness_cp',
                                      val=surface['skin_thickness_cp'],
                                      units='m')

        self.add_subsystem(
            'wingbox_geometry',
            WingboxGeometry(surface=surface),
            promotes_inputs=['mesh'],
            promotes_outputs=['fem_chords', 'fem_twists', 'streamwise_chords'])

        self.add_subsystem('wingbox',
                           SectionPropertiesWingbox(surface=surface),
                           promotes_inputs=[
                               'spar_thickness', 'skin_thickness', 't_over_c',
                               'fem_chords', 'fem_twists', 'streamwise_chords'
                           ],
                           promotes_outputs=[
                               'A', 'Iy', 'Qz', 'Iz', 'J', 'A_enc', 'A_int',
                               'htop', 'hbottom', 'hfront', 'hrear'
                           ])
    def setup(self):
        surface = self.options['surface']
        connect_geom_DVs = self.options['connect_geom_DVs']
        mesh = surface['mesh']
        ny = mesh.shape[1]

        if connect_geom_DVs:
            # Add independent variables that do not belong to a specific component
            indep_var_comp = IndepVarComp()

            # Add structural components to the surface-specific group
            self.add_subsystem('indep_vars', indep_var_comp, promotes=['*'])

        if 'thickness_cp' in surface.keys():
            n_cp = len(surface['thickness_cp'])
            # Add bspline components for active bspline geometric variables.
            self.add_subsystem('thickness_bsp',
                               BsplinesComp(in_name='thickness_cp',
                                            out_name='thickness',
                                            units='m',
                                            num_control_points=n_cp,
                                            num_points=int(ny - 1),
                                            bspline_order=min(n_cp, 4),
                                            distribution='uniform'),
                               promotes_inputs=['thickness_cp'],
                               promotes_outputs=['thickness'])
            if connect_geom_DVs:
                indep_var_comp.add_output('thickness_cp',
                                          val=surface['thickness_cp'],
                                          units='m')

        if 'radius_cp' in surface.keys():
            n_cp = len(surface['radius_cp'])
            # Add bspline components for active bspline geometric variables.
            self.add_subsystem('radius_bsp',
                               BsplinesComp(in_name='radius_cp',
                                            out_name='radius',
                                            units='m',
                                            num_control_points=n_cp,
                                            num_points=int(ny - 1),
                                            bspline_order=min(n_cp, 4),
                                            distribution='uniform'),
                               promotes_inputs=['radius_cp'],
                               promotes_outputs=['radius'])
            if connect_geom_DVs:
                indep_var_comp.add_output('radius_cp',
                                          val=surface['radius_cp'],
                                          units='m')
        else:
            self.add_subsystem('radius_comp',
                               RadiusComp(surface=surface),
                               promotes_inputs=['mesh', 't_over_c'],
                               promotes_outputs=['radius'])

        self.add_subsystem('tube',
                           SectionPropertiesTube(surface=surface),
                           promotes_inputs=['thickness', 'radius'],
                           promotes_outputs=['A', 'Iy', 'Iz', 'J'])
Exemple #3
0
    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(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 setup(self):
        surface = self.options['surface']

        # Get the surface name and create a group to contain components
        # only for this surface
        ny = surface['mesh'].shape[1]

        # Check if any control points were added to the surface dict
        dv_keys = set([
            'twist_cp', 'chord_cp', 'xshear_cp', 'yshear_cp', 'zshear_cp',
            'sweep', 'span', 'taper', 'dihedral', 't_over_c_cp'
        ])
        active_dv_keys = dv_keys.intersection(set(surface.keys()))
        # Make sure that at least one of them is an independent variable
        make_ivc = False
        for key in active_dv_keys:
            if surface.get(key + '_dv', True):
                make_ivc = True
                break

        if make_ivc or self.options['DVGeo']:
            # Add independent variables that do not belong to a specific component
            indep_var_comp = IndepVarComp()

            # Add structural components to the surface-specific group
            self.add_subsystem('indep_vars', indep_var_comp, promotes=['*'])

        if self.options['DVGeo']:
            from openaerostruct.geometry.ffd_component import GeometryMesh
            indep_var_comp.add_output('shape',
                                      val=np.zeros(
                                          (surface['mx'], surface['my'])),
                                      units='m')

            if 't_over_c_cp' in surface.keys():
                n_cp = len(surface['t_over_c_cp'])
                # Add bspline components for active bspline geometric variables.
                self.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'])
                if surface.get('t_over_c_cp_dv', True):
                    indep_var_comp.add_output('t_over_c_cp',
                                              val=surface['t_over_c_cp'])

            self.add_subsystem('mesh',
                               GeometryMesh(surface=surface,
                                            DVGeo=self.options['DVGeo']),
                               promotes_inputs=['shape'],
                               promotes_outputs=['mesh'])

        else:
            from openaerostruct.geometry.geometry_mesh import GeometryMesh

            bsp_inputs = []

            if 'twist_cp' in surface.keys():
                n_cp = len(surface['twist_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('twist_bsp',
                                   BsplinesComp(in_name='twist_cp',
                                                out_name='twist',
                                                units='deg',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['twist_cp'],
                                   promotes_outputs=['twist'])
                bsp_inputs.append('twist')

                # Since default assumption is that we want tail rotation as a design variable, add this to allow for trimmed drag polar where the tail rotation should not be a design variable
                if surface.get('twist_cp_dv', True):
                    indep_var_comp.add_output('twist_cp',
                                              val=surface['twist_cp'],
                                              units='deg')

            if 'chord_cp' in surface.keys():
                n_cp = len(surface['chord_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('chord_bsp',
                                   BsplinesComp(in_name='chord_cp',
                                                out_name='chord',
                                                units='m',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['chord_cp'],
                                   promotes_outputs=['chord'])
                bsp_inputs.append('chord')
                if surface.get('chord_cp_dv', True):
                    indep_var_comp.add_output('chord_cp',
                                              val=surface['chord_cp'],
                                              units='m')

            if 't_over_c_cp' in surface.keys():
                n_cp = len(surface['t_over_c_cp'])
                # Add bspline components for active bspline geometric variables.
                self.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'])
                if surface.get('t_over_c_cp_dv', True):
                    indep_var_comp.add_output('t_over_c_cp',
                                              val=surface['t_over_c_cp'])

            if 'xshear_cp' in surface.keys():
                n_cp = len(surface['xshear_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('xshear_bsp',
                                   BsplinesComp(in_name='xshear_cp',
                                                out_name='xshear',
                                                units='m',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['xshear_cp'],
                                   promotes_outputs=['xshear'])
                bsp_inputs.append('xshear')
                if surface.get('xshear_cp_dv', True):
                    indep_var_comp.add_output('xshear_cp',
                                              val=surface['xshear_cp'],
                                              units='m')

            if 'yshear_cp' in surface.keys():
                n_cp = len(surface['yshear_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('yshear_bsp',
                                   BsplinesComp(in_name='yshear_cp',
                                                out_name='yshear',
                                                units='m',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['yshear_cp'],
                                   promotes_outputs=['yshear'])
                bsp_inputs.append('yshear')
                if surface.get('yshear_cp_dv', True):
                    indep_var_comp.add_output('yshear_cp',
                                              val=surface['yshear_cp'],
                                              units='m')

            if 'zshear_cp' in surface.keys():
                n_cp = len(surface['zshear_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('zshear_bsp',
                                   BsplinesComp(in_name='zshear_cp',
                                                out_name='zshear',
                                                units='m',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['zshear_cp'],
                                   promotes_outputs=['zshear'])
                bsp_inputs.append('zshear')
                if surface.get('zshear_cp_dv', True):
                    indep_var_comp.add_output('zshear_cp',
                                              val=surface['zshear_cp'],
                                              units='m')

            if 'sweep' in surface.keys():
                bsp_inputs.append('sweep')
                if surface.get('sweep_dv', True):
                    indep_var_comp.add_output('sweep',
                                              val=surface['sweep'],
                                              units='deg')

            if 'span' in surface.keys():
                bsp_inputs.append('span')
                if surface.get('span_dv', True):
                    indep_var_comp.add_output('span',
                                              val=surface['span'],
                                              units='m')

            if 'dihedral' in surface.keys():
                bsp_inputs.append('dihedral')
                if surface.get('dihedral_dv', True):
                    indep_var_comp.add_output('dihedral',
                                              val=surface['dihedral'],
                                              units='deg')

            if 'taper' in surface.keys():
                bsp_inputs.append('taper')
                if surface.get('taper_dv', True):
                    indep_var_comp.add_output('taper', val=surface['taper'])

            self.add_subsystem('mesh',
                               GeometryMesh(surface=surface),
                               promotes_inputs=bsp_inputs,
                               promotes_outputs=['mesh'])
    def test2(self):
        """
        This is for checking the computation.
        """

        surface = get_default_surfaces()[0]
        surface['t_over_c_cp'] = np.array([0.1, 0.15, 0.2])
        surface['spar_thickness_cp'] = np.array([0.004, 0.008, 0.02])
        surface['skin_thickness_cp'] = np.array([0.01, 0.015, 0.021])
        surface['fem_chords_cp'] = np.array([2., 3., 4.])
        surface['streamwise_chords_cp'] = np.array([3., 4., 5.])
        surface['fem_twists_cp'] = np.array([5., 3., 2.]) / 180. * np.pi

        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

        mesh = surface['mesh']
        ny = mesh.shape[1]
        nx = mesh.shape[0]
        n_cp = len(surface['t_over_c_cp'])

        prob = Problem()

        indep_var_comp = IndepVarComp()
        indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp'])
        indep_var_comp.add_output('spar_thickness_cp',
                                  val=surface['spar_thickness_cp'])
        indep_var_comp.add_output('skin_thickness_cp',
                                  val=surface['skin_thickness_cp'])
        indep_var_comp.add_output('fem_chords_cp',
                                  val=surface['fem_chords_cp'])
        indep_var_comp.add_output('streamwise_chords_cp',
                                  val=surface['streamwise_chords_cp'])
        indep_var_comp.add_output('fem_twists_cp',
                                  val=surface['fem_twists_cp'])
        prob.model.add_subsystem('indep_var_comp',
                                 indep_var_comp,
                                 promotes=['*'])

        prob.model.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'])

        prob.model.add_subsystem('skin_thickness_bsp',
                                 BsplinesComp(in_name='skin_thickness_cp',
                                              out_name='skin_thickness',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['skin_thickness_cp'],
                                 promotes_outputs=['skin_thickness'])

        prob.model.add_subsystem('spar_thickness_bsp',
                                 BsplinesComp(in_name='spar_thickness_cp',
                                              out_name='spar_thickness',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['spar_thickness_cp'],
                                 promotes_outputs=['spar_thickness'])

        prob.model.add_subsystem('fem_chords_bsp',
                                 BsplinesComp(in_name='fem_chords_cp',
                                              out_name='fem_chords',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['fem_chords_cp'],
                                 promotes_outputs=['fem_chords'])

        prob.model.add_subsystem('streamwise_chords_bsp',
                                 BsplinesComp(in_name='streamwise_chords_cp',
                                              out_name='streamwise_chords',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['streamwise_chords_cp'],
                                 promotes_outputs=['streamwise_chords'])

        prob.model.add_subsystem('fem_twists_bsp',
                                 BsplinesComp(in_name='fem_twists_cp',
                                              out_name='fem_twists',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['fem_twists_cp'],
                                 promotes_outputs=['fem_twists'])

        comp = SectionPropertiesWingbox(surface=surface)
        prob.model.add_subsystem('sec_prop_wb', comp, promotes=['*'])

        prob.setup()
        #
        # from openmdao.api import view_model
        # view_model(prob)

        prob.run_model()

        # print( prob['A'] )
        # print( prob['A_enc'] )
        # print( prob['A_int'] )
        # print( prob['Iy'] )
        # print( prob['Qz'] )
        # print( prob['Iz'] )
        # print( prob['J'] )
        # print( prob['htop'] )
        # print( prob['hbottom'] )
        # print( prob['hfront'] )
        # print( prob['hrear'] )

        assert_rel_error(self, prob['A'],
                         np.array([0.02203548, 0.0563726, 0.11989703]), 1e-6)
        assert_rel_error(self, prob['A_enc'],
                         np.array([0.3243776, 0.978003, 2.17591]), 1e-6)
        assert_rel_error(self, prob['A_int'],
                         np.array([0.3132502, 0.949491, 2.11512]), 1e-6)
        assert_rel_error(self, prob['Iy'],
                         np.array([0.00218612, 0.01455083, 0.06342765]), 1e-6)
        assert_rel_error(self, prob['Qz'],
                         np.array([0.00169233, 0.00820558, 0.02707493]), 1e-6)
        assert_rel_error(self, prob['Iz'],
                         np.array([0.00055292, 0.00520911, 0.02785168]), 1e-6)
        assert_rel_error(self, prob['J'],
                         np.array([0.00124939, 0.01241967, 0.06649673]), 1e-6)
        assert_rel_error(self, prob['htop'],
                         np.array([0.19106873, 0.36005945, 0.5907887]), 1e-6)
        assert_rel_error(self, prob['hbottom'],
                         np.array([0.19906584, 0.37668887, 0.61850335]), 1e-6)
        assert_rel_error(self, prob['hfront'],
                         np.array([0.52341176, 0.78649186, 1.04902676]), 1e-6)
        assert_rel_error(self, prob['hrear'],
                         np.array([0.47524073, 0.71429312, 0.95303545]), 1e-6)
    def test3(self):
        """
        This is an extreme nonphysical case (large twist angles) for checking the computation.
        """

        surface = get_default_surfaces()[0]
        surface['t_over_c_cp'] = np.array([0.1, 0.15, 0.2])
        surface['spar_thickness_cp'] = np.array([0.004, 0.008, 0.02])
        surface['skin_thickness_cp'] = np.array([0.01, 0.015, 0.021])
        surface['fem_chords_cp'] = np.array([2., 3., 4.])
        surface['streamwise_chords_cp'] = np.array([3., 4., 5.])
        surface['fem_twists_cp'] = np.array([5., 3., 2.])

        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

        mesh = surface['mesh']
        ny = mesh.shape[1]
        nx = mesh.shape[0]
        n_cp = len(surface['t_over_c_cp'])

        prob = Problem()

        indep_var_comp = IndepVarComp()
        indep_var_comp.add_output('t_over_c_cp', val=surface['t_over_c_cp'])
        indep_var_comp.add_output('spar_thickness_cp',
                                  val=surface['spar_thickness_cp'])
        indep_var_comp.add_output('skin_thickness_cp',
                                  val=surface['skin_thickness_cp'])
        indep_var_comp.add_output('fem_chords_cp',
                                  val=surface['fem_chords_cp'])
        indep_var_comp.add_output('streamwise_chords_cp',
                                  val=surface['streamwise_chords_cp'])
        indep_var_comp.add_output('fem_twists_cp',
                                  val=surface['fem_twists_cp'])
        prob.model.add_subsystem('indep_var_comp',
                                 indep_var_comp,
                                 promotes=['*'])

        prob.model.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'])

        prob.model.add_subsystem('skin_thickness_bsp',
                                 BsplinesComp(in_name='skin_thickness_cp',
                                              out_name='skin_thickness',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              units='m',
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['skin_thickness_cp'],
                                 promotes_outputs=['skin_thickness'])

        prob.model.add_subsystem('spar_thickness_bsp',
                                 BsplinesComp(in_name='spar_thickness_cp',
                                              out_name='spar_thickness',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              units='m',
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['spar_thickness_cp'],
                                 promotes_outputs=['spar_thickness'])

        prob.model.add_subsystem('fem_chords_bsp',
                                 BsplinesComp(in_name='fem_chords_cp',
                                              out_name='fem_chords',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              units='m',
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['fem_chords_cp'],
                                 promotes_outputs=['fem_chords'])

        prob.model.add_subsystem('streamwise_chords_bsp',
                                 BsplinesComp(in_name='streamwise_chords_cp',
                                              out_name='streamwise_chords',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              units='m',
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['streamwise_chords_cp'],
                                 promotes_outputs=['streamwise_chords'])

        prob.model.add_subsystem('fem_twists_bsp',
                                 BsplinesComp(in_name='fem_twists_cp',
                                              out_name='fem_twists',
                                              units='deg',
                                              num_control_points=n_cp,
                                              num_points=int(ny - 1),
                                              bspline_order=min(n_cp, 4),
                                              distribution='uniform'),
                                 promotes_inputs=['fem_twists_cp'],
                                 promotes_outputs=['fem_twists'])

        comp = SectionPropertiesWingbox(surface=surface)
        prob.model.add_subsystem('sec_prop_wb', comp, promotes=['*'])

        prob.setup()
        #
        # from openmdao.api import view_model
        # view_model(prob)

        prob.run_model()

        # print( prob['A'] )
        # print( prob['A_enc'] )
        # print( prob['A_int'] )
        # print( prob['Iy'] )
        # print( prob['Qz'] )
        # print( prob['Iz'] )
        # print( prob['J'] )
        # print( prob['htop'] )
        # print( prob['hbottom'] )
        # print( prob['hfront'] )
        # print( prob['hrear'] )

        assert_rel_error(self, prob['A'],
                         np.array([0.0058738, -0.05739528, -0.05042289]), 1e-6)
        assert_rel_error(self, prob['A_enc'],
                         np.array([0.3243776, 0.978003, 2.17591]), 1e-6)
        assert_rel_error(self, prob['A_int'],
                         np.array([0.3132502, 0.949491, 2.11512]), 1e-6)
        assert_rel_error(
            self, prob['Iy'],
            np.array([3.59803239e-05, -1.52910019e-02, -4.01035510e-03]), 1e-6)
        assert_rel_error(self, prob['Qz'],
                         np.array([0.00129261, 0.00870662, 0.02500053]), 1e-6)
        assert_rel_error(self, prob['Iz'],
                         np.array([0.00056586, -0.00582207, -0.02877714]),
                         1e-6)
        assert_rel_error(self, prob['J'],
                         np.array([0.00124939, 0.01241967, 0.06649673]), 1e-6)
        assert_rel_error(self, prob['htop'],
                         np.array([0.53933652, -0.23509863, 0.71255343]), 1e-6)
        assert_rel_error(self, prob['hbottom'],
                         np.array([0.50366564, -0.19185349, 0.73525459]), 1e-6)
        assert_rel_error(self, prob['hfront'],
                         np.array([0.13442747, -0.78514756, -0.3919784]), 1e-6)
        assert_rel_error(self, prob['hrear'],
                         np.array([0.12219305, -0.71214916, -0.35484131]),
                         1e-6)
    def setup(self):
        surface = self.options['surface']

        # Get the surface name and create a group to contain components
        # only for this surface
        ny = surface['mesh'].shape[1]

        if 'twist_cp' in surface.keys() or 'chord_cp' in surface.keys(
        ) or 'xshear_cp' in surface.keys() or 'yshear_cp' in surface.keys(
        ) or 'zshear_cp' in surface.keys() or 'sweep' in surface.keys(
        ) or 'taper' in surface.keys() or 'dihedral' in surface.keys(
        ) or self.options['DVGeo']:
            # Add independent variables that do not belong to a specific component
            indep_var_comp = IndepVarComp()

            # Add structural components to the surface-specific group
            self.add_subsystem('indep_vars', indep_var_comp, promotes=['*'])

        if self.options['DVGeo']:
            from openaerostruct.geometry.ffd_component import GeometryMesh
            indep_var_comp.add_output('shape',
                                      val=np.zeros(
                                          (surface['mx'], surface['my'])),
                                      units='m')

            self.add_subsystem('mesh',
                               GeometryMesh(surface=surface,
                                            DVGeo=self.options['DVGeo']),
                               promotes_inputs=['shape'],
                               promotes_outputs=['mesh'])

        else:
            from openaerostruct.geometry.geometry_mesh import GeometryMesh

            bsp_inputs = []

            if 'twist_cp' in surface.keys():
                n_cp = len(surface['twist_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('twist_bsp',
                                   BsplinesComp(in_name='twist_cp',
                                                out_name='twist',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['twist_cp'],
                                   promotes_outputs=['twist'])
                bsp_inputs.append('twist')
                indep_var_comp.add_output('twist_cp', val=surface['twist_cp'])

            if 'chord_cp' in surface.keys():
                n_cp = len(surface['chord_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('chord_bsp',
                                   BsplinesComp(in_name='chord_cp',
                                                out_name='chord',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['chord_cp'],
                                   promotes_outputs=['chord'])
                bsp_inputs.append('chord')
                indep_var_comp.add_output('chord_cp',
                                          val=surface['chord_cp'],
                                          units='m')

            if 'toverc_cp' in surface.keys():
                n_cp = len(surface['toverc_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('toverc_bsp',
                                   BsplinesComp(in_name='toverc_cp',
                                                out_name='toverc',
                                                num_control_points=n_cp,
                                                num_points=int(ny - 1),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['toverc_cp'],
                                   promotes_outputs=['toverc'])
                indep_var_comp.add_output('toverc_cp',
                                          val=surface['toverc_cp'],
                                          units='m')

            if 'xshear_cp' in surface.keys():
                n_cp = len(surface['xshear_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('xshear_bsp',
                                   BsplinesComp(in_name='xshear_cp',
                                                out_name='xshear',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['xshear_cp'],
                                   promotes_outputs=['xshear'])
                bsp_inputs.append('xshear')
                indep_var_comp.add_output('xshear_cp',
                                          val=surface['xshear_cp'],
                                          units='m')

            if 'yshear_cp' in surface.keys():
                n_cp = len(surface['yshear_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('yshear_bsp',
                                   BsplinesComp(in_name='yshear_cp',
                                                out_name='yshear',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['yshear_cp'],
                                   promotes_outputs=['yshear'])
                bsp_inputs.append('yshear')
                indep_var_comp.add_output('yshear_cp',
                                          val=surface['yshear_cp'],
                                          units='m')

            if 'zshear_cp' in surface.keys():
                n_cp = len(surface['zshear_cp'])
                # Add bspline components for active bspline geometric variables.
                self.add_subsystem('zshear_bsp',
                                   BsplinesComp(in_name='zshear_cp',
                                                out_name='zshear',
                                                num_control_points=n_cp,
                                                num_points=int(ny),
                                                bspline_order=min(n_cp, 4),
                                                distribution='uniform'),
                                   promotes_inputs=['zshear_cp'],
                                   promotes_outputs=['zshear'])
                bsp_inputs.append('zshear')
                indep_var_comp.add_output('zshear_cp',
                                          val=surface['zshear_cp'],
                                          units='m')

            if 'sweep' in surface.keys():
                bsp_inputs.append('sweep')
                indep_var_comp.add_output('sweep',
                                          val=surface['sweep'],
                                          units='deg')

            if 'dihedral' in surface.keys():
                bsp_inputs.append('dihedral')
                indep_var_comp.add_output('dihedral',
                                          val=surface['dihedral'],
                                          units='deg')

            if 'taper' in surface.keys():
                bsp_inputs.append('taper')
                indep_var_comp.add_output('taper', val=surface['taper'])

            self.add_subsystem('mesh',
                               GeometryMesh(surface=surface),
                               promotes_inputs=bsp_inputs,
                               promotes_outputs=['mesh'])