def getNodesBoundInSelectedVols(target_list):
    """
    Return nodes bound in mouse selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target nodes
                    
    Return:
        List of indices of nodes bound by the volumes
    """
    
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    
    in_list = []
    
    for v in target_list:
        cords = cubit.get_nodal_coordinates(v)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    cubit.delete_group(group_id)
    return in_list
Beispiel #2
0
def getNodesBoundInSelectedVols(mesh, scale=1e-6):
    """
    Return nodes bound in selected CUBIT volumes.
        
    Parameters:
        * mesh        Associated Tetmesh object created in STEPS
        * scale       LENGTH scale from the CUBIT gemoetry to real geometry.
                    e.g. a radius of 10 in CUBIT to a radius of 1 micron in STEPS, scale is 1e-7.
                    By default the scale is 1e-6, i.e. 1 unit in CUBIT equals 1 micron in STEPS.
                    
    Return:
        list of STEPS indices of vertex nodes
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    nverts = mesh.nverts

    in_list = []

    for v in range(nverts):
        cords = mesh.getVertex(v)
        cords = [x / scale for x in cords]
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    cubit.delete_group(group_id)
    return in_list
Beispiel #3
0
 def pick_hex(self, list_hex=None, volume=None):
     if self.cubit_skew > 0:
         command = "del group skew_top"
         cubit.cmd(command)
         command = "group 'skew_top' add quality volume all skew low " + str(
             self.cubit_skew)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("skew_top")
         self.list_hex = cubit.get_group_hexes(group)
     elif list_hex is not None:
         self.list_hex = list_hex
     elif volume is not None:
         command = "group 'hextmp' add hex in volume " + str(volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif self.volume is not None:
         command = "group 'hextmp' add hex in volume " + str(self.volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif list_hex is None and self.list_hex is None:
         self.list_hex = cubit.parse_cubit_list('hex', 'all')
     print 'list_hex: ', len(self.list_hex), ' hexes'
Beispiel #4
0
def getNodesBoundInSelectedVols(target_list):
    """
    Return nodes bound in selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target nodes
                    
    Return:
        List of indices of nodes bound by the volumes
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)

    in_list = []

    for v in target_list:
        cords = cubit.get_nodal_coordinates(v)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            status = body.point_containment(cords)
            if status == 1 or status == 2:
                in_list.append(v)
                break
    cubit.delete_group(group_id)
    return in_list
Beispiel #5
0
 def pick_hex(self, list_hex=None, volume=None):
     if self.cubit_skew > 0:
         command = "del group skew_top"
         cubit.cmd(command)
         command = "group 'skew_top' add quality volume all skew low " + str(self.cubit_skew)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("skew_top")
         self.list_hex = cubit.get_group_hexes(group)
     elif list_hex is not None:
         self.list_hex = list_hex
     elif volume is not None:
         command = "group 'hextmp' add hex in volume " + str(volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif self.volume is not None:
         command = "group 'hextmp' add hex in volume " + str(self.volume)
         cubit.silent_cmd(command)
         group = cubit.get_id_from_name("hextmp")
         self.list_hex = cubit.get_group_hexes(group)
         command = "del group hextmp"
         cubit.silent_cmd(command)
     elif list_hex is None and self.list_hex is None:
         self.list_hex = cubit.parse_cubit_list("hex", "all")
     print "list_hex: ", len(self.list_hex), " hexes"
Beispiel #6
0
def list_2_curve(X,Y,name='',unit='*km'):
    Vlist = list_2_listofvertices(X,Y,unit)
    finalcmd = "create curve spline from vertex " + str(Vlist[0].id()) + " to " + str(Vlist[-1].id())
    cubit.silent_cmd(finalcmd)
    C = cubit.curve(cubit.get_last_id('curve'))
    if name != '':
        C.entity_name(name)
    return C
Beispiel #7
0
def list_2_listofvertices(X,Y,unit='*km'):
    Vlis_out = []
    for x,y in zip(X,Y):
        komand = "create vertex x { "+str(x)+ unit + "} y { "+str(y) + unit + "}"
        cubit.silent_cmd(komand)
        v = cubit.vertex(cubit.get_last_id('vertex'))
        Vlis_out.append(v)  
    return Vlis_out 
Beispiel #8
0
def curver_desc(Cdesc,dx,unit='*km'):
    if type(Cdesc) is int:
        komand = "curve " + str(Cdesc) + " size {" + str(dx) + unit + "}"
    elif type(Cdesc) is str:
        komand = "curve " + str(cubit.get_id_from_name(Cdesc)) + " size {" + str(dx) + unit +"}"    
    print komand
    cubit.silent_cmd(komand)
    return None
Beispiel #9
0
def curver_desc(Cdesc, dx, unit='*km'):
    if type(Cdesc) is int:
        komand = "curve " + str(Cdesc) + " size {" + str(dx) + unit + "}"
    elif type(Cdesc) is str:
        komand = "curve " + str(
            cubit.get_id_from_name(Cdesc)) + " size {" + str(dx) + unit + "}"
    print komand
    cubit.silent_cmd(komand)
    return None
Beispiel #10
0
def dico_2_listofvertices(dico,unit='*km'):
    Vlis_out = []
    for name , xy in dico.iteritems():
        komand = "create vertex x { "+str(xy[0])+ unit + "} y { "+str(xy[1]) + unit + "}"
        cubit.silent_cmd(komand)
        v = cubit.vertex(cubit.get_last_id('vertex'))
        v.entity_name(name)
        Vlis_out.append(v)  
    return Vlis_out 
Beispiel #11
0
 def get_face_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nf" add Node in face '+str(ind))
             group1 = cubit.get_id_from_name("nf")
             result=cubit.get_group_nodes(group1)
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('face',ind)
     return result
Beispiel #12
0
def list_2_curve(X, Y, name='', unit='*km'):
    Vlist = list_2_listofvertices(X, Y, unit)
    finalcmd = "create curve spline from vertex " + str(
        Vlist[0].id()) + " to " + str(Vlist[-1].id())
    cubit.silent_cmd(finalcmd)
    C = cubit.curve(cubit.get_last_id('curve'))
    if name != '':
        C.entity_name(name)
    return C
Beispiel #13
0
 def get_face_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nf" add Node in face '+str(ind))
             group1 = cubit.get_id_from_name("nf")
             result=cubit.get_group_nodes(group1)
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('face',ind)
     return result
Beispiel #14
0
def list_2_listofvertices(X, Y, unit='*km'):
    Vlis_out = []
    for x, y in zip(X, Y):
        komand = "create vertex x { " + str(x) + unit + "} y { " + str(
            y) + unit + "}"
        cubit.silent_cmd(komand)
        v = cubit.vertex(cubit.get_last_id('vertex'))
        Vlis_out.append(v)
    return Vlis_out
Beispiel #15
0
def dico_2_listofvertices(dico, unit='*km'):
    Vlis_out = []
    for name, xy in dico.iteritems():
        komand = "create vertex x { " + str(xy[0]) + unit + "} y { " + str(
            xy[1]) + unit + "}"
        cubit.silent_cmd(komand)
        v = cubit.vertex(cubit.get_last_id('vertex'))
        v.entity_name(name)
        Vlis_out.append(v)
    return Vlis_out
Beispiel #16
0
def read_file_2_curve(path,name=''):
    Vlist = read_file_2_listofvertices(path)
    finalcmd = "create curve spline from vertex " + str(Vlist[0].id()) + " to " + str(Vlist[-1].id())
    cubit.silent_cmd(finalcmd)
    C = cubit.curve(cubit.get_last_id('curve'))
    if name == '':
        C.entity_name(os.path.basename(path))
    else:
        C.entity_name(name)
    return C
Beispiel #17
0
 def get_hex_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nh" add Node in hex '+str(ind))
             group1 = cubit.get_id_from_name("nh")
             result=cubit.get_group_nodes(group1)
             if len(result) != 27: print 'error hex27'
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('hex',ind)
     return result
Beispiel #18
0
 def get_hex_connectivity(self,ind):
     if self.hex27:
             cubit.silent_cmd('group "nh" add Node in hex '+str(ind))
             group1 = cubit.get_id_from_name("nh")
             result=cubit.get_group_nodes(group1)
             if len(result) != 27: print 'error hex27'
             cubit.cmd('del group '+str(group1))
     else:
         result=cubit.get_connectivity('hex',ind)
     return result
Beispiel #19
0
def read_file_2_listofvertices(path,unit='*km'):
    filein = open(path)
    Vlis_out = []
    for line in filein:
        fields = line.split()
#        v = cubit.create_vertex(float(fields[0]),float(fields[1]),0)    
        komand = "create vertex x { "+str(float(fields[0]))+ unit + "} y { "+str(float(fields[1])) + unit + "}"
        cubit.silent_cmd(komand)
        v = cubit.vertex(cubit.get_last_id('vertex'))
        Vlis_out.append(v)  
    return Vlis_out 
Beispiel #20
0
def read_file_2_curve(path, name=''):
    Vlist = read_file_2_listofvertices(path)
    finalcmd = "create curve spline from vertex " + str(
        Vlist[0].id()) + " to " + str(Vlist[-1].id())
    cubit.silent_cmd(finalcmd)
    C = cubit.curve(cubit.get_last_id('curve'))
    if name == '':
        C.entity_name(os.path.basename(path))
    else:
        C.entity_name(name)
    return C
Beispiel #21
0
def highlightPatch(patch):
    """
    Highlight the patch.
        
    Parameters:
        * patch       ShadowPatch object
        
    Return:
        None
    """
    cubit.silent_cmd("highlight tri " + toStr(patch.indices))
Beispiel #22
0
def highlightComp(comp):
    """
    Highlight the compartment.
    
    Parameters:
        * comp        ShadowComp object
        
    Return:
        None
    """
    cubit.silent_cmd("highlight tet " + toStr(comp.indices))
Beispiel #23
0
def drawPatch(patch):
    """
    Draw the patch.
        
    Parameters:
        * patch       ShadowPatch object
        
    Return:
        None
    """
    cubit.silent_cmd("draw tri " + toStr(patch.indices))
Beispiel #24
0
def drawComp(comp):
    """
    Draw the compartment.
    
    Parameters:
        * comp        ShadowComp object
        
    Return:
        None
    """
    cubit.silent_cmd("draw tet " + toStr(comp.indices))
Beispiel #25
0
def highlightComp(mesh, comp_id):
    """
    Highlight the compartment.
        
    Parameters:
        * mesh        ShadowMesh object
        * comp_id     ID of the ShadowComp object
        
    Return:
        None
    """
    cubit.silent_cmd("highlight tet " + toStr(mesh.comps[comp_id].indices))
Beispiel #26
0
 def highlight_skew(self, low=None, high=None):
     if low is None and high is not None:
         hexlist = self.show(low, self.max_skewness, self.skew_hyst)
     elif low is not None and high is None:
         hexlist = self.show(0, high, self.skew_hyst)
     if low is not None and high is not None:
         hexlist = self.show(low, high, self.skew_hyst)
     else:
         hexlist = self.hex_min_edge_length
     command = "highlight hex " + str(hexlist)
     command = command.replace("[", " ").replace("]", " ").replace("(", " ").replace(")", " ")
     cubit.silent_cmd(command)
Beispiel #27
0
def read_file_2_listofvertices(path, unit='*km'):
    filein = open(path)
    Vlis_out = []
    for line in filein:
        fields = line.split()
        #        v = cubit.create_vertex(float(fields[0]),float(fields[1]),0)
        komand = "create vertex x { " + str(float(
            fields[0])) + unit + "} y { " + str(float(fields[1])) + unit + "}"
        cubit.silent_cmd(komand)
        v = cubit.vertex(cubit.get_last_id('vertex'))
        Vlis_out.append(v)
    return Vlis_out
Beispiel #28
0
def highlightPatch(mesh, patch_id):
    """
    Highlight the patch.
        
    Parameters:
        * mesh        ShadowMesh object
        * patch_id    ID of the ShadowPatch object
        
    Return:
        None
    """
    cubit.silent_cmd("highlight tri " + toStr(mesh.patches[patch_id].indices))
Beispiel #29
0
 def create_line(position):
     if position:
         last_curve_store=cubit.get_last_id("curve")
         command='create curve spline '+position
         cubit.silent_cmd(command)
         last_curve=cubit.get_last_id("curve")
         if last_curve != last_curve_store:
             return last_curve
         else:
             return False
     else:
         return False
Beispiel #30
0
 def highlight_skew(self, low=None, high=None):
     if low is None and high is not None:
         hexlist = self.show(low, self.max_skewness, self.skew_hyst)
     elif low is not None and high is None:
         hexlist = self.show(0, high, self.skew_hyst)
     if low is not None and high is not None:
         hexlist = self.show(low, high, self.skew_hyst)
     else:
         hexlist = self.hex_min_edge_length
     command = "highlight hex " + str(hexlist)
     command = command.replace("[", " ").replace("]", " ").replace(
         "(", " ").replace(")", " ")
     cubit.silent_cmd(command)
def getSelectedTets():
    """
    Return the CUBIT indices of mouse selected tetrahedrons.
    
    Parameters:
        None
        
    Return:
        cubit_ids
    """
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    idxs = cubit.get_group_tets(group_id)
    cubit.delete_group(group_id)
    return idxs
Beispiel #32
0
def getSelectedNodes():
    """
    Return the CUBIT indices of the selected vertex nodes.
        
    Parameters:
        None
        
    Return:
        cubit_ids
    """
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    idxs = cubit.get_group_nodes(group_id)
    cubit.delete_group(group_id)
    return idxs
Beispiel #33
0
def getSelectedTris(tri_proxy):
    """
    Return the STEPS indices and CUBIT indices of the selected triangles.
    
    Parameters:
        * tri_proxy   Triangle element proxy generated by STEPS mesh importing function
    
    Return:
        (steps_ids, cubit_ids)
    """
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    cubit_ids = cubit.get_group_tris(group_id)
    steps_ids = [tri_proxy.getSTEPSID(id) for id in cubit_ids]
    cubit.delete_group(group_id)
    return (steps_ids, cubit_ids)
Beispiel #34
0
def curver_start_end(C,dxstrt,dxend,direct='l',unit='*km'):
    Vtup = cubit.get_relatives("curve", C.id(), "vertex")
    if cubit.vertex(Vtup[1]).coordinates()[0] > cubit.vertex(Vtup[0]).coordinates()[0]:
        vr = cubit.vertex(Vtup[1])
        vl = cubit.vertex(Vtup[0])
    else:
        vr = cubit.vertex(Vtup[0])
        vl = cubit.vertex(Vtup[1])
    if direct == 'l':
        vstart = vr
    elif direct == 'r':
        vstart = vl       
    komand = "curve " + str(C.id()) + " scheme bias fine size {" + str(dxstrt) + unit + "} coarse size  {" + str(dxend) + unit + "} start vertex " + str(vstart.id())
    print komand
    cubit.silent_cmd(komand)
    return None
Beispiel #35
0
 def create_line_v(ind,n,n2,step,data,unit):
     last_curve_store=cubit.get_last_id("curve")
     command='create curve spline '
     for i in range(0,n):
         if i%step == 0:
             lon,lat,z=data[n2*i+ind][0],data[n2*i+ind][1],data[n2*i+ind][2]
             x,y=geo2utm(lon,lat,unit)
             txt=' Position ' +   str(x)  +' '+  str(y) +' '+  str(z)
             command=command+txt
             #print command
     cubit.silent_cmd(command)
     last_curve=cubit.get_last_id("curve")
     if last_curve != last_curve_store:
         return last_curve
     else:
         return 0
Beispiel #36
0
def getTrisBoundInSelectedVols(mesh, scale=1e-6):
    """
    Return triangles bound in selected CUBIT volumes.
        
    Parameters:
        * mesh        Associated Tetmesh object created in STEPS
        * scale       LENGTH scale from the CUBIT gemoetry to real geometry.
                    e.g. a radius of 10 in CUBIT to a radius of 1 micron in STEPS, scale is 1e-7.
                    By default the scale is 1e-6, i.e. 1 unit in CUBIT equals 1 micron in STEPS.
                    
    Return:
        list of STEPS indices of triangles
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    ntris = mesh.ntris

    in_list = []

    for t in range(ntris):
        verts = mesh.getTri(t)
        with_in = True
        cords = []
        for v in verts:
            c = mesh.getVertex(v)
            c = [x / scale for x in c]
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = True
            for cord in cords:
                status = body.point_containment(cord)
                if status == 0:
                    within = False
                    break
            if within:
                in_list.append(t)
                break
    cubit.delete_group(group_id)
    return in_list
Beispiel #37
0
def curver_start_end(C, dxstrt, dxend, direct='l', unit='*km'):
    Vtup = cubit.get_relatives("curve", C.id(), "vertex")
    if cubit.vertex(Vtup[1]).coordinates()[0] > cubit.vertex(
            Vtup[0]).coordinates()[0]:
        vr = cubit.vertex(Vtup[1])
        vl = cubit.vertex(Vtup[0])
    else:
        vr = cubit.vertex(Vtup[0])
        vl = cubit.vertex(Vtup[1])
    if direct == 'l':
        vstart = vr
    elif direct == 'r':
        vstart = vl
    komand = "curve " + str(C.id()) + " scheme bias fine size {" + str(
        dxstrt) + unit + "} coarse size  {" + str(
            dxend) + unit + "} start vertex " + str(vstart.id())
    print komand
    cubit.silent_cmd(komand)
    return None
Beispiel #38
0
def highlightROI(mesh, roi_name):
    """
    Highlight elements stored in ROI database with id roi_name.
    
    Parameters:
        * mesh        ShadowMesh object
        * roi_name    Name of the ROI
        
    Return:
        None
    """
    if roi_name not in mesh.rois:
        raise Exception(roi_name + " is not in ROI database.")

    roi = mesh.rois[roi_name]
    idx_str = toStr(roi["Indices"])

    if roi["Type"] == ELEM_VERTEX:
        cubit.silent_cmd("highlight node " + idx_str)
    elif roi["Type"] == ELEM_TET:
        cubit.silent_cmd("highlight tet " + idx_str)
    elif roi["Type"] == ELEM_TRI:
        cubit.silent_cmd("highlight tri " + idx_str)
    else:
        raise Exception(roi_name + " is undefined element type.")
Beispiel #39
0
def getTrisBoundInSelectedVols(target_list):
    """
    Return triangles bound in selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target triangles
                    
    Return:
        List of indices of triangles bound by the volumes
    """

    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)

    in_list = []

    for t in target_list:
        verts = cubit.get_connectivity("tri", t)
        with_in = True
        cords = []
        for v in verts:
            c = cubit.get_nodal_coordinates(v)
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = True
            for cord in cords:
                status = body.point_containment(cord)
                if status == 0:
                    within = False
                    break
            if within:
                in_list.append(t)
                break
    cubit.delete_group(group_id)
    return in_list
Beispiel #40
0
def create_group_nodeset_desc(Clist,grpname,nodesetID=0,grpname_remove=[]):
    while nodesetID == 0 or (nodesetID in cubit.get_nodeset_id_list()):
        nodesetID = nodesetID +1
    for c in Clist:
        cubit.silent_cmd('group "' + grpname + '" add node in ' + c) 
    #Remove some vertice in nodes if specified
    print grpname_remove
    if len(grpname_remove)!=0:
        # Check if group already specified
        for grp in grpname_remove:
            id_grp=cubit.get_id_from_name(grp)
            if id_grp!=0:
                cubit.silent_cmd('group "' + grpname + '" remove node in group ' + grp) 
    # Name the nodesets
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' group ' + grpname)
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' name "' + grpname + '"' )
def getTrisOverlapSelectedVols(target_list):
    """
    Return triangles overlap with mouse selected CUBIT volumes.
        
    Parameters:
        * target_list List of indices of target triangles
                    
    Return:
        List of indices of triangles overlap with the volumes
    """
    
    group_id = cubit.create_new_group()
    cubit.silent_cmd("group %i add selection" % (group_id))
    volume_ids = cubit.get_group_volumes(group_id)
    
    in_list = []
    
    for t in target_list:
        verts = cubit.get_connectivity("tri", t)
        cords = []
        for v in verts:
            c = cubit.get_nodal_coordinates(v)
            cords.append(c)
        for vol_id in volume_ids:
            volume = cubit.volume(vol_id)
            body = volume.bodies()[0]
            within = False
            for cord in cords:
                status = body.point_containment(cord)
                if status == 1:
                    within = True
                    break
            if within:
                in_list.append(t)
                break
    cubit.delete_group(group_id)
    return in_list
Beispiel #42
0
def create_group_nodeset_desc(Clist, grpname, nodesetID=0, grpname_remove=[]):
    while nodesetID == 0 or (nodesetID in cubit.get_nodeset_id_list()):
        nodesetID = nodesetID + 1
    for c in Clist:
        cubit.silent_cmd('group "' + grpname + '" add node in ' + c)
    #Remove some vertice in nodes if specified
    print grpname_remove
    if len(grpname_remove) != 0:
        # Check if group already specified
        for grp in grpname_remove:
            id_grp = cubit.get_id_from_name(grp)
            if id_grp != 0:
                cubit.silent_cmd('group "' + grpname +
                                 '" remove node in group ' + grp)
    # Name the nodesets
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' group ' + grpname)
    cubit.silent_cmd('nodeset ' + str(nodesetID) + ' name "' + grpname + '"')
def collecting_merging(cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,ckbound_method1=False,ckbound_method2=False,merge_tolerance=None,decimate=False):
    import glob
    import re
    #
    rule_st=re.compile("(.+)_[0-9]+\.")
    rule_ex=re.compile(".+_[0-9]+\.(.+)")
    rule_int=re.compile(".+_([0-9]+)\.")
    boundary_dict={}
    ##
    try:
        from boundary_definition import check_bc, map_boundary
    except:
        pass
    #
    xmin,xmax,ymin,ymax,listfull=map_boundary(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy)
    #
    if cubfiles:
        nf,listip,filenames,cubflag=importing_cubfiles(cubfiles)
    else:
        nf=0
        filenames=[]
        ip=0
    #
    if nf > 0:
        for ip,filename in zip(listip,filenames):
            try:
                if ip in listfull:
                    if cubflag:
                        cubit.cmd('import cubit "'+filename+'"')
                    else:
                        cubit.cmd('import mesh geometry "'+filename+'" block all use nodeset sideset feature_angle 135.00 linear merge')
                    if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
                    boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax,cpuymin,cpuymax)
                    boundary_dict[ip]=boundary
                    list_vol=list(cubit.parse_cubit_list('volume','all'))
                    for v in list_vol:
                        cubit.cmd("disassociate mesh from volume "+str(v))
                        command = "del vol "+str(v)
                        cubit.cmd(command)
            except:
                cubit.cmd('import mesh geometry "'+filename+'" block all use nodeset sideset feature_angle 135.00 linear merge')
                if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
                ip=0
                boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax,cpuymin,cpuymax)
                boundary_dict[ip]=boundary
                list_vol=list(cubit.parse_cubit_list('volume','all'))
                for v in list_vol:
                    cubit.cmd("disassociate mesh from volume "+str(v))
                    command = "del vol "+str(v)
                    cubit.cmd(command)
        cubit.cmd('export mesh "tmp_collect_NOmerging.e" dimension 3 block all overwrite')
    else:
        if decimate: cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
        boundary=check_bc(ip,xmin,xmax,ymin,ymax,cpux,cpuy,cpuxmin,cpuxmax,cpuymin,cpuymax)
    #
    #
    #print boundary_dict
    block_list=cubit.get_block_id_list()
    for block in block_list:
        ty=cubit.get_block_element_type(block)
        if ty == 'HEX8':
            cubit.cmd('block '+str(block)+' name "vol'+str(block)+'"')
    #
    #
    print 'chbound',ckbound_method1,ckbound_method2
    
    
    if ckbound_method1 and not ckbound_method2 and len(filenames) != 1:
        #use the equivalence method for groups
        if isinstance(merge_tolerance,list):
            tol=merge_tolerance[0]
        elif merge_tolerance:
            tol=merge_tolerance
        else:
            tol=100000
        #
        idiag=None
        #cubit.cmd('set info off')
        #cubit.cmd('set journal off')
        #cubit.cmd('set echo off')
        ind=0
        for ix in range(cpuxmin,cpuxmax):
            for iy in range(cpuymin,cpuymax):
                ind=ind+1
                ip=iy*cpux+ix
                print '******************* ',ip, ind,'/',len(listfull)
                #
                #   ileft    |   ip
                #  --------------------
                #   idiag    |   idown
                #
                #
                if ip not in xmin and ip not in ymin:
                    ileft=iy*cpux+ix-1
                    idown=(iy-1)*cpux+ix
                    idiag=idown-1
                elif ip in xmin and ip in ymin:
                    ileft=ip
                    idown=ip
                    idiag=None
                elif ip in xmin:
                    ileft=ip
                    idown=(iy-1)*cpux+ix
                    idiag=idown
                elif ip in ymin:
                    ileft=iy*cpux+ix-1
                    idown=ip
                    idiag=ileft
                #
                print ip,ileft,idiag,idown
                if ip != idown:
                    nup=boundary_dict[ip]['nodes_surf_ymin']
                    ndow=boundary_dict[idown]['nodes_surf_ymax']
                    merge_node_ck(nup,ndow)
                 
                    if idiag != idown:
                        if ip in ymax and ip not in xmin:
                            nlu=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck left up... r u
                            nru=boundary_dict[ileft]['node_curve_xmaxymax']
                            merge_node(nlu,nru)
                        if ip in xmax:
                            nrd=boundary_dict[ip]['node_curve_xmaxymin'] #node in curve chunck left up... r u
                            nru=boundary_dict[idown]['node_curve_xmaxymax']
                            merge_node(nrd,nru)
                        nru=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xminymax']
                        nld=boundary_dict[idiag]['node_curve_xmaxymax']
                        nlu=boundary_dict[ileft]['node_curve_xmaxymin']
                        merge_node_4(nru,nrd,nld,nlu)
                    elif ip in xmin:
                        nlu=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nld=boundary_dict[idown]['node_curve_xminymax']
                        merge_node(nld,nlu)
                        nru=boundary_dict[ip]['node_curve_xmaxymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xmaxymax']
                        merge_node(nrd,nru)
                        
                        
                        
                        
                #
                if ip != ileft:
                    nright=boundary_dict[ip]['nodes_surf_xmin']
                    nleft=boundary_dict[ileft]['nodes_surf_xmax']
                    merge_node_ck(nright,nleft)
                    #
                    #
                    if ip in ymin:
                        nrd=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right down... r u
                        nld=boundary_dict[ileft]['node_curve_xmaxymin']
                        merge_node(nrd,nld)
                    if ip in ymax:
                        nru=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck right up... r u
                        nlu=boundary_dict[ileft]['node_curve_xmaxymax']
                        merge_node(nlu,nru)
        
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        
        
        #
        #
        cmd='group "negativejac" add quality hex all Jacobian high'
        cubit.cmd(cmd) 
        group_id_1=cubit.get_id_from_name("negativejac")
        n1=cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, use --merge2 instead of --equivalence/--merge/--merge1'
    elif ckbound_method2 and not ckbound_method1 and len(filenames) != 1:
        if isinstance(merge_tolerance,list):
            tol=merge_tolerance[0]
        elif merge_tolerance:
            tol=merge_tolerance
        else:
            tol=100000
        #
        idiag=None
        for ix in range(cpuxmin,cpuxmax):
            for iy in range(cpuymin,cpuymax):
                ip=iy*cpux+ix
                print '******************* ',ip
                #
                #   ileft    |   ip
                #  --------------------
                #   idiag    |   idown
                #
                #
                if ip not in xmin and ip not in ymin:
                    ileft=iy*cpux+ix-1
                    idown=(iy-1)*cpux+ix
                    idiag=idown-1
                elif ip in xmin and ip in ymin:
                    ileft=ip
                    idown=ip
                elif ip in xmin:
                    ileft=ip
                    idown=(iy-1)*cpux+ix
                    idiag=idown
                elif ip in ymin:
                    ileft=iy*cpux+ix-1
                    idown=ip
                    idiag=ileft
                #
                #
                if ip != idown:
                    nup=boundary_dict[ip]['nodes_surf_ymin']
                    ndow=boundary_dict[idown]['nodes_surf_ymax']
                    for n1,n2 in zip(nup,ndow):
                        cubit.cmd('equivalence node '+str(n1)+' '+str(n2)+' tolerance '+str(tol))
                    if idiag != idown:
                        if ip in ymax and ip not in xmin:
                            nlu=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck left up... r u
                            nru=boundary_dict[ileft]['node_curve_xmaxymax']
                            for n in zip(nlu,nru):
                                cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                        nru=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xminymax']
                        nld=boundary_dict[idiag]['node_curve_xmaxymax']
                        nlu=boundary_dict[ileft]['node_curve_xmaxymin']
                        for n in zip(nru,nrd,nlu,nld):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                    elif ip in xmin:
                        nru=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right up... r u
                        nrd=boundary_dict[idown]['node_curve_xminymax']
                        for n in zip(nru,nrd):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                #
                #
                if ip != ileft:
                    nright=boundary_dict[ip]['nodes_surf_xmin']
                    nleft=boundary_dict[ileft]['nodes_surf_xmax']
                    for n1,n2 in zip(nleft,nright):
                        cubit.cmd('equivalence node '+str(n1)+' '+str(n2)+' tolerance '+str(tol))
                    #
                    #
                    if ip in ymin:
                        nrd=boundary_dict[ip]['node_curve_xminymin'] #node in curve chunck right down... r u
                        nld=boundary_dict[ileft]['node_curve_xmaxymin']
                        for n in zip(nrd,nld):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
                    if ip in ymax:
                        nru=boundary_dict[ip]['node_curve_xminymax'] #node in curve chunck right up... r u
                        nlu=boundary_dict[ileft]['node_curve_xmaxymax']
                        for n in zip(nru,nlu):
                            cubit.cmd('equivalence node '+' '.join(str(x) for x in n)+' tolerance '+str(tol))
        #
        #
        cmd='topology check coincident node face all tolerance '+str(tol*2)+' nodraw brief result group "checkcoinc"' 
        cubit.silent_cmd(cmd)
        group_id_1=cubit.get_id_from_name("checkcoinc")
        if group_id_1 != 0:
            n1=cubit.get_group_nodes(group_id_1)
            if len(n1) != 0:
                print 'error, coincident nodes after the equivalence node command, check the tolerance'
                import sys
                sys.exit()
        cmd='group "negativejac" add quality hex all Jacobian high'
        cubit.cmd(cmd) 
        group_id_1=cubit.get_id_from_name("negativejac")
        n1=cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, check the mesh'
    elif ckbound_method1 and  ckbound_method2 and len(filenames) != 1:
        block_list=cubit.get_block_id_list()
        i=-1
        for block in block_list:
            ty=cubit.get_block_element_type(block)
            if ty == 'HEX8':
                i=i+1
                if isinstance(merge_tolerance,list):
                    try:
                        tol=merge_tolerance[i]
                    except:
                        tol=merge_tolerance[-1]
                elif merge_tolerance:
                    tol=merge_tolerance
                else:
                    tol=1
                cmd='topology check coincident node face in hex in block '+str(block)+' tolerance '+str(tol)+' nodraw brief result group "b'+str(block)+'"'
                cubit.cmd(cmd)
                print cmd
                cmd='equivalence node in group b'+str(block)+' tolerance '+str(tol)
                cubit.cmd(cmd)
                print cmd
        if isinstance(merge_tolerance,list):
            tol=max(merge_tolerance)
        elif merge_tolerance:
            tol=merge_tolerance
        else:
            tol=1
        #
        #
        cmd='topology check coincident node face all tolerance '+str(tol)+' nodraw brief result group "checkcoinc"' 
        cubit.silent_cmd(cmd)
        group_id_1=cubit.get_id_from_name("checkcoinc")
        if group_id_1 != 0:
            n1=cubit.get_group_nodes(group_id_1)
            if len(n1) != 0:
                print 'error, coincident nodes after the equivalence node command, check the tolerance'
                import sys
                sys.exit()
        cmd='group "negativejac" add quality hex all Jacobian high'
        cubit.silent_cmd(cmd) 
        group_id_1=cubit.get_id_from_name("negativejac")
        n1=cubit.get_group_nodes(group_id_1)
        if len(n1) != 0:
            print 'error, negative jacobian after the equivalence node command, use --merge instead of --equivalence'
Beispiel #44
0
def collect(cpuxmin=0,
            cpuxmax=1,
            cpuymin=0,
            cpuymax=1,
            cpux=1,
            cpuy=1,
            cubfiles=False,
            ckbound_method1=False,
            ckbound_method2=False,
            merge_tolerance=None,
            curverefining=False,
            outfilename='totalmesh_merged',
            qlog=False,
            export2SPECFEM3D=False,
            listblock=None,
            listflag=None,
            outdir='.',
            add_sea=False,
            decimate=False,
            cpml=False,
            cpml_size=False,
            top_absorbing=False,
            hex27=False):
    #
    cubit.cmd('set journal error off')
    cubit.cmd('set verbose error off')
    collecting_merging(cpuxmin,
                       cpuxmax,
                       cpuymin,
                       cpuymax,
                       cpux,
                       cpuy,
                       cubfiles=cubfiles,
                       ckbound_method1=ckbound_method1,
                       ckbound_method2=ckbound_method2,
                       merge_tolerance=merge_tolerance,
                       decimate=decimate)
    cubit.cmd('set journal error on')
    cubit.cmd('set verbose error on')
    #
    if curverefining:
        block = 1001  #topography
        refine_closecurve(block, curverefining, acis=True)
    #
    #
    if add_sea:
        block = 1001
        add_sea_layer(block=block)

    outdir2 = '/'.join(x for x in outfilename.split('/')[:-1])
    if outdir2 == '':
        outdir2 = outdir + '/'
    else:
        outdir2 = outdir + '/' + outdir2 + '/'

    import os
    try:
        os.makedirs(outdir2)
    except OSError:
        pass

    cubit.cmd('compress all')
    command = "export mesh '" + outdir2 + outfilename + ".e' block all overwrite xml '" + outdir2 + outfilename + ".xml'"
    cubit.cmd(command)
    f = open(outdir2 + 'blocks.dat', 'w')
    blocks = cubit.get_block_id_list()
    #
    for block in blocks:
        name = cubit.get_exodus_entity_name('block', block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib = cubit.get_block_attribute_count(block)
        attr = [
            cubit.get_block_attribute_value(block, x)
            for x in range(0, nattrib)
        ]
        ty = cubit.get_block_element_type(block)
        f.write(
            str(block) + ' ; ' + name + ' ; nattr ' + str(nattrib) + ' ; ' +
            ' '.join(str(x) for x in attr) + ' ; ' + ty + ' ' +
            str(element_count) + '\n')
    f.close()
    #
    #
    cubit.cmd('set info echo journ off')
    cmd = 'del group all'
    cubit.silent_cmd(cmd)
    cubit.cmd('set info echo journ on')
    #
    command = "save as '" + outdir2 + outfilename + ".cub' overwrite"
    cubit.cmd(command)
    #
    print 'end meshing'
    #
    #
    if qlog:
        print '\n\nQUALITY CHECK.... ***************\n\n'
        import quality_log
        tq = open(outdir2 + outfilename + '.quality', 'w')
        max_skewness, min_length = quality_log.quality_log(tq)
    #
    #
    #
    if export2SPECFEM3D:
        e2SEM(files=False,
              listblock=listblock,
              listflag=listflag,
              outdir=outdir,
              cpml=cpml,
              cpml_size=cpml_size,
              top_absorbing=top_absorbing,
              hex27=hex27)
  for id in volumeIds:
    overLapping = cubit.get_overlapping_volumes ([id, volIdCutter])
    for vol in overLapping:
      if vol != volIdCutter:
        searchVolumes.append (vol)
  
  # Report
  print "Found " + str (len (searchVolumes)) + " intersecting volumes."

  # Find overlapping ids.
  overlap_tets = []

  # Save to temp file.
  saveTmpFile ()
  
  for id in searchVolumes:
    
    openTmpFile ()
    print "Finding tets in volume: " + str (id),
    tet_list = cubit.get_volume_tets (id)
    temp = es.getTetsOverlapPassedVols (tet_list, [volIdCutter])
    overlap_tets.extend (temp)


  removeTmpFile ()
  cubit.silent_cmd ('set duplicate block elements on')
  cubit.silent_cmd ('block 100 tet ' + es.toStr (overlap_tets))
  cubit.silent_cmd ('block 100 name "kernel"')
  
  cubit.silent_cmd ('set large exodus file on')
  cubit.silent_cmd ('export mesh "' + kernelWritePath + '/kernelMesh.ex2" block 100 overwrite')
Beispiel #46
0
def rename_curve(C, newname):
    # C is a object
    command = 'curve ' + str(C.id()) + ' rename "' + newname + '"'
    cubit.silent_cmd(command)
    return None
Beispiel #47
0
def destroy_curve(Cin):
    # C is a object
    command = 'delete curve ' + str(Cin.id())
    cubit.silent_cmd(command)
    return None
Beispiel #48
0
def rename_curve(C,newname):
    # C is a object
    command = 'curve ' + str(C.id()) + ' rename "' + newname + '"'
    cubit.silent_cmd(command)
    return None  
def collect_new(cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,ckbound_method1=False,ckbound_method2=False,merge_tolerance=None,curverefining=False,outfilename='totalmesh_merged',qlog=False,export2SPECFEM3D=False,listblock=None,listflag=None,outdir='.',add_sea=False,decimate=False,cpml=False,cpml_size=False,top_absorbing=False,hex27=False,save_cubfile=True,check_merging=False):
    #
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    #cubit.cmd('set error off')
    version_cubit=get_cubit_version()
    
    if decimate:
        if version_cubit >= 14.0:
            raise VersionException('check cubit version, decimate capability has been tested only with cubit <= 12.2')
    
    if version_cubit <= 12.2:
        collecting_merging(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy,cubfiles=cubfiles,ckbound_method1=ckbound_method1,ckbound_method2=ckbound_method2,merge_tolerance=merge_tolerance,decimate=decimate)
    elif version_cubit >= 14:
        collecting_merging_new(cpuxmin,cpuxmax+1,cpuymin,cpuymax+1,cpux,cpuy,cubfiles=cubfiles,check_merging=check_merging)
    else:
        raise VersionException('check cubit version, parallel capability of geocubit is working with cubit/trelis 14+ (or cubit 12.2)')
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
    #cubit.cmd('set error on')
    #
    if curverefining:
        if version_cubit <= 12.2:
            block=1001 #topography
            refine_closecurve(block,curverefining,acis=True)
        else:
            raise VersionException('check cubit version, refine curve capability has been tested only with cubit <= 12.2')
        
    #
    #
    if add_sea:
        if version_cubit <= 12.2:
            block=1001
            add_sea_layer(block=block)
        else:
            raise VersionException('check cubit version, sea capability has been tested only with cubit <= 12.2')


    outdir2='/'.join(x for x in outfilename.split('/')[:-1])
    if outdir2 == '': 
        outdir2=outdir+'/'
    else:
        outdir2=outdir+'/'+outdir2+'/'    
    
    import os
    try:
        os.makedirs(outdir2)
    except OSError:
        pass
    
    cubit.cmd('compress all')
    command="export mesh '"+outdir2+outfilename+".e' block all overwrite xml '"+outdir2+outfilename+".xml'"
    cubit.cmd(command)
    f=open(outdir2+'blocks.dat','w')
    blocks=cubit.get_block_id_list()
    #
    for block in blocks:
        name=cubit.get_exodus_entity_name('block',block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib=cubit.get_block_attribute_count(block)
        attr=[cubit.get_block_attribute_value(block,x) for x in range(0,nattrib)]
        ty=cubit.get_block_element_type(block)
        f.write(str(block)+' ; '+name+' ; nattr '+str(nattrib)+' ; '+' '.join(str(x) for x in attr)+' ; '+ty+' '+str(element_count)+'\n')
    f.close()
    #
    #
    cubit.cmd('set info echo journ off')
    cmd='del group all'
    cubit.silent_cmd(cmd)
    cubit.cmd('set info echo journ on')
    #
    #
    print 'end meshing'
    #
    #
    if qlog:
        print '\n\nQUALITY CHECK.... ***************\n\n'
        import quality_log
        tq=open(outdir2+outfilename+'.quality','w')
        max_skewness,min_length=quality_log.quality_log(tq)
    #
    #
    #
    if export2SPECFEM3D:
        e2SEM(files=False,listblock=listblock,listflag=listflag,outdir=outdir,cpml=cpml,cpml_size=cpml_size,top_absorbing=top_absorbing,hex27=hex27)
    
    if save_cubfile:
        vol_blocks=[x for x in blocks if x <=1000]
        cubit.cmd("create mesh geometry block "+' '.join(str(x) for x in vol_blocks)+" feature_angle 135.0")
        command = "save as '"+outdir2+outfilename+".cub' overwrite"
        print command
        cubit.cmd(command)
Beispiel #50
0
def destroy_curve(Cin):
    # C is a object
    command = 'delete curve ' + str(Cin.id())  
    cubit.silent_cmd(command)
    return None 
def collect_old(cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,ckbound_method1=False,ckbound_method2=False,merge_tolerance=None,curverefining=False,outfilename='totalmesh_merged',qlog=False,export2SPECFEM3D=False,listblock=None,listflag=None,outdir='.',add_sea=False,decimate=False,cpml=False,cpml_size=False,top_absorbing=False,hex27=False):
    #
    cubit.cmd('set journal error off')
    cubit.cmd('set verbose error off')
    collecting_merging(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy,cubfiles=cubfiles,ckbound_method1=ckbound_method1,ckbound_method2=ckbound_method2,merge_tolerance=merge_tolerance,decimate=decimate)
    cubit.cmd('set journal error on')
    cubit.cmd('set verbose error on')
    #
    if curverefining:
        block=1001 #topography
        refine_closecurve(block,curverefining,acis=True)
    #
    #
    if add_sea:
        block=1001
        add_sea_layer(block=block)

    outdir2='/'.join(x for x in outfilename.split('/')[:-1])
    if outdir2 == '': 
        outdir2=outdir+'/'
    else:
        outdir2=outdir+'/'+outdir2+'/'    
    
    import os
    try:
        os.makedirs(outdir2)
    except OSError:
        pass
    
    cubit.cmd('compress all')
    command="export mesh '"+outdir2+outfilename+".e' block all overwrite xml '"+outdir2+outfilename+".xml'"
    cubit.cmd(command)
    f=open(outdir2+'blocks.dat','w')
    blocks=cubit.get_block_id_list()
    #
    for block in blocks:
        name=cubit.get_exodus_entity_name('block',block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib=cubit.get_block_attribute_count(block)
        attr=[cubit.get_block_attribute_value(block,x) for x in range(0,nattrib)]
        ty=cubit.get_block_element_type(block)
        f.write(str(block)+' ; '+name+' ; nattr '+str(nattrib)+' ; '+' '.join(str(x) for x in attr)+' ; '+ty+' '+str(element_count)+'\n')
    f.close()
    #
    #
    cubit.cmd('set info echo journ off')
    cmd='del group all'
    cubit.silent_cmd(cmd)
    cubit.cmd('set info echo journ on')
    #
    command = "save as '"+outdir2+outfilename+".cub' overwrite"
    cubit.cmd(command)
    #
    print 'end meshing'
    #
    #
    if qlog:
        print '\n\nQUALITY CHECK.... ***************\n\n'
        import quality_log
        tq=open(outdir2+outfilename+'.quality','w')
        max_skewness,min_length=quality_log.quality_log(tq)
    #
    #
    #
    if export2SPECFEM3D:
        e2SEM(files=False,listblock=listblock,listflag=listflag,outdir=outdir,cpml=cpml,cpml_size=cpml_size,top_absorbing=top_absorbing,hex27=hex27)
def save_elements_nodes(name,quads_fault_u,quads_fault_d):
   fault_file = open(name,'w')
   txt =''
   list_hex=cubit.parse_cubit_list('hex','all')
   txt='%10i %10i\n' % (len(quads_fault_u),len(quads_fault_d))
   fault_file.write(txt)

   dic_quads_fault_u = dict(zip(quads_fault_u,quads_fault_u))
   dic_quads_fault_d = dict(zip(quads_fault_d,quads_fault_d))

   # FAULT SIDE DOWN
  # fault_file.write('upsurface')
   for h in list_hex:
       faces = cubit.get_sub_elements('hex',h,2)
       for f in faces:
           if dic_quads_fault_d.has_key(f):
	      cubit.silent_cmd('group "nf" add Node in face '+str(f))
	      group1 = cubit.get_id_from_name("nf")
	      nodes = cubit.get_group_nodes(group1)
	      cubit.silent_cmd('del group '+ str(group1))
#              nodes=cubit.get_connectivity('Face',f)
#              print 'h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3]
#              txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
#                                                nodes[1],nodes[2],nodes[3])
              ngnod2d = len(nodes)
	      if ngnod2d == 9:
#kangchen added               txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
#                                                nodes[1],nodes[2],nodes[3])
                      txt='%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
	      else:
		      txt='%10i %10i %10i %10i %10i \n' % (h,nodes[0],\
				                                                      nodes[1],nodes[2],nodes[3])




              fault_file.write(txt)

   # FAULT SIDE UP
 #  fault_file.write('downsurface')
   for h in list_hex:
       faces = cubit.get_sub_elements('hex',h,2)
       for f in faces:
           if dic_quads_fault_u.has_key(f):
       	      cubit.silent_cmd('group "nf" add Node in face '+str(f))
	      group1 = cubit.get_id_from_name("nf")
	      nodes = cubit.get_group_nodes(group1)
	      cubit.cmd('del group '+ str(group1))
	      ngnod2d=len(nodes)
	      if ngnod2d == 9:
#	      nodes=cubit.get_connectivity('Face',f)
#             print 'h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3]
#kangchen added               txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
#                                                nodes[1],nodes[2],nodes[3])
                      txt='%10i %10i %10i %10i %10i %10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                                nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],nodes[8])
	      else:
		      txt='%10i %10i %10i %10i %10i \n' % (h,nodes[0],\
				                                                      nodes[1],nodes[2],nodes[3])



              fault_file.write(txt)

   fault_file.close()