示例#1
0
def create_panel(Lx, Ly, use_hole=True):
    '''
    Create a panel with a whole in it
    '''
    # Set the number of load cases
    nu = 2
    nv = 2
    x = np.linspace(-0.5 * Lx, 0.5 * Lx, nu)
    y = np.linspace(-0.5 * Ly, 0.5 * Ly, nv)
    pts = np.zeros((nu, nv, 3))
    for j in range(nv):
        for i in range(nu):
            pts[i, j, 0] = x[i]
            pts[i, j, 1] = y[j]

    # Create the b-spline surface
    surf = TMR.BsplineSurface(pts)
    face = TMR.FaceFromSurface(surf)

    r = 0.2
    c = 0.5
    v1 = TMR.VertexFromFace(face, 0.0, 0.0)
    v2 = TMR.VertexFromFace(face, 1.0, 0.0)
    v3 = TMR.VertexFromFace(face, 1.0, 1.0)
    v4 = TMR.VertexFromFace(face, 0.0, 1.0)
    v5 = TMR.VertexFromFace(face, c - r, c)

    # Set up the first edge
    pcurve1 = TMR.BsplinePcurve(np.array([[0.0, 0.0], [1.0, 0.0]]))
    edge1 = TMR.EdgeFromFace(face, pcurve1)
    edge1.setVertices(v1, v2)
    edge1.setAttribute('y-')

    # Set up the first edge
    pcurve2 = TMR.BsplinePcurve(np.array([[1.0, 0.0], [1.0, 1.0]]))
    edge2 = TMR.EdgeFromFace(face, pcurve2)
    edge2.setVertices(v2, v3)
    edge2.setAttribute('x+')

    # Set up the first edge
    pcurve3 = TMR.BsplinePcurve(np.array([[1.0, 1.0], [0.0, 1.0]]))
    edge3 = TMR.EdgeFromFace(face, pcurve3)
    edge3.setVertices(v3, v4)
    edge3.setAttribute('y+')

    # Set up the first edge
    pcurve4 = TMR.BsplinePcurve(np.array([[0.0, 1.0], [0.0, 0.0]]))
    edge4 = TMR.EdgeFromFace(face, pcurve4)
    edge4.setVertices(v4, v1)
    edge4.setAttribute('x-')

    # Create the inner edge loop
    # (c-r, c+r) -- (c, c+r) -- (c+r, c+r)
    #    |                          |
    #    |                          |
    # (c-r, c)                  (c+r, c)
    #    |                          |
    #    |                          |
    # (c-r, c-r) -- (c, c-r) -- (c+r, c-r)

    pts = [[c - r, c], [c - r, c + r], [c, c + r], [c + r, c + r], [c + r, c],
           [c + r, c - r], [c, c - r], [c - r, c - r], [c - r, c]]
    wts = [
        1.0, 1.0 / np.sqrt(2), 1.0, 1.0 / np.sqrt(2), 1.0, 1.0 / np.sqrt(2),
        1.0, 1.0 / np.sqrt(2), 1.0
    ]
    Tu = [0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1.0, 1.0, 1.0]
    pcurve5 = TMR.BsplinePcurve(np.array(pts),
                                tu=np.array(Tu),
                                wts=np.array(wts),
                                k=3)
    edge5 = TMR.EdgeFromFace(face, pcurve5)
    edge5.setVertices(v5, v5)

    # Create the loop
    dirs = [1, 1, 1, 1]
    loop = TMR.EdgeLoop([edge1, edge2, edge3, edge4], dirs)
    face.addEdgeLoop(loop)

    if use_hole:
        # Create the second edge loop
        loop = TMR.EdgeLoop([edge5], [1])
        face.addEdgeLoop(loop)

        verts = [v1, v2, v3, v4, v5]
        edges = [edge1, edge2, edge3, edge4, edge5]
    else:
        verts = [v1, v2, v3, v4]
        edges = [edge1, edge2, edge3, edge4]

    faces = [face]

    # Create the TMRModel
    geo = TMR.Model(verts, edges, faces)
    return geo
示例#2
0
文件: logo.py 项目: xyuan/tmr
edge2.setVertices(v2, v3)

# Set up the third edge
pcurve3 = TMR.BsplinePcurve(np.array([[1.0, 1.0], [0.0, 1.0]]))
edge3 = TMR.EdgeFromFace(face, pcurve3)
edge3.setVertices(v3, v4)

# Set up the fourth edge
pcurve4 = TMR.BsplinePcurve(np.array([[0.0, 1.0], [0.0, 0.0]]))
edge4 = TMR.EdgeFromFace(face, pcurve4)
edge4.setVertices(v4, v1)
edges = [edge1, edge2, edge3, edge4]

# Create the loop
dirs = [1, 1, 1, 1]
loop = TMR.EdgeLoop([edge1, edge2, edge3, edge4], dirs)
face.addEdgeLoop(1, loop)

# Create the TMRModel
faces = [face]
geo = TMR.Model(verts, edges, faces)

# Create the mesh
comm = MPI.COMM_WORLD
mesh = TMR.Mesh(comm, geo)

# Mesh the part
opts = TMR.MeshOptions()
opts.num_smoothing_steps = 20
opts.write_mesh_quality_histogram = 1
opts.mesh_type_default = TMR.UNSTRUCTURED
def create_geo(AR, prob, forced_portion, MBB_bc_portion,
    ratio1, ratio2, use_hole, hole_radius):

    # Create the surface in the x-y plane
    Ly = 1.0
    Lx = Ly*AR
    nu = 2
    nv = 2
    x = np.linspace(0.0, Lx, nu)
    y = np.linspace(0.0, Ly, nv)
    pts = np.zeros((nu, nv, 3))
    for j in range(nv):
        for i in range(nu):
            pts[i,j,0] = x[i]
            pts[i,j,1] = y[j]

    tu = np.array([0.0, 0.0, Lx, Lx])
    tv = np.array([0.0, 0.0, Ly, Ly])

    # Create the b-spline surface
    surf = TMR.BsplineSurface(pts, tu=tu, tv=tv)
    face = TMR.FaceFromSurface(surf)

    if prob == 'cantilever':

        # Create the vertices on the surface
        v1 = TMR.VertexFromFace(face, 0.0, 0.0)
        v2 = TMR.VertexFromFace(face, Lx, 0.0)
        v3 = TMR.VertexFromFace(face, Lx, forced_portion*Ly)
        v4 = TMR.VertexFromFace(face, Lx, Ly)
        v5 = TMR.VertexFromFace(face, 0.0, Ly)
        verts = [v1, v2, v3, v4, v5]

        # Set up the edges
        pcurve1 = TMR.BsplinePcurve(np.array([[0.0, 0.0], [Lx, 0.0]]))
        pcurve2 = TMR.BsplinePcurve(np.array([[Lx, 0.0], [Lx, forced_portion*Ly]]))
        pcurve3 = TMR.BsplinePcurve(np.array([[Lx, forced_portion*Ly], [Lx, Ly]]))
        pcurve4 = TMR.BsplinePcurve(np.array([[Lx, Ly], [0.0, Ly]]))
        pcurve5 = TMR.BsplinePcurve(np.array([[0.0, Ly], [0.0, 0.0]]))

        edge1 = TMR.EdgeFromFace(face, pcurve1)
        edge2 = TMR.EdgeFromFace(face, pcurve2)
        edge3 = TMR.EdgeFromFace(face, pcurve3)
        edge4 = TMR.EdgeFromFace(face, pcurve4)
        edge5 = TMR.EdgeFromFace(face, pcurve5)

        edge1.setVertices(v1, v2)
        edge2.setVertices(v2, v3)
        edge3.setVertices(v3, v4)
        edge4.setVertices(v4, v5)
        edge5.setVertices(v5, v1)

        edge1.setName('1')
        edge2.setName('2')
        edge3.setName('3')
        edge4.setName('4')
        edge5.setName('5')

        edges = [edge1, edge2, edge3, edge4, edge5]
        dirs = [1, 1, 1, 1, 1]
        loop = TMR.EdgeLoop([edge1, edge2, edge3, edge4, edge5], dirs)
        face.addEdgeLoop(1, loop)

    elif prob == 'michell':

        # Create the vertices on the surface
        v1 = TMR.VertexFromFace(face, 0.0, 0.0)
        v2 = TMR.VertexFromFace(face, Lx, 0.0)
        v3 = TMR.VertexFromFace(face, Lx, 0.5*(1-forced_portion)*Ly)
        v4 = TMR.VertexFromFace(face, Lx, 0.5*(1+forced_portion)*Ly)
        v5 = TMR.VertexFromFace(face, Lx, Ly)
        v6 = TMR.VertexFromFace(face, 0.0, Ly)
        verts = [v1, v2, v3, v4, v5, v6]

        # Set up the edges
        pcurve1 = TMR.BsplinePcurve(np.array([[0.0, 0.0], [Lx, 0.0]]))
        pcurve2 = TMR.BsplinePcurve(np.array([[Lx, 0.0], [Lx, 0.5*(1-forced_portion)*Ly]]))
        pcurve3 = TMR.BsplinePcurve(np.array([[Lx, 0.5*(1-forced_portion)*Ly], [Lx, 0.5*(1+forced_portion)*Ly]]))
        pcurve4 = TMR.BsplinePcurve(np.array([[Lx, 0.5*(1+forced_portion)*Ly], [Lx, Ly]]))
        pcurve5 = TMR.BsplinePcurve(np.array([[Lx, Ly], [0.0, Ly]]))
        pcurve6 = TMR.BsplinePcurve(np.array([[0.0, Ly], [0.0, 0.0]]))

        edge1 = TMR.EdgeFromFace(face, pcurve1)
        edge2 = TMR.EdgeFromFace(face, pcurve2)
        edge3 = TMR.EdgeFromFace(face, pcurve3)
        edge4 = TMR.EdgeFromFace(face, pcurve4)
        edge5 = TMR.EdgeFromFace(face, pcurve5)
        edge6 = TMR.EdgeFromFace(face, pcurve6)

        edge1.setVertices(v1, v2)
        edge2.setVertices(v2, v3)
        edge3.setVertices(v3, v4)
        edge4.setVertices(v4, v5)
        edge5.setVertices(v5, v6)
        edge6.setVertices(v6, v1)

        edge1.setName('1')
        edge2.setName('2')
        edge3.setName('3')
        edge4.setName('4')
        edge5.setName('5')
        edge6.setName('6')

        edges = [edge1, edge2, edge3, edge4, edge5, edge6]
        dirs = [1, 1, 1, 1, 1, 1]
        loop = TMR.EdgeLoop([edge1, edge2, edge3, edge4, edge5, edge6], dirs)
        face.addEdgeLoop(1, loop)

    elif prob == 'MBB':

        # Create the vertices on the surface
        v1 = TMR.VertexFromFace(face, 0.0, 0.0)
        v2 = TMR.VertexFromFace(face, Lx*(1-MBB_bc_portion), 0.0)
        v3 = TMR.VertexFromFace(face, Lx, 0.0)
        v4 = TMR.VertexFromFace(face, Lx, Ly)
        v5 = TMR.VertexFromFace(face, Lx*forced_portion, Ly)
        v6 = TMR.VertexFromFace(face, 0.0, Ly)
        verts = [v1, v2, v3, v4, v5, v6]

        # Set up the edges
        pcurve1 = TMR.BsplinePcurve(np.array([[0.0, 0.0], [Lx*(1-MBB_bc_portion), 0.0]]))
        pcurve2 = TMR.BsplinePcurve(np.array([[Lx*(1-MBB_bc_portion), 0.0], [Lx, 0.0]]))
        pcurve3 = TMR.BsplinePcurve(np.array([[Lx, 0.0], [Lx, Ly]]))
        pcurve4 = TMR.BsplinePcurve(np.array([[Lx, Ly], [Lx*forced_portion, Ly]]))
        pcurve5 = TMR.BsplinePcurve(np.array([[Lx*forced_portion, Ly], [0.0, Ly]]))
        pcurve6 = TMR.BsplinePcurve(np.array([[0.0, Ly], [0.0, 0.0]]))

        edge1 = TMR.EdgeFromFace(face, pcurve1)
        edge2 = TMR.EdgeFromFace(face, pcurve2)
        edge3 = TMR.EdgeFromFace(face, pcurve3)
        edge4 = TMR.EdgeFromFace(face, pcurve4)
        edge5 = TMR.EdgeFromFace(face, pcurve5)
        edge6 = TMR.EdgeFromFace(face, pcurve6)

        edge1.setVertices(v1, v2)
        edge2.setVertices(v2, v3)
        edge3.setVertices(v3, v4)
        edge4.setVertices(v4, v5)
        edge5.setVertices(v5, v6)
        edge6.setVertices(v6, v1)

        edge1.setName('1')
        edge2.setName('2')
        edge3.setName('3')
        edge4.setName('4')
        edge5.setName('5')
        edge6.setName('6')

        edges = [edge1, edge2, edge3, edge4, edge5, edge6]
        dirs = [1, 1, 1, 1, 1, 1]
        loop = TMR.EdgeLoop([edge1, edge2, edge3, edge4, edge5, edge6], dirs)
        face.addEdgeLoop(1, loop)

    elif prob == 'lbracket':

        # Create the vertices on the surface
        v1 = TMR.VertexFromFace(face, 0.0, 0.0)
        v2 = TMR.VertexFromFace(face, Lx, 0.0)
        v3 = TMR.VertexFromFace(face, Lx, Ly*ratio2*(1-forced_portion))
        v4 = TMR.VertexFromFace(face, Lx, Ly*ratio2)
        v5 = TMR.VertexFromFace(face, Lx*ratio1, Ly*ratio2)
        v6 = TMR.VertexFromFace(face, Lx*ratio1, Ly)
        v7 = TMR.VertexFromFace(face, 0.0, Ly)
        verts = [v1, v2, v3, v4, v5, v6, v7]

        # Set up the edges
        pcurve1 = TMR.BsplinePcurve(np.array([[0.0, 0.0], [Lx, 0.0]]))
        pcurve2 = TMR.BsplinePcurve(np.array([[Lx, 0.0], [Lx, Ly*ratio2*(1-forced_portion)]]))
        pcurve3 = TMR.BsplinePcurve(np.array([[Lx, Ly*ratio2*(1-forced_portion)], [Lx, Ly*ratio2]]))
        pcurve4 = TMR.BsplinePcurve(np.array([[Lx, Ly*ratio2], [Lx*ratio1, Ly*ratio2]]))
        pcurve5 = TMR.BsplinePcurve(np.array([[Lx*ratio1, Ly*ratio2], [Lx*ratio1, Ly]]))
        pcurve6 = TMR.BsplinePcurve(np.array([[Lx*ratio1, Ly], [0.0, Ly]]))
        pcurve7 = TMR.BsplinePcurve(np.array([[0.0, Ly], [0.0, 0.0]]))

        edge1 = TMR.EdgeFromFace(face, pcurve1)
        edge2 = TMR.EdgeFromFace(face, pcurve2)
        edge3 = TMR.EdgeFromFace(face, pcurve3)
        edge4 = TMR.EdgeFromFace(face, pcurve4)
        edge5 = TMR.EdgeFromFace(face, pcurve5)
        edge6 = TMR.EdgeFromFace(face, pcurve6)
        edge7 = TMR.EdgeFromFace(face, pcurve7)

        edge1.setVertices(v1, v2)
        edge2.setVertices(v2, v3)
        edge3.setVertices(v3, v4)
        edge4.setVertices(v4, v5)
        edge5.setVertices(v5, v6)
        edge6.setVertices(v6, v7)
        edge7.setVertices(v7, v1)

        edge1.setName('1')
        edge2.setName('2')
        edge3.setName('3')
        edge4.setName('4')
        edge5.setName('5')
        edge6.setName('6')
        edge7.setName('7')

        edges = [edge1, edge2, edge3, edge4, edge5, edge6, edge7]
        dirs = [1, 1, 1, 1, 1, 1, 1]
        loop = TMR.EdgeLoop([edge1, edge2, edge3, edge4, edge5, edge6, edge7], dirs)
        face.addEdgeLoop(1, loop)

    # Set up the hole
    if use_hole:

        if prob == 'lbracket':
            r = hole_radius*Ly*ratio2
            xc = 0.5*(1+ratio1)*Lx
            yc = 0.5*Ly*ratio2

        else:
            r = hole_radius *Ly
            xc = 0.5*Lx
            yc = 0.5*Ly

        vc = TMR.VertexFromFace(face, xc - r, yc)

        pts = [[-r, 0.0], [-r, r], [0.0, r], [r, r],
            [r, 0.0], [r, -r], [0.0, -r], [-r, -r], [-r, 0.0]]
        pts = np.array(pts)
        for i in range(pts.shape[0]):
            pts[i,0] += xc
            pts[i,1] += yc

        wts = [1.0, 1.0/np.sqrt(2), 1.0, 1.0/np.sqrt(2),
            1.0, 1.0/np.sqrt(2), 1.0, 1.0/np.sqrt(2), 1.0]
        Tu = [0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1.0, 1.0, 1.0]

        pcurvec = TMR.BsplinePcurve(np.array(pts),
            tu=np.array(Tu), wts=np.array(wts), k=3)

        edgec = TMR.EdgeFromFace(face, pcurvec)
        edgec.setVertices(vc, vc)

        loop = TMR.EdgeLoop([edgec], [1])
        face.addEdgeLoop(-1, loop)

        verts.append(vc)
        edges.append(edgec)


    # Create the TMRModel
    faces = [face]
    geo = TMR.Model(verts, edges, faces)

    return geo
示例#4
0
# Create the vertices from the curves
v1 = TMR.VertexFromEdge(curves[0], 0.0)
v2 = TMR.VertexFromEdge(curves[1], 0.0)
v3 = TMR.VertexFromEdge(curves[2], 0.0)
v4 = TMR.VertexFromEdge(curves[3], 0.0)
vertices = [v1, v2, v3, v4]

# Set the vertices in the curves
curves[0].setVertices(v1, v2)
curves[1].setVertices(v2, v3)
curves[2].setVertices(v3, v4)
curves[3].setVertices(v4, v1)

# Set the curve segments around the surface
direct = [1, 1, 1, 1]
loop = TMR.EdgeLoop(curves, direct)
face.addEdgeLoop(1, loop)

# Create the model object
geo = TMR.Model(vertices, curves, faces)

# Mesh the geometry
comm = MPI.COMM_WORLD
mesh = TMR.Mesh(comm, geo)
hval = 0.1
mesh.mesh(hval)

# Extract the quadrilaterals/points
pts = mesh.getMeshPoints()
quads = mesh.getQuadConnectivity()
npts = pts.shape[0]
示例#5
0
def geomach_to_tmr(bse):
    '''
    Convert a BSE-GeoMach model to a TMR model
    '''

    # Compute the number of vertices, edges and faces
    num = bse._num
    nverts = num['vert']
    nedges = num['edge']
    nfaces = num['surf']

    # Create the list of edges, faces and
    verts = nverts * [None]
    edges = nedges * [None]
    faces = nfaces * [None]
    surfs = nfaces * [None]

    # Set the topology object
    topo = bse._topo
    size = bse._size
    str_indices = bse._str_indices
    bspline = bse._bspline

    # Extract the control point array
    cp_str = bse.vec['cp_str'].array

    # Point from the edge index on each face to the i/j locations
    # in the surf_ptrs array
    face_to_edge = [[1, 0], [2, 1], [1, 2], [0, 1]]

    # Point from the edge index on each face to the corresponding
    # vertices on each face
    face_to_edge_verts = [[[0, 0], [2, 0]], [[2, 0], [2, 2]], [[0, 2], [2, 2]],
                          [[0, 0], [0, 2]]]

    # Create the surfaces
    surf_ptrs = topo['surf_ptrs']
    edge_ptrs = topo['edge_ptrs']
    for i in range(nfaces):
        cp_offset = str_indices['cp'][i, 0]
        ku = bspline['order'][topo['surf_group'][i, 0] - 1]
        kv = bspline['order'][topo['surf_group'][i, 1] - 1]
        nu = bspline['num_cp'][topo['surf_group'][i, 0] - 1]
        nv = bspline['num_cp'][topo['surf_group'][i, 1] - 1]

        # Extract and create the b-spline surfaces
        cp = np.zeros((nu, nv, 3), dtype=np.double)
        for jj in range(nv):
            for ii in range(nu):
                cp_index = cp_offset + ii + jj * nu
                cp[ii, jj, :] = cp_str[cp_index]

        surfs[i] = TMR.BsplineSurface(cp, ku=ku, kv=kv)
        faces[i] = TMR.FaceFromSurface(surfs[i])

    # Create the vertices from the faces
    for i in range(nfaces):
        for jj in range(2):
            for ii in range(2):
                # Get the vertex index
                index = surf_ptrs[i, 2 * ii, 2 * jj] - 1
                # If the vertex has not be allocated, create it now
                if verts[index] is None:
                    u = 1.0 * ii
                    v = 1.0 * jj
                    verts[index] = TMR.VertexFromFace(faces[i], u, v)

    for i in range(nverts):
        if verts[i] is None:
            raise ValueError('TMRVertex %d was not initialized\n' % (i))

    # Create the edges
    for i in range(nfaces):
        for ii in range(4):
            i1 = face_to_edge[ii][0]
            j1 = face_to_edge[ii][1]

            # Keep track of the direction
            edge_num = surf_ptrs[i, i1, j1]
            index = abs(edge_num) - 1

            # Find the vertex numbers
            v1 = edge_ptrs[index, 0] - 1
            v2 = edge_ptrs[index, 1] - 1

            # The start/end vertex location
            vert1 = None
            vert2 = None

            # Get the indices of the vertices within the surf_ptrs array
            i1 = face_to_edge_verts[ii][0][0]
            j1 = face_to_edge_verts[ii][0][1]
            i2 = face_to_edge_verts[ii][1][0]
            j2 = face_to_edge_verts[ii][1][1]

            if (v1 == surf_ptrs[i, i1, j1] - 1
                    and v2 == surf_ptrs[i, i2, j2] - 1):
                vert1 = verts[v1]
                vert2 = verts[v2]
                pts = np.array(
                    [face_to_edge_verts[ii][0], face_to_edge_verts[ii][1]],
                    dtype=np.double)
            elif (v2 == surf_ptrs[i, i1, j1] - 1
                  and v1 == surf_ptrs[i, i2, j2] - 1):
                vert1 = verts[v2]
                vert2 = verts[v1]
                pts = np.array(
                    [face_to_edge_verts[ii][1], face_to_edge_verts[ii][0]],
                    dtype=np.double)
            pts = pts / 2.0

            # Check whether this is a degenerate edge
            is_degen = 0
            if v1 == v2:
                is_degen = 1

            # Create the parametric curve
            pcurve = TMR.BsplinePcurve(pts)
            if edges[index] is None:
                edges[index] = TMR.EdgeFromFace(faces[i], pcurve, is_degen)
                edges[index].setVertices(vert1, vert2)
            else:
                edges[index].addEdgeFromFace(faces[i], pcurve)

    for i in range(nedges):
        if edges[i] is None:
            raise ValueError('TMREdge %d was not initialized\n' % (i))

    # After all of the edges are created, create the edge loops
    # for each face. Account for the CCW orientation.
    ccw_order = [1, 1, -1, -1]
    for i in range(nfaces):
        # Find the edges and directions for this edge loop
        e = []
        dirs = []
        for ii in range(4):
            i1 = face_to_edge[ii][0]
            j1 = face_to_edge[ii][1]
            edge_num = surf_ptrs[i, i1, j1]
            e.append(edges[abs(edge_num) - 1])
            dirs.append(np.sign(edge_num) * ccw_order[ii])

        # Set the loop
        loop = TMR.EdgeLoop(e, dirs)
        faces[i].addEdgeLoop(loop)

    # Create the model
    geo = TMR.Model(verts, edges, faces)
    return geo