Exemple #1
0
def collecting_cpml(ip,size=None,cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,decimate=False,layers=2):
    import glob
    import re
    from utilities import list2str
    #
    if not size:
        print 'cpml size must be specified'
        return
        
        
    boundary_dict={}
    ##
    try:
        from boundary_definition import check_bc, map_boundary, define_surf
    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 ')
            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
        if decimate: cubit.cmd('export mesh "decimated_before_cmpl.e" dimension 3 block all overwrite')
    else:
        if decimate: 
            cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
            cubit.cmd('export mesh "decimated_before_cmpl.e" dimension 3 block all overwrite')

    
    #
    #
    #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)+'"')
            
    list_vol=list(cubit.parse_cubit_list('volume','all'))
    create_pml(xmin=xmin,xmax=xmax,ymax=ymax,ymin=ymin,zmin=zmin,zmax=zmax,size=size,layers=layers,vol=list_vol)
Exemple #2
0
def collecting_cpml(ip,size=None,cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,decimate=False,layers=2):
    import glob
    import re
    from utilities import list2str
    #
    if not size:
        print 'cpml size must be specified'
        return


    boundary_dict={}
    ##
    try:
        from boundary_definition import check_bc, map_boundary, define_surf
    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 ')
            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
        if decimate: cubit.cmd('export mesh "decimated_before_cmpl.e" dimension 3 block all overwrite')
    else:
        if decimate:
            cubit.cmd('refine volume all numsplit 1 bias 1.0 depth 1 ')
            cubit.cmd('export mesh "decimated_before_cmpl.e" dimension 3 block all overwrite')


    #
    #
    #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)+'"')

    list_vol=list(cubit.parse_cubit_list('volume','all'))
    create_pml(xmin=xmin,xmax=xmax,ymax=ymax,ymin=ymin,zmin=zmin,zmax=zmax,size=size,layers=layers,vol=list_vol)
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 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')
Exemple #5
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'