def collect_new(cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1,cubfiles=False,ckbound_method1=False,ckbound_method2=False,merge_tolerance=None,curverefining=False,outfilename='totalmesh_merged',qlog=False,export2SPECFEM3D=False,listblock=None,listflag=None,outdir='.',add_sea=False,decimate=False,cpml=False,cpml_size=False,top_absorbing=False,hex27=False,save_cubfile=True,check_merging=False):
    #
    cubit.cmd('set info off')
    cubit.cmd('set echo off')
    cubit.cmd('set journal off')
    #cubit.cmd('set error off')
    version_cubit=get_cubit_version()
    
    if decimate:
        if version_cubit >= 14.0:
            raise VersionException('check cubit version, decimate capability has been tested only with cubit <= 12.2')
    
    if version_cubit <= 12.2:
        collecting_merging(cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy,cubfiles=cubfiles,ckbound_method1=ckbound_method1,ckbound_method2=ckbound_method2,merge_tolerance=merge_tolerance,decimate=decimate)
    elif version_cubit >= 14:
        collecting_merging_new(cpuxmin,cpuxmax+1,cpuymin,cpuymax+1,cpux,cpuy,cubfiles=cubfiles,check_merging=check_merging)
    else:
        raise VersionException('check cubit version, parallel capability of geocubit is working with cubit/trelis 14+ (or cubit 12.2)')
    cubit.cmd('set info on')
    cubit.cmd('set echo on')
    cubit.cmd('set journal on')
    #cubit.cmd('set error on')
    #
    if curverefining:
        if version_cubit <= 12.2:
            block=1001 #topography
            refine_closecurve(block,curverefining,acis=True)
        else:
            raise VersionException('check cubit version, refine curve capability has been tested only with cubit <= 12.2')
        
    #
    #
    if add_sea:
        if version_cubit <= 12.2:
            block=1001
            add_sea_layer(block=block)
        else:
            raise VersionException('check cubit version, sea capability has been tested only with cubit <= 12.2')


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

    outdir2='/'.join(x for x in outfilename.split('/')[:-1])
    if outdir2 == '': 
        outdir2=outdir+'/'
    else:
        outdir2=outdir+'/'+outdir2+'/'    
    
    import os
    try:
        os.makedirs(outdir2)
    except OSError:
        pass
    
    cubit.cmd('compress all')
    command="export mesh '"+outdir2+outfilename+".e' block all overwrite xml '"+outdir2+outfilename+".xml'"
    cubit.cmd(command)
    f=open(outdir2+'blocks.dat','w')
    blocks=cubit.get_block_id_list()
    #
    for block in blocks:
        name=cubit.get_exodus_entity_name('block',block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib=cubit.get_block_attribute_count(block)
        attr=[cubit.get_block_attribute_value(block,x) for x in range(0,nattrib)]
        ty=cubit.get_block_element_type(block)
        f.write(str(block)+' ; '+name+' ; nattr '+str(nattrib)+' ; '+' '.join(str(x) for x in attr)+' ; '+ty+' '+str(element_count)+'\n')
    f.close()
    #
    #
    cubit.cmd('set info echo journ off')
    cmd='del group all'
    cubit.silent_cmd(cmd)
    cubit.cmd('set info echo journ on')
    #
    command = "save as '"+outdir2+outfilename+".cub' overwrite"
    cubit.cmd(command)
    #
    print 'end meshing'
    #
    #
    if qlog:
        print '\n\nQUALITY CHECK.... ***************\n\n'
        import quality_log
        tq=open(outdir2+outfilename+'.quality','w')
        max_skewness,min_length=quality_log.quality_log(tq)
    #
    #
    #
    if export2SPECFEM3D:
        e2SEM(files=False,listblock=listblock,listflag=listflag,outdir=outdir,cpml=cpml,cpml_size=cpml_size,top_absorbing=top_absorbing,hex27=hex27)
def refine_closecurve(block=1001,closed_filenames=None,acis=True):
    from utilities import load_curves
    from boundary_definition import build_block_side,define_surf
    from mesh_volume import refine_inside_curve
    #
    #
    curves=[]
    if not isinstance(closed_filenames,list): closed_filenames=[closed_filenames]
    for f in closed_filenames:
        print f
        if acis: 
            curves=curves+load_curves(f)
    print curves
    blist=list(cubit.get_block_id_list())
    try:
        blist.remove(1001)
    except:
        pass
    try:
        blist.remove(1002)
    except:
        pass
    try:
        blist.remove(1003)
    except:
        pass        
    try:
        blist.remove(1004)    
    except:                             
        pass             
    try:
        blist.remove(1005)
    except:
        pass
    try:
        blist.remove(1006)
    except:
        pass
    id_top=max(blist)
    cmd='group "coi" add node in hex in block '+str(id_top)
    cubit.cmd(cmd)
    #
    id_inside_arc=None
    for c in map(int,curves[0].split()):   #curves is a list of one string
        c1001 = cubit.get_exodus_element_count(1001, "block")
        c1002 = cubit.get_exodus_element_count(1002, "block")
        c1003 = cubit.get_exodus_element_count(1003, "block")
        c1004 = cubit.get_exodus_element_count(1004, "block")
        c1005 = cubit.get_exodus_element_count(1005, "block")
        c1006 = cubit.get_exodus_element_count(1006, "block")
        #
        refine_inside_curve(c,ntimes=1,depth=1,block=block,surface=False)
        blist=list(cubit.get_block_id_list())
        cmd='create mesh geometry hex all except hex in block all feature_angle 135'
        cubit.cmd(cmd)
        blist_after=list(cubit.get_block_id_list())
        [blist_after.remove(x) for x in blist]
        id_inside=max(blist_after)
        cmd='group "coi" add node in hex in block '+str(id_inside)
        cubit.cmd(cmd)
        if id_inside_arc: 
                cmd='del block '+str(id_inside-1)
                cubit.cmd(cmd)
        cmd='block '+str(id_inside)+' name "refined"'
        cubit.cmd(cmd)
        id_inside_arc=id_inside                                            
        #
        _,_,_,_,_,top_surf,bottom_surf,surf_xmin,surf_ymin,surf_xmax,surf_ymax=define_surf()
        #
        c1001_after = cubit.get_exodus_element_count(1001, "block")
        c1002_after = cubit.get_exodus_element_count(1002, "block")
        c1003_after = cubit.get_exodus_element_count(1003, "block")
        c1004_after = cubit.get_exodus_element_count(1004, "block")
        c1005_after = cubit.get_exodus_element_count(1005, "block")
        c1006_after = cubit.get_exodus_element_count(1006, "block")
        entity='face'
        if c1001_after != c1001:
            refname=entity+'_topo'
            build_block_side(top_surf,refname,obj=entity,id_0=1001)
        #
        if c1002_after != c1002:
            refname=entity+'_bottom'
            build_block_side(bottom_surf,refname,obj=entity,id_0=1002)
        #
        if c1003_after != c1003:
            refname=entity+'_abs_xmin'
            build_block_side(surf_xmin,refname,obj=entity,id_0=1003)
        #                                                              
        if c1004_after != c1004:
            refname=entity+'_abs_ymin'
            build_block_side(surf_ymin,refname,obj=entity,id_0=1004)
        #                                                              
        if c1005_after != c1005:  
            refname=entity+'_abs_xmax'                                     
            build_block_side(surf_xmax,refname,obj=entity,id_0=1005)
        #
        if c1006_after != c1006:    
            refname=entity+'_abs_ymax'                                   
            build_block_side(surf_ymax,refname,obj=entity,id_0=1006)
        #
        cmd='disassociate mesh from volume all'
        cubit.cmd(cmd)
        cmd='group "coi" add node in face in block 1001 1002 1003 1004 1005 1006'
        cubit.cmd(cmd)
        cubit.cmd('del vol all')
        cubit.cmd('group "removedouble" add hex all except hex in block all')
        cubit.cmd('delete hex in removedouble')
        cubit.cmd('delet group removedouble')
        cmd='equivalence node in group coi tolerance 20'
        cubit.cmd(cmd)
    cmd='equivalence node all tolerance 10'
    cubit.cmd(cmd)
    cubit.cmd('del curve '+' '.join(str(x) for x in curves) )
示例#4
0
def collect(cpuxmin=0,
            cpuxmax=1,
            cpuymin=0,
            cpuymax=1,
            cpux=1,
            cpuy=1,
            cubfiles=False,
            ckbound_method1=False,
            ckbound_method2=False,
            merge_tolerance=None,
            curverefining=False,
            outfilename='totalmesh_merged',
            qlog=False,
            export2SPECFEM3D=False,
            listblock=None,
            listflag=None,
            outdir='.',
            add_sea=False,
            decimate=False,
            cpml=False,
            cpml_size=False,
            top_absorbing=False,
            hex27=False):
    #
    cubit.cmd('set journal error off')
    cubit.cmd('set verbose error off')
    collecting_merging(cpuxmin,
                       cpuxmax,
                       cpuymin,
                       cpuymax,
                       cpux,
                       cpuy,
                       cubfiles=cubfiles,
                       ckbound_method1=ckbound_method1,
                       ckbound_method2=ckbound_method2,
                       merge_tolerance=merge_tolerance,
                       decimate=decimate)
    cubit.cmd('set journal error on')
    cubit.cmd('set verbose error on')
    #
    if curverefining:
        block = 1001  #topography
        refine_closecurve(block, curverefining, acis=True)
    #
    #
    if add_sea:
        block = 1001
        add_sea_layer(block=block)

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

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

    cubit.cmd('compress all')
    command = "export mesh '" + outdir2 + outfilename + ".e' block all overwrite xml '" + outdir2 + outfilename + ".xml'"
    cubit.cmd(command)
    f = open(outdir2 + 'blocks.dat', 'w')
    blocks = cubit.get_block_id_list()
    #
    for block in blocks:
        name = cubit.get_exodus_entity_name('block', block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib = cubit.get_block_attribute_count(block)
        attr = [
            cubit.get_block_attribute_value(block, x)
            for x in range(0, nattrib)
        ]
        ty = cubit.get_block_element_type(block)
        f.write(
            str(block) + ' ; ' + name + ' ; nattr ' + str(nattrib) + ' ; ' +
            ' '.join(str(x) for x in attr) + ' ; ' + ty + ' ' +
            str(element_count) + '\n')
    f.close()
    #
    #
    cubit.cmd('set info echo journ off')
    cmd = 'del group all'
    cubit.silent_cmd(cmd)
    cubit.cmd('set info echo journ on')
    #
    command = "save as '" + outdir2 + outfilename + ".cub' overwrite"
    cubit.cmd(command)
    #
    print 'end meshing'
    #
    #
    if qlog:
        print '\n\nQUALITY CHECK.... ***************\n\n'
        import quality_log
        tq = open(outdir2 + outfilename + '.quality', 'w')
        max_skewness, min_length = quality_log.quality_log(tq)
    #
    #
    #
    if export2SPECFEM3D:
        e2SEM(files=False,
              listblock=listblock,
              listflag=listflag,
              outdir=outdir,
              cpml=cpml,
              cpml_size=cpml_size,
              top_absorbing=top_absorbing,
              hex27=hex27)
示例#5
0
def refine_closecurve(block=1001, closed_filenames=None, acis=True):
    from utilities import load_curves
    from boundary_definition import build_block_side, define_surf
    from mesh_volume import refine_inside_curve
    #
    #
    curves = []
    if not isinstance(closed_filenames, list):
        closed_filenames = [closed_filenames]
    for f in closed_filenames:
        print f
        if acis:
            curves = curves + load_curves(f)
    print curves
    blist = list(cubit.get_block_id_list())
    try:
        blist.remove(1001)
    except:
        pass
    try:
        blist.remove(1002)
    except:
        pass
    try:
        blist.remove(1003)
    except:
        pass
    try:
        blist.remove(1004)
    except:
        pass
    try:
        blist.remove(1005)
    except:
        pass
    try:
        blist.remove(1006)
    except:
        pass
    id_top = max(blist)
    cmd = 'group "coi" add node in hex in block ' + str(id_top)
    cubit.cmd(cmd)
    #
    id_inside_arc = None
    for c in map(int, curves[0].split()):  #curves is a list of one string
        c1001 = cubit.get_exodus_element_count(1001, "block")
        c1002 = cubit.get_exodus_element_count(1002, "block")
        c1003 = cubit.get_exodus_element_count(1003, "block")
        c1004 = cubit.get_exodus_element_count(1004, "block")
        c1005 = cubit.get_exodus_element_count(1005, "block")
        c1006 = cubit.get_exodus_element_count(1006, "block")
        #
        refine_inside_curve(c, ntimes=1, depth=1, block=block, surface=False)
        blist = list(cubit.get_block_id_list())
        cmd = 'create mesh geometry hex all except hex in block all feature_angle 135'
        cubit.cmd(cmd)
        blist_after = list(cubit.get_block_id_list())
        [blist_after.remove(x) for x in blist]
        id_inside = max(blist_after)
        cmd = 'group "coi" add node in hex in block ' + str(id_inside)
        cubit.cmd(cmd)
        if id_inside_arc:
            cmd = 'del block ' + str(id_inside - 1)
            cubit.cmd(cmd)
        cmd = 'block ' + str(id_inside) + ' name "refined"'
        cubit.cmd(cmd)
        id_inside_arc = id_inside
        #
        _, _, _, _, _, top_surf, bottom_surf, surf_xmin, surf_ymin, surf_xmax, surf_ymax = define_surf(
        )
        #
        c1001_after = cubit.get_exodus_element_count(1001, "block")
        c1002_after = cubit.get_exodus_element_count(1002, "block")
        c1003_after = cubit.get_exodus_element_count(1003, "block")
        c1004_after = cubit.get_exodus_element_count(1004, "block")
        c1005_after = cubit.get_exodus_element_count(1005, "block")
        c1006_after = cubit.get_exodus_element_count(1006, "block")
        entity = 'face'
        if c1001_after != c1001:
            refname = entity + '_topo'
            build_block_side(top_surf, refname, obj=entity, id_0=1001)
        #
        if c1002_after != c1002:
            refname = entity + '_bottom'
            build_block_side(bottom_surf, refname, obj=entity, id_0=1002)
        #
        if c1003_after != c1003:
            refname = entity + '_abs_xmin'
            build_block_side(surf_xmin, refname, obj=entity, id_0=1003)
        #
        if c1004_after != c1004:
            refname = entity + '_abs_ymin'
            build_block_side(surf_ymin, refname, obj=entity, id_0=1004)
        #
        if c1005_after != c1005:
            refname = entity + '_abs_xmax'
            build_block_side(surf_xmax, refname, obj=entity, id_0=1005)
        #
        if c1006_after != c1006:
            refname = entity + '_abs_ymax'
            build_block_side(surf_ymax, refname, obj=entity, id_0=1006)
        #
        cmd = 'disassociate mesh from volume all'
        cubit.cmd(cmd)
        cmd = 'group "coi" add node in face in block 1001 1002 1003 1004 1005 1006'
        cubit.cmd(cmd)
        cubit.cmd('del vol all')
        cubit.cmd('group "removedouble" add hex all except hex in block all')
        cubit.cmd('delete hex in removedouble')
        cubit.cmd('delet group removedouble')
        cmd = 'equivalence node in group coi tolerance 20'
        cubit.cmd(cmd)
    cmd = 'equivalence node all tolerance 10'
    cubit.cmd(cmd)
    cubit.cmd('del curve ' + ' '.join(str(x) for x in curves))
示例#6
0
def savemesh(mpiflag, iproc=0, filename=None):
    import start as start
    cfg = start.start_cfg(filename=filename)
    mpiflag, iproc, numproc, mpi = start.start_mpi()

    def runsave(meshfile, iproc, filename=None):
        import start as start
        cubit = start.start_cubit()
        cfg = start.start_cfg(filename=filename)
        flag = 0
        ner = cubit.get_error_count()
        cubitcommand = 'save as "' + cfg.output_dir + \
            '/' + meshfile + '.cub' + '" overwrite'
        cubit.cmd(cubitcommand)
        ner2 = cubit.get_error_count()
        if ner == ner2:
            cubitcommand = 'export mesh "' + cfg.output_dir + '/' + \
                meshfile + '.e' + '" dimension 3 block all overwrite'
            cubit.cmd(cubitcommand)
            ner2 = cubit.get_error_count()
        if ner == ner2:
            flag = 1
        return flag

    meshfile = 'mesh_vol_' + str(iproc)

    flagsaved = 0
    infosave = (iproc, flagsaved)

    mpi.barrier()
    total_saved = mpi.allgather(flagsaved)
    if isinstance(total_saved, int):
        total_saved = [total_saved]

    ind = 0
    saving = True
    while saving:
        if len(total_saved) != sum(total_saved):
            #
            if not flagsaved:
                flagsaved = runsave(meshfile, iproc, filename=filename)
                if flagsaved:
                    infosave = (iproc, flagsaved)
                    if numproc > 1:
                        f = open('mesh_saved' + str(iproc), 'w')
                        f.close()
            mpi.barrier()
            total_saved = mpi.allgather(flagsaved)
            if isinstance(total_saved, int):
                total_saved = [total_saved]
            ind = ind + 1
        else:
            saving = False
        if ind > len(total_saved) + 10:
            saving = False
        print sum(total_saved), '/', len(total_saved), ' saved'

    info_total_saved = mpi.allgather(infosave)
    if isinstance(info_total_saved, int):
        info_total_saved = [info_total_saved]

    if iproc == 0:
        f = open('mesh_saving.log', 'w')
        f.write('\n'.join(str(x) for x in info_total_saved))
        f.close()

    f = open(cfg.output_dir + '/' + 'blocks_' + str(iproc).zfill(5), 'w')
    blocks = cubit.get_block_id_list()

    for block in blocks:
        name = cubit.get_exodus_entity_name('block', block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib = cubit.get_block_attribute_count(block)
        attr = [cubit.get_block_attribute_value(
            block, x) for x in range(0, nattrib)]
        ty = cubit.get_block_element_type(block)
        f.write(str(block) + ' ; ' + name + ' ; nattr ' + str(nattrib) +
                ' ; ' + ' '.join(str(x) for x in attr) + ' ; ' + ty + ' ' +
                str(element_count) + '\n')
    f.close()

    import quality_log
    f = open(cfg.output_dir + '/' + 'quality_' + str(iproc).zfill(5), 'w')
    max_skewness, min_length = quality_log.quality_log(f)
    f.close()

    count_hex = [cubit.get_hex_count()]
    count_node = [cubit.get_node_count()]
    max_skew = [(iproc, max_skewness)]
    min_l = [(iproc, min_length)]

    mpi.barrier()
    total_min_l = mpi.gather(min_l)
    total_hex = mpi.gather(count_hex)
    total_node = mpi.gather(count_node)
    total_max_skew = mpi.gather(max_skew)

    mpi.barrier()
    if iproc == 0:
        min_total_min_l = min([ms[1] for ms in total_min_l])
        max_total_max_skew = max([ms[1] for ms in total_max_skew])
        sum_total_node = sum(total_node)
        sum_total_hex = sum(total_hex)

        totstat_file = open(cfg.output_dir + '/totstat.log', 'w')
        text = 'hex total number,node total number,max skew, min length\n'
        totstat_file.write(text)

        text = str(sum_total_hex) + ' , ' + str(sum_total_node) + ' , ' + \
            str(max_total_max_skew) + ' , ' + str(min_total_min_l) + '\n'
        totstat_file.write(text)

        totstat_file.write(str(total_max_skew))
        totstat_file.close()

    print 'meshing process end... proc ', iproc
示例#7
0
def savemesh(mpiflag, iproc=0, filename=None):
    import start as start
    cfg = start.start_cfg(filename=filename)
    mpiflag, iproc, numproc, mpi = start.start_mpi()

    def runsave(meshfile, iproc, filename=None):
        import start as start
        cubit = start.start_cubit()
        cfg = start.start_cfg(filename=filename)
        flag = 0
        ner = cubit.get_error_count()
        cubitcommand = 'save as "' + cfg.output_dir + '/' + meshfile + '.cub' + '" overwrite'
        cubit.cmd(cubitcommand)
        ner2 = cubit.get_error_count()
        if ner == ner2:
            cubitcommand = 'export mesh "' + cfg.output_dir + '/' + meshfile + '.e' + '" dimension 3 block all overwrite'
            cubit.cmd(cubitcommand)
            ner2 = cubit.get_error_count()
        if ner == ner2:
            flag = 1
        return flag

    meshfile = 'mesh_vol_' + str(iproc)

    flagsaved = 0
    infosave = (iproc, flagsaved)

    mpi.barrier()
    total_saved = mpi.allgather(flagsaved)
    if isinstance(total_saved, int): total_saved = [total_saved]

    ind = 0
    saving = True
    while saving:
        if len(total_saved) != sum(total_saved):
            #
            if not flagsaved:
                flagsaved = runsave(meshfile, iproc, filename=filename)
                if flagsaved:
                    infosave = (iproc, flagsaved)
                    if numproc > 1:
                        f = open('mesh_saved' + str(iproc), 'w')
                        f.close()
            mpi.barrier()
            total_saved = mpi.allgather(flagsaved)
            if isinstance(total_saved, int): total_saved = [total_saved]
            ind = ind + 1
        else:
            saving = False
        if ind > len(total_saved) + 10: saving = False
        print sum(total_saved), '/', len(total_saved), ' saved'

    info_total_saved = mpi.allgather(infosave)
    if isinstance(info_total_saved, int): info_total_saved = [info_total_saved]

    if iproc == 0:
        f = open('mesh_saving.log', 'w')
        f.write('\n'.join(str(x) for x in info_total_saved))
        f.close()

    f = open(cfg.output_dir + '/' + 'blocks_' + str(iproc).zfill(5), 'w')
    blocks = cubit.get_block_id_list()

    for block in blocks:
        name = cubit.get_exodus_entity_name('block', block)
        element_count = cubit.get_exodus_element_count(block, "block")
        nattrib = cubit.get_block_attribute_count(block)
        attr = [
            cubit.get_block_attribute_value(block, x)
            for x in range(0, nattrib)
        ]
        ty = cubit.get_block_element_type(block)
        f.write(
            str(block) + ' ; ' + name + ' ; nattr ' + str(nattrib) + ' ; ' +
            ' '.join(str(x) for x in attr) + ' ; ' + ty + ' ' +
            str(element_count) + '\n')
    f.close()

    import quality_log
    f = open(cfg.output_dir + '/' + 'quality_' + str(iproc).zfill(5), 'w')
    max_skewness, min_length = quality_log.quality_log(f)
    f.close()

    count_hex = [cubit.get_hex_count()]
    count_node = [cubit.get_node_count()]
    max_skew = [(iproc, max_skewness)]
    min_l = [(iproc, min_length)]

    mpi.barrier()
    total_min_l = mpi.gather(min_l)
    total_hex = mpi.gather(count_hex)
    total_node = mpi.gather(count_node)
    total_max_skew = mpi.gather(max_skew)

    mpi.barrier()
    if iproc == 0:
        min_total_min_l = min([ms[1] for ms in total_min_l])
        max_total_max_skew = max([ms[1] for ms in total_max_skew])
        sum_total_node = sum(total_node)
        sum_total_hex = sum(total_hex)

        totstat_file = open(cfg.output_dir + '/totstat.log', 'w')
        text = 'hex total number,node total number,max skew, min length\n'
        totstat_file.write(text)

        text = str(sum_total_hex) + ' , ' + str(sum_total_node) + ' , ' + str(
            max_total_max_skew) + ' , ' + str(min_total_min_l) + '\n'
        totstat_file.write(text)

        totstat_file.write(str(total_max_skew))
        totstat_file.close()

    print 'meshing process end... proc ', iproc