def material_write(self,mat_name): mat=open(mat_name,'w') print 'Writing '+mat_name+'.....' for block,flag in zip(self.block_mat,self.block_flag): hexes=cubit.get_block_hexes(block) for hexa in hexes: mat.write(('%10i %10i\n') % (hexa,flag)) mat.close()
def material_write(self, mat_name): mat = open(mat_name, "w") print "Writing " + mat_name + "....." for block, flag in zip(self.block_mat, self.block_flag): hexes = cubit.get_block_hexes(block) for hexa in hexes: mat.write(("%10i %10i\n") % (hexa, flag)) mat.close() print "Ok"
def material_write(self, mat_name): mat = open(mat_name, 'w') print 'Writing ' + mat_name + '.....' for block, flag in zip(self.block_mat, self.block_flag): hexes = cubit.get_block_hexes(block) for hexa in hexes: mat.write(('%10i %10i\n') % (hexa, flag)) mat.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 ' 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 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 getstats(self): ''' Get statistics for differend blocks in the hexmesh ''' ############################## READ BLOCKS ###################### try: blocks=cubit.get_block_id_list() except: print('no blocks defined') nblocks=len(blocks) print('Found ',nblocks,' Blocks') # lists of details of all elastic blocks. For each elastic block, append respective values name=[] typ=[] nattrib=[] vp=[] vs=[] rho=[] minEdge=[] maxEdge=[] minEdgeMesh = [] maxEdgeMesh = [] # k: counter of all elastic blocks k=0 for block in blocks: minEdgeMeshTmp = [] maxEdgeMeshTmp = [] blockname=cubit.get_exodus_entity_name('block',block) # only apply stats to elastic blocks if blockname.find("elastic") >= 0: # NOW APPEND VALUES OF THIS ELASTIC BLOCK TO LISTS (defined as empty above) name.append(blockname) typ.append(cubit.get_block_element_type(block)) # attribute count nattrib.append(cubit.get_block_attribute_count(block)) # vp vp.append(cubit.get_block_attribute_value(block,1)) # vs vs.append(cubit.get_block_attribute_value(block,2)) # rho rho.append(cubit.get_block_attribute_value(block,3)) hexes=cubit.get_block_hexes(block) print(block, k,'name: ',name[k],'#hexes:',len(hexes),'type: ',typ[k],'attribute count: ',nattrib[k],'vp: ',vp[k],'vs: ',vs[k],'rho: ',rho[k]) # minimum/maximum edgelength search for this elastic block # initiate with very large minEdge and very small maxEdge minEdge.append(1e9) maxEdge.append(1e-9) # now search for hexa in hexes: nodes=cubit.get_connectivity('Hex',hexa) # get coordinates of nodes of this hexahedron node_coords=[] for node in nodes: node_coords.append(cubit.get_nodal_coordinates(node)) minv=self.minEdgeHex(node_coords) minEdgeMeshTmp.append(minv) maxv=self.maxEdgeHex(node_coords) maxEdgeMeshTmp.append(maxv) # is minimum edgelength of this this element smaller than minimum edgelength found before? if minv < minEdge[k]: minEdge[k]=minv # is maximum edgelength of this this element larger than maximum edgelength found before? if maxv > maxEdge[k]: maxEdge[k]=maxv minEdgeMesh.append(minEdgeMeshTmp) maxEdgeMesh.append(maxEdgeMeshTmp) # end of processing of this elastic block. incremet counter k=k+1 # if not "elastic" in this blockname else: print(blockname, '--no elastic') # now calculate maximum frequency for which the mesh is stable # and maximal dt # first do that for each block fmax=[] dtmax_05=[] for i in range(len(name)): fmax.append(self.calcMaxFreq(maxEdge[i],vs[i])) dtmax_05.append(self.calcMaxDt(minEdge[i],vp[i],cn=0.5)) min_dx = minEdge[i]*0.1727 max_dx = maxEdge[i]*0.3272*sqrt(3.) print('Block ', name[i], ' min dx: ',min_dx, ' max dx: ',max_dx, 'max frequency: ',fmax[i], ' maximal dt (C=0.5):',dtmax_05[i]) vals,bin_edges = histogram(minEdgeMesh[i],10) nhexa = sum(vals) print(' '+str(nhexa)+' HEXAS IN THIS BLOCK') print(' histogram of minimum edge length of hexa of this block:') for j,val in enumerate(vals): print(' %6.3f %% of hexas have minimum edgelength between %3.3f and %3.3f -> dt (C=0.5) is %8.3e'%(100.*val/float(nhexa),bin_edges[j],bin_edges[j+1],self.calcMaxDt(bin_edges[j],vp[i],cn=0.5))) vals,bin_edges = histogram(maxEdgeMesh[i],10) nhexa = sum(vals) print(' '+str(nhexa)+' HEXAS IN THIS BLOCK') print(' histogram of maximum edge length of hexa of this block:') for j,val in enumerate(vals): print(' %6.3f %% of hexas have maximum edgelength between %3.3f and %3.3f -> fmax (5 GLL points per wavelength) is %8.3e'%(100.*val/float(nhexa),bin_edges[j],bin_edges[j+1],self.calcMaxFreq(bin_edges[j+1],vs[i]))) # now compare the values for all the blocks dtm_05=sorted(dtmax_05) print('The minimum over all blocks of the respective maximal dt for C=0.5 is: ',dtm_05[0]) fmax_min=sorted(fmax) print('The minimum over all blocks of the respective maximal frequency is: ',fmax_min[0])
def getstats(self): ''' Get statistics for differend blocks in the hexmesh ''' ############################## READ BLOCKS ###################### try: blocks = cubit.get_block_id_list() except: print('no blocks defined') nblocks = len(blocks) print('Found ', nblocks, ' Blocks') # lists of details of all elastic blocks. For each elastic block, append respective values name = [] typ = [] nattrib = [] vp = [] vs = [] rho = [] minEdge = [] maxEdge = [] minEdgeMesh = [] maxEdgeMesh = [] # k: counter of all elastic blocks k = 0 for block in blocks: minEdgeMeshTmp = [] maxEdgeMeshTmp = [] blockname = cubit.get_exodus_entity_name('block', block) # only apply stats to elastic blocks if blockname.find("elastic") >= 0: # NOW APPEND VALUES OF THIS ELASTIC BLOCK TO LISTS (defined as empty above) name.append(blockname) typ.append(cubit.get_block_element_type(block)) # attribute count nattrib.append(cubit.get_block_attribute_count(block)) # vp vp.append(cubit.get_block_attribute_value(block, 1)) # vs vs.append(cubit.get_block_attribute_value(block, 2)) # rho rho.append(cubit.get_block_attribute_value(block, 3)) hexes = cubit.get_block_hexes(block) print(block, k, 'name: ', name[k], '#hexes:', len(hexes), 'type: ', typ[k], 'attribute count: ', nattrib[k], 'vp: ', vp[k], 'vs: ', vs[k], 'rho: ', rho[k]) # minimum/maximum edgelength search for this elastic block # initiate with very large minEdge and very small maxEdge minEdge.append(1e9) maxEdge.append(1e-9) # now search for hexa in hexes: nodes = cubit.get_connectivity('Hex', hexa) # get coordinates of nodes of this hexahedron node_coords = [] for node in nodes: node_coords.append(cubit.get_nodal_coordinates(node)) minv = self.minEdgeHex(node_coords) minEdgeMeshTmp.append(minv) maxv = self.maxEdgeHex(node_coords) maxEdgeMeshTmp.append(maxv) # is minimum edgelength of this this element smaller than minimum edgelength found before? if minv < minEdge[k]: minEdge[k] = minv # is maximum edgelength of this this element larger than maximum edgelength found before? if maxv > maxEdge[k]: maxEdge[k] = maxv minEdgeMesh.append(minEdgeMeshTmp) maxEdgeMesh.append(maxEdgeMeshTmp) # end of processing of this elastic block. incremet counter k = k + 1 # if not "elastic" in this blockname else: print(blockname, '--no elastic') # now calculate maximum frequency for which the mesh is stable # and maximal dt # first do that for each block fmax = [] dtmax_05 = [] for i in range(len(name)): fmax.append(self.calcMaxFreq(maxEdge[i], vs[i])) dtmax_05.append(self.calcMaxDt(minEdge[i], vp[i], cn=0.5)) min_dx = minEdge[i] * 0.1727 max_dx = maxEdge[i] * 0.3272 * sqrt(3.) print('Block ', name[i], ' min dx: ', min_dx, ' max dx: ', max_dx, 'max frequency: ', fmax[i], ' maximal dt (C=0.5):', dtmax_05[i]) vals, bin_edges = histogram(minEdgeMesh[i], 10) nhexa = sum(vals) print(' ' + str(nhexa) + ' HEXAS IN THIS BLOCK') print(' histogram of minimum edge length of hexa of this block:') for j, val in enumerate(vals): print( ' %6.3f %% of hexas have minimum edgelength between %3.3f and %3.3f -> dt (C=0.5) is %8.3e' % (100. * val / float(nhexa), bin_edges[j], bin_edges[j + 1], self.calcMaxDt(bin_edges[j], vp[i], cn=0.5))) vals, bin_edges = histogram(maxEdgeMesh[i], 10) nhexa = sum(vals) print(' ' + str(nhexa) + ' HEXAS IN THIS BLOCK') print(' histogram of maximum edge length of hexa of this block:') for j, val in enumerate(vals): print( ' %6.3f %% of hexas have maximum edgelength between %3.3f and %3.3f -> fmax (5 GLL points per wavelength) is %8.3e' % (100. * val / float(nhexa), bin_edges[j], bin_edges[j + 1], self.calcMaxFreq(bin_edges[j + 1], vs[i]))) # now compare the values for all the blocks dtm_05 = sorted(dtmax_05) print( 'The minimum over all blocks of the respective maximal dt for C=0.5 is: ', dtm_05[0]) fmax_min = sorted(fmax) print( 'The minimum over all blocks of the respective maximal frequency is: ', fmax_min[0])