def test_stretch_symmetry(self):
        symmetry = True
        mesh = get_mesh(symmetry)

        prob = Problem()
        group = prob.model

        val = np.random.random(1)

        comp = Stretch(val=val, mesh_shape=mesh.shape, symmetry=symmetry)
        group.add_subsystem('comp', comp)

        prob.setup()

        prob['comp.in_mesh'] = mesh

        prob.run_model()

        check = prob.check_partials(compact_print=True, abs_err_tol=1e-5, rel_err_tol=1e-5)
        assert_check_partials(check, atol=1e-6, rtol=1e-6)
Esempio n. 2
0
    def setup(self):
        surface = self.options['surface']

        mesh = surface['mesh']
        ny = mesh.shape[1]
        mesh_shape = mesh.shape
        symmetry = surface['symmetry']

        # This flag determines whether or not changes in z (dihedral) add an
        # additional rotation matrix to modify the twist direction
        self.rotate_x = True

        # 1. Taper

        if 'taper' in surface:
            val = surface['taper']
            promotes = ['taper']
        else:
            val = 1.
            promotes = []

        self.add_subsystem('taper',
                           Taper(val=val, mesh=mesh, symmetry=symmetry),
                           promotes_inputs=promotes)

        # 2. Scale X

        val = np.ones(ny)
        if 'chord_cp' in surface:
            promotes = ['chord']
        else:
            promotes = []

        self.add_subsystem('scale_x',
                           ScaleX(val=val, mesh_shape=mesh_shape),
                           promotes_inputs=promotes)

        # 3. Sweep

        if 'sweep' in surface:
            val = surface['sweep']
            promotes = ['sweep']
        else:
            val = 0.
            promotes = []

        self.add_subsystem('sweep',
                           Sweep(val=val,
                                 mesh_shape=mesh_shape,
                                 symmetry=symmetry),
                           promotes_inputs=promotes)

        # 4. Shear X

        val = np.zeros(ny)
        if 'xshear_cp' in surface:
            promotes = ['xshear']
        else:
            promotes = []

        self.add_subsystem('shear_x',
                           ShearX(val=val, mesh_shape=mesh_shape),
                           promotes_inputs=promotes)

        # 5. Stretch

        if 'span' in surface:
            promotes = ['span']
            val = surface['span']
        else:
            # Compute span. We need .real to make span to avoid OpenMDAO warnings.
            quarter_chord = 0.25 * mesh[-1, :, :] + 0.75 * mesh[0, :, :]
            span = max(quarter_chord[:, 1]).real - min(quarter_chord[:,
                                                                     1]).real
            if symmetry:
                span *= 2.
            val = span
            promotes = []

        self.add_subsystem('stretch',
                           Stretch(val=val,
                                   mesh_shape=mesh_shape,
                                   symmetry=symmetry),
                           promotes_inputs=promotes)

        # 6. Shear Y

        val = np.zeros(ny)
        if 'yshear_cp' in surface:
            promotes = ['yshear']
        else:
            promotes = []

        self.add_subsystem('shear_y',
                           ShearY(val=val, mesh_shape=mesh_shape),
                           promotes_inputs=promotes)

        # 7. Dihedral

        if 'dihedral' in surface:
            val = surface['dihedral']
            promotes = ['dihedral']
        else:
            val = 0.
            promotes = []

        self.add_subsystem('dihedral',
                           Dihedral(val=val,
                                    mesh_shape=mesh_shape,
                                    symmetry=symmetry),
                           promotes_inputs=promotes)

        # 8. Shear Z

        val = np.zeros(ny)
        if 'zshear_cp' in surface:
            promotes = ['zshear']
        else:
            promotes = []

        self.add_subsystem('shear_z',
                           ShearZ(val=val, mesh_shape=mesh_shape),
                           promotes_inputs=promotes)

        #Ajout Rémy :
        # 10. Dihedral Distrib
        val = np.zeros(ny - 1)
        if 'dihedral_distrib_cp' in surface:
            promotes = ['dihedral_distrib']
        else:
            val = np.zeros(ny - 1)
            promotes = []

        self.add_subsystem('dihedral_distrib',
                           Dihedral_distrib(val=val,
                                            mesh_shape=mesh_shape,
                                            symmetry=symmetry),
                           promotes_inputs=promotes)

        # 9. Rotate

        val = np.zeros(ny)
        if 'twist_cp' in surface:
            promotes = ['twist']
        else:
            val = np.zeros(ny)
            promotes = []

        self.add_subsystem('rotate',
                           Rotate(val=val,
                                  mesh_shape=mesh_shape,
                                  symmetry=symmetry),
                           promotes_inputs=promotes,
                           promotes_outputs=['mesh'])

        # #Ajout Rémy :
        # # 10. Dihedral Distrib
        # val = np.zeros(ny)
        # if 'dihedral_distrib_cp' in surface:
        #     promotes = ['dihedral_distrib']
        # else:
        #     val = np.zeros(ny)
        #     promotes = []

        # self.add_subsystem('dihedral_distrib', Dihedral_distrib(val=val, mesh_shape=mesh_shape, symmetry=symmetry),
        #                    promotes_inputs=promotes, promotes_outputs=['mesh'])

        # names = ['taper', 'scale_x', 'sweep', 'shear_x', 'stretch', 'shear_y', 'dihedral',
        #          'shear_z', 'rotate']
        #Ajout rémy :
        names = [
            'taper', 'scale_x', 'sweep', 'shear_x', 'stretch', 'shear_y',
            'dihedral', 'shear_z', 'dihedral_distrib', 'rotate'
        ]

        for j in np.arange(len(names) - 1):
            self.connect(names[j] + '.mesh', names[j + 1] + '.in_mesh')