def refinement(nvol, vol, filename=None): import start as start cfg = start.start_cfg(filename=filename) from utilities import get_v_h_list # # vertical refinement # for nvol = 3 # # ___________________________ interface 4 # # vol 2 # ___________________________ interface 3 # # vol 1 # ___________________________ interface 2 # # vol 0 # ___________________________ interface 1 # # if cfg.ntripl != 0: if len(cfg.refinement_depth) != 0: _, _, _, _, _, tsurf = get_v_h_list([vol[nvol - 1].ID]) tsurf = ' '.join(str(x) for x in tsurf) for idepth in cfg.refinement_depth: cubitcommand = 'refine node in surf ' + \ str(tsurf) + ' numsplit 1 bias 1.0 depth ' + str(idepth) cubit.cmd(cubitcommand) else: for ir in cfg.tripl: if ir == 1: print( 'interface = 1 means that the refinement' 'interface is at the bottom of the volume') txt = ' all ' idepth = 1 cubitcommand = 'refine hex in vol ' + txt elif ir != nvol + 1: txt = '' for id_vol_ref in range(ir - 1, nvol): txt = txt + str(vol[id_vol_ref].ID) + ' ' cubitcommand = 'refine hex in vol ' + txt else: # refinement on the top surface _, _, _, _, _, tsurf = get_v_h_list([vol[ir - 2].ID]) tsurf = ' '.join(str(x) for x in tsurf) idepth = 1 cubitcommand = 'refine node in surf ' + str(tsurf) + \ ' numsplit 1 bias 1.0 depth ' + str(idepth) cubit.cmd(cubitcommand) sandwich = 'verticalsandwich_volume_ascii_regulargrid_mpiregularmap' if not nvol and cfg.volume_type == sandwich: # AAA # Volume 2 is always in between the 2nd and 3rd vertical # surfaces from the left cubitcommand = "refine node in volume 2 numsplit 1 depth 0" cubit.cmd(cubitcommand)
def refinement(nvol, vol, filename=None): import start as start cfg = start.start_cfg(filename=filename) from utilities import get_v_h_list # # vertical refinement # for nvol = 3 # # ___________________________ interface 4 # # vol 2 # ___________________________ interface 3 # # vol 1 # ___________________________ interface 2 # # vol 0 # ___________________________ interface 1 # # if cfg.ntripl != 0: if len(cfg.refinement_depth) != 0: _, _, _, _, _, tsurf = get_v_h_list([vol[nvol - 1].ID]) tsurf = ' '.join(str(x) for x in tsurf) for idepth in cfg.refinement_depth: cubitcommand = 'refine node in surf ' + \ str(tsurf) + ' numsplit 1 bias 1.0 depth ' + str(idepth) cubit.cmd(cubitcommand) else: for ir in cfg.tripl: if ir == 1: print ('interface = 1 means that the refinement' 'interface is at the bottom of the volume') txt = ' all ' idepth = 1 cubitcommand = 'refine hex in vol ' + txt elif ir != nvol + 1: txt = '' for id_vol_ref in range(ir - 1, nvol): txt = txt + str(vol[id_vol_ref].ID) + ' ' cubitcommand = 'refine hex in vol ' + txt else: # refinement on the top surface _, _, _, _, _, tsurf = get_v_h_list([vol[ir - 2].ID]) tsurf = ' '.join(str(x) for x in tsurf) idepth = 1 cubitcommand = 'refine node in surf ' + str(tsurf) + \ ' numsplit 1 bias 1.0 depth ' + str(idepth) cubit.cmd(cubitcommand) sandwich = 'verticalsandwich_volume_ascii_regulargrid_mpiregularmap' if not nvol and cfg.volume_type == sandwich: # AAA # Volume 2 is always in between the 2nd and 3rd vertical # surfaces from the left cubitcommand = "refine node in volume 2 numsplit 1 depth 0" cubit.cmd(cubitcommand)
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 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 refinement(nvol,vol,filename=None): import start as start cfg = start.start_cfg(filename=filename) from utilities import get_v_h_list # #vertical refinement #for nvol = 3 # #___________________________ interface 4 # #vol 2 #___________________________ interface 3 # #vol 1 #___________________________ interface 2 # #vol 0 #___________________________ interface 1 # # if cfg.ntripl != 0: if len(cfg.refinement_depth) != 0: #get the topo surface.... #surf=cubit.get_relatives('volume',vol[nvol-1].ID,'surface') #zstore=[-1,-999999999] #for s in surf: # c=cubit.get_center_point('surface',s) # z=c[2] # print s,z # if z > zstore[1]: # zstore=[s,z] #tsurf=zstore[0] _,_,_,_,_,tsurf = get_v_h_list([vol[nvol-1].ID]) tsurf=' '.join(str(x) for x in tsurf) for idepth in cfg.refinement_depth: cubitcommand= 'refine node in surf '+str(tsurf)+' numsplit 1 bias 1.0 depth '+str(idepth) cubit.cmd(cubitcommand) else: for ir in cfg.tripl: if ir == 1: command = "comment '"+"interface = 1 means that the refinement interface is at the bottom of the volume"+"'" cubit.cmd(command) txt=' all ' idepth = 1 cubitcommand= 'refine hex in vol '+txt elif ir != nvol+1: txt='' for id_vol_ref in range(ir-1,nvol): txt=txt+str(vol[id_vol_ref].ID)+' ' #txt=txt+'except hex in vol '+str(vol[ir-2].ID) #idepth = 1 #try: # if cfg.refine_basin: # idepth=2 #except: # pass cubitcommand= 'refine hex in vol '+txt else: #refinement on the top surface _,_,_,_,_,tsurf = get_v_h_list([vol[ir-2].ID]) tsurf=' '.join(str(x) for x in tsurf) idepth=1 cubitcommand= 'refine node in surf '+str(tsurf)+' numsplit 1 bias 1.0 depth '+str(idepth) cubit.cmd(cubitcommand) if not nvol and cfg.volume_type == 'verticalsandwich_volume_ascii_regulargrid_mpiregularmap': # AAA # Volume 2 is always in between the 2nd and 3rd vertical surfaces from the left cubitcommand = "refine node in volume 2 numsplit 1 depth 0" cubit.cmd(cubitcommand)
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 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)