Esempio n. 1
0
def read_tetgen(surface=True, volume=True):
    """Read a tetgen model from files  fn.node, fn.ele, fn.smesh."""
    ftype = ''
    if surface:
        ftype += ' *.smesh'
    if volume:
        ftype += ' *.ele'
    fn = askFilename(GD.cfg['workdir'],"Tetgen files (%s)" % ftype,exist=True)
    nodes = elems =surf = None
    if fn:
        chdir(fn)
        project = utils.projectName(fn)
        set_project(project)
        nodes,nodenrs = tetgen.readNodes(project+'.node')
#        print "Read %d nodes" % nodes.shape[0]
        if volume:
            elems,elemnrs,elemattr = tetgen.readElems(project+'.ele')
            print "Read %d tetraeders" % elems.shape[0]
            PF['volume'] = (nodes,elems)
        if surface:
            surf = tetgen.readSurface(project+'.smesh')
            print "Read %d triangles" % surf.shape[0]
            PF['surface'] = (nodes,surf)
    if surface:
        show_surface()
    else:
        show_volume()
Esempio n. 2
0
    def read(clas,fn,ftype=None):
        """Read a surface from file.

        If no file type is specified, it is derived from the filename
        extension.
        Currently supported file types:
          - .stl (ASCII or BINARY)
          - .gts
          - .off
          - .neu (Gambit Neutral)
          - .smesh (Tetgen)
        """
        if ftype is None:
            ftype = os.path.splitext(fn)[1]  # deduce from extension
        ftype = ftype.strip('.').lower()
        if ftype == 'off':
            return Surface(*read_off(fn))
        elif ftype == 'gts':
            #print "READING GTS"
            ret = read_gts(fn)
            #print ret
            S = Surface(*ret)
            #print S.shape()
            return S
        elif ftype == 'stl':
            return Surface(*read_stl(fn))
        elif ftype == 'neu':
            return Surface(*read_gambit_neutral(fn))
        elif ftype == 'smesh':
            return Surface(*tetgen.readSurface(fn))
        else:
            raise "Unknown Surface type, cannot read file %s" % fn
Esempio n. 3
0
def read_tetgen(fn):
    """Read a tetgen model from files  fn.node, fn.ele, fn.smesh."""
    nodes = tetgen.readNodes(fn+'.node')
    print "Read %d nodes" % nodes.shape[0]
    elems = tetgen.readElems(fn+'.ele')
    print "Read %d tetraeders" % elems.shape[0]
    surf = tetgen.readSurface(fn+'.smesh')
    print "Read %d triangles" % elems.shape[0]
    return nodes,elems,surf
def stl_to_abaqus(fn):
    print "Converting %s to Abaqus .INP format" % fn
    stl_tetgen(fn)
    fb = os.path.splitext(fn)[0]
    nodes = tetgen.readNodes(fb+'.1.node')
    elems = tetgen.readElems(fb+'.1.ele')
    faces = tetgen.readSurface(fb+'.1.smesh')
    print "Exporting surface model"
    abq_export(fb+'-surface.inp',nodes,faces,'S3',"Abaqus model generated by tetgen from surface in STL file %s" % fn)
    print "Exporting volume model"
    abq_export(fb+'-volume.inp',nodes,elems,'C3D%d' % elems.shape[1],"Abaqus model generated by tetgen from surface in STL file %s" % fn)
def stl_to_abaqus(fn):
    print("Converting %s to Abaqus .INP format" % fn)
    tetgen.runTetgen(fn)
    fb = os.path.splitext(fn)[0]
    nodes = tetgen.readNodes(fb+'.1.node')
    elems = tetgen.readElems(fb+'.1.ele')
    faces = tetgen.readSurface(fb+'.1.smesh')
    print("Exporting surface model")
    smesh = Mesh(nodes,faces,eltype='S3')
    fe_abq.exportMesh(fb+'-surface.inp',smesh,"Abaqus model generated by tetgen from surface in STL file %s" % fn)
    print("Exporting volume model")
    vmesh = Mesh(nodes,elems,eltype='C3D%d' % elems.shape[1])
    abq_export(fb+'-volume.inp',vmesh,"Abaqus model generated by tetgen from surface in STL file %s" % fn)
Esempio n. 6
0
def stl_to_abaqus(fn):
    print("Converting %s to Abaqus .INP format" % fn)
    tetgen.runTetgen(fn)
    fb = os.path.splitext(fn)[0]
    nodes = tetgen.readNodes(fb + '.1.node')
    elems = tetgen.readElems(fb + '.1.ele')
    faces = tetgen.readSurface(fb + '.1.smesh')
    print("Exporting surface model")
    smesh = Mesh(nodes, faces, eltype='S3')
    fe_abq.exportMesh(
        fb + '-surface.inp', smesh,
        "Abaqus model generated by tetgen from surface in STL file %s" % fn)
    print("Exporting volume model")
    vmesh = Mesh(nodes, elems, eltype='C3D%d' % elems.shape[1])
    abq_export(
        fb + '-volume.inp', vmesh,
        "Abaqus model generated by tetgen from surface in STL file %s" % fn)
Esempio n. 7
0
def read_tetgen(surface=True, volume=True):
    """Read a tetgen model from files  fn.node, fn.ele, fn.smesh."""
    global nodes,elems,surf
    fn = askFilename(GD.cfg['workdir'],"Tetgen files (*.node)")
    nodes = elems =surf = None
    if fn:
        os.chdir(os.path.dirname(fn))
        message("Your current workdir is %s" % os.getcwd())
        project = os.path.splitext(fn)[0]
        nodes = tetgen.readNodes(project+'.node')
        print "Read %d nodes" % nodes.shape[0]
        if volume:
            elems = tetgen.readElems(project+'.ele')
            print "Read %d tetraeders" % elems.shape[0]
        if surface:
            surf = tetgen.readSurface(project+'.smesh')
            print "Read %d triangles" % surf.shape[0]
    show_tetgen_surface()
Esempio n. 8
0
def readSurface(fn,ftype=None):
    if ftype is None:
        ftype = os.path.splitext(fn)[1]  # deduce from extension
    ftype = ftype.strip('.').lower()
    if ftype == 'stl':
        ofn = changeExt(fn,'.gts')
        if (not os.path.exists(ofn)) or (mtime(ofn) < mtime(fn)):
            stl_to_gts(fn)
        nodes,edges,faces = read_gts(ofn)
        elems = expandEdges(edges,faces)
    elif ftype == 'off':
        nodes,elems = read_off(fn)
    elif ftype == 'neu':
        nodes,elems = read_gambit_neutral(fn)
    elif ftype == 'smesh':
        nodes,elems = tetgen.readSurface(fn)
    elif ftype == 'gts':
        nodes,edges,faces = read_gts(fn)
        elems = expandEdges(edges,faces)
    else:
        print "Cannot read file %s" % fn
    return nodes,elems