Ejemplo n.º 1
0
def refine_inside_curve(curves,ntimes=1,depth=1,block=1,surface=False):
    if not isinstance(curves,list): 
       if isinstance(curves,str):
          curves=map(int,curves.split())
       else:
          curves=[curves]
    for curve in curves:
        cubit.cmd('del group ntop')
        if not surface:
            cubit.cmd("group 'ntop' add node in face in block "+str(block))
        else:
            cubit.cmd("group 'ntop' add node in face in surface "+str(surface))
        group1 = cubit.get_id_from_name("ntop")
        nodes = list(cubit.get_group_nodes(group1))
        ni=get_nodes_inside_curve(nodes, curve)
        if ntimes > 1:
            cmd='del group hex_refining'
            cubit.cmd(cmd)
            command = "group 'hex_refining' add hex propagate face in node "+' '.join(str(x) for x in ni)+"times "+str(ntimes)
            cubit.cmd(command)
            id_group=cubit.get_id_from_name('hex_refining')
            command='refine hex in group "hex_refining" numsplit 1 bias 1.0 depth '+str(depth)+' smooth'
            cubit.cmd(command)
        else:
            command='refine node '+" ".join(str(x) for x in ni)+' numsplit 1 bias 1.0 depth '+str(depth)+' smooth'
            cubit.cmd(command)
    #
    #
    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 refining'
        import sys
Ejemplo n.º 2
0
def check_lateral_nodes(name_group='lateral'):
    cubit.cmd("group 'lateral_nodes' add Node in face in group "+name_group)
    ilateral_nodes=cubit.get_id_from_name('lateral_nodes')
    lateral_nodes=cubit.get_group_nodes(ilateral_nodes)
    cubit.cmd('del group '+str(ilateral_nodes))
    print name_group, ' nodes ',len(lateral_nodes)
    return len(lateral_nodes)
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def merge_node_ck(n1, n2):
    factor, minvalue, inv_length = prepare_equivalence(n1, n2)

    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    cubit.cmd('set error off')

    for k in inv_length.keys()[:-1]:
        if len(inv_length[k]) > 0:
            cmd = 'equivalence node ' + ' '.join(
                ' '.join(str(n) for n in x)
                for x in inv_length[k]) + ' tolerance ' + str(k * factor +
                                                              minvalue / 2.)
            cubit.cmd(cmd)
            print 'equivalence ' + str(len(
                inv_length[k])) + ' couples of nodes -  tolerance ' + str(
                    k * factor + minvalue / 2.)

    cubit.cmd('group "checkmerge" add node ' + ' '.join(str(n) for n in n1) +
              ' ' + ' '.join(str(n) for n in n2))
    idg = cubit.get_id_from_name('checkmerge')
    remainnodes = cubit.get_group_nodes(idg)
    print 'from ' + str(len(n1) + len(n2)) + ' nodes -> ' + str(
        len(remainnodes)) + ' nodes'
    if len(n1) != len(remainnodes):
        print 'equivalence ' + str(
            len(remainnodes)) + ' couples of nodes -  tolerance ' + str(
                minvalue / 2.)
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        cmd = 'equivalence node in group ' + str(idg) + ' tolerance ' + str(
            minvalue / 2.)
        cubit.cmd(cmd)
        cmd = 'block 3000 node in group ' + str(idg)
        cubit.cmd(cmd)

    if len(n1) != len(remainnodes):
        cubit.cmd(
            'export mesh "error_merging.e" dimension 3 block all overwrite')
        cubit.cmd(
            'save as "error_merging.cub" dimension 3 block all overwrite')
        print 'error merging '
        if False:
            import sys
            sys.exit(2)

    cubit.cmd('delete group checkmerge')
    cubit.cmd('delete block 3000')

    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
Ejemplo n.º 8
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
def getSelectedNodes():
    """
    Return the CUBIT indices of mouse 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
Ejemplo n.º 10
0
def getSelectedNodes(node_proxy):
    """
    Return the STEPS indices and CUBIT indices of the selected vertex nodes.
        
    Parameters:
        * node_proxy   Vertex node 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_nodes(group_id)
    steps_ids = [node_proxy.getSTEPSID(id) for id in cubit_ids]
    cubit.delete_group(group_id)
    return (steps_ids, cubit_ids)
Ejemplo n.º 11
0
def merge_node_ck(n1,n2):
    factor,minvalue,inv_length=prepare_equivalence(n1,n2)
    
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    #cubit.cmd('set error off')
    
    for k in inv_length.keys()[:-1]:
        if len(inv_length[k]) > 0:
            cmd='equivalence node '+' '.join(' '.join(str(n) for n in x) for x in inv_length[k])+' tolerance '+str(k*factor+minvalue/2.)
            cubit.cmd(cmd)
            print 'equivalence '+str(len(inv_length[k]))+' couples of nodes -  tolerance '+str(k*factor+minvalue/2.)
             

    cubit.cmd('group "checkmerge" add node '+' '.join(str(n) for n in n1)+' '+' '.join(str(n) for n in n2))
    idg=cubit.get_id_from_name('checkmerge')
    remainnodes=cubit.get_group_nodes(idg)
    print 'from '+str(len(n1)+len(n2))+' nodes -> '+str(len(remainnodes)) +' nodes'
    if len(n1) != len(remainnodes):
        print 'equivalence '+str(len(remainnodes))+' couples of nodes -  tolerance '+str(minvalue/2.)
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        cmd='equivalence node in group '+str(idg)+' tolerance '+str(minvalue/2.)
        cubit.cmd(cmd)
        cmd='block 3000 node in group '+str(idg)
        cubit.cmd(cmd)
        
    if len(n1) != len(remainnodes):
        cubit.cmd('export mesh "error_merging.e" dimension 3 block all overwrite')
        cubit.cmd('save as "error_merging.cub" dimension 3 block all overwrite')
        print 'error merging '
        if False:
            import sys
            sys.exit(2)
    
    cubit.cmd('delete group checkmerge')
    cubit.cmd('delete block 3000')
    
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
Ejemplo n.º 12
0
def get_ordered_node_surf(lsurface, icurve):
    if not isinstance(lsurface, str):
        lsurf = list2str(lsurface)
    #
    if not isinstance(icurve, str):
        icurvestr = str(icurve)
    # initializes
    orient_nodes_surf = []
    nodes_curve = []
    #
    #get the nodes on a surface, I don't use the method get_surface_nodes since it has different behavior in cubit12.2 and cubit13.2+
    k = cubit.get_id_from_name('sl')
    if k != 0:
        cubit.cmd('del group sl')
    else:
        print 'initializing group sl'
    cubit.cmd("group 'sl' add node in surf " + lsurf)
    group1 = cubit.get_id_from_name("sl")
    nodes_ls = list(cubit.get_group_nodes(group1))
    nnode = len(nodes_ls)
    #
    #get the nodes on curves
    orient = []
    k = cubit.get_id_from_name('n1')
    if k != 0:
        cubit.cmd('del group n1')
    else:
        print 'initializing group n1'
    cubit.cmd("group 'n1' add node in curve " + icurvestr)
    x = cubit.get_bounding_box('curve', icurve)
    # checks if anything to do
    if len(x) == 0:
        return nodes_curve, orient_nodes_surf
    # gets nodes
    if x[2] > x[5]:
        idx = 0
    else:
        idx = 1
    group1 = cubit.get_id_from_name("n1")
    nodes1 = list(cubit.get_group_nodes(group1))
    for n in nodes1:
        v = cubit.get_nodal_coordinates(n)
        orient.append(v[idx])
    result = zip(orient, nodes1)
    result.sort()
    nodes2 = [c[1] for c in result]
    for n in nodes2:
        try:
            nodes_ls.remove(n)
        except:
            pass
    orient_nodes_surf = orient_nodes_surf + nodes2
    #
    while len(orient_nodes_surf) < nnode:
        cubit.cmd('del group n1')
        cubit.cmd("group 'n1' add node in edge in node " +
                  str(nodes2).replace('[', ' ').replace(']', ' '))
        group1 = cubit.get_id_from_name("n1")
        nodes1 = list(cubit.get_group_nodes(group1))
        orient = []
        nd = []
        for n in nodes1:
            if n in nodes_ls:
                v = cubit.get_nodal_coordinates(n)
                orient.append(v[idx])
                nd.append(n)
        result = zip(orient, nd)
        result.sort()
        nodes2 = [c[1] for c in result]
        for n in nodes2:
            try:
                nodes_ls.remove(n)
            except:
                pass
        orient_nodes_surf = orient_nodes_surf + nodes2
    #get the vertical curve
    curve_vertical = []
    for s in lsurface:
        lcs = cubit.get_relatives("surface", s, "curve")
        for l in lcs:
            x = cubit.get_bounding_box('curve', l)
            length = [(x[2], 1), (x[5], 2), (x[8], 3)]
            length.sort()
            if length[-1][1] == 3:
                curve_vertical.append(l)
    #
    kcurve = list2str(curve_vertical)
    k = cubit.get_id_from_name('curve_vertical')
    if k != 0:
        cubit.cmd('del group curve_vertical')
    else:
        print 'initializing group curve_vertical'
    cubit.cmd("group 'curve_vertical' add node in curve " + kcurve)
    group1 = cubit.get_id_from_name('curve_vertical')
    nodes_curve = list(cubit.get_group_nodes(group1))
    for n in nodes_curve:
        try:
            orient_nodes_surf.remove(n)
        except:
            pass
    #
    return nodes_curve, orient_nodes_surf
Ejemplo n.º 13
0
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'
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()
Ejemplo n.º 15
0
def collecting_merging_new(cpuxmin=0,cpuxmax=0,cpuymin=0,cpuymax=0,cpux=1,cpuy=1,cubfiles=False,check_merging=False):
    import glob
    import re
    #
    ##
    try:
        from boundary_definition import check_bc, map_boundary
    except:
        pass
    #
    print 'cpu',cpuxmin,cpuxmax,cpuymin,cpuymax
    xmin,xmax,ymin,ymax,listfull=map_boundary(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy)
    #
    if cubfiles:
        nf,listip,filenames,cubflag=importing_cubfiles(cubfiles)
        print nf,listip,filenames,cubflag,listfull
    else:
        nf=0
        filenames=[]
        ip=0
    #
    
    index_block=-1
    store_group_name=[]
    side_name=['topo','xmin','ymin','xmax','ymax','bot']
    side_val=['1001','1003','1004','1005','1006','1002']
    side_block_name=['face_topo','face_abs_xmin','face_abs_ymin','face_abs_xmax','face_abs_ymax','face_abs_bottom']
    cubit.cmd('set duplicate block elements on')
    
    if nf > 0:
        for ip,filename in zip(listip,filenames):
            print ip,filename,ip in listfull
            try:
                if ip in listfull:
                    print filename
                    index_block=index_block+1
                    if cubflag:
                        cubit.cmd('import cubit "'+filename+'"')
                    else:
                        cubit.cmd('import mesh "'+filename+'" block all  no_geom')
            except:
                cubit.cmd('import mesh "'+filename+'" block all  no_geom')
            #print ip,xmin,xmax,ymin,ymax,ip in xmin,ip in xmax,ip in ymin,ip in ymax
            store_tmp=collecting_block(store_group_name,ip,xmin,xmax,ymin,ymax,index_block)
            if len(store_tmp)!=0: store_group_name=store_tmp
            print check_lateral_nodes()
            
        #cubit.cmd('export mesh "tmp_collect_NOmerging.e" dimension 3 block all overwrite')
        cubit.cmd('save as "tmp_nomerging.cub" 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+1,cpuymin,cpuymax+1)
        cubit.cmd('disassociate mesh from volume all')
        cubit.cmd('del vol all')
        cubit.cmd('set info on')
        cubit.cmd('set echo on')
        cubit.cmd('set journal on')
        return

    
    if check_merging:
        print 'cpu',cpuxmin,cpuxmax,cpuymin,cpuymax
        nodes_before_ymin=check_lateral_nodes('ymin')
        nlatline_ymin=(cpuxmax-cpuxmin)-1
        print 'lines',nlatline_ymin
        nodes_before_xmin=check_lateral_nodes('xmin')
        nlatline_xmin=(cpuymax-cpuymin)-1
        print 'lines',nlatline_xmin
        nodes_before_all=check_lateral_nodes()
    
    factor,minvalue,inv_length=prepare_equivalence_new()
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    #cubit.cmd('set error off')
    for k in inv_length.keys():
        print k, 'tolerance', str(k*factor+minvalue/2.)
        check_lateral_nodes()
        if len(inv_length[k]) > 0:
            print 'equivalence node in '+str(len(inv_length[k]))+' edges  tolerance '+str(k*factor+minvalue/2.)
            cmd='equivalence node in edge '+' '.join(str(x) for x in inv_length[k])+' tolerance '+str(k*factor+minvalue/2.)
            cubit.cmd(cmd)
    
    if check_merging:
        nodes_after_all=check_lateral_nodes()
        nodes_after_ymin=check_lateral_nodes('ymin')
        if nlatline_ymin !=0: 
            node_lines_ymin=(nodes_before_ymin-nodes_after_ymin)/nlatline_ymin
        else:
            node_lines_ymin=0
        nodes_after_xmin=check_lateral_nodes('xmin')
        if nlatline_xmin !=0: 
            node_lines_xmin=(nodes_before_xmin-nodes_after_xmin)/nlatline_xmin
        else:
            node_lines_xmin=0
        if node_lines_xmin and nlatline_ymin:
            checklines = node_lines_xmin == node_lines_ymin
        else:
            checklines=True
            
        checknodes = nodes_before_all == 2*(nodes_after_all+node_lines_xmin*(nlatline_xmin*nlatline_ymin))
        print 'check lines',checklines
        print 'check nodes',checknodes
        if not checknodes:
            diff_nodes=-nodes_before_all + 2*(nodes_after_all+node_lines_xmin*(nlatline_xmin*nlatline_ymin))
            print diff_nodes
            for tol in range(100,10000,100):
                cubit.cmd('topology check coincident node node in face in group lateral tolerance '+str(tol)+' draw brief result group "diff_node"')
                idiff=cubit.get_id_from_name('diff_node')
                idnodes=cubit.get_group_nodes(idiff)
                if len(idnodes)==diff_nodes:
                    print diff_nodes,idnodes
                    cmd='equivalence node '+' '.join(str(x) for x in idnodes)+' tolerance '+str(tol)
                    cubit.cmd(cmd)
                    break
            
            nodes_after_all=check_lateral_nodes()
            checknodes = nodes_before_all == 2*(nodes_after_all+node_lines_xmin*(nlatline_xmin*nlatline_ymin))
            print 'check nodes',checknodes
            
    else:
        print 'no merging check'
        checklines = True
        checknodes = True
    
    if checknodes and checklines:
        for ig,g in enumerate(store_group_name):
            cubit.cmd('block '+str(ig+1)+' hex in group '+g)
            cubit.cmd('block '+str(ig+1)+' name "vol'+str(ig+1)+'"')
            print 'block '+str(ig+1)+' hex in group '+g
        for ig,g in enumerate(side_name):
            cubit.cmd('block '+side_val[ig]+' face in group '+g)
            print 'block '+side_val[ig]+' face in group '+g
            cubit.cmd('block '+side_val[ig]+' name "'+side_block_name[ig]+'"')
        cubit.cmd('del group all')
    else:
        raise MergingError('merging failed... please check the blocks')
    
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
def get_ordered_node_surf(lsurface,icurve):
    if not isinstance(lsurface,str):
        lsurf=list2str(lsurface)
    #
    if not isinstance(icurve,str):
        icurvestr=str(icurve)
    orient_nodes_surf=[]
    #
    #get the nodes on a surface, I don't use the method get_surface_nodes since it has different behavior in cubit12.2 and cubit13.2+
    k=cubit.get_id_from_name('sl')
    if k!=0:
        cubit.cmd('del group sl')
    else:
        print 'initializing group sl'
    cubit.cmd("group 'sl' add node in surf "+lsurf)
    group1 = cubit.get_id_from_name("sl")
    nodes_ls =list(cubit.get_group_nodes(group1))
    nnode=len(nodes_ls)
    #
    #get the nodes on curves
    orient=[]
    k=cubit.get_id_from_name('n1')
    if k!=0:
        cubit.cmd('del group n1')
    else:
        print 'initializing group n1'
    cubit.cmd("group 'n1' add node in curve "+icurvestr)
    x=cubit.get_bounding_box('curve', icurve)
    if x[2]>x[5]:
        idx=0
    else:
        idx=1
    group1 = cubit.get_id_from_name("n1")
    nodes1 = list(cubit.get_group_nodes(group1))
    for n in nodes1:
        v = cubit.get_nodal_coordinates(n)
        orient.append(v[idx])
    result=zip(orient,nodes1)
    result.sort()
    nodes2=[c[1] for c in result]
    for n in nodes2:
        try:
            nodes_ls.remove(n)
        except:
            pass
    orient_nodes_surf=orient_nodes_surf+nodes2
    #
    while len(orient_nodes_surf) < nnode:
        cubit.cmd('del group n1')
        cubit.cmd("group 'n1' add node in edge in node "+str(nodes2).replace('[',' ').replace(']',' '))
        group1 = cubit.get_id_from_name("n1")
        nodes1 = list(cubit.get_group_nodes(group1))
        orient=[]
        nd=[]
        for n in nodes1:
            if n in nodes_ls:
                v = cubit.get_nodal_coordinates(n)
                orient.append(v[idx])
                nd.append(n)
        result=zip(orient,nd)
        result.sort()
        nodes2=[c[1] for c in result]
        for n in nodes2:
            try:
                nodes_ls.remove(n)
            except:
                pass
        orient_nodes_surf=orient_nodes_surf+nodes2
    #get the vertical curve
    curve_vertical=[]
    for s in lsurface:
        lcs=cubit.get_relatives("surface",s,"curve")
        for l in lcs:
            x=cubit.get_bounding_box('curve', l)
            length=[(x[2],1),(x[5],2),(x[8],3)]
            length.sort()
            if length[-1][1] == 3:
                curve_vertical.append(l)
    #
    kcurve=list2str(curve_vertical)
    k=cubit.get_id_from_name('curve_vertical')
    if k!=0:
        cubit.cmd('del group curve_vertical')
    else:
        print 'initializing group curve_vertical'
    cubit.cmd("group 'curve_vertical' add node in curve "+kcurve)
    group1 = cubit.get_id_from_name('curve_vertical')
    nodes_curve = list(cubit.get_group_nodes(group1))
    for n in nodes_curve:
        try:
            orient_nodes_surf.remove(n)
        except:
            pass
    #
    return nodes_curve,orient_nodes_surf
Ejemplo n.º 17
0
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()
Ejemplo n.º 18
0
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'
Ejemplo n.º 19
0
def save_elements_nodes(name, quads_fault_u, quads_fault_d):
    print('')
    print('## save fault nodes elements: file = ', name)
    print('##')
    fault_file = open(name, 'w')
    txt = ''
    list_hex = cubit.parse_cubit_list('hex', 'all')

    # number of fault elements up/down
    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))

    #cubit.cmd('set info off')
    #cubit.cmd('set echo off')

    # 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 f in dic_quads_fault_d.keys():
                cubit.silent_cmd('group "nf" add Node in face ' + str(f))

        group1 = cubit.get_id_from_name("nf")
        nodes = []
        if not group1 == 0:
            nodes = cubit.get_group_nodes(group1)
            cubit.silent_cmd('del group ' + str(group1))
            #debug
            #print('#fault down nodes: ',nodes,len(nodes),group1)

        #debug
        #nodes=cubit.get_connectivity('Face',f)
        #print('h,fault nodes side down :',h,nodes[0],nodes[1],nodes[2],nodes[3])

        if len(nodes) > 0:
            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 f in dic_quads_fault_u.keys():
                cubit.silent_cmd('group "nf" add Node in face ' + str(f))

        group1 = cubit.get_id_from_name("nf")
        nodes = []
        if not group1 == 0:
            nodes = cubit.get_group_nodes(group1)
            cubit.silent_cmd('del group ' + str(group1))
            #debug
            #print('#fault up   nodes: ',nodes,len(nodes),group1)

        #debug
        #nodes=cubit.get_connectivity('Face',f)
        #print('h,fault nodes side up :',h,nodes[0],nodes[1],nodes[2],nodes[3])

        if len(nodes) > 0:
            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_file.close()

    #cubit.cmd('set info on')
    #cubit.cmd('set echo on')

    print('## done fault file: ', name)
    print('')