def __init__(self): self.filename_nodes = 'node_coordinates' self.filename_hex8 = 'cell_connectivity_hex8' self.filename_tet4 = 'cell_connectivity_tet4' # self.hex8 = [] self.tet4 = [] # print "number of volumes = " + str(cubit.get_volume_count()) print "number of hexes in entire mesh: cubit.get_hex_count = " + str( cubit.get_hex_count()) print "number of tets in entire mesh: cubit.get_tet_count = " + str( cubit.get_tet_count()) # for volume in cubit.get_entities("volume"): print "VOLUME " + str(volume) + ":" print " number of elements: " + str( cubit.get_volume_element_count(volume)) hex8_list = cubit.get_volume_hexes(volume) self.hex8 += hex8_list print " number of hexes: " + str(len(hex8_list)) tet4_list = cubit.get_volume_tets(volume) self.tet4 += tet4_list print " number of tets: " + str(len(tet4_list)) # print "number of hexes found while iterating over all volumes: " + str( len(self.hex8)) print "number of tets found while iterating over all volumes: " + str( len(self.tet4))
def mesh_write(self,mesh_name): meshfile=open(mesh_name,'w') print 'Writing '+mesh_name+'.....' num_elems=cubit.get_hex_count() print ' total number of elements:',str(num_elems) meshfile.write(str(num_elems)+'\n') for block,flag in zip(self.block_mat,self.block_flag): hexes=cubit.get_block_hexes(block) print 'block ',block,' hexes ',len(hexes) for hexa in hexes: txt=self.create_hexnode_string(hexa) meshfile.write(txt) meshfile.close()
def mesh_write(self, mesh_name): meshfile = open(mesh_name, 'w') print 'Writing ' + mesh_name + '.....' num_elems = cubit.get_hex_count() print ' total number of elements:', str(num_elems) meshfile.write(str(num_elems) + '\n') for block, flag in zip(self.block_mat, self.block_flag): hexes = cubit.get_block_hexes(block) print 'block ', block, ' hexes ', len(hexes) for hexa in hexes: txt = self.create_hexnode_string(hexa) meshfile.write(txt) meshfile.close()
def main(): cubit.init(['']) cubit.cmd('## Cubit Version 11.0') cubit.cmd('## -warning = On') cubit.cmd('## -information = On') cubit.cmd('reset') # cubit.cmd('brick x 10 y 10 z 10') cubit.cmd('volume 1 size auto factor 4') cubit.cmd('mesh volume 1') cubit.cmd('sideset 1 surface 4') cubit.cmd('sideset 2 surface 6') # hexs = cubit.get_hex_count() for i in xrange(1, hexs+1): cubit.cmd('block ' + str(i) + ' hex ' + str(i)) # cubit.cmd('export genesis "large_sub_cube.e" dimension 3 overwrite')
def mesh_write(self, mesh_name): meshfile = open(mesh_name, "w") print "Writing " + mesh_name + "....." num_elems = cubit.get_hex_count() print " number of elements:", str(num_elems) meshfile.write(str(num_elems) + "\n") num_write = 0 for block, flag in zip(self.block_mat, self.block_flag): # print block,flag hexes = cubit.get_block_hexes(block) # print len(hexes) for hexa in hexes: # print hexa nodes = cubit.get_connectivity("Hex", hexa) # nodes=self.jac_check(nodes) #is it valid for 3D? TODO txt = ("%10i ") % hexa txt = txt + ("%10i %10i %10i %10i %10i %10i %10i %10i\n") % nodes[:] meshfile.write(txt) meshfile.close() print "Ok"
def mesh_write(self,mesh_name): meshfile=open(mesh_name,'w') print 'Writing '+mesh_name+'.....' num_elems=cubit.get_hex_count() print ' number of elements:',str(num_elems) meshfile.write(str(num_elems)+'\n') num_write=0 for block,flag in zip(self.block_mat,self.block_flag): #print block,flag hexes=cubit.get_block_hexes(block) #print len(hexes) for hexa in hexes: #print hexa nodes=cubit.get_connectivity('Hex',hexa) #nodes=self.jac_check(nodes) #is it valid for 3D? TODO txt=('%10i ')% hexa txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:] meshfile.write(txt) meshfile.close() print 'Ok'
def mesh_write(self, mesh_name): meshfile = open(mesh_name, 'w') print 'Writing ' + mesh_name + '.....' num_elems = cubit.get_hex_count() print ' number of elements:', str(num_elems) meshfile.write(str(num_elems) + '\n') num_write = 0 for block, flag in zip(self.block_mat, self.block_flag): #print block,flag hexes = cubit.get_block_hexes(block) #print len(hexes) for hexa in hexes: #print hexa nodes = cubit.get_connectivity('Hex', hexa) #nodes=self.jac_check(nodes) #is it valid for 3D? TODO txt = ('%10i ') % hexa txt = txt + ( '%10i %10i %10i %10i %10i %10i %10i %10i\n') % nodes[:] meshfile.write(txt) meshfile.close() print 'Ok'
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 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
cubit.cmd('Block ' + str(b) + ' name "face_abs_ymin"') b = b + 1 for i in side_xmax: cmd = 'block ' + str(b) + ' face in surface ' + str(i) cubit.cmd(cmd) cubit.cmd('Block ' + str(b) + ' name "face_abs_xmax"') b = b + 1 for i in side_ymax: cmd = 'block ' + str(b) + ' face in surface ' + str(i) cubit.cmd(cmd) cubit.cmd('Block ' + str(b) + ' name "face_abs_ymax"') b = b + 1 for i in side_zmin: cmd = 'block ' + str(b) + ' face in surface ' + str(i) cubit.cmd(cmd) cubit.cmd('Block ' + str(b) + ' name "face_abs_bottom"') b = b + 1 cubit.cmd('Block ' + str(b) + ' face in surface ' + str(s[0])) cubit.cmd('Block ' + str(b) + ' name "face_topo"') print '##total number of hex: ', cubit.get_hex_count(), ' ##' os.system('mkdir -p MESH') #### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT cubit2specfem3d.export2SESAME('MESH')
import cubit, os, sys cubit.init(['']) cubit.cmd("reset") cubit.cmd("playback 'Mandel3D_msh.jou'") cubit.cmd("reset") cubit.cmd( "import mesh geometry './Mandel3D.exo' block all use nodeset sideset") surf_list = cubit.get_sideset_surfaces(1) quad_list = [ cubit.get_surface_quads(surf_list[i]) for i in range(len(surf_list)) ] vol_list = cubit.get_block_volumes(1) hex_list = [cubit.get_volume_hexes(vol_list[i]) for i in range(len(vol_list))] trac_el = [] mat_typ = np.ones(shape=(cubit.get_hex_count(), 1), dtype=np.uint8) for quadset, hexset in zip(quad_list, hex_list): for quad in quadset: nodes = cubit.get_connectivity("quad", quad) for hx in hexset: nodes_hx = cubit.get_connectivity("hex", hx) if set(nodes).issubset(set(nodes_hx)): if set(nodes).issubset(set(np.array(nodes_hx)[[0, 1, 5, 4]])): side = 1 elif set(nodes).issubset(set(np.array(nodes_hx)[[1, 2, 6, 6]])): side = 2 elif set(nodes).issubset(set(np.array(nodes_hx)[[2, 3, 7, 7]])): side = 3 elif set(nodes).issubset(set(np.array(nodes_hx)[[3, 2, 6,