コード例 #1
0
ファイル: rubik_cube.py プロジェクト: GregVernon/anteater
def main(linear_number_grains, grain_size, num_elements_grain):
    ## Create the brick and move the back corner to the origin
    cubit.cmd("create brick x " + str(linear_number_grains * grain_size))
    cubit.cmd("move vertex 7 location 0 0 0 include_merged")
    xmin, xmax, xrange, ymin, ymax, yrange, zmin, zmax, zrange, diagMeasure = cubit.get_bounding_box(
        "volume", 1)

    ## Create the boundary conditions
    cubit.cmd("sideset 100 surface 3")
    cubit.cmd('sideset 100 name "bottom"')
    cubit.cmd("sideset 200 surface 4")
    cubit.cmd('sideset 200 name "left"')
    cubit.cmd("sideset 300 surface 2")
    cubit.cmd('sideset 300 name "back"')
    cubit.cmd("sideset 400 surface 5")
    cubit.cmd('sideset 400 name "top"')
    cubit.cmd("sideset 500 surface 6")
    cubit.cmd('sideset 500 name "right"')
    cubit.cmd("sideset 600 surface 1")
    cubit.cmd('sideset 600 name "front"')

    ## Webcut sections to make the grains
    for i in range(0, linear_number_grains):
        cubit.cmd("webcut volume all with plane xplane offset " +
                  str(grain_size * (i + 1)))
        cubit.cmd("webcut volume all with plane yplane offset " +
                  str(grain_size * (i + 1)))
        cubit.cmd("webcut volume all with plane zplane offset " +
                  str(grain_size * (i + 1)))

    cubit.cmd("imprint all")
    cubit.cmd("merge all")

    ## check visually that all interior surfaces are merged
    cubit.cmd("draw surf with is_merged")

    ## Set mesh up
    cubit.cmd("volume all scheme submap")
    cubit.cmd("volume all size " + str(grain_size / num_elements_grain))
    cubit.cmd("mesh volume all")

    ## Create a separate block for each grain
    VOL = cubit.get_entities("volume")
    for i in range(0, len(VOL)):
        cubit.cmd("Block " + str(i + 1) + " Volume " + str(i + 1))

    cubit.cmd("block all element type HEX8")

    ## And now save the generated mesh
    cubit.cmd(
        'export mesh "~/projects/anteater/problems/geom/rubik_polyxtal.e" dimension 3 block all overwrite'
    )
コード例 #2
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
コード例 #3
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
コード例 #4
0
def define_absorbing_surf():
    """
    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
    where
    absorbing_surf is the list of all the absorbing boundary surf
    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
    ...
    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
    """
    try:
        cubit.cmd('comment')
    except:
        try:
            import cubit
            cubit.init([""])
        except:
            print 'error importing cubit'
            import sys
            sys.exit()
    absorbing_surf=[]
    absorbing_surf_xmin=[]
    absorbing_surf_xmax=[]
    absorbing_surf_ymin=[]
    absorbing_surf_ymax=[]
    absorbing_surf_bottom=[]
    top_surf=[]


    list_vol=cubit.parse_cubit_list("volume","all")
    init_n_vol=len(list_vol)
    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
    list_surf=cubit.parse_cubit_list("surface","all")
#    for k in list_surf:
#        center_point = cubit.get_center_point("surface", k)
#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
#             absorbing_surf_xmin.append(k)
#             absorbing_surf.append(k)
#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
#             absorbing_surf_xmax.append(k)
#             absorbing_surf.append(k)
#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
#             absorbing_surf_ymin.append(k)
#             absorbing_surf.append(k)
#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
#             absorbing_surf_ymax.append(k)
#             absorbing_surf.append(k)
#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
#             absorbing_surf_bottom.append(k)
#             absorbing_surf.append(k)
#        else:
#            sbox=cubit.get_bounding_box('surface',k)
#            dz=abs((sbox[7] - zmax_box)/zmax_box)
#            normal=cubit.get_surface_normal(k)
#            zn=normal[2]
#            dn=abs(zn-1)
#            if dz <= 0.001 and dn < 0.2:
#                top_surf.append(k)

    #box lengths
    x_len = abs( xmax_box - xmin_box)
    y_len = abs( ymax_box - ymin_box)
    z_len = abs( zmax_box - zmin_box)

    print '##boundary box: '
    print '##  x length: ' + str(x_len)
    print '##  y length: ' + str(y_len)
    print '##  z length: ' + str(z_len)

    # tolerance parameters
    absorbing_surface_distance_tolerance=0.005
    topographic_surface_distance_tolerance=0.001
    topographic_surface_normal_tolerance=0.2

    for k in list_surf:
        center_point = cubit.get_center_point("surface", k)
        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
             absorbing_surf_xmin.append(k)
             absorbing_surf.append(k)
        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
             absorbing_surf_xmax.append(k)
             absorbing_surf.append(k)
        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
             absorbing_surf_ymin.append(k)
             absorbing_surf.append(k)
        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
             absorbing_surf_ymax.append(k)
             absorbing_surf.append(k)
        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
             absorbing_surf_bottom.append(k)
             absorbing_surf.append(k)
        else:
            sbox=cubit.get_bounding_box('surface',k)
            dz=abs((sbox[7] - zmax_box)/z_len)
            normal=cubit.get_surface_normal(k)
            zn=normal[2]
            dn=abs(zn-1)
            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
                top_surf.append(k)

    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
コード例 #5
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
コード例 #6
0
ファイル: arvore.py プロジェクト: Aldaaron/ProjetoDoutorado
    def saveMesh2D2(self):
        cubit.cmd("create surface rectangle width 5000 height 5000 zplane")
        cubit.cmd("create surface rectangle width 1000 height 1000 zplane")
        cubit.cmd("subtract body 2 from body 1")
        surfID = cubit.get_last_id("surface")
        cubit.cmd("surface all size auto factor 4")
        cubit.cmd("surface all scheme TriMesh")
        cubit.cmd("mesh surface all") 
        
        nNodes = cubit.get_node_count()
        meshFile = open(folder+"mesh2D2.xml", 'w')
        meshFile.write('<mesh celltype="triangle" dim="2">\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')
        

        tris = cubit.get_surface_tris(surfID)
        meshFile.write('  <elements size="%d">\n' % (len(tris)))
        for x in range(0, len(tris)):
            nd = cubit.get_connectivity("tri", tris[x])
            meshFile.write('    <element id="%d" v0="%d" v1="%d" v2="%d"/>\n' % (x,nd[0]-1,nd[1]-1,nd[2]-1))
        meshFile.write('  </elements>\n')
        meshFile.write('  <element_data type="fiber_transversely_isotropic">\n')
        for x in range(0, len(tris)):
            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="line" dim="1">\n')
        
        eds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

        ec = 1
        surf = cubit.surface(surfID)
        
        for y in range(0, len(eds)):
            nodes = cubit.get_connectivity("edge", eds[y])
            element = [nodes[0]-1, nodes[1]-1]
            #cp = cubit.get_center_point("edge", eds[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))
            #ec = ec+1
            #meshFile.write('    <element id="%d" marker="%d" v0="%d" v1="%d" nx="%f" ny="%f" nz="%f"/>\n' % (ec,1,element[0],element[1], norm[0], norm[1], norm[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="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.write('<electrophysiology>\n')
        meshFile.write('  <stimuli number="1">\n')
        bb = cubit.get_bounding_box("surface", surfID)
        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" />\n' % (x0,x1,y0,y1))
        meshFile.write('  </stimuli>\n')
        meshFile.write('</electrophysiology>\n')
        meshFile.close()
コード例 #7
0
def define_parallel_absorbing_surf():
    """
    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
    where
    absorbing_surf is the list of all the absorbing boundary surf
    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
    ...
    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
    """
    try:
        cubit.cmd('comment')
    except:
        try:
            import cubit
            cubit.init([""])
        except:
            print 'error importing cubit'
            import sys
            sys.exit()
    absorbing_surf_xmin = []
    absorbing_surf_xmax = []
    absorbing_surf_ymin = []
    absorbing_surf_ymax = []
    absorbing_surf_bottom = []
    top_surf = []

    list_vol = cubit.parse_cubit_list("volume", "all")
    init_n_vol = len(list_vol)
    zmax_box = cubit.get_total_bounding_box("volume", list_vol)[7]
    zmin_box = cubit.get_total_bounding_box(
        "volume", list_vol
    )[6]  #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
    xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0]
    xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1]
    ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3]
    ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4]
    list_surf = cubit.parse_cubit_list("surface", "all")
    print '##boundary box: '
    print '##  x min: ' + str(xmin_box)
    print '##  y min: ' + str(ymin_box)
    print '##  z min: ' + str(zmin_box)
    print '##  x max: ' + str(xmax_box)
    print '##  y max: ' + str(ymax_box)
    print '##  z max: ' + str(zmax_box)

    #box lengths
    x_len = abs(xmax_box - xmin_box)
    y_len = abs(ymax_box - ymin_box)
    z_len = abs(zmax_box - zmin_box)

    print '##boundary box: '
    print '##  x length: ' + str(x_len)
    print '##  y length: ' + str(y_len)
    print '##  z length: ' + str(z_len)

    # tolerance parameters
    absorbing_surface_distance_tolerance = 0.005
    topographic_surface_distance_tolerance = 0.001
    topographic_surface_normal_tolerance = 0.2

    for k in list_surf:
        center_point = cubit.get_center_point("surface", k)
        if abs((center_point[0] - xmin_box) /
               x_len) <= absorbing_surface_distance_tolerance:
            absorbing_surf_xmin.append(k)
        elif abs((center_point[0] - xmax_box) /
                 x_len) <= absorbing_surface_distance_tolerance:
            absorbing_surf_xmax.append(k)
        elif abs((center_point[1] - ymin_box) /
                 y_len) <= absorbing_surface_distance_tolerance:
            absorbing_surf_ymin.append(k)
        elif abs((center_point[1] - ymax_box) /
                 y_len) <= absorbing_surface_distance_tolerance:
            absorbing_surf_ymax.append(k)
        elif abs((center_point[2] - zmin_box) /
                 z_len) <= absorbing_surface_distance_tolerance:
            print 'center_point[2]' + str(center_point[2])
            print 'kz:' + str(k)
            absorbing_surf_bottom.append(k)

        else:
            sbox = cubit.get_bounding_box('surface', k)
            dz = abs((sbox[7] - zmax_box) / z_len)
            normal = cubit.get_surface_normal(k)
            zn = normal[2]
            dn = abs(zn - 1)
            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
                top_surf.append(k)

    return absorbing_surf_xmin, absorbing_surf_xmax, absorbing_surf_ymin, absorbing_surf_ymax, absorbing_surf_bottom, top_surf
コード例 #8
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
コード例 #9
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
コード例 #10
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
コード例 #11
0
def define_surf(ip=0,cpuxmin=0,cpuxmax=1,cpuymin=0,cpuymax=1,cpux=1,cpuy=1):
    """
    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
    where
    absorbing_surf is the list of all the absorbing boundary surf
    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
    ...
    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
    """
    from utilities import get_v_h_list
    #
    from sets import Set
    def product(*args, **kwds):
        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
        # for compatibility with python2.5
        pools = map(tuple, args) * kwds.get('repeat', 1)
        result = [[]]
        for pool in pools:
            result = [x+[y] for x in result for y in pool]
        return result
    absorbing_surf=[]
    xmin=[]
    xmax=[]
    ymin=[]
    ymax=[]
    #
    top_surf=[]
    bottom_surf=[]
    list_vol=cubit.parse_cubit_list("volume","all")
    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
    list_surf=cubit.parse_cubit_list("surface","all")

    absorbing_surface_distance_tolerance=0.001
    topographic_surface_distance_tolerance=0.1
    topographic_surface_normal_tolerance=0.4

    lv=[]
    for k in list_surf:
        sbox=cubit.get_bounding_box('surface',k)
        if zmax_box == 0 and sbox[7] == 0:
             dzmax=0
        elif zmax_box == 0 or sbox[7] == 0:
            dzmax=abs(sbox[7] - zmax_box)
        else:
            dzmax=abs(sbox[7] - zmax_box)/max(abs(sbox[7]),abs(zmax_box))
        if zmin_box == 0 and sbox[6] == 0:
             dzmin=0
        elif zmin_box == 0 or sbox[6] == 0:
            dzmin=abs(sbox[6] - zmin_box)
        else:
            dzmin=abs(sbox[6] - zmin_box)/max(abs(sbox[6]),abs(zmin_box))
        normal=cubit.get_surface_normal(k)
        zn=normal[2]
        if dzmax <= topographic_surface_distance_tolerance and zn > topographic_surface_normal_tolerance:
            top_surf.append(k)
            list_vertex=cubit.get_relatives('surface',k,'vertex')
            for v in list_vertex:
                valence=cubit.get_valence(v)
                if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
                    lv.append(v)
        elif dzmin <= 0.001 and zn < -1+topographic_surface_normal_tolerance:
            bottom_surf.append(k)
    if len(top_surf) ==0: #assuming that one topo surface need to be selected
            _,_,_,_,_,top_surf=get_v_h_list(list_vol,chktop=False)
    lp=[]
    labelp=[]
    combs=product(lv,lv)
    for comb in combs:
        v1=comb[0]
        v2=comb[1]
        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
        if len(c) == 1:
            p=cubit.get_center_point("curve",list(c)[0])
            labelp.append(list(c)[0])
    labelps=Set(labelp)
    for c in labelps:
        p=cubit.get_center_point("curve",c)
        lp.append(p)

    for k in list_surf:
        center_point = cubit.get_center_point("surface", k)
        for p in lp:
            try:
                if abs((center_point[0] - p[0])/p[0]) <= absorbing_surface_distance_tolerance and abs((center_point[1] - p[1])/p[1]) <= absorbing_surface_distance_tolerance:
                    absorbing_surf.append(k)
                    break
            except:
                if -1 <= center_point[0] <= 1 and -1 <= center_point[1] <= 1:
                    absorbing_surf.append(k)
                    break
    #
    four_side=True
    if four_side:
        xmintmp,ymintmp,xmaxtmp,ymaxtmp=define_4side_lateral_surfaces()
        xmin=list(Set(xmintmp)-Set(xmaxtmp))
        xmax=list(Set(xmaxtmp)-Set(xmintmp))
        ymin=list(Set(ymintmp)-Set(ymaxtmp))
        ymax=list(Set(ymaxtmp)-Set(ymintmp))
        abs_xmintmp,abs_xmaxtmp,abs_ymintmp,abs_ymaxtmp=lateral_boundary_are_absorbing(ip,cpuxmin,cpuxmax,cpuymin,cpuymax,cpux,cpuy)
        abs_xmin=list(Set(abs_xmintmp)-Set(abs_xmaxtmp))
        abs_xmax=list(Set(abs_xmaxtmp)-Set(abs_xmintmp))
        abs_ymin=list(Set(abs_ymintmp)-Set(abs_ymaxtmp))
        abs_ymax=list(Set(abs_ymaxtmp)-Set(abs_ymintmp))
    return absorbing_surf,abs_xmin,abs_xmax,abs_ymin,abs_ymax,top_surf,bottom_surf,xmin,ymin,xmax,ymax
コード例 #12
0
def define_top_bottom_absorbing_surf(zmin_box, zmax_box):
    """
      absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
    """
    try:
        cubit.cmd('comment')
    except:
        try:
            import cubit
            cubit.init([""])
        except:
            print('error importing cubit')
            import sys
            sys.exit()
    absorbing_surf_bottom = []
    top_surf = []

    list_vol = cubit.parse_cubit_list("volume", "all")
    init_n_vol = len(list_vol)
    #   TO DO : Make zmin_box work properly.
    #   zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
    #   zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
    xmin_box = cubit.get_total_bounding_box("volume", list_vol)[0]
    xmax_box = cubit.get_total_bounding_box("volume", list_vol)[1]
    ymin_box = cubit.get_total_bounding_box("volume", list_vol)[3]
    ymax_box = cubit.get_total_bounding_box("volume", list_vol)[4]
    list_surf = cubit.parse_cubit_list("surface", "all")

    print('##boundary box: ')
    print('##  x min: ' + str(xmin_box))
    print('##  y min: ' + str(ymin_box))
    print('##  z min: ' + str(zmin_box))
    print('##  x max: ' + str(xmax_box))
    print('##  y max: ' + str(ymax_box))
    print('##  z max: ' + str(zmax_box))

    #box lengths
    x_len = abs(xmax_box - xmin_box)
    y_len = abs(ymax_box - ymin_box)
    z_len = abs(zmax_box - zmin_box)

    print('##boundary box: ')
    print('##  x length: ' + str(x_len))
    print('##  y length: ' + str(y_len))
    print('##  z length: ' + str(z_len))

    # tolerance parameters
    absorbing_surface_distance_tolerance = 0.005
    topographic_surface_distance_tolerance = 0.001
    topographic_surface_normal_tolerance = 0.2

    for k in list_surf:
        center_point = cubit.get_center_point("surface", k)
        if abs((center_point[2] - zmin_box) /
               z_len) <= absorbing_surface_distance_tolerance:
            print('center_point[2] ' + str(center_point[2]))
            print('kz: ' + str(k))
            absorbing_surf_bottom.append(k)

        else:
            sbox = cubit.get_bounding_box('surface', k)
            dz = abs((sbox[7] - zmax_box) / z_len)
            normal = cubit.get_surface_normal(k)
            zn = normal[2]
            dn = abs(zn - 1)
            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
                top_surf.append(k)

    return absorbing_surf_bottom, top_surf
コード例 #13
0
def get_v_h_list(vol_id_list, chktop=False):
    """return the lists of the cubit ID of vertical/horizontal surface and vertical/horizontal curves
    where v/h is defined by the distance of the z normal component from the axis direction
    the parameter cfg.tres is the threshold as for example if 
    -tres <= normal[2] <= tres 
    then the surface is vertical
    #
    usage: surf_or,surf_vertical,list_curve_or,list_curve_vertical,bottom,top = get_v_h_list(list_vol,chktop=False)
    """
    #
    tres = 0.3

    try:
        nvol = len(vol_id_list)
    except:
        nvol = 1
        vol_id_list = [vol_id_list]
    surf_vertical = []
    surf_or = []
    list_curve_vertical = []
    list_curve_or = []
    #
    #
    for id_vol in vol_id_list:
        lsurf = cubit.get_relatives("volume", id_vol, "surface")
        for k in lsurf:
            normal = cubit.get_surface_normal(k)
            center_point = cubit.get_center_point("surface", k)
            if -1 * tres <= normal[2] <= tres:
                surf_vertical.append(k)
                lcurve = cubit.get_relatives("surface", k, "curve")
                list_curve_vertical = list_curve_vertical + list(lcurve)
            else:
                surf_or.append(k)
                lcurve = cubit.get_relatives("surface", k, "curve")
                list_curve_or = list_curve_or + list(lcurve)
    for x in list_curve_or:
        try:
            list_curve_vertical.remove(x)
        except:
            pass

    #find the top and the bottom surfaces
    k = surf_or[0]
    center_point = cubit.get_center_point("surface", k)[2]
    center_point_top = center_point
    center_point_bottom = center_point
    top = k
    bottom = k
    for k in surf_or[1:]:
        center_point = cubit.get_center_point("surface", k)[2]
        if center_point > center_point_top:
            center_point_top = center_point
            top = k
        elif center_point < center_point_bottom:
            center_point_bottom = center_point
            bottom = k
    #check that a top surface exists
    #it assume that the z coord of the center point
    if chktop:
        k = lsurf[0]
        vertical_centerpoint_top = cubit.get_center_point("surface", k)[2]
        vertical_zmax_box_top = cubit.get_bounding_box('surface', k)[7]
        normal_top = cubit.get_surface_normal(k)
        top = k
        for k in lsurf:
            vertical_centerpoint = cubit.get_center_point("surface", k)[2]
            vertical_zmax_box = cubit.get_bounding_box('surface', k)[7]
            normal = cubit.get_surface_normal(k)
            check = (vertical_centerpoint >= vertical_centerpoint_top) and (
                vertical_zmax_box >= vertical_zmax_box_top) and (normal >=
                                                                 normal_top)
            if check:
                top = k
        if top in surf_vertical:
            surf_vertical.remove(top)
        if top not in surf_or:
            surf_or.append(top)
    #if more than one surf is on the top, I get all the surfaces that are in touch with top surface but not the vertical surfaces
    surftop = list(cubit.get_adjacent_surfaces(
        "surface", top))  #top is included in the list
    for s in surf_vertical:
        try:
            surftop.remove(s)
        except:
            pass
    top = surftop
    #check that all the surf are Horizontal or vertical
    surf_all = surf_vertical + surf_or
    if len(surf_all) != len(lsurf):
        print 'not all the surf are horizontal or vertical, check the normals'
        print 'list of surfaces: ', surf_all
        print 'list of vertical surface', surf_vertical
        print 'list of horizontal surface', surf_or

    bottom = [bottom]
    return surf_or, surf_vertical, list_curve_or, list_curve_vertical, bottom, top
コード例 #14
0
def define_top_bottom_absorbing_surf(zmin_box,zmax_box):
    """
      absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
    """
    try:
        cubit.cmd('comment')
    except:
        try:
            import cubit
            cubit.init([""])
        except:
            print 'error importing cubit'
            import sys
            sys.exit()
    absorbing_surf_bottom=[]
    top_surf = []
    
    list_vol=cubit.parse_cubit_list("volume","all")
    init_n_vol=len(list_vol)
#   TO DO : Make zmin_box work properly.
#   zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
#   zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
    list_surf=cubit.parse_cubit_list("surface","all")
   
    print '##boundary box: '
    print '##  x min: ' + str(xmin_box)
    print '##  y min: ' + str(ymin_box)
    print '##  z min: ' + str(zmin_box)
    print '##  x max: ' + str(xmax_box)
    print '##  y max: ' + str(ymax_box)
    print '##  z max: ' + str(zmax_box)

    #box lengths
    x_len = abs( xmax_box - xmin_box)
    y_len = abs( ymax_box - ymin_box)
    z_len = abs( zmax_box - zmin_box)
    
    print '##boundary box: '
    print '##  x length: ' + str(x_len)
    print '##  y length: ' + str(y_len)
    print '##  z length: ' + str(z_len)
    
    # tolerance parameters 
    absorbing_surface_distance_tolerance=0.005
    topographic_surface_distance_tolerance=0.001
    topographic_surface_normal_tolerance=0.2

    for k in list_surf:
        center_point = cubit.get_center_point("surface", k)
        if abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
             print 'center_point[2]' + str(center_point[2])
             print 'kz:' + str(k)
             absorbing_surf_bottom.append(k)
   
        else:
            sbox=cubit.get_bounding_box('surface',k)
            dz=abs((sbox[7] - zmax_box)/z_len)
            normal=cubit.get_surface_normal(k)
            zn=normal[2]
            dn=abs(zn-1)
            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
                top_surf.append(k)
    
    return absorbing_surf_bottom,top_surf
コード例 #15
0
def cohgen(exodusIn, fileOutPrefix):
    """
    This function operates within Cubit. It imports an exodus mesh of
    polycrystalline geometry with the void meshed, generates a skin of zero
    thickness cohesive elements surrounding individual crystals, and exports
    a valid ABAQUS mesh.
    """
    # Provide the installation path of Cubit
    sys.path.append('~/Software/Cubit-15.3-Lin64/bin')
    # sys.path.append('/Applications/Cubit-15.3/Cubit.app/Contents/MacOS/')
    import cubit as cb
    # Start cubit
    cb.init(['cubit', '-nojournal'])

    # Import model while creating geometry
    fileIn = "'" + exodusIn + ".e'"
    print fileIn
    cb.cmd("import mesh geometry %s feature_angle 135.00 merge" % fileIn)

    # Get volumes and separate into blocks
    # Compress volume id's and sort by volume (likely void volume is largest)
    cb.cmd('compress all sort')
    # cb.cmd('label volume id')
    # cb.cmd('label volume name id')

    # Remove pre-established element blocks
    cb.cmd('del block all')
    vols = cb.get_volume_count()
    print "Number of volumes: %s" % vols

    # Check if volumes sorted properly (largest last)
    firstvol = cb.volume(1)
    lastvol = cb.volume(vols)
    firstvol_vol = firstvol.volume()
    lastvol_vol = lastvol.volume()

    # Set volume number containing matrix material
    # Proper sort should set last (assuming it is the largest individual volume)
    # One case, it left the matrix material as volume 1
    # Could be other cases requiring a more generic fix (check cuibt file manually)
    if firstvol_vol > lastvol_vol:
        matrix_vol_num = 1
    elif firstvol_vol < lastvol_vol:
        matrix_vol_num = vols

    # Assign each grain its own element block and name.
    grain_list = []
    for cv in range(1, vols + 1):
        cb.cmd("block %s add volume %s" % (repr(cv + 1), repr(cv)))
        if cv == matrix_vol_num:
            cb.cmd("block %s name 'Matrix'" % repr(cv + 1))
        else:
            cb.cmd("block %s name 'Grain_%s'" % (repr(cv + 1), repr(cv)))
            grain_list.append('Grain_%s' % repr(cv))

    cb.cmd('disassociate mesh from Volume all')
    # cb.cmd('delete volume all')

    # Pillow each grain to skin with 0 thickness hexes for cohesive elements
    el_blocks = cb.get_block_count()
    # Note, indexing skips last element block (presumed binder)
    for block in range(2, el_blocks + 1):
        if block == matrix_vol_num + 1:
            pass
        else:
            cb.cmd("pillow hex in block %s distance 0 no_smooth" % repr(block))

    cb.cmd('block 1 add hex not block_assigned')
    cb.cmd("block 1 name 'Coh_El'")

    # Get bounding box for removing cohesive elements on the domain boundary
    # cb.get_bounding_box('entity',id) returns a vector with the following info:
    #(min_x, max_x, range_x, min_y, max_y, range_y, min_z, max_z, range_z, diag)
    bbox = cb.get_bounding_box("volume", matrix_vol_num)

    cb.cmd('delete hex in block 1 with X_Coord == %s' % repr(bbox[0]))
    cb.cmd('delete hex in block 1 with X_Coord == %s' % repr(bbox[1]))
    cb.cmd('delete hex in block 1 with Y_Coord == %s' % repr(bbox[3]))
    cb.cmd('delete hex in block 1 with Y_Coord == %s' % repr(bbox[4]))
    cb.cmd('delete hex in block 1 with Z_Coord == %s' % repr(bbox[6]))
    cb.cmd('delete hex in block 1 with Z_Coord == %s' % repr(bbox[7]))

    # Reassign domain nodesets since pillowing and removing domain hexes messes this up
    cb.cmd('delete nodeset all')
    cb.cmd('delete sideset all')

    cb.cmd('nodeset 1 add node with X_Coord == %s' % repr(bbox[0]))
    cb.cmd('nodeset 2 add node with X_Coord == %s' % repr(bbox[1]))
    cb.cmd('nodeset 3 add node with Y_Coord == %s' % repr(bbox[3]))
    cb.cmd('nodeset 4 add node with Y_Coord == %s' % repr(bbox[4]))
    cb.cmd('nodeset 5 add node with Z_Coord == %s' % repr(bbox[6]))
    cb.cmd('nodeset 6 add node with Z_Coord == %s' % repr(bbox[7]))
    cb.cmd('nodeset 7 add node in nodeset 1 to 6')
    cb.cmd('nodeset 8 add node in hex in block 1')  # Interface nodes

    cb.cmd('nodeset 1 name "negXNodes"')
    cb.cmd('nodeset 2 name "posXNodes"')
    cb.cmd('nodeset 3 name "negYNodes"')
    cb.cmd('nodeset 4 name "posYNodes"')
    cb.cmd('nodeset 5 name "negZNodes"')
    cb.cmd('nodeset 6 name "posZNodes"')
    cb.cmd('nodeset 7 name "allBoundaryNodes"')
    cb.cmd('nodeset 8 name "matIntNodes"')

    # Define nodesets for periodic boundary conditions. For universal application
    # to implicit and explicit analyses, corners, edges, and faces cannot contain
    # duplicate nodes (restriction for implicit only). Therefore, new specific
    # nodesets are defined in a way to eleminate this duplicate definition problem.

    # Redefine Faces for PBC's
    cb.cmd('nodeset 101 add node in nodeset 1')
    cb.cmd('nodeset 102 add node in nodeset 2')
    cb.cmd('nodeset 103 add node in nodeset 3')
    cb.cmd('nodeset 104 add node in nodeset 4')
    cb.cmd('nodeset 105 add node in nodeset 5')
    cb.cmd('nodeset 106 add node in nodeset 6')

    cb.cmd('nodeset 101 name "PBCnXF"')
    cb.cmd('nodeset 102 name "PBCpXF"')
    cb.cmd('nodeset 103 name "PBCnYF"')
    cb.cmd('nodeset 104 name "PBCpYF"')
    cb.cmd('nodeset 105 name "PBCnZF"')
    cb.cmd('nodeset 106 name "PBCpZF"')

    # Define Edges for PBC's
    cb.cmd(
        'nodeset 1001 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[3])))
    cb.cmd('nodeset 1001 name "PBCnXnYE"')
    cb.cmd(
        'nodeset 1002 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[4])))
    cb.cmd('nodeset 1002 name "PBCnXpYE"')
    cb.cmd(
        'nodeset 1003 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[3])))
    cb.cmd('nodeset 1003 name "PBCpXnYE"')
    cb.cmd(
        'nodeset 1004 add node with X_Coord == {x:s} and with Y_Coord == {y:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[4])))
    cb.cmd('nodeset 1004 name "PBCpXpYE"')
    cb.cmd(
        'nodeset 1005 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[3]), z=repr(bbox[6])))
    cb.cmd('nodeset 1005 name "PBCnYnZE"')
    cb.cmd(
        'nodeset 1006 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[3]), z=repr(bbox[7])))
    cb.cmd('nodeset 1006 name "PBCnYpZE"')
    cb.cmd(
        'nodeset 1007 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[4]), z=repr(bbox[6])))
    cb.cmd('nodeset 1007 name "PBCpYnZE"')
    cb.cmd(
        'nodeset 1008 add node with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(y=repr(bbox[4]), z=repr(bbox[7])))
    cb.cmd('nodeset 1008 name "PBCpYpZE"')
    cb.cmd(
        'nodeset 1009 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), z=repr(bbox[6])))
    cb.cmd('nodeset 1009 name "PBCnXnZE"')
    cb.cmd(
        'nodeset 1010 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), z=repr(bbox[7])))
    cb.cmd('nodeset 1010 name "PBCnXpZE"')
    cb.cmd(
        'nodeset 1011 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), z=repr(bbox[6])))
    cb.cmd('nodeset 1011 name "PBCpXnZE"')
    cb.cmd(
        'nodeset 1012 add node with X_Coord == {x:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), z=repr(bbox[7])))
    cb.cmd('nodeset 1012 name "PBCpXpZE"')

    # Remove nodes in edge sets from face sets
    for nn in range(101, 107):
        cb.cmd('nodeset {num:s} remove node in nodeset 1001 to 1012'.format(
            num=repr(nn)))

    # Define Corners for PBC's
    cb.cmd(
        'nodeset 10001 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[3]), z=repr(bbox[6])))
    cb.cmd('nodeset 10001 name "PBCnXnYnZC"')
    cb.cmd(
        'nodeset 10002 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[3]), z=repr(bbox[7])))
    cb.cmd('nodeset 10002 name "PBCnXnYpZC"')
    cb.cmd(
        'nodeset 10003 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[4]), z=repr(bbox[6])))
    cb.cmd('nodeset 10003 name "PBCnXpYnZC"')
    cb.cmd(
        'nodeset 10004 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[0]), y=repr(bbox[4]), z=repr(bbox[7])))
    cb.cmd('nodeset 10004 name "PBCnXpYpZC"')
    cb.cmd(
        'nodeset 10005 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[3]), z=repr(bbox[6])))
    cb.cmd('nodeset 10005 name "PBCpXnYnZC"')
    cb.cmd(
        'nodeset 10006 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[3]), z=repr(bbox[7])))
    cb.cmd('nodeset 10006 name "PBCpXnYpZC"')
    cb.cmd(
        'nodeset 10007 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[4]), z=repr(bbox[6])))
    cb.cmd('nodeset 10007 name "PBCpXpYnZC"')
    cb.cmd(
        'nodeset 10008 add node with X_Coord == {x:s} and with Y_Coord == {y:s} and with Z_Coord == {z:s}'
        .format(x=repr(bbox[1]), y=repr(bbox[4]), z=repr(bbox[7])))
    cb.cmd('nodeset 10008 name "PBCpXpYpZC"')

    # Remove nodes in corner sets from edge sets
    for nn in range(1001, 1013):
        cb.cmd('nodeset {num:s} remove node in nodeset 10001 to 10008'.format(
            num=repr(nn)))

    # Export abaqus file
    absFileOutPrefix = os.path.abspath(fileOutPrefix)
    cb.cmd("set Abaqus precision 4")
    cb.cmd(
        'export abaqus "%s.inp" block all nodeset all dimension 3 overwrite' %
        absFileOutPrefix)
    cb.cmd('save as "%s.cub" overwrite' % absFileOutPrefix)
    return absFileOutPrefix, grain_list