コード例 #1
0
ファイル: volumes.py プロジェクト: zyex1108/specfem3d
 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
コード例 #2
0
ファイル: volumes.py プロジェクト: EtienneBachmann/specfem3d
 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
コード例 #3
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
コード例 #4
0
import pickle

cubit.init(['test', '-nojournal'])
cubit.cmd('reset')
cubit.cmd('create brick x 4000 y 4000 z 645')
cubit.cmd('move volume all x 0 y 0 z +222.5')

cubit.cmd('webcut body all with general plane xy move x 0 y 0 z 0')
cubit.cmd('webcut body all with general plane xy move x 0 y 0 z 27')
cubit.cmd('webcut body all with general plane xy move x 0 y 0 z -7')
cubit.cmd('webcut body all with general plane yz move x -500 y 0 z 0')
cubit.cmd('webcut body all with general plane yz move x +500 y 0 z 0')
cubit.cmd('webcut body all with general plane xz move x 0 y -500 z 0')
cubit.cmd('webcut body all with general plane xz move x 0 y +500 z 0')

xmin = cubit.get_total_bounding_box('volume', cubit.get_entities('volume'))[0]
xmax = cubit.get_total_bounding_box('volume', cubit.get_entities('volume'))[1]
ymin = cubit.get_total_bounding_box('volume', cubit.get_entities('volume'))[3]
ymax = cubit.get_total_bounding_box('volume', cubit.get_entities('volume'))[4]
zmin = cubit.get_total_bounding_box('volume', cubit.get_entities('volume'))[6]
zmax = cubit.get_total_bounding_box('volume', cubit.get_entities('volume'))[7]

cubit.cmd('webcut volume all with cylinder radius 20.0 axis z center 0,0,0')
cubit.cmd('webcut volume all with cylinder radius  2.0 axis z center 0,0,0')
cubit.cmd('webcut volume all with cylinder radius  1.8 axis z center 0,0,0')

for icurve in cubit.get_entities('curve'):
    l = cubit.get_curve_length(icurve)
    r1 = 2 * math.pi * 1.8
    r2 = 2 * math.pi * 2.0
    r3 = 2 * math.pi * 20.0
コード例 #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
ファイル: volumes.py プロジェクト: EtienneBachmann/specfem3d
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)
コード例 #9
0
ファイル: mesh_volume.py プロジェクト: hejunzhu/specfem3d
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)
コード例 #10
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
コード例 #11
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
コード例 #12
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
コード例 #13
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
コード例 #14
0
ファイル: volumes.py プロジェクト: hejunzhu/specfem3d
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)
コード例 #15
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