コード例 #1
0
def extract_bottom_curves(surf_xmin,surf_ymin,surf_xmax,surf_ymax):
    curve_xmin=[]
    curve_ymin=[]
    curve_xmax=[]
    curve_ymax=[]
    from sets import Set #UPGRADE.... the sets module is deprecated after python 2.6
    for s in surf_xmin:
        lcs=cubit.get_relatives("surface",s,"curve")
        for lc in lcs:
            curve_xmin.append(lc)
    for s in surf_xmax:
        lcs=cubit.get_relatives("surface",s,"curve")
        for lc in lcs:
            curve_xmax.append(lc)
    for s in surf_ymin:
        lcs=cubit.get_relatives("surface",s,"curve")
        for lc in lcs:
            curve_ymin.append(lc)
    for s in surf_ymax:
        lcs=cubit.get_relatives("surface",s,"curve")
        for lc in lcs:
            curve_ymax.append(lc)
    curve_xmin=list(Set(curve_xmin))
    curve_ymin=list(Set(curve_ymin))
    curve_xmax=list(Set(curve_xmax))
    curve_ymax=list(Set(curve_ymax))
    curve_bottom_xmin=select_bottom_curve(curve_xmin)
    curve_bottom_ymin=select_bottom_curve(curve_ymin)
    curve_bottom_xmax=select_bottom_curve(curve_xmax)
    curve_bottom_ymax=select_bottom_curve(curve_ymax)
    #
    return curve_bottom_xmin,curve_bottom_ymin,curve_bottom_xmax,curve_bottom_ymax
コード例 #2
0
def extract_bottom_curves(surf_xmin, surf_ymin, surf_xmax, surf_ymax):
    curve_xmin = []
    curve_ymin = []
    curve_xmax = []
    curve_ymax = []
    from sets import Set  #UPGRADE.... the sets module is deprecated after python 2.6
    for s in surf_xmin:
        lcs = cubit.get_relatives("surface", s, "curve")
        for lc in lcs:
            curve_xmin.append(lc)
    for s in surf_xmax:
        lcs = cubit.get_relatives("surface", s, "curve")
        for lc in lcs:
            curve_xmax.append(lc)
    for s in surf_ymin:
        lcs = cubit.get_relatives("surface", s, "curve")
        for lc in lcs:
            curve_ymin.append(lc)
    for s in surf_ymax:
        lcs = cubit.get_relatives("surface", s, "curve")
        for lc in lcs:
            curve_ymax.append(lc)
    curve_xmin = list(Set(curve_xmin))
    curve_ymin = list(Set(curve_ymin))
    curve_xmax = list(Set(curve_xmax))
    curve_ymax = list(Set(curve_ymax))
    curve_bottom_xmin = select_bottom_curve(curve_xmin)
    curve_bottom_ymin = select_bottom_curve(curve_ymin)
    curve_bottom_xmax = select_bottom_curve(curve_xmax)
    curve_bottom_ymax = select_bottom_curve(curve_ymax)
    #
    return curve_bottom_xmin, curve_bottom_ymin, curve_bottom_xmax, curve_bottom_ymax
コード例 #3
0
ファイル: volumes.py プロジェクト: EtienneBachmann/specfem3d
def create_volume(surf1,surf2,method='loft'):
    if method == 'loft':
        cmd='create volume loft surface '+str(surf1)+' '+str(surf2)
        cubit.cmd(cmd)
    else:
        lcurve1=cubit.get_relatives("surface",surf1,"curve")
        lcurve2=cubit.get_relatives("surface",surf2,"curve")
        couples=coupling_curve(lcurve1,lcurve2)
        is_start=cubit.get_last_id('surface')+1
        for cs in couples:
            cmd='create surface skin curve '+str(cs[1])+' '+str(cs[0])
            cubit.cmd(cmd)
        is_stop=cubit.get_last_id('surface')
        cmd="create volume surface "+str(surf1)+' '+str(surf2)+' '+str(is_start)+' to '+str(is_stop)+"  heal keep"
        cubit.cmd(cmd)
コード例 #4
0
ファイル: volumes.py プロジェクト: zyex1108/specfem3d
def create_volume(surf1,surf2,method='loft'):
    if method == 'loft':
        cmd='create volume loft surface '+str(surf1)+' '+str(surf2)
        cubit.cmd(cmd)
    else:
        lcurve1=cubit.get_relatives("surface",surf1,"curve")
        lcurve2=cubit.get_relatives("surface",surf2,"curve")
        couples=coupling_curve(lcurve1,lcurve2)
        is_start=cubit.get_last_id('surface')+1
        for cs in couples:
            cmd='create surface skin curve '+str(cs[1])+' '+str(cs[0])
            cubit.cmd(cmd)
        is_stop=cubit.get_last_id('surface')
        cmd="create volume surface "+str(surf1)+' '+str(surf2)+' '+str(is_start)+' to '+str(is_stop)+"  heal"
        cubit.cmd(cmd)
コード例 #5
0
ファイル: mesh_volume.py プロジェクト: hejunzhu/specfem3d
def get_uv_curve(list_curve_or):
    import math
    import numpy as np
    klen={}
    for curve in list_curve_or:
      vertex_list = cubit.get_relatives("curve", curve, "vertex")
      coord0=cubit.get_center_point('vertex', vertex_list[0])
      coord1=cubit.get_center_point('vertex', vertex_list[1])
      klen[curve]=np.array(coord1)-np.array(coord0)
    #
    l0=list_curve_or[0]
    c0=klen[l0]
    angles={}
    angles[l0]=0
    for curve in list_curve_or[1:]:
      c1=klen[curve]
      angletmp=np.dot(c0,c1)/(np.dot(c0,c0)**.5*np.dot(c1,c1)**.5)
      if -1 < angletmp < 1:
        angle=math.sin(np.arccos(angletmp))
      else:
        angle=0.        
      angles[curve]=angle
    a=angles.values()
    diff=max(a)-min(a)
    ucurve=[]
    vcurve=[]
    for curve in list_curve_or:
      if -diff < angles[curve] < diff:
        ucurve.append(curve)
      else:
        vcurve.append(curve)
    #
    return ucurve,vcurve
コード例 #6
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
コード例 #7
0
ファイル: arvore.py プロジェクト: Aldaaron/ProjetoDoutorado
 def fixCurves(self):
     small = self.root.radius/100
     cvs = cubit.get_relatives("volume", self.vol, "curve")
     for x in range(0, len(cvs)):
         type1 = cubit.get_curve_type(cvs[x])
         virtual1 = cubit.is_virtual("curve", cvs[x])
         if type1 == "Ellipse curve" or type1 == "Arc curve" or virtual1 or type1 == "Spline curve":
             vts1 = cubit.get_relatives("curve", cvs[x], "vertex")
             for y in range(0, len(cvs)):
                 type2 = cubit.get_curve_type(cvs[y])
                 virtual2 = cubit.is_virtual("curve", cvs[y])
                 vts2 = cubit.get_relatives("curve", cvs[y], "vertex")
                 equal = False
                 arcEli = type2 == "Ellipse curve" or type2 == "Arc curve" or type2 == "Spline curve"
                 equal = type1 == type2 or virtual2 or (virtual1 and arcEli)
                 if equal and x != y and len(vts1) > 1 and len(vts2) > 1:
                     if vts1[0] == vts2[0] or vts1[0] == vts2[1] or vts1[1] == vts2[0] or vts1[1] == vts2[1]:
                         cubit.set_modified()
                         geo.compositeCurve(cvs[x], cvs[y])
                         if cubit.is_modified():
                             return True
                 
     return False                            
コード例 #8
0
ファイル: mesh_volume.py プロジェクト: hejunzhu/specfem3d
def curve2poly(line):
    curve=int(line)
    cubit.cmd('curve '+str(curve)+' size auto factor 1')
    cubit.cmd('mesh curve '+str(curve))
    n=cubit.get_curve_nodes(curve)
    orientnode=[]
    vertex_list = cubit.get_relatives("curve", curve, "vertex")
    if len(vertex_list) != 0:
        startnode=cubit.get_vertex_node(vertex_list[0])
        cubit.cmd('del group pgon')
        cubit.cmd("group 'pgon' add edge in node "+str(startnode))
        group1 = cubit.get_id_from_name("pgon")
        edges = list(cubit.get_group_edges(group1))
        edgestart=edges[0]
    else:
        startnode=n[0]
        cubit.cmd('del group pgon')
        cubit.cmd("group 'pgon' add edge in node "+str(startnode))
        group1 = cubit.get_id_from_name("pgon")
        edges = list(cubit.get_group_edges(group1))
        edgestart=edges[0]
    begin=startnode
    orientnode.append(begin)
    node_id_list = list(cubit.get_connectivity("edge", edgestart))
    node_id_list.remove(startnode)
    startnode=node_id_list[0]
    orientnode.append(startnode)
    stopflag=False
    while startnode != begin and not stopflag:
        cubit.cmd('del group pgon')
        cubit.cmd("group 'pgon' add edge in node "+str(startnode))
        group1 = cubit.get_id_from_name("pgon")
        edges = list(cubit.get_group_edges(group1))
        if len(edges) != 1:
            edges.remove(edgestart)
            edgestart=edges[0]
            node_id_list = list(cubit.get_connectivity("edge", edgestart))
            node_id_list.remove(startnode)
            orientnode.append(node_id_list[0])
            startnode=node_id_list[0]
        else:
            stopflag=True
    vx=[]
    vy=[]
    for n in orientnode:
        v=cubit.get_nodal_coordinates(n)
        vx.append(v[0])
        vy.append(v[1])    
    return vx,vy,orientnode
コード例 #9
0
def curver_start_end(C,dxstrt,dxend,direct='l',unit='*km'):
    Vtup = cubit.get_relatives("curve", C.id(), "vertex")
    if cubit.vertex(Vtup[1]).coordinates()[0] > cubit.vertex(Vtup[0]).coordinates()[0]:
        vr = cubit.vertex(Vtup[1])
        vl = cubit.vertex(Vtup[0])
    else:
        vr = cubit.vertex(Vtup[0])
        vl = cubit.vertex(Vtup[1])
    if direct == 'l':
        vstart = vr
    elif direct == 'r':
        vstart = vl       
    komand = "curve " + str(C.id()) + " scheme bias fine size {" + str(dxstrt) + unit + "} coarse size  {" + str(dxend) + unit + "} start vertex " + str(vstart.id())
    print komand
    cubit.silent_cmd(komand)
    return None
コード例 #10
0
def define_absorbing_surf_sphere():
    try:
        cubit.cmd('comment')
    except:
        try:
            import cubit
            cubit.init([""])
        except:
            print 'error importing cubit'
            import sys
            sys.exit()
    surf = []
    list_surf = cubit.parse_cubit_list("surface", "all")
    for s in list_surf:
        v = cubit.get_relatives('surface', s, 'volume')
        if len(v) == 1:
            surf.append(s)
    return surf
コード例 #11
0
def define_absorbing_surf_sphere():
    try:
        cubit.cmd('comment')
    except:
        try:
            import cubit
            cubit.init([""])
        except:
            print 'error importing cubit'
            import sys
            sys.exit()
    surf=[]
    list_surf=cubit.parse_cubit_list("surface","all")
    for s in list_surf:
       v=cubit.get_relatives('surface',s,'volume')
       if len(v) == 1:
           surf.append(s)
    return surf
コード例 #12
0
def curver_start_end(C, dxstrt, dxend, direct='l', unit='*km'):
    Vtup = cubit.get_relatives("curve", C.id(), "vertex")
    if cubit.vertex(Vtup[1]).coordinates()[0] > cubit.vertex(
            Vtup[0]).coordinates()[0]:
        vr = cubit.vertex(Vtup[1])
        vl = cubit.vertex(Vtup[0])
    else:
        vr = cubit.vertex(Vtup[0])
        vl = cubit.vertex(Vtup[1])
    if direct == 'l':
        vstart = vr
    elif direct == 'r':
        vstart = vl
    komand = "curve " + str(C.id()) + " scheme bias fine size {" + str(
        dxstrt) + unit + "} coarse size  {" + str(
            dxend) + unit + "} start vertex " + str(vstart.id())
    print komand
    cubit.silent_cmd(komand)
    return None
コード例 #13
0
ファイル: arvore.py プロジェクト: Aldaaron/ProjetoDoutorado
    def boundary(self):
        boundary = []
        surfs = cubit.get_relatives("volume", self.vol, "surface")
        for x in range(6, len(surfs)):
            tris = cubit.get_surface_tris(surfs[x])
            for y in range(0, len(tris)):
                nodes = cubit.get_connectivity("tri", tris[y])
                p1 = cubit.get_nodal_coordinates(nodes[0])
                p2 = cubit.get_nodal_coordinates(nodes[1])
                p3 = cubit.get_nodal_coordinates(nodes[2])
                u_0 = [p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
                u_1 = [p3[0]-p1[0],p3[1]-p1[1],p3[2]-p1[2]]
                u1 = geo2.crossProduct(u_0, u_1)
                u1 = geo2.getVector4_3(u1)
                geo2.normalizeVector(u1)
#                 if y == 0:
#                     center_point = cubit.get_center_point("tri", tris[y])
#                     cubit.cmd("create curve location %f %f %f direction %f %f %f length %f" %(center_point[0],center_point[1],center_point[2],u1[0],u1[1],u1[2],self.root.radius))
                element = [nodes[0]-1, nodes[1]-1, nodes[2]-1, u1[0], u1[1], u1[2]]
                boundary.append(element)
        return boundary
コード例 #14
0
ファイル: arvore.py プロジェクト: Aldaaron/ProjetoDoutorado
 def saveMeshPoisson(self):
     nNodes = cubit.get_node_count()
     nTets = cubit.get_tet_count()
     meshFile = open(folder+"meshPoisson.xml", 'w')
     meshFile.write('<mesh celltype="tetrahedron" dim="3">\n')
     meshFile.write('  <nodes size="%d">\n' % (nNodes))
     for x in range(0, nNodes):
         coords = cubit.get_nodal_coordinates(x+1)
         meshFile.write('    <node id="%d" x="%f" y="%f" z="%f"/>\n' % (x,coords[0],coords[1],coords[2]))
     meshFile.write('  </nodes>\n')
     meshFile.write('  <elements size="%d">\n' % (nTets))
     for x in range(0, nTets):
         nodes = cubit.get_connectivity("tet", x+1)
         meshFile.write('    <element id="%d" v0="%d" v1="%d" v2="%d" v3="%d"/>\n' % (x,nodes[0]-1,nodes[1]-1,nodes[2]-1,nodes[3]-1))
     meshFile.write('  </elements>\n')
     meshFile.write('  <boundary celltype="triangle" dim="2">\n')
     
     surfs = cubit.get_relatives("volume", self.vol, "surface")
     ec = 0
     for x in range(0, 2):
         tris = cubit.get_surface_tris(surfs[x])
         for y in range(0, len(tris)):
             nodes = cubit.get_connectivity("tri", tris[y])
             element = [nodes[0]-1, nodes[1]-1, nodes[2]-1]
             ec = ec+1
             meshFile.write('    <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec,x,element[0],element[1],element[2]))
     meshFile.write('    <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec+1,2,element[0],element[1],element[2]))
     meshFile.write('  </boundary>\n')
     
     meshFile.write('</mesh>\n')
     meshFile.write('<poisson>\n')
     meshFile.write('  <neumann>\n')
     meshFile.write('    <node id="0" marker="0" value="-1.0" />\n')
     meshFile.write('    <node id="1" marker="1" value="1.0" />\n')
     meshFile.write('  </neumann>\n')
     meshFile.write('  <dirichlet>\n')
     meshFile.write('    <node id="2" marker="2" value="0.0" />\n')
     meshFile.write('  </dirichlet>\n')
     meshFile.write('</poisson>\n')
     meshFile.close()
コード例 #15
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
コード例 #16
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
コード例 #17
0
def get_ordered_node_surf(lsurface, icurve):
    if not isinstance(lsurface, str):
        lsurf = list2str(lsurface)
    #
    if not isinstance(icurve, str):
        icurvestr = str(icurve)
    # initializes
    orient_nodes_surf = []
    nodes_curve = []
    #
    #get the nodes on a surface, I don't use the method get_surface_nodes since it has different behavior in cubit12.2 and cubit13.2+
    k = cubit.get_id_from_name('sl')
    if k != 0:
        cubit.cmd('del group sl')
    else:
        print 'initializing group sl'
    cubit.cmd("group 'sl' add node in surf " + lsurf)
    group1 = cubit.get_id_from_name("sl")
    nodes_ls = list(cubit.get_group_nodes(group1))
    nnode = len(nodes_ls)
    #
    #get the nodes on curves
    orient = []
    k = cubit.get_id_from_name('n1')
    if k != 0:
        cubit.cmd('del group n1')
    else:
        print 'initializing group n1'
    cubit.cmd("group 'n1' add node in curve " + icurvestr)
    x = cubit.get_bounding_box('curve', icurve)
    # checks if anything to do
    if len(x) == 0:
        return nodes_curve, orient_nodes_surf
    # gets nodes
    if x[2] > x[5]:
        idx = 0
    else:
        idx = 1
    group1 = cubit.get_id_from_name("n1")
    nodes1 = list(cubit.get_group_nodes(group1))
    for n in nodes1:
        v = cubit.get_nodal_coordinates(n)
        orient.append(v[idx])
    result = zip(orient, nodes1)
    result.sort()
    nodes2 = [c[1] for c in result]
    for n in nodes2:
        try:
            nodes_ls.remove(n)
        except:
            pass
    orient_nodes_surf = orient_nodes_surf + nodes2
    #
    while len(orient_nodes_surf) < nnode:
        cubit.cmd('del group n1')
        cubit.cmd("group 'n1' add node in edge in node " +
                  str(nodes2).replace('[', ' ').replace(']', ' '))
        group1 = cubit.get_id_from_name("n1")
        nodes1 = list(cubit.get_group_nodes(group1))
        orient = []
        nd = []
        for n in nodes1:
            if n in nodes_ls:
                v = cubit.get_nodal_coordinates(n)
                orient.append(v[idx])
                nd.append(n)
        result = zip(orient, nd)
        result.sort()
        nodes2 = [c[1] for c in result]
        for n in nodes2:
            try:
                nodes_ls.remove(n)
            except:
                pass
        orient_nodes_surf = orient_nodes_surf + nodes2
    #get the vertical curve
    curve_vertical = []
    for s in lsurface:
        lcs = cubit.get_relatives("surface", s, "curve")
        for l in lcs:
            x = cubit.get_bounding_box('curve', l)
            length = [(x[2], 1), (x[5], 2), (x[8], 3)]
            length.sort()
            if length[-1][1] == 3:
                curve_vertical.append(l)
    #
    kcurve = list2str(curve_vertical)
    k = cubit.get_id_from_name('curve_vertical')
    if k != 0:
        cubit.cmd('del group curve_vertical')
    else:
        print 'initializing group curve_vertical'
    cubit.cmd("group 'curve_vertical' add node in curve " + kcurve)
    group1 = cubit.get_id_from_name('curve_vertical')
    nodes_curve = list(cubit.get_group_nodes(group1))
    for n in nodes_curve:
        try:
            orient_nodes_surf.remove(n)
        except:
            pass
    #
    return nodes_curve, orient_nodes_surf
コード例 #18
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)
コード例 #19
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
コード例 #20
0
def layercake_volume_ascii_regulargrid_mpiregularmap(filename=None,
                                                     verticalsandwich=False,
                                                     onlysurface=False):
    import start as start
    #
    mpiflag, iproc, numproc, mpi = start.start_mpi()
    #
    numpy = start.start_numpy()
    cfg = start.start_cfg(filename=filename)

    from utilities import geo2utm, savegeometry, cubit_command_check

    #
    try:
        mpi.barrier()
    except:
        pass
    #
    #
    command = "comment '" + "PROC: " + str(iproc) + "/" + str(numproc) + " '"
    cubit_command_check(iproc, command, stop=True)
    if verticalsandwich:
        cubit.cmd("comment 'Starting Vertical Sandwich'")
    #
    # get icpuy,icpux values
    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

    #
    if cfg.geometry_format == 'ascii':
        # for the original surfaces
        # number of points in the files that describe the topography
        import local_volume as lvolume
        if cfg.localdir_is_globaldir:
            if iproc == 0 or not mpiflag:
                coordx_0, coordy_0, elev_0, nx_0, ny_0 = lvolume.read_grid(
                    filename)
                print 'end reading grd files ' + str(nx_0 * ny_0) + ' points'
            else:
                pass
            if iproc == 0 or not mpiflag:
                coordx = mpi.bcast(coordx_0)
            else:
                coordx = mpi.bcast()
            if iproc == 0 or not mpiflag:
                coordy = mpi.bcast(coordy_0)
            else:
                coordy = mpi.bcast()
            if iproc == 0 or not mpiflag:
                elev = mpi.bcast(elev_0)
            else:
                elev = mpi.bcast()
            if iproc == 0 or not mpiflag:
                nx = mpi.bcast(nx_0)
            else:
                nx = mpi.bcast()
            if iproc == 0 or not mpiflag:
                ny = mpi.bcast(ny_0)
            else:
                ny = mpi.bcast()
        else:
            coordx, coordy, elev, nx, ny = lvolume.read_grid(filename)
        print str(iproc) + ' end of receving grd files '
        nx_segment = int(nx / cfg.nproc_xi) + 1
        ny_segment = int(ny / cfg.nproc_eta) + 1

    elif cfg.geometry_format == 'regmesh':  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        if cfg.depth_bottom != cfg.zdepth[0]:
            if iproc == 0:
                print 'the bottom of the block is at different \
                depth than depth[0] in the configuration file'
        nx = cfg.nproc_xi + 1
        ny = cfg.nproc_eta + 1
        nx_segment = 2
        ny_segment = 2
        # if iproc == 0: print nx,ny,cfg.cpux,cfg.cpuy
        # xp = (cfg.xmax - cfg.xmin) / float((nx - 1))
        # yp = (cfg.ymax - cfg.ymin) / float((ny - 1))
        #
        if verticalsandwich:
            elev = numpy.zeros([nx, ny, cfg.nxvol], float)
        else:
            elev = numpy.zeros([nx, ny, cfg.nz], float)
        coordx = numpy.zeros([nx, ny], float)
        coordy = numpy.zeros([nx, ny], float)
        #
        #
        # length of x slide for chunk
        xlength = (cfg.xmax - cfg.xmin) / float(cfg.nproc_xi)
        # length of y slide for chunk
        ylength = (cfg.ymax - cfg.ymin) / float(cfg.nproc_eta)
        # nelem_chunk_x = 1
        # nelem_chunk_y = 1
        # ivxtot = nelem_chunk_x + 1
        # ivytot = nelem_chunk_y + 1
        # xstep = xlength  # distance between vertex on x
        # ystep = ylength
        if verticalsandwich:
            for i in range(0, cfg.nxvol):
                elev[:, :, i] = cfg.xwidth[i]
        else:
            for i in range(0, cfg.nz):
                elev[:, :, i] = cfg.zdepth[i]

        icoord = 0
        for iy in range(0, ny):
            for ix in range(0, nx):
                icoord = icoord + 1
                coordx[ix, iy] = cfg.xmin + xlength * (ix)
                coordy[ix, iy] = cfg.ymin + ylength * (iy)

        # print coordx,coordy,nx,ny
    #
    print 'end of building grid ' + str(iproc)
    print 'number of point: ', len(coordx) * len(coordy)
    #
    # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    # for each processor
    #
    nxmin_cpu = (nx_segment - 1) * (icpux)
    nymin_cpu = (ny_segment - 1) * (icpuy)
    nxmax_cpu = min(nx - 1, (nx_segment - 1) * (icpux + 1))
    nymax_cpu = min(ny - 1, (ny_segment - 1) * (icpuy + 1))
    # if iproc == 0:
    #    print nx_segment,ny_segment,nx,ny
    #    print icpux,icpuy,nxmin_cpu,nxmax_cpu
    #    print icpux,icpuy,nymin_cpu,nymax_cpu
    #    print coordx[0,0],coordx[nx-1,ny-1]
    #    print coordy[0,0],coordy[nx-1,ny-1]
    #
    #
    # icurve = 0
    isurf = 0
    # ivertex = 0
    #
    # create vertex
    if verticalsandwich:
        nlayer = cfg.nxvol
    else:
        nlayer = cfg.nz

    for inz in range(0, nlayer):
        if cfg.sea and inz == cfg.nz - 1:  # sea layer
            sealevel = True
            bathymetry = False
        elif cfg.sea and inz == cfg.nz - 2:  # bathymetry layer
            sealevel = False
            bathymetry = True
        else:
            sealevel = False
            bathymetry = False
        print sealevel, bathymetry

        if cfg.bottomflat and inz == 0:  # bottom layer
                #
            if cfg.geometry_format == 'ascii' and not verticalsandwich:
                lv = cubit.get_last_id("vertex")

                x_current, y_current = (coordx[nxmin_cpu, nymin_cpu], coordy[
                                        nxmin_cpu, nymin_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_bottom)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = (coordx[nxmin_cpu, nymax_cpu], coordy[
                                        nxmin_cpu, nymax_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_bottom)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = (coordx[nxmax_cpu, nymax_cpu], coordy[
                                        nxmax_cpu, nymax_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_bottom)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = (coordx[nxmax_cpu, nymin_cpu], coordy[
                                        nxmax_cpu, nymin_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_bottom)
                cubit.cmd(cubitcommand)
                #
                lv2 = cubit.get_last_id("vertex")

                cubitcommand = 'create surface vertex ' + \
                    str(lv + 1) + ' to ' + str(lv2)
                cubit.cmd(cubitcommand)
                #
                isurf = isurf + 1
            else:
                lv = cubit.get_last_id("vertex")
                x_current, y_current = geo2utm(coordx[nxmin_cpu, nymin_cpu],
                                               coordy[nxmin_cpu, nymin_cpu],
                                               'utm')
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_bottom)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = geo2utm(coordx[nxmin_cpu, nymax_cpu],
                                               coordy[nxmin_cpu, nymax_cpu],
                                               'utm')
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_bottom)
                cubit.cmd(cubitcommand)
                #
                if verticalsandwich:
                    x_current, y_current = geo2utm(
                        coordx[nxmin_cpu, nymax_cpu],
                        coordy[nxmin_cpu, nymax_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + ' ' + str(0)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmin_cpu, nymin_cpu],
                        coordy[nxmin_cpu, nymin_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + ' ' + str(0)
                    cubit.cmd(cubitcommand)
                else:
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymax_cpu],
                        coordy[nxmax_cpu, nymax_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + \
                        ' ' + str(cfg.depth_bottom)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymin_cpu],
                        coordy[nxmax_cpu, nymin_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + \
                        ' ' + str(cfg.depth_bottom)
                    cubit.cmd(cubitcommand)
                #
                lv2 = cubit.get_last_id("vertex")
                cubitcommand = 'create surface vertex ' + \
                    str(lv + 1) + ' to ' + str(lv2)
                cubit.cmd(cubitcommand)
                #
                isurf = isurf + 1

        elif cfg.topflat and inz == nlayer - 1:
            if cfg.geometry_format == 'ascii' and not verticalsandwich:
                lv = cubit.get_last_id("vertex")

                x_current, y_current = (coordx[nxmin_cpu, nymin_cpu], coordy[
                                        nxmin_cpu, nymin_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_top)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = (coordx[nxmin_cpu, nymax_cpu], coordy[
                                        nxmin_cpu, nymax_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_top)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = (coordx[nxmax_cpu, nymax_cpu], coordy[
                                        nxmax_cpu, nymax_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_top)
                cubit.cmd(cubitcommand)
                #
                x_current, y_current = (coordx[nxmax_cpu, nymin_cpu], coordy[
                                        nxmax_cpu, nymin_cpu])
                cubitcommand = 'create vertex ' + \
                    str(x_current) + ' ' + str(y_current) + \
                    ' ' + str(cfg.depth_top)
                cubit.cmd(cubitcommand)
                #
                lv2 = cubit.get_last_id("vertex")

                cubitcommand = 'create surface vertex ' + \
                    str(lv + 1) + ' to ' + str(lv2)
                cubit.cmd(cubitcommand)
                #
                isurf = isurf + 1
            else:
                print "top_flat is not a valid option for sandwich"

        else:
            print inz, 'layer'
            if cfg.geometry_format == 'regmesh':
                if verticalsandwich:
                    zvertex = cfg.xwidth[inz]
                    lv = cubit.get_last_id("vertex")
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymin_cpu],
                        coordy[nxmax_cpu, nymin_cpu],
                        'utm')
                    x_current = x_current + zvertex
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + \
                        ' ' + str(cfg.depth_bottom)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymax_cpu],
                        coordy[nxmax_cpu, nymax_cpu],
                        'utm')
                    x_current = x_current + zvertex
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + \
                        ' ' + str(cfg.depth_bottom)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymax_cpu],
                        coordy[nxmax_cpu, nymax_cpu],
                        'utm')
                    x_current = x_current + zvertex
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + ' ' + str(0)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymin_cpu],
                        coordy[nxmax_cpu, nymin_cpu],
                        'utm')
                    x_current = x_current + zvertex
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + str(y_current) + ' ' + str(0)
                    cubit.cmd(cubitcommand)
                else:
                    zvertex = cfg.zdepth[inz]
                    lv = cubit.get_last_id("vertex")
                    x_current, y_current = geo2utm(
                        coordx[nxmin_cpu, nymin_cpu],
                        coordy[nxmin_cpu, nymin_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + \
                        str(y_current) + ' ' + str(zvertex)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmin_cpu, nymax_cpu],
                        coordy[nxmin_cpu, nymax_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + \
                        str(y_current) + ' ' + str(zvertex)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymax_cpu],
                        coordy[nxmax_cpu, nymax_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + \
                        str(y_current) + ' ' + str(zvertex)
                    cubit.cmd(cubitcommand)
                    #
                    x_current, y_current = geo2utm(
                        coordx[nxmax_cpu, nymin_cpu],
                        coordy[nxmax_cpu, nymin_cpu],
                        'utm')
                    cubitcommand = 'create vertex ' + \
                        str(x_current) + ' ' + \
                        str(y_current) + ' ' + str(zvertex)
                    cubit.cmd(cubitcommand)
                #
                cubitcommand = 'create surface vertex ' + \
                    str(lv + 1) + ' ' + str(lv + 2) + ' ' + \
                    str(lv + 3) + ' ' + str(lv + 4)
                cubit.cmd(cubitcommand)
                #
                isurf = isurf + 1
            elif cfg.geometry_format == 'ascii':

                vertex = []

                for iy in range(nymin_cpu, nymax_cpu + 1):
                    for ix in range(nxmin_cpu, nxmax_cpu + 1):
                        zvertex = elev[ix, iy, inz]
                        x_current, y_current = (coordx[ix, iy], coordy[ix, iy])
                        #
                        vertex.append(' Position ' + str(x_current) +
                                      ' ' + str(y_current) + ' ' +
                                      str(zvertex))
                #
                print 'proc', iproc, 'vertex list created....', len(vertex)

                uline = []
                vline = []
                iv = 0

                cubit.cmd("set info off")
                cubit.cmd("set echo off")
                cubit.cmd("set journal off")

                for iy in range(0, nymax_cpu - nymin_cpu + 1):
                    positionx = ''
                    for ix in range(0, nxmax_cpu - nxmin_cpu + 1):
                        positionx = positionx + vertex[iv]
                        iv = iv + 1
                    command = 'create curve spline ' + positionx
                    cubit.cmd(command)
                    # print command
                    uline.append(cubit.get_last_id("curve"))
                for ix in range(0, nxmax_cpu - nxmin_cpu + 1):
                    positiony = ''
                    for iy in range(0, nymax_cpu - nymin_cpu + 1):
                        positiony = positiony + \
                            vertex[ix + iy * (nxmax_cpu - nxmin_cpu + 1)]
                    command = 'create curve spline ' + positiony
                    cubit.cmd(command)
                    # print command
                    vline.append(cubit.get_last_id("curve"))
                #
                cubit.cmd("set info " + cfg.cubit_info)
                cubit.cmd("set echo " + cfg.echo_info)
                cubit.cmd("set journal " + cfg.jou_info)
                #
                #
                print 'proc', iproc, 'lines created....', \
                    len(uline), '*', len(vline)
                umax = max(uline)
                umin = min(uline)
                vmax = max(vline)
                vmin = min(vline)
                ner = cubit.get_error_count()
                cubitcommand = 'create surface net u curve ' + \
                    str(umin) + ' to ' + str(umax) + ' v curve ' + \
                    str(vmin) + ' to ' + str(vmax) + ' heal'
                cubit.cmd(cubitcommand)
                ner2 = cubit.get_error_count()
                if ner == ner2:
                    command = "del curve all"
                    cubit.cmd(command)
                    isurf = isurf + 1
                else:
                    raise ValueError('error creating the surface')
                #
            else:
                raise ValueError(
                    'check geometry_format, it should be ascii or regmesh')
                #
        cubitcommand = 'del vertex all'
        cubit.cmd(cubitcommand)
    if cfg.save_surface_cubit:
        savegeometry(iproc=iproc, surf=True, filename=filename)
    #
    #
    # !create volume
    if not onlysurface:
        if nlayer == 1:
            nsurface = 2
        else:
            nsurface = nlayer
        for inz in range(1, nsurface):
            ner = cubit.get_error_count()
            create_volume(inz, inz + 1, method=cfg.volumecreation_method)
            ner2 = cubit.get_error_count()
            if ner != ner2:
                if cfg.volumecreation_method != 'loft':
                    ner = cubit.get_error_count()
                    create_volume(inz, inz + 1, method='loft')
                    ner2 = cubit.get_error_count()
                    if ner != ner2:
                        print 'ERROR creating volume'
                        break
                else:
                    print 'ERROR creating volume'
                    break
        if ner == ner2 and not cfg.debug_geometry:
            # cubitcommand= 'del surface 1 to '+ str( cfg.nz )
            cubitcommand = 'del surface all'
            cubit.cmd(cubitcommand)
            list_vol = cubit.parse_cubit_list("volume", "all")
            for v in list_vol:
                sv = cubit.get_relatives("volume", v, "surface")
                if len(sv) <= 1:
                    cubit.cmd("del vol " + str(v))
            list_vol = cubit.parse_cubit_list("volume", "all")
            if len(list_vol) > 1:
                cubitcommand = 'imprint volume all'
                cubit.cmd(cubitcommand)
                cubitcommand = 'merge all'
                cubit.cmd(cubitcommand)
            # ner=cubit.get_error_count()
            # cubitcommand= 'composite create curve in vol all'
            # cubit.cmd(cubitcommand)
    savegeometry(iproc, filename=filename)
    # if cfg.geological_imprint:
    #    curvesname=[cfg.outlinebasin_curve,cfg.transition_curve,cfg.faulttrace_curve]
    #    outdir=cfg.working_dir
    #    imprint_topography_with_geological_outline(curvesname,outdir)
    #
    #
    cubit.cmd("set info " + cfg.cubit_info)
    cubit.cmd("set echo " + cfg.echo_info)
    cubit.cmd("set journal " + cfg.jou_info)
コード例 #21
0
import os
import sys

#Domain parameters
Lx = 250
Ly = 200
depth = 50
Cx = Lx / 2
Cy = Ly / 2
mesh_size = 2.5
cubit.cmd('brick x ' + str(Lx) + ' y ' + str(Ly) + ' z ' + str(depth))
cubit.cmd('volume 1 move x ' + str(Lx / 2) + ' y ' + str(Ly / 2) + ' z ' +
          str(-depth / 2))

id_intern = cubit.get_last_id("volume")
s = cubit.get_relatives("volume", id_intern, "surface")
print s
side_xmin = []
side_xmax = []
side_ymin = []
side_ymax = []
side_zmin = []
side_xmax.append(s[5])
side_xmin.append(s[3])
side_ymax.append(s[4])
side_ymin.append(s[2])
side_zmin.append(s[1])
surf_id = s[0]

#meshing
cubit.cmd('volume all size ' + str(mesh_size))
コード例 #22
0
# torre means tower, here pile
id_torre_surf_orig = [i for i in range(nt)]
id_torre_surf = [i for i in range(4 * nt)]
#each pile is divided into 4 surfaces after imprint and merge with 4 soil layers

id_layer0 = [i for i in range(nt + 1)]
id_layer1 = [i for i in range(nt + 1)]
id_layer2 = [i for i in range(nt + 1)]
id_layer3 = [i for i in range(1)]
#sheet body are volume, though surface-like

for n in range(0, nt, 1):
    fid2.write("%04.1f\n" % (xr + dx * n))
    id_torre[n], id_torre_surf_orig[n], id_curv = add_beam(
        xr + dx * n, hr - n * dh, lr)
    c = cubit.get_relatives("volume", id_torre[n], "curve")
    bordo[n] = c[2]
    cmd = 'imprint volume ' + str(id_base0) + ' ' + str(id_base1) + ' ' + str(
        id_base2) + ' ' + str(id_base3) + ' with ' + str(id_torre[n])
    cubit.cmd(cmd)
    cmd = 'merge volume ' + str(id_base0) + ' ' + str(id_base1) + ' ' + str(
        id_base2) + ' ' + str(id_base3) + ' ' + str(id_torre[n])
    cubit.cmd(cmd)
    p = cubit.get_relatives("volume", id_torre[n], "surface")
    id_torre_surf[4 * n] = p[0]
    id_torre_surf[4 * n + 1] = p[1]
    id_torre_surf[4 * n + 2] = p[2]
    id_torre_surf[4 * n + 3] = p[3]
    cmd = 'surf ' + str(id_torre_surf[4 * n]) + ' ' + str(
        id_torre_surf[4 * n + 1]) + ' ' + str(
            id_torre_surf[4 * n + 2]) + ' ' + str(
コード例 #23
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
コード例 #24
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
コード例 #25
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
コード例 #26
0
ファイル: arvore.py プロジェクト: Aldaaron/ProjetoDoutorado
    def genSons(self, branch):
        ipr = self.points[branch.initialPoint]
        fpr = self.points[branch.finalPoint]
        fp = self.points[branch.son1.finalPoint]
        fp2 = self.points[branch.son2.finalPoint]
        lenght = geo.distance(ipr, fpr)
        t=(lenght-branch.radius)/lenght
        ref = [(1-t)*ipr[0]+t*fpr[0],((1-t)*ipr[1]+t*fpr[1]),((1-t)*ipr[2]+t*fpr[2])]
        t2=(lenght+branch.radius)/lenght
        ref2 = [(1-t2)*ipr[0]+t2*fpr[0],((1-t2)*ipr[1]+t2*fpr[1]),((1-t2)*ipr[2]+t2*fpr[2])]
        u_0 = [fp[0]-fpr[0],fp[1]-fpr[1],fp[2]-fpr[2]]
        u_1 = [fp2[0]-fpr[0],fp2[1]-fpr[1],fp2[2]-fpr[2]]
        u_2 = [ref[0]-fp2[0],ref[1]-fp2[1],ref[2]-fp2[2]]
        u1 = geo2.crossProduct(u_0, u_1)
        u1 = geo2.getVector4_3(u1)
        geo2.normalizeVector(u1)
        u2 = geo2.crossProduct(u_0, u_2)
        u2 = geo2.getVector4_3(u2)
        geo2.normalizeVector(u2)
        coords = geo2.rotateByAxis(geo2.getVector4_3(ref), geo2.getVector4_3(fpr), u1, -90)
        vAux1 = geo.createVertex(coords[0],coords[1],coords[2])
        vAP = geo.createVertex(ref2[0],ref2[1],ref2[2])
#         
        circleAux = geo.createCircleNormal2(branch.finalPoint+1,vAux1,vAux1,branch.radius,branch.index)
        v1 = geo.createVertexOnCurveFraction(circleAux, 0.25)
        v2 = geo.createVertexOnCurveFraction(circleAux, 0.75)
        geo.deleteCurve(circleAux)
        arc1 = geo.createCircleNormal2(branch.finalPoint+1, v1, v2, branch.radius, branch.index)
        arc2 = geo.createCircleNormal2(branch.finalPoint+1, v2, v1, branch.radius, branch.index)
        vts1 = cubit.get_relatives("curve", arc1, "vertex")
        vts2 = cubit.get_relatives("curve", arc2, "vertex")
        l1 = geo.createLine(vts1[0], vts1[1])
        #l2 = geo.createLine(vts2[0], vts2[1])
        t=(lenght-branch.radius*1)/lenght
        u_3 = [cubit.vertex(vts1[0]).coordinates()[0]-cubit.vertex(vts1[1]).coordinates()[0],cubit.vertex(vts1[0]).coordinates()[1]-cubit.vertex(vts1[1]).coordinates()[1],cubit.vertex(vts1[0]).coordinates()[2]-cubit.vertex(vts1[1]).coordinates()[2]]
        u3 = geo2.getVector4_3(u_3)
        geo2.normalizeVector(u3)
        refE1 = [(1-t)*ipr[0]+t*fpr[0],((1-t)*ipr[1]+t*fpr[1]),((1-t)*ipr[2]+t*fpr[2])]
        coords = geo2.rotateByAxis(geo2.getVector4_3(refE1), geo2.getVector4_3(fpr), u3, 90)
        vE = geo.createVertex(coords[0],coords[1],coords[2])
        mid = geo.createVertexOnCurveFraction(l1, 0.5)
        eli = geo.createEllipseFull(vts1[0], vE, mid)
        eli1 = geo.splitCurve2(eli, vts1[0], vts1[1])
        eli2 = eli1-1
        
        e1 = geo.createEllipse(vts1[0], vAP, branch.finalPoint+1)
        e2 = geo.createEllipse(vts1[1], vAP, branch.finalPoint+1)
        e3 = geo.createCombineCurve([e1,e2])
        #e3 = geo.createSpline(vts1[0], vAP, vts1[1])
        
        circleI = branch.circleF
        
        uaux = cubit.vertex(v1).coordinates() 
        uaux2 = cubit.vertex(v2).coordinates() 
        u = [uaux2[0]-uaux[0],uaux2[1]-uaux[1],uaux2[2]-uaux[2]]
        u = geo2.getVector4_3(u)
        geo2.normalizeVector(u)
        ip = self.points[branch.son1.initialPoint]
        fp = self.points[branch.son1.finalPoint]
        fps = self.points[branch.son1.son1.finalPoint]
        lenght = geo.distance(ip, fp)
        t=(lenght-branch.son1.radius)/lenght
        ref = [(1-t)*ip[0]+t*fp[0],((1-t)*ip[1]+t*fp[1]),((1-t)*ip[2]+t*fp[2])]
        arcsf1 = self.genArc2(branch.son1, branch.son1.finalPoint+1,ref,u1,branch.son1.radius,1)
        branch.son1.circleI = circleI
        branch.son1.circleF = arcsf1[2]
        branch.son1.link = arcsf1[2]
        branch.son1.tube = Tube([arc1,e3], arcsf1)
        branch.son1.tube.line = l1
        
        ip = self.points[branch.son2.initialPoint]
        fp = self.points[branch.son2.finalPoint]
        fps = self.points[branch.son2.son1.finalPoint]
        lenght = geo.distance(ip, fp)
        t=(lenght-branch.son2.radius)/lenght
        ref = [(1-t)*ip[0]+t*fp[0],((1-t)*ip[1]+t*fp[1]),((1-t)*ip[2]+t*fp[2])]
        arcsf2 = self.genArc2(branch.son2, branch.son2.finalPoint+1,ref,u1,branch.son2.radius,2)
        branch.son2.circleI = circleI
        branch.son2.circleF = arcsf2[2]
        branch.son2.link = arcsf2[2]
        branch.son2.tube = Tube([arc2,e3], arcsf2)
        branch.son2.tube.line = l1
コード例 #27
0
ファイル: arvore.py プロジェクト: Aldaaron/ProjetoDoutorado
    def saveMesh(self):
        nNodes = cubit.get_node_count()
        nTets = cubit.get_tet_count()
        meshFile = open(folder+"Cubo.xml", 'w')
        meshFile.write('<mesh celltype="tetrahedron" dim="3">\n')
        meshFile.write('  <nodes size="%d">\n' % (nNodes))
        for x in range(0, nNodes):
            coords = cubit.get_nodal_coordinates(x+1)
            meshFile.write('    <node id="%d" x="%f" y="%f" z="%f"/>\n' % (x,coords[0],coords[1],coords[2]))
        meshFile.write('  </nodes>\n')
        
        meshFile.write('  <elements size="%d">\n' % (nTets))
        for x in range(0, nTets):
            nodes = cubit.get_connectivity("tet", x+1)
            meshFile.write('    <element id="%d" v0="%d" v1="%d" v2="%d" v3="%d"/>\n' % (x,nodes[0]-1,nodes[1]-1,nodes[2]-1,nodes[3]-1))
        meshFile.write('  </elements>\n')
        meshFile.write('  <element_data type="fiber_transversely_isotropic">\n')
        for x in range(0, nTets):
            meshFile.write('    <element id="%d">\n' %(x))
            meshFile.write('      <fiber>1.000000,0.000000,0.000000</fiber>\n')
            meshFile.write('    </element>\n')
        meshFile.write('  </element_data>\n')
        
        meshFile.write('  <boundary celltype="triangle" dim="2">\n')
        bsurfs = cubit.get_relatives("volume", self.vol, "surface")
        ec = 0
        for x in range(0, len(bsurfs)):
        #for x in range(6, len(bsurfs)):
            #if x is not 16 and x is not 14:
            tris = cubit.get_surface_tris(bsurfs[x])
            surf = cubit.surface(bsurfs[x])
            for y in range(0, len(tris)):
                cp = cubit.get_center_point("tri", tris[y])
                norm = surf.normal_at([cp[0],cp[1],cp[2]])
                #cubit.cmd("create curve location %f %f %f direction %f %f %f length %f" % (cp[0],cp[1],cp[2],norm[0],norm[1],norm[2],200))

                nodes = cubit.get_connectivity("tri", tris[y])
                element = [nodes[0]-1, nodes[1]-1, nodes[2]-1]
                meshFile.write('    <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d" nx="%f" ny="%f" nz="%f"/>\n' % (ec,1.0,element[0],element[1],element[2],norm[0],norm[1],norm[2]))
                ec = ec+1
        meshFile.write('  </boundary>\n')

        
        
        #meshFile.write('  <boundary celltype="triangle" dim="2">\n')
        #surfs = cubit.get_relatives("volume", self.vol, "surface")
        #ec = 0
        #for x in range(0, 2):
        #    tris = cubit.get_surface_tris(surfs[x])
        #    for y in range(0, len(tris)):
        #        nodes = cubit.get_connectivity("tri", tris[y])
        #        element = [nodes[0]-1, nodes[1]-1, nodes[2]-1]
        #        ec = ec+1
        #        meshFile.write('    <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec,x,element[0],element[1],element[2]))
        #meshFile.write('    <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec+1,2,element[0],element[1],element[2]))
        #meshFile.write('  </boundary>\n')
        
        meshFile.write('</mesh>\n')
        meshFile.write('<poisson>\n')
        meshFile.write('  <neumann>\n')
        #meshFile.write('    <node id="0" marker="0" value="-1.0" />\n')
        meshFile.write('    <node id="1" marker="1" value="0.05"/>\n')
        meshFile.write('  </neumann>\n')
        #meshFile.write('  <dirichlet>\n')
        #meshFile.write('    <node id="2" marker="2" value="0.0" />\n')
        #meshFile.write('  </dirichlet>\n')
        meshFile.write('</poisson>\n')
        
        #meshFile.write('<electrophysiology>\n')
        #meshFile.write('  <stimuli number="1">\n')
        #bb = cubit.get_bounding_box("volume", self.vol)
        #x0 = bb[0]
        #x1 = 0.8*x0 + 0.2*bb[1]
        #y0 = bb[3]
        #y1 = 0.8*y0 + 0.2*bb[4]
        #z0 = bb[6]
        #z1 = 0.8*z0 + 0.2*bb[7]
        #meshFile.write('    <stim start="0.00" duration="4.00" value="-35.7140" x0="%f" x1="%f" y0="%f" y1="%f" z0="%f" z1="%f" />\n' % (x0,x1,y0,y1,z0,z1))
        #meshFile.write('  </stimuli>\n')
        #meshFile.write('</electrophysiology>\n')
        meshFile.close()
コード例 #28
0
def get_ordered_node_surf(lsurface,icurve):
    if not isinstance(lsurface,str):
        lsurf=list2str(lsurface)
    #
    if not isinstance(icurve,str):
        icurvestr=str(icurve)
    orient_nodes_surf=[]
    #
    #get the nodes on a surface, I don't use the method get_surface_nodes since it has different behavior in cubit12.2 and cubit13.2+
    k=cubit.get_id_from_name('sl')
    if k!=0:
        cubit.cmd('del group sl')
    else:
        print 'initializing group sl'
    cubit.cmd("group 'sl' add node in surf "+lsurf)
    group1 = cubit.get_id_from_name("sl")
    nodes_ls =list(cubit.get_group_nodes(group1))
    nnode=len(nodes_ls)
    #
    #get the nodes on curves
    orient=[]
    k=cubit.get_id_from_name('n1')
    if k!=0:
        cubit.cmd('del group n1')
    else:
        print 'initializing group n1'
    cubit.cmd("group 'n1' add node in curve "+icurvestr)
    x=cubit.get_bounding_box('curve', icurve)
    if x[2]>x[5]:
        idx=0
    else:
        idx=1
    group1 = cubit.get_id_from_name("n1")
    nodes1 = list(cubit.get_group_nodes(group1))
    for n in nodes1:
        v = cubit.get_nodal_coordinates(n)
        orient.append(v[idx])
    result=zip(orient,nodes1)
    result.sort()
    nodes2=[c[1] for c in result]
    for n in nodes2:
        try:
            nodes_ls.remove(n)
        except:
            pass
    orient_nodes_surf=orient_nodes_surf+nodes2
    #
    while len(orient_nodes_surf) < nnode:
        cubit.cmd('del group n1')
        cubit.cmd("group 'n1' add node in edge in node "+str(nodes2).replace('[',' ').replace(']',' '))
        group1 = cubit.get_id_from_name("n1")
        nodes1 = list(cubit.get_group_nodes(group1))
        orient=[]
        nd=[]
        for n in nodes1:
            if n in nodes_ls:
                v = cubit.get_nodal_coordinates(n)
                orient.append(v[idx])
                nd.append(n)
        result=zip(orient,nd)
        result.sort()
        nodes2=[c[1] for c in result]
        for n in nodes2:
            try:
                nodes_ls.remove(n)
            except:
                pass
        orient_nodes_surf=orient_nodes_surf+nodes2
    #get the vertical curve
    curve_vertical=[]
    for s in lsurface:
        lcs=cubit.get_relatives("surface",s,"curve")
        for l in lcs:
            x=cubit.get_bounding_box('curve', l)
            length=[(x[2],1),(x[5],2),(x[8],3)]
            length.sort()
            if length[-1][1] == 3:
                curve_vertical.append(l)
    #
    kcurve=list2str(curve_vertical)
    k=cubit.get_id_from_name('curve_vertical')
    if k!=0:
        cubit.cmd('del group curve_vertical')
    else:
        print 'initializing group curve_vertical'
    cubit.cmd("group 'curve_vertical' add node in curve "+kcurve)
    group1 = cubit.get_id_from_name('curve_vertical')
    nodes_curve = list(cubit.get_group_nodes(group1))
    for n in nodes_curve:
        try:
            orient_nodes_surf.remove(n)
        except:
            pass
    #
    return nodes_curve,orient_nodes_surf
コード例 #29
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
コード例 #30
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
コード例 #31
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
    if cubit.get_relatives('curve', icurve, 'volume') > 36:
        if np.abs(l - r1) < 0.01 or np.abs(l - r2) < 0.01 or np.abs(l -
                                                                    r3) < 0.01:
            cubit.cmd('curve %i interval 6' % icurve)

for ivol in cubit.get_entities('volume'):
    for icurve in cubit.get_relatives('volume', ivol, 'curve'):
        v = [
            cubit.vertex(ivertex)
            for ivertex in cubit.get_relatives('curve', icurve, 'vertex')
        ]
        if len(v) == 2:
            x0, y0, z0 = v[0].coordinates()
            x1, y1, z1 = v[1].coordinates()
            if np.abs(x0 - x1) < 0.01 and np.abs(y0 - y1) < 0.01:
                z = 0.5 * (z0 + z1)
コード例 #32
0
cubit.cmd("Graphics Pause")
(OUTSIDE_3D,
 GRAINS_3D) = pymef90.PacmanCoinCrystalCreate(R, r, lz, thetac, xc, ngrains)
cubit.cmd("Display")
###
### imprint and merge
###
#for i in range(len(GRAINS_3D)):
#    cubit.cmd("imprint volume in OUTSIDE_3D with volume in Grain%i" % (i-1))
cubit.cmd("imprint all")
cubit.cmd("merge all")
###
### find edges of the domain and create nodesets
###
allcurves = []
allcurves.extend(cubit.get_relatives("volume", OUTSIDE_3D, "curve"))
for grain in GRAINS_3D:
    for vol in grain:
        allcurves.extend(cubit.get_relatives("volume", vol, "curve"))
alledges = [
    c for c in allcurves if len(cubit.get_relatives("curve", c, "volume")) == 1
]
for e in alledges:
    cubit.cmd('group "ALLEDGES" add curve %i' % e)
cubit.cmd("nodeset 1 curve with z_min>0 in ALLEDGES")
cubit.cmd("delete ALLEDGES")
cubit.cmd("nodeset 1 remove curve with z_min>0 and x_max=%f" % R)
cubit.cmd("nodeset 2 curve with z_min>0 and x_max=%f" % R)
###
### create element blocks
###
コード例 #33
0
ファイル: mesh_volume.py プロジェクト: ZQiwen/specfem3d
def mesh_layercake_regularmap(filename=None):

    import start as start
    mpiflag, iproc, numproc, mpi = start.start_mpi()
    from utilities import importgeometry, savemesh, get_v_h_list
    from utilities import cubit_command_check, get_cubit_version
    #
    # numpy = start.start_numpy()
    cfg = start.start_cfg(filename=filename)
    # from math import sqrt

    version_cubit = get_cubit_version()

    list_vol = cubit.parse_cubit_list("volume", "all")
    if len(list_vol) != 0:
        pass
    else:
        geometryfile = 'geometry_vol_' + str(iproc) + '.cub'
        importgeometry(geometryfile, iproc=iproc)

    command = 'composite create curve all'
    cubit.cmd(command)
    print('###"No valid composites can be created from the specified curves." \
          is NOT a critical ERROR.')
    #
    command = "compress all"
    cubit.cmd(command)
    list_vol = cubit.parse_cubit_list("volume", "all")
    nvol = len(list_vol)
    vol = []
    for id_vol in list_vol:
        p = cubit.get_center_point("volume", id_vol)
        vol.append(cubitvolume(id_vol, 1, p[2], 0))
    vol.sort(by_z)
    #
    for id_vol in range(0, nvol):
        vol[id_vol].intervalv = cfg.iv_interval[id_vol]
    #
    #
    surf_vertical = []
    surf_or = []
    # top_surface = 0
    # top_surface_add = ''
    # bottom_surface = 0
    # #
    # zmin_box = cubit.get_total_bounding_box("volume", list_vol)[6]
    # xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0]
    # xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1]
    # ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3]
    # ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4]
    #
    #
    # interval assignement
    surf_or, surf_vertical, list_curve_or, list_curve_vertical, \
        bottom, top = get_v_h_list(list_vol, chktop=cfg.chktop)
    print('vertical surfaces: ', surf_vertical)

    for k in surf_vertical:
        command = "surface " + str(k) + " scheme submap"
        cubit.cmd(command)
    for k in surf_or:
        command = "surface " + str(k) + " scheme " + cfg.or_mesh_scheme
        cubit.cmd(command)
    #
    ucurve, vcurve = get_uv_curve(list_curve_or)
    schemepave = False
    #
    ucurve_interval = {}
    for k in ucurve:
        length = cubit.get_curve_length(k)
        interval = int(2 * round(.5 * length / cfg.size, 0))
        ucurve_interval[k] = interval
        command = "curve " + str(k) + " interval " + str(interval)
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)
        command = "curve " + str(k) + " scheme equal"
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)
    if max(ucurve_interval.values()) != min(ucurve_interval.values()):
        schemepave = True
        print('mesh scheme is set to pave')
        for sk in surf_or:
            command = "surface " + str(sk) + " scheme pave"
            cubit.cmd(command)
    #
    vcurve_interval = {}
    for k in vcurve:
        length = cubit.get_curve_length(k)
        interval = int(2 * round(.5 * length / cfg.size, 0))
        vcurve_interval[k] = interval
        command = "curve " + str(k) + " interval " + str(interval)
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)
        command = "curve " + str(k) + " scheme equal"
        cubit.cmd(command)
        # cubit_error_stop(iproc,command,ner)

    if max(vcurve_interval.values()) != min(vcurve_interval.values()):
        print('mesh scheme is set to pave')
        schemepave = True
        for sk in surf_or:
            command = "surface " + str(sk) + " scheme pave"
            cubit.cmd(command)
    #
    for s in surf_vertical:
        lcurve = cubit.get_relatives("surface", s, "curve")
        interval_store = []
        for k in lcurve:
            interval_curve = cubit.get_mesh_intervals('curve', k)
            if k in list_curve_vertical:
                volume_id = cubit.get_owning_volume("curve", k)
                for idv in range(0, nvol):
                    if vol[idv].ID == volume_id:
                        int_v = vol[idv].intervalv
                command = "curve " + str(k) + " interval " + str(int_v)
                cubit.cmd(command)
                # cubit_error_stop(iproc,command,ner)
                command = "curve " + str(k) + " scheme equal"
                cubit.cmd(command)
                # cubit_error_stop(iproc,command,ner)
            else:
                interval_store.append((k, interval_curve))
            if len(interval_store) != 0:
                interval_min = min([iv[1] for iv in interval_store])
                str_interval = [str(iv[0]) for iv in interval_store]
                cmd = "curve " + ' '.join(str_interval) + \
                      " interval " + str(interval_min)
                cubit.cmd(cmd)
                command = "curve " + \
                    ' '.join(str(iv[0])
                             for iv in interval_store) + " scheme equal"
                cubit.cmd(command)
        command = "surface " + str(s) + " scheme submap"
        cubit.cmd(command)

    # meshing
    if cfg.or_mesh_scheme == 'pave' or schemepave:
        command = 'mesh surf ' + ' '.join(str(t) for t in top)
        status = cubit_command_check(iproc, command, stop=True)
        # cubit.cmd(command)
    elif cfg.or_mesh_scheme == 'map':
        command = 'mesh surf ' + ' '.join(str(t) for t in bottom)
        status = cubit_command_check(iproc, command, stop=True)
        # cubit.cmd(command)
    for id_volume in range(nvol - 1, -1, -1):
        command = "mesh vol " + str(vol[id_volume].ID)
        status = cubit_command_check(iproc, command, stop=False)
        if not status:
            for s in surf_vertical:
                command_surf = "mesh surf " + str(s)
                cubit.cmd(command_surf)
            if version_cubit < 16:
                command_set_meshvol = '''volume all redistribute nodes on
                volume all autosmooth target off
                volume all scheme Sweep Vector 0 0 -1
                volume all sweep smooth Auto
                '''
            else:
                command_set_meshvol = '''volume all redistribute nodes on
                volume all autosmooth target off
                volume all scheme Sweep Vector 0 0 -1
                '''
            status2 = cubit_command_check(
                iproc, command_set_meshvol, stop=False)
            status2 = cubit_command_check(iproc, command, stop=False)
            if not status2:
                _surf = cubit.get_relatives(
                    'volume', vol[id_volume].ID, 'surface')
                local_o_surf = [x for x in _surf if x in surf_or]
                cubit.cmd('volume ' + str(vol[id_volume].ID) +
                          ' redistribute nodes off')
                cubit.cmd('volume ' + str(vol[id_volume].ID) +
                          ' scheme Sweep  source surface ' +
                          ' '.join(str(x) for x in local_o_surf[0:-1]) +
                          ' target surface ' + str(local_o_surf[-1]))
                cubit.cmd('volume ' + str(vol[id_volume].ID) +
                          ' autosmooth_target off')
                status = cubit_command_check(iproc, command, stop=True)

    #
    # smoothing
    print(iproc, 'untangling...')
    cmd = "volume all smooth scheme untangle beta 0.02 cpu 10"
    cubit.cmd(cmd)
    cmd = "smooth volume all"
    cubit.cmd(cmd)

    if cfg.smoothing:
        print('smoothing .... ' + str(cfg.smoothing))
        cubitcommand = 'surf all smooth scheme laplacian '
        cubit.cmd(cubitcommand)
        cubitcommand = 'smooth surf all'
        cubit.cmd(cubitcommand)
        #
        cubitcommand = 'vol all smooth scheme laplacian '
        cubit.cmd(cubitcommand)
        cubitcommand = 'smooth vol all'
        cubit.cmd(cubitcommand)
    #
    #
    # vertical refinement
    # for nvol = 3
    ##
    # ___________________________ interface 4
    ##
    # vol 2
    # ___________________________ interface 3
    ##
    # vol 1
    # ___________________________ interface 2
    ##
    # vol 0
    # ___________________________ interface 1
    ##
    refinement(nvol, vol, filename=filename)
    #
    # top layer vertical coarsening
    print('coarsening top layer... ', cfg.coarsening_top_layer)
    if cfg.coarsening_top_layer:
        cubitcommand = 'del mesh vol ' + str(vol[-1].ID) + ' propagate'
        cubit.cmd(cubitcommand)
        s1 = set(list_curve_vertical)
        command = "group 'list_curve_tmp' add curve " + \
            "in vol " + str(vol[-1].ID)
        cubit.cmd(command)
        group = cubit.get_id_from_name("list_curve_tmp")
        list_curve_tmp = cubit.get_group_curves(group)
        command = "delete group " + str(group)
        cubit.cmd(command)
        s2 = set(list_curve_tmp)
        lc = list(s1 & s2)
        #
        cubitcommand = 'curve ' + \
            ' '.join(str(x) for x in lc) + ' interval ' + \
            str(cfg.actual_vertical_interval_top_layer)
        cubit.cmd(cubitcommand)
        cubitcommand = 'mesh vol ' + str(vol[-1].ID)
        cubit.cmd(cubitcommand)
    #
    n = cubit.get_sideset_id_list()
    if len(n) != 0:
        command = "del sideset all"
        cubit.cmd(command)
    n = cubit.get_block_id_list()
    if len(n) != 0:
        command = "del block all"
        cubit.cmd(command)
    #
    import boundary_definition
    entities = ['face']
    print(iproc, 'hex block definition...')
    boundary_definition.define_bc(entities, parallel=True,
                                  cpux=cfg.cpux, cpuy=cfg.cpuy,
                                  cpuxmin=0, cpuymin=0, optionsea=False)
    # save mesh

    print(iproc, 'untangling...')
    cmd = "volume all smooth scheme untangle beta 0.02 cpu 10"
    cubit.cmd(cmd)
    cmd = "smooth volume all"
    cubit.cmd(cmd)

    print(iproc, 'saving...')
    savemesh(mpiflag, iproc=iproc, filename=filename)