Example #1
0
    def _create_nodes_elements(self, xyz_size, xyz_dim, stack=True):
        """helper for ``read_input_c3d``"""
        xmin, xmax, ymin, ymax, zmin, zmax = xyz_size
        xdim, ydim, zdim = xyz_dim
        x = linspace(0., 1., num=xdim)
        y = linspace(0., 1., num=ydim)
        z = linspace(0., 1., num=zdim)
        self.log.debug(str(x))

        # organized in x, y, z planes order
        planes = (
            # yz
            # xmin, xmax
            ((xmin, ymin, zmin), (xmin, ymin, zmax), (xmin, ymax, zmax),
             (xmin, ymax, zmin), y, z),
            ((xmax, ymin, zmin), (xmax, ymin, zmax), (xmax, ymax, zmax),
             (xmax, ymax, zmin), y, z),  # wrong

            ## xz
            # ymin, ymax
            ((xmin, ymin, zmin), (xmin, ymin, zmax), (xmax, ymin, zmax),
             (xmax, ymin, zmin), x, z),
            ((xmin, ymax, zmin), (xmin, ymax, zmax), (xmax, ymax, zmax),
             (xmax, ymax, zmin), x, z),

            # xy
            # zmin, zmax
            ((xmin, ymin, zmin), (xmin, ymax, zmin), (xmax, ymax, zmin),
             (xmax, ymin, zmin), x, y),
            ((xmin, ymin, zmax), (xmin, ymax, zmax), (xmax, ymax, zmax),
             (xmax, ymin, zmax), x, y),
        )
        points = []
        elements = []
        nnodes = 0
        for plane in planes:
            p1, p2, p3, p4, xi, yi = plane
            p1 = array(p1, dtype='float32')
            p2 = array(p2, dtype='float32')
            p3 = array(p3, dtype='float32')
            p4 = array(p4, dtype='float32')
            self.log.debug(str(plane[:1]))

            pointsi, elementsi = points_elements_from_quad_points(
                p1, p2, p3, p4, xi, yi)
            points.append(pointsi)
            if stack:
                elements.append(elementsi + nnodes)
                nnodes += pointsi.shape[0]
            else:
                elements.append(elementsi)
            #break
            #print(points)

        if stack:
            points = vstack(points)
            elements = vstack(elements)
        return points, elements
Example #2
0
def create_structured_cquad4s(model, pid,
                              p1, p2, p3, p4, nx, ny, nid=1, eid=1):
    nid0 = nid
    x = np.linspace(0., 1., nx + 1)
    y = np.linspace(0., 1., ny + 1)
    points, elements = points_elements_from_quad_points(p1, p2, p3, p4, x, y, dtype='int32')
    for point in points:
        model.add_grid(nid, point)
        nid += 1

    for node_ids in elements + nid0:
        model.add_cquad4(eid, pid, node_ids)
        eid += 1
    return nid, eid
Example #3
0
def create_structured_cquad4s(model,
                              pid,
                              p1,
                              p2,
                              p3,
                              p4,
                              nx,
                              ny,
                              nid=1,
                              eid=1,
                              theta_mcid=0.):
    """
    Parameters
    ----------
    p1 / p2 / p3 / p4 : (3, ) float ndarray
        points defining the quad
    nx : int
        points in the p1-p2 direction
    ny : int
        points in the p1-p4 direction
    nid / eid : int
        node / element id offset

    Returns
    -------
    nid : int
        ???
    eid : int
        ???
    """
    nid0 = nid
    x = np.linspace(0., 1., nx + 1)
    y = np.linspace(0., 1., ny + 1)
    points, elements = points_elements_from_quad_points(p1,
                                                        p2,
                                                        p3,
                                                        p4,
                                                        x,
                                                        y,
                                                        dtype='int32')
    for point in points:
        model.add_grid(nid, point)
        nid += 1

    for node_ids in elements + nid0:
        model.add_cquad4(eid, pid, node_ids, theta_mcid=theta_mcid)
        eid += 1
    return nid, eid
Example #4
0
def get_fuselage(dirname, isurface, surface, xyz_scale, dxyz, yduplicate,
                 nodes, line_elements, quad_elements, surfaces, ipoint):
    #print('----------------------------------------')
    #print(surface)
    nchord, chord_spacing = surface['chord']
    #nchord = 1
    assert nchord >= 1, nchord
    x = np.linspace(0.,
                    1.,
                    num=nchord + 1,
                    endpoint=True,
                    retstep=False,
                    dtype=None)
    y = np.array([0., 1.])
    #assert len(x) == len(y), 'x=%s y=%s' % (x, y)
    sections = surface['sections']
    del surface['sections']

    #print(surface)
    #print(sections)
    nsections = len(sections)
    if nsections == 0:
        #print('*****from file')
        ipoint, nelement2 = get_fuselage_from_file(dirname, isurface, surface,
                                                   xyz_scale, dxyz, nodes,
                                                   quad_elements, surfaces,
                                                   ipoint, nchord)
        return ipoint

    for i in range(nsections - 1):
        section0 = sections[i]
        if 'afile' in section0:
            del section0['afile']
        if 'control' in section0:
            del section0['control']

        section1 = sections[i + 1]
        if 'afile' in section1:
            del section1['afile']
        if 'control' in section1:
            del section1['control']
        #print(section0)
        #print(section1)
        p1 = np.array(section0['xyz_LE'])
        p4 = np.array(section1['xyz_LE'])
        chord0 = section0['section'][0]
        chord1 = section1['section'][0]
        #print('chords =', chord0, chord1)
        #print('xyz_scale =', xyz_scale)
        #incidence = section[1]
        p2 = p1 + np.array([chord0, 0., 0.])
        p3 = p4 + np.array([chord1, 0., 0.])

        point, element = points_elements_from_quad_points(p1,
                                                          p2,
                                                          p3,
                                                          p4,
                                                          x,
                                                          y,
                                                          dtype='int32')
        ipoint = save_wing_elements(isurface, point, element, xyz_scale, dxyz,
                                    nodes, quad_elements, surfaces, ipoint)

        if yduplicate is not None:
            assert np.allclose(yduplicate, 0.0), 'yduplicate=%s' % yduplicate
            p1[1] *= -1
            p2[1] *= -1
            p3[1] *= -1
            p4[1] *= -1

            # dxyz2 has to be calculated like this because dxyz is global to the surface
            # and we need a mirrored dxyz
            dxyz2 = np.array([dxyz[0], -dxyz[1], dxyz[2]])

            point2, element2 = points_elements_from_quad_points(p1,
                                                                p2,
                                                                p3,
                                                                p4,
                                                                x,
                                                                y,
                                                                dtype='int32')
            ipoint = save_wing_elements(isurface, point2, element2, xyz_scale,
                                        dxyz2, nodes, quad_elements, surfaces,
                                        ipoint)
            nodes_temp = np.vstack(nodes)
            assert nodes_temp.shape[
                0] == ipoint, 'nodes_temp.shape=%s ipoint=%s' % (
                    nodes_temp.shape, ipoint)

        #print('npoint=%s nelement=%s' % (npoint, nelement2))

    return ipoint
Example #5
0
    def get_nodes_elements(self):
        dirname = os.path.dirname(self.avl_filename)
        nodes = []
        quad_elements = []
        line_elements = []
        ipoint = 0
        surfaces = []

        #print('----')
        for isurface, surface in enumerate(self.surfaces):
            #print('isurface =', isurface)
            xyz_scale = np.ones(3)
            if 'scale' in surface:
                xyz_scale = np.array(surface['scale'])

            dxyz = np.zeros(3)
            if 'translate' in surface:
                dxyz = np.array(surface['translate'])

            yduplicate = None
            if 'yduplicate' in surface:
                yduplicate = surface['yduplicate']

            if 'name' not in surface:
                print('no name...%s' % surface)

            name = surface['name']
            #print("name=%r ipoint=%s" % (name, ipoint))
            if 'chord' not in surface:
                print('no chord for %s...' % name)
                continue

            if 'span' not in surface:
                print('fuselage surface: %s\n' % simplify_surface(surface))
                if nodes:
                    nodes_temp = np.vstack(nodes)
                    assert nodes_temp.shape[
                        0] == ipoint, 'nodes_temp.shape=%s ipoint=%s' % (
                            nodes_temp.shape, ipoint)

                ipoint = get_fuselage(dirname, isurface, surface, xyz_scale,
                                      dxyz, yduplicate, nodes, line_elements,
                                      quad_elements, surfaces, ipoint)
                #if npoint == 0:
                #self.log.info('skipping %s because there are no sections' % surface)
                #ipoint += npoint
                #print("npoint = ", npoint)
                #print('-----------')
                nodes_temp = np.vstack(nodes)
                assert nodes_temp.shape[
                    0] == ipoint, 'nodes_temp.shape=%s ipoint=%s' % (
                        nodes_temp.shape, ipoint)
                #break
                continue

        #def get_wing(isurface, surface, xyz_scale, dxyz, nodes,
        #quad_elements, surfaces, ipoint):
            nchord, chord_spacing = surface['chord']
            nspan, span_spacing = surface['span']
            sections = surface['sections']

            span_stations, airfoil_sections = get_airfoils_from_sections(
                sections)

            #for iairfoil, is_afile in enumerate(surface['is_afile']):
            #pass

            #surface['naca']
            #print('naca =', naca)
            loft_sections = []
            #for naca in airfoils:
            #get_lofted_sections(None)

            assert nchord > 0, nchord
            assert nspan > 0, nspan
            #nchord = 1 #  breaks b737 independently of nspan if we use the real value
            #nspan = 1 #  breaks b737 independently of nchord if we use the real value
            #nchord = 2
            #nspan = 2
            x = np.linspace(0.,
                            1.,
                            num=nchord + 1,
                            endpoint=True,
                            retstep=False,
                            dtype=None)
            y = np.linspace(0.,
                            1.,
                            num=nspan + 1,
                            endpoint=True,
                            retstep=False,
                            dtype=None)
            #print('x =', x)
            #print('y =', y)

            del surface['sections']

            print('wing surface:', simplify_surface(surface))

            #print(surface.keys())
            #print('name =', surface['name'])

            nsections = len(sections)
            for i in range(nsections - 1):
                end = i == nsections - 1

                section0 = sections[i]
                #if 'afile' in section0:
                #del section0['afile']
                #if 'control' in section0:
                #del section0['control']

                section1 = sections[i + 1]
                #if 'afile' in section1:
                #del section1['afile']
                #if 'control' in section1:
                #del section1['control']

                #print(section0)
                #print('*****************')
                #print(section1)
                p1 = np.array(section0['xyz_LE'])
                p4 = np.array(section1['xyz_LE'])
                #Xle,Yle,Zle =  airfoil's leading edge location
                #Chord       =  the airfoil's chord  (trailing edge is at Xle+Chord,Yle,Zle)
                #Ainc        =  incidence angle, taken as a rotation (+ by RH rule) about
                #the surface's spanwise axis projected onto the Y-Z plane.
                #Nspan       =  number of spanwise vortices until the next section [ optional ]
                #Sspace      =  controls the spanwise spacing of the vortices      [ optional ]

                #section = [chord, ainc]
                #section = [chord, ainc, nspan, span_spacing]
                chord0 = section0['section'][0]
                chord1 = section1['section'][0]

                #print('chords =', chord0, chord1)
                #print('xyz_scale =', xyz_scale)
                #incidence = section[1]
                p2 = p1 + np.array([chord0, 0., 0.])
                p3 = p4 + np.array([chord1, 0., 0.])

                alpha0 = section0['section'][1]
                alpha1 = section1['section'][1]

                if airfoil_sections[i] is not None:
                    interpolated_stations = interp_stations(
                        y,
                        nspan,
                        airfoil_sections[i],
                        chord0,
                        alpha0,
                        p1,
                        airfoil_sections[i + 1],
                        chord1,
                        alpha1,
                        p4,
                        end=end)

                #loft_sections.append(chord0*airfoil_sections[i])
                #loft_sections.append(chord1*airfoil_sections[i+1])

                assert len(x) > 1, x
                point, element = points_elements_from_quad_points(
                    p1, p2, p3, p4, x, y, dtype='int32')

                #dxyz[1] = 0.

                ipoint = save_wing_elements(isurface, point, element,
                                            xyz_scale, dxyz, nodes,
                                            quad_elements, surfaces, ipoint)

                nodes_temp = np.vstack(nodes)
                assert nodes_temp.shape[
                    0] == ipoint, 'nodes_temp.shape=%s ipoint=%s' % (
                        nodes_temp.shape, ipoint)

                #point2 = None
                #element2 = None
                #print("p1[%i]  = %s" % (i, p1[:2]))
                if yduplicate is not None:
                    assert np.allclose(yduplicate,
                                       0.0), 'yduplicate=%s' % yduplicate
                    p1[1] *= -1
                    p2[1] *= -1
                    p3[1] *= -1
                    p4[1] *= -1

                    # dxyz2 has to be calculated like this because dxyz is global to the surface
                    # and we need a mirrored dxyz
                    dxyz2 = np.array([dxyz[0], -dxyz[1], dxyz[2]])

                    point2, element2 = points_elements_from_quad_points(
                        p1, p2, p3, p4, x, y, dtype='int32')
                    ipoint = save_wing_elements(isurface, point2, element2,
                                                xyz_scale, dxyz2, nodes,
                                                quad_elements, surfaces,
                                                ipoint)
                    nodes_temp = np.vstack(nodes)
                    assert nodes_temp.shape[
                        0] == ipoint, 'nodes_temp.shape=%s ipoint=%s' % (
                            nodes_temp.shape, ipoint)

                #for e in elements:
                #print("  ", e)
                #print('npoint=%s nelement=%s' % (npoint, nelement2))
                #break
                #if not section['afile']:
                #del section['afile']
                #if not section['control']:
                #del section['control']
                #print('  ', section)
            #print('-----------')
            nodes_temp = np.vstack(nodes)
            assert nodes_temp.shape[
                0] == ipoint, 'nodes_temp.shape=%s ipoint=%s' % (
                    nodes_temp.shape, ipoint)
            #print('')
            #break
        #print("end ipoint=%s" % (ipoint))

        nodes = np.vstack(nodes)
        #print(nodes.shape)
        quad_elements = np.vstack(quad_elements)
        if line_elements:
            line_elements = np.vstack(line_elements)
        surfaces = np.hstack(surfaces)
        assert len(surfaces) == quad_elements.shape[0]
        return nodes, quad_elements, line_elements, surfaces