def get_uv_curve(list_curve_or): import math import numpy as np klen={} for curve in list_curve_or: vertex_list = cubit.get_relatives("curve", curve, "vertex") coord0=cubit.get_center_point('vertex', vertex_list[0]) coord1=cubit.get_center_point('vertex', vertex_list[1]) klen[curve]=np.array(coord1)-np.array(coord0) # l0=list_curve_or[0] c0=klen[l0] angles={} angles[l0]=0 for curve in list_curve_or[1:]: c1=klen[curve] angletmp=np.dot(c0,c1)/(np.dot(c0,c0)**.5*np.dot(c1,c1)**.5) if -1 < angletmp < 1: angle=math.sin(np.arccos(angletmp)) else: angle=0. angles[curve]=angle a=angles.values() diff=max(a)-min(a) ucurve=[] vcurve=[] for curve in list_curve_or: if -diff < angles[curve] < diff: ucurve.append(curve) else: vcurve.append(curve) # return ucurve,vcurve
def ordering_surfaces(list_surfaces): list_z=[] for s in list_surfaces: _,_,z=cubit.get_center_point("surface",s) list_z.append(z) ord_list_surfaces=[s for s,z in sorted(zip(list_surfaces,list_z),key=lambda x: (x[1]))] return ord_list_surfaces
def select_bottom_curve(lc): z = [] for l in lc: center_point = cubit.get_center_point("curve", l) z.append(center_point[2]) result = zip(z, lc) result.sort() return result[0][1]
def select_bottom_curve(lc): z=[] for l in lc: center_point = cubit.get_center_point("curve", l) z.append(center_point[2]) result=zip(z,lc) result.sort() return result[0][1]
def select_bottom_curve(lc): z=[] for l in lc: center_point = cubit.get_center_point("curve", l) z.append(center_point[2]) result=zip(z,lc) # takes line number from first entry curve=0 if len(result) > 0: result.sort() curve=result[0][1] return curve
def define_4side_lateral_surfaces(tres=0.0003, tol=0.000001): list_vol = cubit.parse_cubit_list("volume", "all") surf_xmin = [] surf_ymin = [] surf_xmax = [] surf_ymax = [] # min/max of bounding box xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] zmin_box = cubit.get_total_bounding_box("volume", list_vol)[6] zmax_box = cubit.get_total_bounding_box("volume", list_vol)[7] #print('absorbing boundary xmin:' + str(xmin_box) + ' xmax: ' + str(xmax_box)) #print('absorbing boundary ymin:' + str(ymin_box) + ' ymax: ' + str(ymax_box)) #print('absorbing boundary zmin:' + str(zmin_box) + ' zmax: ' + str(zmax_box)) for id_vol in list_vol: surf_vertical = [] xsurf = [] ysurf = [] lsurf = cubit.get_relatives("volume", id_vol, "surface") for k in lsurf: normal = cubit.get_surface_normal(k) # checks if normal is horizontal (almost 0, i.e., +/- tres) if normal[2] >= -1 * tres and normal[2] <= tres: # checks if surface is on minimum/maximum side of the whole model center_point = cubit.get_center_point("surface", k) # note: for models with smaller volumes inscribed, we want only the outermost surfaces # as absorbing ones #sbox = cubit.get_bounding_box('surface', k) # xmin of surface box relative to total box xmin if (abs(center_point[0] - xmin_box) / abs(xmax_box - xmin_box) <= tol) or \ (abs(center_point[0] - xmax_box) / abs(xmax_box - xmin_box) <= tol) or \ (abs(center_point[1] - ymin_box) / abs(ymax_box - ymin_box) <= tol) or \ (abs(center_point[1] - ymax_box) / abs(ymax_box - ymin_box) <= tol): # adds as vertical surface surf_vertical.append(k) xsurf.append(center_point[0]) ysurf.append(center_point[1]) # adds surfaces when on boundary if len(surf_vertical) > 0: surf_xmin.append(surf_vertical[xsurf.index(min(xsurf))]) surf_ymin.append(surf_vertical[ysurf.index(min(ysurf))]) surf_xmax.append(surf_vertical[xsurf.index(max(xsurf))]) surf_ymax.append(surf_vertical[ysurf.index(max(ysurf))]) #debug #print('define_4side_lateral_surfaces: xmin ',surf_xmin) #print('define_4side_lateral_surfaces: xmax ',surf_xmax) #print('define_4side_lateral_surfaces: ymin ',surf_ymin) #print('define_4side_lateral_surfaces: ymax ',surf_ymax) return surf_xmin, surf_ymin, surf_xmax, surf_ymax
def select_bottom_curve(lc): z = [] for l in lc: center_point = cubit.get_center_point("curve", l) z.append(center_point[2]) result = zip(z, lc) # takes line number from first entry curve = 0 if len(result) > 0: result.sort() curve = result[0][1] return curve
def define_4side_lateral_surfaces(): list_vol=cubit.parse_cubit_list("volume","all") surf_xmin=[] surf_ymin=[] surf_xmax=[] surf_ymax=[] for id_vol in list_vol: surf_vertical=[] xsurf=[] ysurf=[] tres=0.3 lsurf=cubit.get_relatives("volume",id_vol,"surface") for k in lsurf: normal=cubit.get_surface_normal(k) center_point = cubit.get_center_point("surface", k) if normal[2] >= -1*tres and normal[2] <= tres: surf_vertical.append(k) xsurf.append(center_point[0]) ysurf.append(center_point[1]) surf_xmin.append(surf_vertical[xsurf.index(min(xsurf))]) surf_ymin.append(surf_vertical[ysurf.index(min(ysurf))]) surf_xmax.append(surf_vertical[xsurf.index(max(xsurf))]) surf_ymax.append(surf_vertical[ysurf.index(max(ysurf))]) return surf_xmin,surf_ymin,surf_xmax,surf_ymax
def define_4side_lateral_surfaces(): list_vol = cubit.parse_cubit_list("volume", "all") surf_xmin = [] surf_ymin = [] surf_xmax = [] surf_ymax = [] for id_vol in list_vol: surf_vertical = [] xsurf = [] ysurf = [] tres = 0.3 lsurf = cubit.get_relatives("volume", id_vol, "surface") for k in lsurf: normal = cubit.get_surface_normal(k) center_point = cubit.get_center_point("surface", k) if normal[2] >= -1 * tres and normal[2] <= tres: surf_vertical.append(k) xsurf.append(center_point[0]) ysurf.append(center_point[1]) surf_xmin.append(surf_vertical[xsurf.index(min(xsurf))]) surf_ymin.append(surf_vertical[ysurf.index(min(ysurf))]) surf_xmax.append(surf_vertical[xsurf.index(max(xsurf))]) surf_ymax.append(surf_vertical[ysurf.index(max(ysurf))]) return surf_xmin, surf_ymin, surf_xmax, surf_ymax
def hor_distance(c1,c2): p1=cubit.get_center_point("curve", c1) p2=cubit.get_center_point("curve", c2) d=(p1[0]-p2[0])**2+(p1[1]-p2[1])**2 return d
def define_top_bottom_absorbing_surf(zmin_box,zmax_box): """ absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin """ try: cubit.cmd('comment') except: try: import cubit cubit.init([""]) except: print 'error importing cubit' import sys sys.exit() absorbing_surf_bottom=[] top_surf = [] list_vol=cubit.parse_cubit_list("volume","all") init_n_vol=len(list_vol) # TO DO : Make zmin_box work properly. # zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7] # zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0] xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1] ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3] ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4] list_surf=cubit.parse_cubit_list("surface","all") print '##boundary box: ' print '## x min: ' + str(xmin_box) print '## y min: ' + str(ymin_box) print '## z min: ' + str(zmin_box) print '## x max: ' + str(xmax_box) print '## y max: ' + str(ymax_box) print '## z max: ' + str(zmax_box) #box lengths x_len = abs( xmax_box - xmin_box) y_len = abs( ymax_box - ymin_box) z_len = abs( zmax_box - zmin_box) print '##boundary box: ' print '## x length: ' + str(x_len) print '## y length: ' + str(y_len) print '## z length: ' + str(z_len) # tolerance parameters absorbing_surface_distance_tolerance=0.005 topographic_surface_distance_tolerance=0.001 topographic_surface_normal_tolerance=0.2 for k in list_surf: center_point = cubit.get_center_point("surface", k) if abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance: print 'center_point[2]' + str(center_point[2]) print 'kz:' + str(k) absorbing_surf_bottom.append(k) else: sbox=cubit.get_bounding_box('surface',k) dz=abs((sbox[7] - zmax_box)/z_len) normal=cubit.get_surface_normal(k) zn=normal[2] dn=abs(zn-1) if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance: top_surf.append(k) return absorbing_surf_bottom,top_surf
def layercake_volume_fromacis_mpiregularmap(filename=None): import sys import start as start # mpiflag,iproc,numproc,mpi = start.start_mpi() # cfg = start.start_cfg(filename=filename) # from utilities import geo2utm, savegeometry # from math import sqrt # try: mpi.barrier() except: pass # # command = "comment '"+"PROC: "+str(iproc)+"/"+str(numproc)+" '" cubit.cmd(command) # #get the limit of the volume considering the cpu def xwebcut(x): command='create planar surface with plane xplane offset '+str(x) cubit.cmd(command) last_surface=cubit.get_last_id("surface") command="webcut volume all tool volume in surf "+str(last_surface) cubit.cmd(command) command="del surf "+str(last_surface) cubit.cmd(command) def ywebcut(x): command='create planar surface with plane yplane offset '+str(x) cubit.cmd(command) last_surface=cubit.get_last_id("surface") command="webcut volume all tool volume in surf "+str(last_surface) cubit.cmd(command) command="del surf "+str(last_surface) cubit.cmd(command) def translate2zero(): ss=cubit.parse_cubit_list('surface','all') box = cubit.get_total_bounding_box("surface", ss) xmin=box[0] ymin=box[3] cubit.cmd('move surface all x '+str(-1*xmin)+' y '+str(-1*ymin)) return xmin,ymin def translate2original(xmin,ymin): cubit.cmd('move surface all x '+str(xmin)+' y '+str(ymin)) if mpiflag: icpux = iproc % cfg.nproc_xi icpuy = int(iproc / cfg.nproc_xi) else: icpuy=int(cfg.id_proc/cfg.nproc_xi) icpux=cfg.id_proc%cfg.nproc_xi # ner=cubit.get_error_count() # icurve=0 isurf=0 ivertex=0 # xlength=(cfg.xmax-cfg.xmin)/float(cfg.cpux) #length of x slide for chunk ylength=(cfg.ymax-cfg.ymin)/float(cfg.cpuy) #length of y slide for chunk xmin_cpu=cfg.xmin+(xlength*(icpux)) ymin_cpu=cfg.ymin+(ylength*(icpuy)) xmax_cpu=xmin_cpu+xlength ymax_cpu=ymin_cpu+ylength # #importing the surfaces for inz in range(cfg.nz-2,-2,-1): if cfg.bottomflat and inz==-1: command = "create planar surface with plane zplane offset "+str(cfg.depth_bottom) cubit.cmd(command) else: command = "import cubit '"+cfg.filename[inz]+"'" cubit.cmd(command) #translate xmin,ymin=translate2zero() print 'translate ...', -xmin,-ymin xmin_cpu=xmin_cpu-xmin ymin_cpu=ymin_cpu-ymin xmax_cpu=xmax_cpu-xmin ymax_cpu=ymax_cpu-ymin ss=cubit.parse_cubit_list('surface','all') box = cubit.get_total_bounding_box("surface", ss) print 'dimension... ', box #cutting the surfaces xwebcut(xmin_cpu) xwebcut(xmax_cpu) ywebcut(ymin_cpu) ywebcut(ymax_cpu) # list_surface_all=cubit.parse_cubit_list("surface","all") #condisidering only the surfaces inside the boundaries dict_surf={} for isurf in list_surface_all: p=cubit.get_center_point("surface",isurf) if p[0] < xmin_cpu or p[0] > xmax_cpu or p[1] > ymax_cpu or p[1] < ymin_cpu: command = "del surf "+str(isurf) cubit.cmd(command) else: dict_surf[str(isurf)]=p[2] z=dict_surf.values() z.sort() list_surf=[] for val in z: isurf=[k for k, v in dict_surf.iteritems() if v == val][0] list_surf.append(int(isurf)) # #lofting the volume for i,j in zip(list_surf,list_surf[1:]): ner=cubit.get_error_count() create_volume(i,j,method=cfg.volumecreation_method) #cubitcommand= 'create volume loft surface '+ str(i)+' '+str(j) #cubit.cmd(cubitcommand) ner2=cubit.get_error_count() # translate2original(xmin,ymin) if ner == ner2: cubitcommand= 'del surface all' cubit.cmd(cubitcommand) # # #cubitcommand= 'composite create curve in vol all' #cubit.cmd(cubitcommand) list_vol=cubit.parse_cubit_list("volume","all") if len(list_vol) > 1: cubitcommand= 'imprint volume all' cubit.cmd(cubitcommand) #cubit_error_stop(iproc,cubitcommand,ner) # cubitcommand= 'merge all' cubit.cmd(cubitcommand) # savegeometry(iproc,filename=filename)
def saveMesh3D(self): cubit.cmd("brick x 5000 y 5000 z 5000") cubit.cmd("create cylinder height 4000 radius 500") cubit.cmd("subtract body 2 from body 1") volID = cubit.get_last_id("volume") self.vol = volID self.mesh() nNodes = cubit.get_node_count() meshFile = open(folder+"mesh3D2.xml", 'w') meshFile.write('<mesh celltype="tetrahedron" dim="3">\n') meshFile.write(' <nodes size="%d">\n' % (nNodes)) for x in range(0, nNodes): coords = cubit.get_nodal_coordinates(x+1) meshFile.write(' <node id="%d" x="%f" y="%f" z="%f"/>\n' % (x,coords[0],coords[1],coords[2])) meshFile.write(' </nodes>\n') nTets = cubit.get_tet_count() meshFile.write(' <elements size="%d">\n' % (nTets)) for x in range(0, nTets): nodes = cubit.get_connectivity("tet", x+1) meshFile.write(' <element id="%d" v0="%d" v1="%d" v2="%d" v3="%d"/>\n' % (x,nodes[0]-1,nodes[1]-1,nodes[2]-1,nodes[3]-1)) meshFile.write(' </elements>\n') meshFile.write(' <element_data type="fiber_transversely_isotropic">\n') for x in range(0, nTets): meshFile.write(' <element id="%d">\n' %(x)) meshFile.write(' <fiber>1.000000,0.000000,0.000000</fiber>\n') meshFile.write(' </element>\n') meshFile.write(' </element_data>\n') meshFile.write(' <boundary celltype="triangle" dim="2">\n') bsurfs = [10, 11, 12] ec = 0 for x in range(0, len(bsurfs)): tris = cubit.get_surface_tris(bsurfs[x]) surf = cubit.surface(bsurfs[x]) for y in range(0, len(tris)): cp = cubit.get_center_point("tri", tris[y]) norm = surf.normal_at([cp[0],cp[1],cp[2]]) #cubit.cmd("create curve location %f %f %f direction %f %f %f length %f" % (cp[0],cp[1],cp[2],norm[0],norm[1],norm[2],200)) nodes = cubit.get_connectivity("tri", tris[y]) element = [nodes[0]-1, nodes[1]-1, nodes[2]-1] meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d" nx="%f" ny="%f" nz="%f"/>\n' % (ec,1.0,element[0],element[1],element[2],norm[0],norm[1],norm[2])) ec = ec+1 meshFile.write(' </boundary>\n') meshFile.write('</mesh>\n') meshFile.write('<poisson>\n') meshFile.write(' <neumann>\n') meshFile.write(' <node id="1" marker="1" value="0.5" />\n') meshFile.write(' </neumann>\n') meshFile.write('</poisson>\n') #meshFile.write('<electrophysiology>\n') #meshFile.write(' <stimuli number="1">\n') #bb = cubit.get_bounding_box("volume", self.vol) #x0 = bb[0] #x1 = 0.8*x0 + 0.2*bb[1] #y0 = bb[3] #y1 = 0.8*y0 + 0.2*bb[4] #z0 = bb[6] #z1 = 0.8*z0 + 0.2*bb[7] #meshFile.write(' <stim start="0.00" duration="4.00" value="-35.7140" x0="%f" x1="%f" y0="%f" y1="%f" z0="%f" z1="%f" />\n' % (x0,x1,y0,y1,z0,z1)) #meshFile.write(' </stimuli>\n') #meshFile.write('</electrophysiology>\n') meshFile.close()
def saveMesh(self): nNodes = cubit.get_node_count() nTets = cubit.get_tet_count() meshFile = open(folder+"Cubo.xml", 'w') meshFile.write('<mesh celltype="tetrahedron" dim="3">\n') meshFile.write(' <nodes size="%d">\n' % (nNodes)) for x in range(0, nNodes): coords = cubit.get_nodal_coordinates(x+1) meshFile.write(' <node id="%d" x="%f" y="%f" z="%f"/>\n' % (x,coords[0],coords[1],coords[2])) meshFile.write(' </nodes>\n') meshFile.write(' <elements size="%d">\n' % (nTets)) for x in range(0, nTets): nodes = cubit.get_connectivity("tet", x+1) meshFile.write(' <element id="%d" v0="%d" v1="%d" v2="%d" v3="%d"/>\n' % (x,nodes[0]-1,nodes[1]-1,nodes[2]-1,nodes[3]-1)) meshFile.write(' </elements>\n') meshFile.write(' <element_data type="fiber_transversely_isotropic">\n') for x in range(0, nTets): meshFile.write(' <element id="%d">\n' %(x)) meshFile.write(' <fiber>1.000000,0.000000,0.000000</fiber>\n') meshFile.write(' </element>\n') meshFile.write(' </element_data>\n') meshFile.write(' <boundary celltype="triangle" dim="2">\n') bsurfs = cubit.get_relatives("volume", self.vol, "surface") ec = 0 for x in range(0, len(bsurfs)): #for x in range(6, len(bsurfs)): #if x is not 16 and x is not 14: tris = cubit.get_surface_tris(bsurfs[x]) surf = cubit.surface(bsurfs[x]) for y in range(0, len(tris)): cp = cubit.get_center_point("tri", tris[y]) norm = surf.normal_at([cp[0],cp[1],cp[2]]) #cubit.cmd("create curve location %f %f %f direction %f %f %f length %f" % (cp[0],cp[1],cp[2],norm[0],norm[1],norm[2],200)) nodes = cubit.get_connectivity("tri", tris[y]) element = [nodes[0]-1, nodes[1]-1, nodes[2]-1] meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d" nx="%f" ny="%f" nz="%f"/>\n' % (ec,1.0,element[0],element[1],element[2],norm[0],norm[1],norm[2])) ec = ec+1 meshFile.write(' </boundary>\n') #meshFile.write(' <boundary celltype="triangle" dim="2">\n') #surfs = cubit.get_relatives("volume", self.vol, "surface") #ec = 0 #for x in range(0, 2): # tris = cubit.get_surface_tris(surfs[x]) # for y in range(0, len(tris)): # nodes = cubit.get_connectivity("tri", tris[y]) # element = [nodes[0]-1, nodes[1]-1, nodes[2]-1] # ec = ec+1 # meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec,x,element[0],element[1],element[2])) #meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec+1,2,element[0],element[1],element[2])) #meshFile.write(' </boundary>\n') meshFile.write('</mesh>\n') meshFile.write('<poisson>\n') meshFile.write(' <neumann>\n') #meshFile.write(' <node id="0" marker="0" value="-1.0" />\n') meshFile.write(' <node id="1" marker="1" value="0.05"/>\n') meshFile.write(' </neumann>\n') #meshFile.write(' <dirichlet>\n') #meshFile.write(' <node id="2" marker="2" value="0.0" />\n') #meshFile.write(' </dirichlet>\n') meshFile.write('</poisson>\n') #meshFile.write('<electrophysiology>\n') #meshFile.write(' <stimuli number="1">\n') #bb = cubit.get_bounding_box("volume", self.vol) #x0 = bb[0] #x1 = 0.8*x0 + 0.2*bb[1] #y0 = bb[3] #y1 = 0.8*y0 + 0.2*bb[4] #z0 = bb[6] #z1 = 0.8*z0 + 0.2*bb[7] #meshFile.write(' <stim start="0.00" duration="4.00" value="-35.7140" x0="%f" x1="%f" y0="%f" y1="%f" z0="%f" z1="%f" />\n' % (x0,x1,y0,y1,z0,z1)) #meshFile.write(' </stimuli>\n') #meshFile.write('</electrophysiology>\n') meshFile.close()
print "Convert mesh to Specfem-format..." os.system('mkdir -p MESH') ## fault surfaces (up/down) Au = [cubit.get_id_from_name("fault1")] Ad = [cubit.get_id_from_name("fault2")] ### Obtain the id of boundaries # I define the original sphere surface as spheresurf. After webcut, CUBIT renames the new-cutted surface by adding @A, @B ... SpheresurfID = [cubit.get_id_from_name("spheresurf@A")] # Find the surface ID for the free surface freesur_tolerance = 3e3 FreesurfID = [] list_surf = cubit.parse_cubit_list("surface", "all") for k in list_surf: center_point = cubit.get_center_point("surface", k) if abs(center_point[2]) <= freesur_tolerance: FreesurfID.append(k) print SpheresurfID, FreesurfID # define blocks Vol_num = cubit.get_volume_count() for i in range(Vol_num): cubit.cmd('block {0} hex in vol {0}'.format(i + 1)) cubit.cmd('block 1000 face in surface ' + str(list(SpheresurfID)).replace("[", " ").replace("]", " ")) cubit.cmd('block 1000 name "face_semisphere"') cubit.cmd('block 1001 face in surface ' + str(list(FreesurfID)).replace("[", " ").replace("]", " ")) cubit.cmd('block 1001 name "face_topo"')
def define_top_bottom_absorbing_surf(zmin_box, zmax_box): """ absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin """ try: cubit.cmd('comment') except: try: import cubit cubit.init([""]) except: print('error importing cubit') import sys sys.exit() absorbing_surf_bottom = [] top_surf = [] list_vol = cubit.parse_cubit_list("volume", "all") init_n_vol = len(list_vol) # TO DO : Make zmin_box work properly. # zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7] # zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] list_surf = cubit.parse_cubit_list("surface", "all") print('##boundary box: ') print('## x min: ' + str(xmin_box)) print('## y min: ' + str(ymin_box)) print('## z min: ' + str(zmin_box)) print('## x max: ' + str(xmax_box)) print('## y max: ' + str(ymax_box)) print('## z max: ' + str(zmax_box)) #box lengths x_len = abs(xmax_box - xmin_box) y_len = abs(ymax_box - ymin_box) z_len = abs(zmax_box - zmin_box) print('##boundary box: ') print('## x length: ' + str(x_len)) print('## y length: ' + str(y_len)) print('## z length: ' + str(z_len)) # tolerance parameters absorbing_surface_distance_tolerance = 0.005 topographic_surface_distance_tolerance = 0.001 topographic_surface_normal_tolerance = 0.2 for k in list_surf: center_point = cubit.get_center_point("surface", k) if abs((center_point[2] - zmin_box) / z_len) <= absorbing_surface_distance_tolerance: print('center_point[2] ' + str(center_point[2])) print('kz: ' + str(k)) absorbing_surf_bottom.append(k) else: sbox = cubit.get_bounding_box('surface', k) dz = abs((sbox[7] - zmax_box) / z_len) normal = cubit.get_surface_normal(k) zn = normal[2] dn = abs(zn - 1) if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance: top_surf.append(k) return absorbing_surf_bottom, top_surf
def mesh_layercake_regularmap(filename=None): import sys,os import start as start mpiflag,iproc,numproc,mpi = start.start_mpi() from utilities import importgeometry,savemesh,get_v_h_list,cubit_command_check # numpy = start.start_numpy() cfg = start.start_cfg(filename=filename) from math import sqrt from sets import Set # class cubitvolume: def __init__(self,ID,intervalv,centerpoint,dimension): self.ID=ID self.intervalv=intervalv self.centerpoint=centerpoint self.dim=dimension def __repr__(self): msg="(vol:%3i, vertical interval: %4i, centerpoint: %8.2f)" % (self.ID, self.intervalv,self.centerpoint) return msg # def by_z(x,y): return cmp(x.centerpoint,y.centerpoint) # # # list_vol=cubit.parse_cubit_list("volume","all") if len(list_vol) != 0: pass else: geometryfile='geometry_vol_'+str(iproc)+'.cub' importgeometry(geometryfile,iproc=iproc) # command = 'composite create curve all' cubit.cmd(command) print '###"No valid composites can be created from the specified curves." is NOT a critical ERROR.' # command = "compress all" cubit.cmd(command) list_vol=cubit.parse_cubit_list("volume","all") nvol=len(list_vol) vol=[] for id_vol in list_vol: p=cubit.get_center_point("volume",id_vol) vol.append(cubitvolume(id_vol,1,p[2],0)) vol.sort(by_z) # for id_vol in range(0,nvol): vol[id_vol].intervalv=cfg.iv_interval[id_vol] # # surf_vertical=[] surf_or=[] top_surface=0 top_surface_add='' bottom_surface=0 # zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0] xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1] ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3] ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4] # # #interval assignement surf_or,surf_vertical,list_curve_or,list_curve_vertical,bottom,top = get_v_h_list(list_vol,chktop=cfg.chktop) print 'vertical surfaces: ',surf_vertical for k in surf_vertical: command = "surface "+str(k)+" scheme submap" cubit.cmd(command) for k in surf_or: command = "surface "+str(k)+" scheme "+cfg.or_mesh_scheme cubit.cmd(command) # ucurve,vcurve=get_uv_curve(list_curve_or) schemepave=False # ucurve_interval={} for k in ucurve: length=cubit.get_curve_length(k) interval=int(2*round(.5*length/cfg.size,0)) ucurve_interval[k]=interval command = "curve "+str(k)+" interval "+str(interval) cubit.cmd(command) #cubit_error_stop(iproc,command,ner) command = "curve "+str(k)+" scheme equal" cubit.cmd(command) #cubit_error_stop(iproc,command,ner) if max(ucurve_interval.values()) != min(ucurve_interval.values()): schemepave=True print 'mesh scheme is set to pave' for sk in surf_or: command = "surface "+str(sk)+" scheme pave" cubit.cmd(command) # vcurve_interval={} for k in vcurve: length=cubit.get_curve_length(k) interval=int(2*round(.5*length/cfg.size,0)) vcurve_interval[k]=interval command = "curve "+str(k)+" interval "+str(interval) cubit.cmd(command) #cubit_error_stop(iproc,command,ner) command = "curve "+str(k)+" scheme equal" cubit.cmd(command) #cubit_error_stop(iproc,command,ner) if max(vcurve_interval.values()) != min(vcurve_interval.values()): print 'mesh scheme is set to pave' schemepave=True for sk in surf_or: command = "surface "+str(sk)+" scheme pave" cubit.cmd(command) # for s in surf_vertical: lcurve=cubit.get_relatives("surface",s,"curve") interval_store=[] for k in lcurve: interval_curve=cubit.get_mesh_intervals('curve',k) if k in list_curve_vertical: volume_id = cubit.get_owning_volume("curve", k) for idv in range(0,nvol): if vol[idv].ID == volume_id: int_v=vol[idv].intervalv command = "curve "+str(k)+" interval "+str(int_v) cubit.cmd(command) #cubit_error_stop(iproc,command,ner) command = "curve "+str(k)+" scheme equal" cubit.cmd(command) #cubit_error_stop(iproc,command,ner) else: interval_store.append((k,interval_curve)) if len(interval_store) != 0: interval_min=min([iv[1] for iv in interval_store]) command = "curve "+' '.join(str(iv[0]) for iv in interval_store)+" interval "+str(interval_min) cubit.cmd(command) #cubit_error_stop(iproc,command,ner) command = "curve "+' '.join(str(iv[0]) for iv in interval_store)+" scheme equal" cubit.cmd(command) #cubit_error_stop(iproc,command,ner) command = "surface "+str(s)+" scheme submap" cubit.cmd(command) #cubit_error_stop(iproc,command,ner) # #meshing if cfg.or_mesh_scheme == 'pave' or schemepave: command='mesh surf '+' '.join(str(t) for t in top) status=cubit_command_check(iproc,command,stop=True) #cubit.cmd(command) elif cfg.or_mesh_scheme == 'map': command='mesh surf '+' '.join(str(t) for t in bottom) status=cubit_command_check(iproc,command,stop=True) #cubit.cmd(command) for id_volume in range(nvol-1,-1,-1): command = "mesh vol "+str(vol[id_volume].ID) status=cubit_command_check(iproc,command,stop=False) if not status: for s in surf_vertical: command_surf="mesh surf "+str(s) cubit.cmd(command_surf) command_set_meshvol='volume all redistribute nodes on\nvolume all autosmooth target off\nvolume all scheme Sweep Vector 0 0 -1\nvolume all sweep smooth Auto\n' status=cubit_command_check(iproc,command_set_meshvol,stop=False) status=cubit_command_check(iproc,command,stop=True) # #smoothing print iproc, 'untangling...' cmd="volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd="smooth volume all" cubit.cmd(cmd) if cfg.smoothing: print 'smoothing .... '+str(cfg.smoothing) cubitcommand= 'surf all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand= 'smooth surf all' cubit.cmd(cubitcommand) # cubitcommand= 'vol all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand= 'smooth vol all' cubit.cmd(cubitcommand) # # ##vertical refinement ##for nvol = 3 ## ##___________________________ interface 4 ## ##vol 2 ##___________________________ interface 3 ## ##vol 1 ##___________________________ interface 2 ## ##vol 0 ##___________________________ interface 1 ## refinement(nvol,vol,filename=filename) # #top layer vertical coarsening print 'coarsening top layer... ',cfg.coarsening_top_layer if cfg.coarsening_top_layer: from sets import Set cubitcommand= 'del mesh vol '+str(vol[-1].ID)+ ' propagate' cubit.cmd(cubitcommand) s1=Set(list_curve_vertical) command = "group 'list_curve_tmp' add curve "+"in vol "+str(vol[-1].ID) cubit.cmd(command) group=cubit.get_id_from_name("list_curve_tmp") list_curve_tmp=cubit.get_group_curves(group) command = "delete group "+ str(group) cubit.cmd(command) s2=Set(list_curve_tmp) lc=list(s1 & s2) # cubitcommand= 'curve '+' '.join(str(x) for x in lc)+' interval '+str(cfg.actual_vertical_interval_top_layer) cubit.cmd(cubitcommand) cubitcommand= 'mesh vol '+str(vol[-1].ID) cubit.cmd(cubitcommand) # n=cubit.get_sideset_id_list() if len(n) != 0: command = "del sideset all" cubit.cmd(command) n=cubit.get_block_id_list() if len(n) != 0: command = "del block all" cubit.cmd(command) # import boundary_definition entities=['face'] print iproc, 'hex block definition...' boundary_definition.define_bc(entities,parallel=True,cpux=cfg.cpux,cpuy=cfg.cpuy,cpuxmin=0,cpuymin=0,optionsea=False) #save mesh print iproc, 'untangling...' cmd="volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd="smooth volume all" cubit.cmd(cmd) print iproc, 'saving...' savemesh(mpiflag,iproc=iproc,filename=filename)
def define_parallel_absorbing_surf(): """ define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis. it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf where absorbing_surf is the list of all the absorbing boundary surf absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin ... absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin """ try: cubit.cmd('comment') except: try: import cubit cubit.init([""]) except: print 'error importing cubit' import sys sys.exit() absorbing_surf_xmin = [] absorbing_surf_xmax = [] absorbing_surf_ymin = [] absorbing_surf_ymax = [] absorbing_surf_bottom = [] top_surf = [] list_vol = cubit.parse_cubit_list("volume", "all") init_n_vol = len(list_vol) zmax_box = cubit.get_total_bounding_box("volume", list_vol)[7] zmin_box = cubit.get_total_bounding_box( "volume", list_vol )[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] list_surf = cubit.parse_cubit_list("surface", "all") print '##boundary box: ' print '## x min: ' + str(xmin_box) print '## y min: ' + str(ymin_box) print '## z min: ' + str(zmin_box) print '## x max: ' + str(xmax_box) print '## y max: ' + str(ymax_box) print '## z max: ' + str(zmax_box) #box lengths x_len = abs(xmax_box - xmin_box) y_len = abs(ymax_box - ymin_box) z_len = abs(zmax_box - zmin_box) print '##boundary box: ' print '## x length: ' + str(x_len) print '## y length: ' + str(y_len) print '## z length: ' + str(z_len) # tolerance parameters absorbing_surface_distance_tolerance = 0.005 topographic_surface_distance_tolerance = 0.001 topographic_surface_normal_tolerance = 0.2 for k in list_surf: center_point = cubit.get_center_point("surface", k) if abs((center_point[0] - xmin_box) / x_len) <= absorbing_surface_distance_tolerance: absorbing_surf_xmin.append(k) elif abs((center_point[0] - xmax_box) / x_len) <= absorbing_surface_distance_tolerance: absorbing_surf_xmax.append(k) elif abs((center_point[1] - ymin_box) / y_len) <= absorbing_surface_distance_tolerance: absorbing_surf_ymin.append(k) elif abs((center_point[1] - ymax_box) / y_len) <= absorbing_surface_distance_tolerance: absorbing_surf_ymax.append(k) elif abs((center_point[2] - zmin_box) / z_len) <= absorbing_surface_distance_tolerance: print 'center_point[2]' + str(center_point[2]) print 'kz:' + str(k) absorbing_surf_bottom.append(k) else: sbox = cubit.get_bounding_box('surface', k) dz = abs((sbox[7] - zmax_box) / z_len) normal = cubit.get_surface_normal(k) zn = normal[2] dn = abs(zn - 1) if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance: top_surf.append(k) return absorbing_surf_xmin, absorbing_surf_xmax, absorbing_surf_ymin, absorbing_surf_ymax, absorbing_surf_bottom, top_surf
def get_v_h_list(vol_id_list, chktop=False): """return the lists of the cubit ID of vertical/horizontal surface and vertical/horizontal curves where v/h is defined by the distance of the z normal component from the axis direction the parameter cfg.tres is the threshold as for example if -tres <= normal[2] <= tres then the surface is vertical # usage: surf_or,surf_vertical,list_curve_or,list_curve_vertical,bottom,top = get_v_h_list(list_vol,chktop=False) """ # tres = 0.3 try: nvol = len(vol_id_list) except: nvol = 1 vol_id_list = [vol_id_list] surf_vertical = [] surf_or = [] list_curve_vertical = [] list_curve_or = [] # # for id_vol in vol_id_list: lsurf = cubit.get_relatives("volume", id_vol, "surface") for k in lsurf: normal = cubit.get_surface_normal(k) center_point = cubit.get_center_point("surface", k) if -1 * tres <= normal[2] <= tres: surf_vertical.append(k) lcurve = cubit.get_relatives("surface", k, "curve") list_curve_vertical = list_curve_vertical + list(lcurve) else: surf_or.append(k) lcurve = cubit.get_relatives("surface", k, "curve") list_curve_or = list_curve_or + list(lcurve) for x in list_curve_or: try: list_curve_vertical.remove(x) except: pass #find the top and the bottom surfaces k = surf_or[0] center_point = cubit.get_center_point("surface", k)[2] center_point_top = center_point center_point_bottom = center_point top = k bottom = k for k in surf_or[1:]: center_point = cubit.get_center_point("surface", k)[2] if center_point > center_point_top: center_point_top = center_point top = k elif center_point < center_point_bottom: center_point_bottom = center_point bottom = k #check that a top surface exists #it assume that the z coord of the center point if chktop: k = lsurf[0] vertical_centerpoint_top = cubit.get_center_point("surface", k)[2] vertical_zmax_box_top = cubit.get_bounding_box('surface', k)[7] normal_top = cubit.get_surface_normal(k) top = k for k in lsurf: vertical_centerpoint = cubit.get_center_point("surface", k)[2] vertical_zmax_box = cubit.get_bounding_box('surface', k)[7] normal = cubit.get_surface_normal(k) check = (vertical_centerpoint >= vertical_centerpoint_top) and ( vertical_zmax_box >= vertical_zmax_box_top) and (normal >= normal_top) if check: top = k if top in surf_vertical: surf_vertical.remove(top) if top not in surf_or: surf_or.append(top) #if more than one surf is on the top, I get all the surfaces that are in touch with top surface but not the vertical surfaces surftop = list(cubit.get_adjacent_surfaces( "surface", top)) #top is included in the list for s in surf_vertical: try: surftop.remove(s) except: pass top = surftop #check that all the surf are Horizontal or vertical surf_all = surf_vertical + surf_or if len(surf_all) != len(lsurf): print 'not all the surf are horizontal or vertical, check the normals' print 'list of surfaces: ', surf_all print 'list of vertical surface', surf_vertical print 'list of horizontal surface', surf_or bottom = [bottom] return surf_or, surf_vertical, list_curve_or, list_curve_vertical, bottom, top
def define_surf(ip=0, cpuxmin=0, cpuxmax=1, cpuymin=0, cpuymax=1, cpux=1, cpuy=1): """ define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis. it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf where absorbing_surf is the list of all the absorbing boundary surf absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin ... absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin """ from utilities import get_v_h_list # from sets import Set def product(*args, **kwds): # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111 # for compatibility with python2.5 pools = map(tuple, args) * kwds.get('repeat', 1) result = [[]] for pool in pools: result = [x + [y] for x in result for y in pool] return result absorbing_surf = [] xmin = [] xmax = [] ymin = [] ymax = [] # top_surf = [] bottom_surf = [] list_vol = cubit.parse_cubit_list("volume", "all") zmax_box = cubit.get_total_bounding_box("volume", list_vol)[7] zmin_box = cubit.get_total_bounding_box( "volume", list_vol )[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] list_surf = cubit.parse_cubit_list("surface", "all") absorbing_surface_distance_tolerance = 0.001 topographic_surface_distance_tolerance = 0.1 topographic_surface_normal_tolerance = 0.4 lv = [] for k in list_surf: sbox = cubit.get_bounding_box('surface', k) if zmax_box == 0 and sbox[7] == 0: dzmax = 0 elif zmax_box == 0 or sbox[7] == 0: dzmax = abs(sbox[7] - zmax_box) else: dzmax = abs(sbox[7] - zmax_box) / max(abs(sbox[7]), abs(zmax_box)) if zmin_box == 0 and sbox[6] == 0: dzmin = 0 elif zmin_box == 0 or sbox[6] == 0: dzmin = abs(sbox[6] - zmin_box) else: dzmin = abs(sbox[6] - zmin_box) / max(abs(sbox[6]), abs(zmin_box)) normal = cubit.get_surface_normal(k) zn = normal[2] if dzmax <= topographic_surface_distance_tolerance and zn > topographic_surface_normal_tolerance: top_surf.append(k) list_vertex = cubit.get_relatives('surface', k, 'vertex') for v in list_vertex: valence = cubit.get_valence(v) if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries lv.append(v) elif dzmin <= 0.001 and zn < -1 + topographic_surface_normal_tolerance: bottom_surf.append(k) if len(top_surf) == 0: #assuming that one topo surface need to be selected _, _, _, _, _, top_surf = get_v_h_list(list_vol, chktop=False) lp = [] labelp = [] combs = product(lv, lv) for comb in combs: v1 = comb[0] v2 = comb[1] c = Set(cubit.get_relatives("vertex", v1, "curve")) & Set( cubit.get_relatives("vertex", v2, "curve")) if len(c) == 1: p = cubit.get_center_point("curve", list(c)[0]) labelp.append(list(c)[0]) labelps = Set(labelp) for c in labelps: p = cubit.get_center_point("curve", c) lp.append(p) for k in list_surf: center_point = cubit.get_center_point("surface", k) for p in lp: try: if abs((center_point[0] - p[0]) / p[0]) <= absorbing_surface_distance_tolerance and abs( (center_point[1] - p[1]) / p[1]) <= absorbing_surface_distance_tolerance: absorbing_surf.append(k) break except: if -1 <= center_point[0] <= 1 and -1 <= center_point[1] <= 1: absorbing_surf.append(k) break # four_side = True if four_side: xmintmp, ymintmp, xmaxtmp, ymaxtmp = define_4side_lateral_surfaces() xmin = list(Set(xmintmp) - Set(xmaxtmp)) xmax = list(Set(xmaxtmp) - Set(xmintmp)) ymin = list(Set(ymintmp) - Set(ymaxtmp)) ymax = list(Set(ymaxtmp) - Set(ymintmp)) abs_xmintmp, abs_xmaxtmp, abs_ymintmp, abs_ymaxtmp = lateral_boundary_are_absorbing( ip, cpuxmin, cpuxmax, cpuymin, cpuymax, cpux, cpuy) abs_xmin = list(Set(abs_xmintmp) - Set(abs_xmaxtmp)) abs_xmax = list(Set(abs_xmaxtmp) - Set(abs_xmintmp)) abs_ymin = list(Set(abs_ymintmp) - Set(abs_ymaxtmp)) abs_ymax = list(Set(abs_ymaxtmp) - Set(abs_ymintmp)) return absorbing_surf, abs_xmin, abs_xmax, abs_ymin, abs_ymax, top_surf, bottom_surf, xmin, ymin, xmax, ymax
def layercake_volume_fromacis_mpiregularmap(filename=None): import sys import start as start # mpiflag, iproc, numproc, mpi = start.start_mpi() # cfg = start.start_cfg(filename=filename) # from utilities import geo2utm, savegeometry # from math import sqrt # try: mpi.barrier() except: pass # # command = "comment '" + "PROC: " + str(iproc) + "/" + str(numproc) + " '" cubit.cmd(command) # #get the limit of the volume considering the cpu def xwebcut(x): command = 'create planar surface with plane xplane offset ' + str(x) cubit.cmd(command) last_surface = cubit.get_last_id("surface") command = "webcut volume all tool volume in surf " + str(last_surface) cubit.cmd(command) command = "del surf " + str(last_surface) cubit.cmd(command) def ywebcut(x): command = 'create planar surface with plane yplane offset ' + str(x) cubit.cmd(command) last_surface = cubit.get_last_id("surface") command = "webcut volume all tool volume in surf " + str(last_surface) cubit.cmd(command) command = "del surf " + str(last_surface) cubit.cmd(command) def translate2zero(): ss = cubit.parse_cubit_list('surface', 'all') box = cubit.get_total_bounding_box("surface", ss) xmin = box[0] ymin = box[3] cubit.cmd('move surface all x ' + str(-1 * xmin) + ' y ' + str(-1 * ymin)) return xmin, ymin def translate2original(xmin, ymin): cubit.cmd('move surface all x ' + str(xmin) + ' y ' + str(ymin)) if mpiflag: icpux = iproc % cfg.nproc_xi icpuy = int(iproc / cfg.nproc_xi) else: icpuy = int(cfg.id_proc / cfg.nproc_xi) icpux = cfg.id_proc % cfg.nproc_xi # ner = cubit.get_error_count() # icurve = 0 isurf = 0 ivertex = 0 # xlength = (cfg.xmax - cfg.xmin) / float( cfg.cpux) #length of x slide for chunk ylength = (cfg.ymax - cfg.ymin) / float( cfg.cpuy) #length of y slide for chunk xmin_cpu = cfg.xmin + (xlength * (icpux)) ymin_cpu = cfg.ymin + (ylength * (icpuy)) xmax_cpu = xmin_cpu + xlength ymax_cpu = ymin_cpu + ylength # #importing the surfaces for inz in range(cfg.nz - 2, -2, -1): if cfg.bottomflat and inz == -1: command = "create planar surface with plane zplane offset " + str( cfg.depth_bottom) cubit.cmd(command) else: command = "import cubit '" + cfg.filename[inz] + "'" cubit.cmd(command) #translate xmin, ymin = translate2zero() print 'translate ...', -xmin, -ymin xmin_cpu = xmin_cpu - xmin ymin_cpu = ymin_cpu - ymin xmax_cpu = xmax_cpu - xmin ymax_cpu = ymax_cpu - ymin ss = cubit.parse_cubit_list('surface', 'all') box = cubit.get_total_bounding_box("surface", ss) print 'dimension... ', box #cutting the surfaces xwebcut(xmin_cpu) xwebcut(xmax_cpu) ywebcut(ymin_cpu) ywebcut(ymax_cpu) # list_surface_all = cubit.parse_cubit_list("surface", "all") #condisidering only the surfaces inside the boundaries dict_surf = {} for isurf in list_surface_all: p = cubit.get_center_point("surface", isurf) if p[0] < xmin_cpu or p[0] > xmax_cpu or p[1] > ymax_cpu or p[ 1] < ymin_cpu: command = "del surf " + str(isurf) cubit.cmd(command) else: dict_surf[str(isurf)] = p[2] z = dict_surf.values() z.sort() list_surf = [] for val in z: isurf = [k for k, v in dict_surf.iteritems() if v == val][0] list_surf.append(int(isurf)) # #lofting the volume for i, j in zip(list_surf, list_surf[1:]): ner = cubit.get_error_count() create_volume(i, j, method=cfg.volumecreation_method) #cubitcommand= 'create volume loft surface '+ str(i)+' '+str(j) #cubit.cmd(cubitcommand) ner2 = cubit.get_error_count() # translate2original(xmin, ymin) if ner == ner2: cubitcommand = 'del surface all' cubit.cmd(cubitcommand) # # #cubitcommand= 'composite create curve in vol all' #cubit.cmd(cubitcommand) list_vol = cubit.parse_cubit_list("volume", "all") if len(list_vol) > 1: cubitcommand = 'imprint volume all' cubit.cmd(cubitcommand) #cubit_error_stop(iproc,cubitcommand,ner) # cubitcommand = 'merge all' cubit.cmd(cubitcommand) # savegeometry(iproc, filename=filename)
def define_surf(ip=0,cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1): """ define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis. it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf where absorbing_surf is the list of all the absorbing boundary surf absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin ... absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin """ from utilities import get_v_h_list # from sets import Set def product(*args, **kwds): # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111 # for compatibility with python2.5 pools = map(tuple, args) * kwds.get('repeat', 1) result = [[]] for pool in pools: result = [x+[y] for x in result for y in pool] return result absorbing_surf=[] xmin=[] xmax=[] ymin=[] ymax=[] # top_surf=[] bottom_surf=[] list_vol=cubit.parse_cubit_list("volume","all") zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7] zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0] xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1] ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3] ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4] list_surf=cubit.parse_cubit_list("surface","all") absorbing_surface_distance_tolerance=0.001 topographic_surface_distance_tolerance=0.1 topographic_surface_normal_tolerance=0.4 lv=[] for k in list_surf: sbox=cubit.get_bounding_box('surface',k) if zmax_box == 0 and sbox[7] == 0: dzmax=0 elif zmax_box == 0 or sbox[7] == 0: dzmax=abs(sbox[7] - zmax_box) else: dzmax=abs(sbox[7] - zmax_box)/max(abs(sbox[7]),abs(zmax_box)) if zmin_box == 0 and sbox[6] == 0: dzmin=0 elif zmin_box == 0 or sbox[6] == 0: dzmin=abs(sbox[6] - zmin_box) else: dzmin=abs(sbox[6] - zmin_box)/max(abs(sbox[6]),abs(zmin_box)) normal=cubit.get_surface_normal(k) zn=normal[2] if dzmax <= topographic_surface_distance_tolerance and zn > topographic_surface_normal_tolerance: top_surf.append(k) list_vertex=cubit.get_relatives('surface',k,'vertex') for v in list_vertex: valence=cubit.get_valence(v) if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries lv.append(v) elif dzmin <= 0.001 and zn < -1+topographic_surface_normal_tolerance: bottom_surf.append(k) if len(top_surf) ==0: #assuming that one topo surface need to be selected _,_,_,_,_,top_surf=get_v_h_list(list_vol,chktop=False) lp=[] labelp=[] combs=product(lv,lv) for comb in combs: v1=comb[0] v2=comb[1] c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve")) if len(c) == 1: p=cubit.get_center_point("curve",list(c)[0]) labelp.append(list(c)[0]) labelps=Set(labelp) for c in labelps: p=cubit.get_center_point("curve",c) lp.append(p) for k in list_surf: center_point = cubit.get_center_point("surface", k) for p in lp: try: if abs((center_point[0] - p[0])/p[0]) <= absorbing_surface_distance_tolerance and abs((center_point[1] - p[1])/p[1]) <= absorbing_surface_distance_tolerance: absorbing_surf.append(k) break except: if -1 <= center_point[0] <= 1 and -1 <= center_point[1] <= 1: absorbing_surf.append(k) break # four_side=True if four_side: xmintmp,ymintmp,xmaxtmp,ymaxtmp=define_4side_lateral_surfaces() xmin=list(Set(xmintmp)-Set(xmaxtmp)) xmax=list(Set(xmaxtmp)-Set(xmintmp)) ymin=list(Set(ymintmp)-Set(ymaxtmp)) ymax=list(Set(ymaxtmp)-Set(ymintmp)) abs_xmintmp,abs_xmaxtmp,abs_ymintmp,abs_ymaxtmp=lateral_boundary_are_absorbing(ip,cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy) abs_xmin=list(Set(abs_xmintmp)-Set(abs_xmaxtmp)) abs_xmax=list(Set(abs_xmaxtmp)-Set(abs_xmintmp)) abs_ymin=list(Set(abs_ymintmp)-Set(abs_ymaxtmp)) abs_ymax=list(Set(abs_ymaxtmp)-Set(abs_ymintmp)) return absorbing_surf,abs_xmin,abs_xmax,abs_ymin,abs_ymax,top_surf,bottom_surf,xmin,ymin,xmax,ymax
def define_absorbing_surf_nopar(): """ define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis. it returns absorbing_surf,topo_surf where absorbing_surf is the list of all the absorbing boundary surf """ try: cubit.cmd('comment') except: try: import cubit cubit.init([""]) except: print 'error importing cubit' import sys sys.exit() from sets import Set def product(*args, **kwds): # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111 pools = map(tuple, args) * kwds.get('repeat', 1) result = [[]] for pool in pools: result = [x+[y] for x in result for y in pool] return result absorbing_surf=[] absorbing_surf_xmin=[] absorbing_surf_xmax=[] absorbing_surf_ymin=[] absorbing_surf_ymax=[] absorbing_surf_bottom=[] top_surf=[] list_vol=cubit.parse_cubit_list("volume","all") init_n_vol=len(list_vol) zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7] zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0] xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1] ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3] ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4] list_surf=cubit.parse_cubit_list("surface","all") lv=[] for k in list_surf: sbox=cubit.get_bounding_box('surface',k) dzmax=abs((sbox[7] - zmax_box)/zmax_box) dzmin=abs((sbox[6] - zmin_box)/zmin_box) normal=cubit.get_surface_normal(k) zn=normal[2] if dzmax <= 0.001 and zn > 0.7: top_surf.append(k) list_vertex=cubit.get_relatives('surface',k,'vertex') for v in list_vertex: valence=cubit.get_valence(v) if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries lv.append(v) elif dzmin <= 0.001 and zn < -0.7: absorbing_surf.append(k) lp=[] combs=product(lv,lv) for comb in combs: v1=comb[0] v2=comb[1] c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve")) if len(c) == 1: p=cubit.get_center_point("curve",list(c)[0]) lp.append(p) for k in list_surf: center_point = cubit.get_center_point("surface", k) for p in lp: if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005: absorbing_surf.append(k) break return absorbing_surf,top_surf
## fault surfaces (up/down) Au = [cubit.get_id_from_name("fault1")] Ad = [cubit.get_id_from_name("fault2")] # FOR THE BULK (Seismic wave propagation part for SPECFEM3D) entities = ['face'] xmin, xmax, ymin, ymax, bottom, topo = absorbing_boundary.define_parallel_absorbing_surf( ) # The above function is expected to obtain the correct topo and bottom surfaces, but for curved fault this function may fail (I don't know why). # Here I try to obtain the topo and bottom surface automaticly in case the above function fails. # If this part also doesn't work well (such as the topography has more than one surfaces), please setup bottom=[surface_list] and topo=[surface_list] manually. list_surf = cubit.parse_cubit_list("surface", "all") center_depth = [] for k in list_surf: center_depth.append(cubit.get_center_point("surface", k)[2]) bottom = numpy.asarray(list_surf)[numpy.argwhere( center_depth == numpy.amin(center_depth))[:, 0]].tolist() topo = numpy.asarray(list_surf)[numpy.argwhere( center_depth == numpy.amax(center_depth))[:, 0]].tolist() #bottom = [surface_list] #topo = [surface_list] if (len(bottom) == 0 or len(topo) == 0): print "Fail in obtaining the topo and bottom surfaces." print "Please change setup topo and bottom surfaces manually." exit() print "Xmin surface list: ", xmin print "Xmax surface list: ", xmax print "Ymin surface list: ", ymin print "Ymax surface list: ", ymax print "Bott surface list: ", bottom
def define_absorbing_surf(): """ define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis. it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf where absorbing_surf is the list of all the absorbing boundary surf absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin ... absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin """ try: cubit.cmd('comment') except: try: import cubit cubit.init([""]) except: print 'error importing cubit' import sys sys.exit() absorbing_surf=[] absorbing_surf_xmin=[] absorbing_surf_xmax=[] absorbing_surf_ymin=[] absorbing_surf_ymax=[] absorbing_surf_bottom=[] top_surf=[] list_vol=cubit.parse_cubit_list("volume","all") init_n_vol=len(list_vol) zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7] zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0] xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1] ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3] ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4] list_surf=cubit.parse_cubit_list("surface","all") # for k in list_surf: # center_point = cubit.get_center_point("surface", k) # if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005: # absorbing_surf_xmin.append(k) # absorbing_surf.append(k) # elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005: # absorbing_surf_xmax.append(k) # absorbing_surf.append(k) # elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005: # absorbing_surf_ymin.append(k) # absorbing_surf.append(k) # elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005: # absorbing_surf_ymax.append(k) # absorbing_surf.append(k) # elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005: # absorbing_surf_bottom.append(k) # absorbing_surf.append(k) # else: # sbox=cubit.get_bounding_box('surface',k) # dz=abs((sbox[7] - zmax_box)/zmax_box) # normal=cubit.get_surface_normal(k) # zn=normal[2] # dn=abs(zn-1) # if dz <= 0.001 and dn < 0.2: # top_surf.append(k) #box lengths x_len = abs( xmax_box - xmin_box) y_len = abs( ymax_box - ymin_box) z_len = abs( zmax_box - zmin_box) print '##boundary box: ' print '## x length: ' + str(x_len) print '## y length: ' + str(y_len) print '## z length: ' + str(z_len) # tolerance parameters absorbing_surface_distance_tolerance=0.005 topographic_surface_distance_tolerance=0.001 topographic_surface_normal_tolerance=0.2 for k in list_surf: center_point = cubit.get_center_point("surface", k) if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance: absorbing_surf_xmin.append(k) absorbing_surf.append(k) elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance: absorbing_surf_xmax.append(k) absorbing_surf.append(k) elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance: absorbing_surf_ymin.append(k) absorbing_surf.append(k) elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance: absorbing_surf_ymax.append(k) absorbing_surf.append(k) elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance: absorbing_surf_bottom.append(k) absorbing_surf.append(k) else: sbox=cubit.get_bounding_box('surface',k) dz=abs((sbox[7] - zmax_box)/z_len) normal=cubit.get_surface_normal(k) zn=normal[2] dn=abs(zn-1) if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance: top_surf.append(k) return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
def hor_distance(c1, c2): p1 = cubit.get_center_point("curve", c1) p2 = cubit.get_center_point("curve", c2) d = (p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 return d
def get_v_h_list(vol_id_list, chktop=False): """ return the lists of the cubit ID of vertical/horizontal surface and vertical/horizontal curves where v/h is defined by the distance of the z normal component from the axis direction the parameter cfg.tres is the threshold as for example if -tres <= normal[2] <= tres then the surface is vertical # usage: surf_or,surf_vertical,list_curve_or, list_curve_vertical,bottom,top = get_v_h_list(list_vol,chktop=False) """ # tres = 0.3 try: _ = len(vol_id_list) except: vol_id_list = [vol_id_list] surf_vertical = [] surf_or = [] list_curve_vertical = [] list_curve_or = [] # # for id_vol in vol_id_list: lsurf = cubit.get_relatives("volume", id_vol, "surface") for k in lsurf: normal = cubit.get_surface_normal(k) center_point = cubit.get_center_point("surface", k) if -1 * tres <= normal[2] <= tres: surf_vertical.append(k) lcurve = cubit.get_relatives("surface", k, "curve") list_curve_vertical = list_curve_vertical + list(lcurve) else: surf_or.append(k) lcurve = cubit.get_relatives("surface", k, "curve") list_curve_or = list_curve_or + list(lcurve) for x in list_curve_or: try: list_curve_vertical.remove(x) except: pass # find the top and the bottom surfaces k = surf_or[0] center_point = cubit.get_center_point("surface", k)[2] center_point_top = center_point center_point_bottom = center_point top = k bottom = k for k in surf_or[1:]: center_point = cubit.get_center_point("surface", k)[2] if center_point > center_point_top: center_point_top = center_point top = k elif center_point < center_point_bottom: center_point_bottom = center_point bottom = k # check that a top surface exists # it assume that the z coord of the center point if chktop: k = lsurf[0] vertical_centerpoint_top = cubit.get_center_point("surface", k)[2] vertical_zmax_box_top = cubit.get_bounding_box('surface', k)[7] normal_top = cubit.get_surface_normal(k) top = k for k in lsurf: vertical_centerpoint = cubit.get_center_point("surface", k)[2] vertical_zmax_box = cubit.get_bounding_box('surface', k)[7] normal = cubit.get_surface_normal(k) check = (vertical_centerpoint >= vertical_centerpoint_top) and ( vertical_zmax_box >= vertical_zmax_box_top) and ( normal >= normal_top) if check: top = k if top in surf_vertical: surf_vertical.remove(top) if top not in surf_or: surf_or.append(top) # if more than one surf is on the top, I get all the surfaces that are in # touch with top surface but not the vertical surfaces surftop = list(cubit.get_adjacent_surfaces( "surface", top)) # top is included in the list for s in surf_vertical: try: surftop.remove(s) except: pass top = surftop # check that all the surf are Horizontal or vertical surf_all = surf_vertical + surf_or if len(surf_all) != len(lsurf): print 'not all the surf are horizontal or vertical, check the normals' print 'list of surfaces: ', surf_all print 'list of vertical surface', surf_vertical print 'list of horizontal surface', surf_or bottom = [bottom] return surf_or, surf_vertical, list_curve_or, \ list_curve_vertical, bottom, top
def define_absorbing_surf_nopar(): """ define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis. it returns absorbing_surf,topo_surf where absorbing_surf is the list of all the absorbing boundary surf """ try: cubit.cmd('comment') except: try: import cubit cubit.init([""]) except: print 'error importing cubit' import sys sys.exit() from sets import Set def product(*args, **kwds): # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111 pools = map(tuple, args) * kwds.get('repeat', 1) result = [[]] for pool in pools: result = [x + [y] for x in result for y in pool] return result absorbing_surf = [] absorbing_surf_xmin = [] absorbing_surf_xmax = [] absorbing_surf_ymin = [] absorbing_surf_ymax = [] absorbing_surf_bottom = [] top_surf = [] list_vol = cubit.parse_cubit_list("volume", "all") init_n_vol = len(list_vol) zmax_box = cubit.get_total_bounding_box("volume", list_vol)[7] zmin_box = cubit.get_total_bounding_box( "volume", list_vol )[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin... xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] list_surf = cubit.parse_cubit_list("surface", "all") lv = [] for k in list_surf: sbox = cubit.get_bounding_box('surface', k) dzmax = abs((sbox[7] - zmax_box) / zmax_box) dzmin = abs((sbox[6] - zmin_box) / zmin_box) normal = cubit.get_surface_normal(k) zn = normal[2] if dzmax <= 0.001 and zn > 0.7: top_surf.append(k) list_vertex = cubit.get_relatives('surface', k, 'vertex') for v in list_vertex: valence = cubit.get_valence(v) if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries lv.append(v) elif dzmin <= 0.001 and zn < -0.7: absorbing_surf.append(k) lp = [] combs = product(lv, lv) for comb in combs: v1 = comb[0] v2 = comb[1] c = Set(cubit.get_relatives("vertex", v1, "curve")) & Set( cubit.get_relatives("vertex", v2, "curve")) if len(c) == 1: p = cubit.get_center_point("curve", list(c)[0]) lp.append(p) for k in list_surf: center_point = cubit.get_center_point("surface", k) for p in lp: if abs((center_point[0] - p[0]) / p[0]) <= 0.005 and abs( (center_point[1] - p[1]) / p[1]) <= 0.005: absorbing_surf.append(k) break return absorbing_surf, top_surf
cubit.cmd('sideset 1 add surface %i' % isurf) # N if np.abs(y0 - ymax) < 0.1: cubit.cmd('sideset 2 add surface %i' % isurf) # S if c0[0] == 1 or c0[0] == -1: if np.abs(x0 - xmin) < 0.1: cubit.cmd('sideset 3 add surface %i' % isurf) # E if np.abs(x0 - xmax) < 0.1: cubit.cmd('sideset 4 add surface %i' % isurf) # W if c0[2] == 1 or c0[2] == -1: if np.abs(z0 - zmin) < 0.1: cubit.cmd('sideset 5 add surface %i' % isurf) # lower if np.abs(z0 - zmax) < 0.1: isWell = False ovol = cubit.get_owning_volume('surface', isurf) if np.sum((np.array([0, 0]) - np.array(cubit.get_center_point('volume', ovol)[0:2]))** 2)**0.5 < 0.1: if np.abs(cubit.get_surface_area(isurf) - (math.pi * 1.8**2)) < 0.01: print ovol isWell = True if isWell: cubit.cmd('sideset 7 add surface %i' % (isurf)) # injection else: cubit.cmd('sideset 6 add surface %i' % isurf) # upper hex_ids = np.zeros([0, 3], dtype='int') hex_xyzs = np.zeros([0, 3], dtype='float') hex_types = np.zeros([0, 1], dtype='float') iblock = 0 for ivol in range(1, cubit.get_volume_count() + 1):
def mesh_layercake_regularmap(filename=None): import start as start mpiflag, iproc, numproc, mpi = start.start_mpi() from utilities import importgeometry, savemesh, get_v_h_list from utilities import cubit_command_check, get_cubit_version # # numpy = start.start_numpy() cfg = start.start_cfg(filename=filename) # from math import sqrt version_cubit = get_cubit_version() list_vol = cubit.parse_cubit_list("volume", "all") if len(list_vol) != 0: pass else: geometryfile = 'geometry_vol_' + str(iproc) + '.cub' importgeometry(geometryfile, iproc=iproc) command = 'composite create curve all' cubit.cmd(command) print('###"No valid composites can be created from the specified curves." \ is NOT a critical ERROR.') # command = "compress all" cubit.cmd(command) list_vol = cubit.parse_cubit_list("volume", "all") nvol = len(list_vol) vol = [] for id_vol in list_vol: p = cubit.get_center_point("volume", id_vol) vol.append(cubitvolume(id_vol, 1, p[2], 0)) vol.sort(by_z) # for id_vol in range(0, nvol): vol[id_vol].intervalv = cfg.iv_interval[id_vol] # # surf_vertical = [] surf_or = [] # top_surface = 0 # top_surface_add = '' # bottom_surface = 0 # # # zmin_box = cubit.get_total_bounding_box("volume", list_vol)[6] # xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0] # xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1] # ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3] # ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4] # # # interval assignement surf_or, surf_vertical, list_curve_or, list_curve_vertical, \ bottom, top = get_v_h_list(list_vol, chktop=cfg.chktop) print('vertical surfaces: ', surf_vertical) for k in surf_vertical: command = "surface " + str(k) + " scheme submap" cubit.cmd(command) for k in surf_or: command = "surface " + str(k) + " scheme " + cfg.or_mesh_scheme cubit.cmd(command) # ucurve, vcurve = get_uv_curve(list_curve_or) schemepave = False # ucurve_interval = {} for k in ucurve: length = cubit.get_curve_length(k) interval = int(2 * round(.5 * length / cfg.size, 0)) ucurve_interval[k] = interval command = "curve " + str(k) + " interval " + str(interval) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) if max(ucurve_interval.values()) != min(ucurve_interval.values()): schemepave = True print('mesh scheme is set to pave') for sk in surf_or: command = "surface " + str(sk) + " scheme pave" cubit.cmd(command) # vcurve_interval = {} for k in vcurve: length = cubit.get_curve_length(k) interval = int(2 * round(.5 * length / cfg.size, 0)) vcurve_interval[k] = interval command = "curve " + str(k) + " interval " + str(interval) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) if max(vcurve_interval.values()) != min(vcurve_interval.values()): print('mesh scheme is set to pave') schemepave = True for sk in surf_or: command = "surface " + str(sk) + " scheme pave" cubit.cmd(command) # for s in surf_vertical: lcurve = cubit.get_relatives("surface", s, "curve") interval_store = [] for k in lcurve: interval_curve = cubit.get_mesh_intervals('curve', k) if k in list_curve_vertical: volume_id = cubit.get_owning_volume("curve", k) for idv in range(0, nvol): if vol[idv].ID == volume_id: int_v = vol[idv].intervalv command = "curve " + str(k) + " interval " + str(int_v) cubit.cmd(command) # cubit_error_stop(iproc,command,ner) command = "curve " + str(k) + " scheme equal" cubit.cmd(command) # cubit_error_stop(iproc,command,ner) else: interval_store.append((k, interval_curve)) if len(interval_store) != 0: interval_min = min([iv[1] for iv in interval_store]) str_interval = [str(iv[0]) for iv in interval_store] cmd = "curve " + ' '.join(str_interval) + \ " interval " + str(interval_min) cubit.cmd(cmd) command = "curve " + \ ' '.join(str(iv[0]) for iv in interval_store) + " scheme equal" cubit.cmd(command) command = "surface " + str(s) + " scheme submap" cubit.cmd(command) # meshing if cfg.or_mesh_scheme == 'pave' or schemepave: command = 'mesh surf ' + ' '.join(str(t) for t in top) status = cubit_command_check(iproc, command, stop=True) # cubit.cmd(command) elif cfg.or_mesh_scheme == 'map': command = 'mesh surf ' + ' '.join(str(t) for t in bottom) status = cubit_command_check(iproc, command, stop=True) # cubit.cmd(command) for id_volume in range(nvol - 1, -1, -1): command = "mesh vol " + str(vol[id_volume].ID) status = cubit_command_check(iproc, command, stop=False) if not status: for s in surf_vertical: command_surf = "mesh surf " + str(s) cubit.cmd(command_surf) if version_cubit < 16: command_set_meshvol = '''volume all redistribute nodes on volume all autosmooth target off volume all scheme Sweep Vector 0 0 -1 volume all sweep smooth Auto ''' else: command_set_meshvol = '''volume all redistribute nodes on volume all autosmooth target off volume all scheme Sweep Vector 0 0 -1 ''' status2 = cubit_command_check( iproc, command_set_meshvol, stop=False) status2 = cubit_command_check(iproc, command, stop=False) if not status2: _surf = cubit.get_relatives( 'volume', vol[id_volume].ID, 'surface') local_o_surf = [x for x in _surf if x in surf_or] cubit.cmd('volume ' + str(vol[id_volume].ID) + ' redistribute nodes off') cubit.cmd('volume ' + str(vol[id_volume].ID) + ' scheme Sweep source surface ' + ' '.join(str(x) for x in local_o_surf[0:-1]) + ' target surface ' + str(local_o_surf[-1])) cubit.cmd('volume ' + str(vol[id_volume].ID) + ' autosmooth_target off') status = cubit_command_check(iproc, command, stop=True) # # smoothing print(iproc, 'untangling...') cmd = "volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd = "smooth volume all" cubit.cmd(cmd) if cfg.smoothing: print('smoothing .... ' + str(cfg.smoothing)) cubitcommand = 'surf all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand = 'smooth surf all' cubit.cmd(cubitcommand) # cubitcommand = 'vol all smooth scheme laplacian ' cubit.cmd(cubitcommand) cubitcommand = 'smooth vol all' cubit.cmd(cubitcommand) # # # vertical refinement # for nvol = 3 ## # ___________________________ interface 4 ## # vol 2 # ___________________________ interface 3 ## # vol 1 # ___________________________ interface 2 ## # vol 0 # ___________________________ interface 1 ## refinement(nvol, vol, filename=filename) # # top layer vertical coarsening print('coarsening top layer... ', cfg.coarsening_top_layer) if cfg.coarsening_top_layer: cubitcommand = 'del mesh vol ' + str(vol[-1].ID) + ' propagate' cubit.cmd(cubitcommand) s1 = set(list_curve_vertical) command = "group 'list_curve_tmp' add curve " + \ "in vol " + str(vol[-1].ID) cubit.cmd(command) group = cubit.get_id_from_name("list_curve_tmp") list_curve_tmp = cubit.get_group_curves(group) command = "delete group " + str(group) cubit.cmd(command) s2 = set(list_curve_tmp) lc = list(s1 & s2) # cubitcommand = 'curve ' + \ ' '.join(str(x) for x in lc) + ' interval ' + \ str(cfg.actual_vertical_interval_top_layer) cubit.cmd(cubitcommand) cubitcommand = 'mesh vol ' + str(vol[-1].ID) cubit.cmd(cubitcommand) # n = cubit.get_sideset_id_list() if len(n) != 0: command = "del sideset all" cubit.cmd(command) n = cubit.get_block_id_list() if len(n) != 0: command = "del block all" cubit.cmd(command) # import boundary_definition entities = ['face'] print(iproc, 'hex block definition...') boundary_definition.define_bc(entities, parallel=True, cpux=cfg.cpux, cpuy=cfg.cpuy, cpuxmin=0, cpuymin=0, optionsea=False) # save mesh print(iproc, 'untangling...') cmd = "volume all smooth scheme untangle beta 0.02 cpu 10" cubit.cmd(cmd) cmd = "smooth volume all" cubit.cmd(cmd) print(iproc, 'saving...') savemesh(mpiflag, iproc=iproc, filename=filename)