コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
                cubit.cmd('curve %i interval %i scheme dualbias %f' %
                          (icurve, intv, bias))
            if np.abs(x0 - x1) < 0.01 and np.abs(z0 - z1) < 0.01 and np.abs(
                    0.5 * (y0 + y1) - 0) < 1:
                intv = 14
                bias = 0.95
                cubit.cmd('curve %i interval %i scheme dualbias %f' %
                          (icurve, intv, bias))

cubit.cmd('imprint body all')
cubit.cmd('merge body all')
cubit.cmd('mesh volume all')

for isurf in cubit.get_entities('surface'):
    x0, y0, z0 = cubit.get_surface_centroid(isurf)
    c0 = cubit.get_surface_normal(isurf)
    if c0[1] == 1 or c0[1] == -1:
        if np.abs(y0 - ymin) < 0.1:
            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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
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
コード例 #9
0
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
コード例 #10
0
ファイル: utilities.py プロジェクト: carltape/specfem3d
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
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
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