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