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 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 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
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)
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