Пример #1
0
def fib2meshalyzer(filename):
    """
    Given a filename for a CARP mesh (.pts, .elem and .lon) this functions
    generates the .vec and .vpts files necessary to visualize vector data
    in meshalyzer.
    """
    ptsFile = "%s.pts" % filename
    lonFile = "%s.lon" % filename
    vecFile = "%s.vec" % filename
    elemFile = "%s.elem" % filename
    vptsFile = "%s.vpts" % filename

    np_xyz = read_array_pts(ptsFile)
    elemList = read_array_elem(elemFile)

    # copy filename.lon to filename.vec
    shutil.copy(lonFile, vecFile)

    # create .vpts file
    f = open(vptsFile, "w")
    f.write("%d\n" % len(elemList))

    for e in elemList:
        numNode = getNumNode[e[0]]
        nodeList = [e[j + 1] for j in xrange(numNode)]
        centroid = get_element_center(nodeList, np_xyz)
        f.write("%f %f %f\n" % (centroid[0], centroid[1], centroid[2]))

    f.close()

    print ".vec and .vpts files were generated!"
Пример #2
0
def tag_elem_file (elem_file, node_file, region_list):
    """
    Function to tag rectangular areas in structured meshes in CARP
    Bernardo M. Rocha, 2009
    """   
    new_efile = open('element.elem', 'w')
    
    elem = read_array_elem (elem_file)
    pts  = read_array_pts  (node_file)

    for r in region_list:
        
        for e in elem:
            elem_type = e[0]   
            if elem_type == 'Qd':
                node_range = xrange(1,4+1)
                node_tag   = e[5]
                for n in node_range:
                    g = int( e[n] )
                    node = Point ( pts[g][0], pts[g][1], pts[g][2] )        
                    # check if node is inside region
                    if ( (node.x >= r.bottom.x) and
                         (node.x <= r.bottom.x + r.width) and
                         (node.y >= r.top.y - r.height) and
                         (node.y <= r.top.y)):
                        node_tag = r.tag
                    # end if
                # end for n
                e[5] = node_tag
            # end if Qd
        # end for e
    # end for r
    
    # write to file
    
    new_efile.write('%d\n' % len(elem))
    for e in elem:
        new_efile.write('Qd %d %d %d %d %d \n' %
            (int(e[1]), int(e[2]),int(e[3]),int(e[4]),int(e[5])))

    new_efile.close()

    new_efile.close()