Пример #1
0
def computeNonlinearConstraint(x, y):
    nlcon = numpy.zeros(len(x))
    target_surface = cubit.surface(1)
    vertex_on_surface = [False for i in range(0, len(x))]
    # First, determine whether the nonlinear constraint is satisfied
    for i in range(0, len(x)):
        vertex_on_surface[i] = target_surface.point_containment(
            [x[i], y[i], 0.])
    # Second, determine the magnitude of the nonlinear constraint value
    #         which is the distance of the point to the closest curve
    cid = cubit.get_entities("Curve")
    for i in range(0, len(x)):
        dist = numpy.zeros(len(cid))
        pXYZ = numpy.array([x[i], y[i], 0.])
        for c in range(0, 1):
            C = cubit.curve(cid[c])
            cpXYZ = numpy.array(C.closest_point(pXYZ))
            dist[c] = numpy.linalg.norm(cpXYZ - pXYZ)
        if vertex_on_surface[i] == True:
            # Nonlinear constraint is satisfied
            nlcon[i] = -1. * numpy.min(dist)
        else:
            # Nonlinear constraint not satisfied
            nlcon[i] = +1. * numpy.min(dist)
    return nlcon
 def __init__(self):
     self.filename_nodes = 'node_coordinates'
     self.filename_hex8 = 'cell_connectivity_hex8'
     self.filename_tet4 = 'cell_connectivity_tet4'
     #
     self.hex8 = []
     self.tet4 = []
     #
     print "number of volumes = " + str(cubit.get_volume_count())
     print "number of hexes in entire mesh: cubit.get_hex_count = " + str(
         cubit.get_hex_count())
     print "number of tets in entire mesh: cubit.get_tet_count =  " + str(
         cubit.get_tet_count())
     #
     for volume in cubit.get_entities("volume"):
         print "VOLUME " + str(volume) + ":"
         print "  number of elements: " + str(
             cubit.get_volume_element_count(volume))
         hex8_list = cubit.get_volume_hexes(volume)
         self.hex8 += hex8_list
         print "  number of hexes:    " + str(len(hex8_list))
         tet4_list = cubit.get_volume_tets(volume)
         self.tet4 += tet4_list
         print "  number of tets:     " + str(len(tet4_list))
     #
     print "number of hexes found while iterating over all volumes: " + str(
         len(self.hex8))
     print "number of tets found while iterating over all volumes: " + str(
         len(self.tet4))
def getMeshData():
    ELEM = cubit.get_entities("tri")
    NODE = cubit.get_entities("node")

    nELEM = len(ELEM)
    nNODE = len(NODE)

    eCONNECT = numpy.zeros(shape=(nELEM,3),dtype="int64")
    COORD = numpy.zeros(shape=(nNODE,3),dtype="double")

    for i in range(0,nELEM):
      eCONNECT[i,:] = list(cubit.get_connectivity("tri",ELEM[i]))
    eCONNECT = eCONNECT - 1

    for i in range(0,nNODE):
      COORD[i,:] = list(cubit.get_nodal_coordinates(NODE[i]))

    return ELEM, NODE, eCONNECT, COORD
Пример #4
0
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'
    )
Пример #5
0
import pickle

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

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

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

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

for icurve in cubit.get_entities('curve'):
    l = cubit.get_curve_length(icurve)
    r1 = 2 * math.pi * 1.8
    r2 = 2 * math.pi * 2.0
    r3 = 2 * math.pi * 20.0
Пример #6
0
def geom_cubit_solo(configfile):
    if not os.path.isfile(configfile):
        raise Exception("ERR: CONFIG FILE DON'T EXIST !!!")
    #  READ CONFIGFILE
    cf = ConfigParser.ConfigParser()
    cf.optionxform = str
    cf.read(configfile)
    bathyfile = cf.get('Input', 'bathyfile')
    slabfile = cf.get('Input', 'slabfile')
    left_extension = cf.getfloat('Parameters',
                                 'left_extension')  # (always positive)
    right_extension = cf.getfloat('Parameters', 'right_extension')
    down_limit = cf.getfloat('Parameters', 'down_limit')  # (always positive)
    EET_OP = cf.getfloat('Parameters', 'eet_op')  #  Thickness of the OP Litho
    EET_DP = cf.getfloat('Parameters', 'eet_dp')  #  Thickness of the DP Litho
    #    backstop_bool=cf.getboolean('Parameters','backstop_bool') # True or False
    x_backstop = cf.getfloat('Parameters', 'backstop_distance')
    dip_backstop = cf.getfloat('Parameters', 'backstop_angle')
    output_path = cf.get('Output', 'output_path')
    output_file_prefix = cf.get('Output', 'output_prefix')
    output_file_suffix = cf.get('Output', 'output_suffix')
    output_pathfile = output_path + '/' + output_file_prefix + '_' + output_file_suffix + '.exo'
    dx1 = cf.getfloat('Parameters', 'dx_fine')
    dx2 = cf.getfloat('Parameters', 'dx_coarse')
    # =======================================================================
    #  PRIOR DESIGN
    # =======================================================================
    # Loading the BATHY and SLAB files
    XYbathy = np.loadtxt(bathyfile)
    XYslab = np.loadtxt(slabfile)
    # Creating the bottom of the slab
    XslabBot, YslabBot, _ = rcl.shift_thickness(XYslab[:, 0], XYslab[:, 1],
                                                EET_DP)
    # Creating the bounding points in a dictionnary
    outpts = rcl.make_bounding_points(XYbathy[:, 0], XYbathy[:, 1], XYslab[:,
                                                                           0],
                                      XYslab[:, 1], EET_OP, EET_DP, down_limit,
                                      left_extension, right_extension)
    # Creating the backstop
    Xbackstop, Ybackstop = rcl.make_backstop(XYbathy[:, 0],
                                             XYbathy[:, 1],
                                             XYslab[:, 0],
                                             XYslab[:, 1],
                                             x_backstop,
                                             dip_backstop,
                                             dupdown=150)
    # Adding the 'Bottom_Litho_DP' point to the Litho_DP Bottom
    rcl.add_point_in_list(XslabBot, YslabBot, outpts['vBottom_Litho_DP'])
    # Changing the description concept : Bathy & Slab ==> OP & DP
    Xop, Yop, Xdp, Ydp = rcl.bathyslab_2_OPDPtop(XYbathy[:, 0], XYbathy[:, 1],
                                                 XYslab[:, 0], XYslab[:, 1])
    # Adding the limit points of OP & DP
    Xop, Yop = rcl.add_point_in_list(Xop, Yop, outpts['vBathy_OP'])
    Xdp, Ydp = rcl.add_point_in_list(Xdp, Ydp, outpts['vBathy_DP'])
    # PLOT FOR SECURITY
    #plt.clf()
    #plt.axis('equal')
    #plt.plot(XYbathy[:,0],XYbathy[:,1],'+b')
    #plt.plot(XYslab[:,0],XYslab[:,1],'r+-')
    #plt.plot(XslabBot,YslabBot,'k+-')
    #plt.plot(Xbackstop,Ybackstop,'*-y')
    #for p in outpts.viewvalues():
    #    plt.plot(p[0],p[1],'*k')
    #plt.plot(Xop,Yop,'b-')
    #plt.plot(Xdp,Ydp,'r-')
    # =======================================================================
    #  CUBIT MESHING
    # =======================================================================
    # Initalisation
    cubit.cmd('reset')
    cubit.cmd("#{Units('si')}")
    # Chargement des courbes
    rcl.list_2_curve(Xop, Yop, 'Top_Litho_OP')
    rcl.list_2_curve(Xdp, Ydp, 'Top_Litho_limit_DP')
    rcl.list_2_curve(XslabBot, YslabBot, 'Bottom_Litho_DP')
    rcl.list_2_curve(Xbackstop, Ybackstop, 'Backstop')
    # Chargement des Points Isoles
    rcl.dico_2_listofvertices(outpts)
    ## fabrication de "courbes-segments" a partir de vertex
    v_Bottom_Litho_OP = cubit.vertex(
        cubit.get_id_from_name('vBottom_Litho_OP'))
    v_Bathy_DP = rcl.find_extrema(
        cubit.curve(cubit.get_id_from_name("Top_Litho_limit_DP")), 'r')
    v_Bathy_OP = rcl.find_extrema(
        cubit.curve(cubit.get_id_from_name('Top_Litho_OP')), 'l')
    v_Bottom_Litho_DP = rcl.find_extrema(
        cubit.curve(cubit.get_id_from_name("Bottom_Litho_DP")), 'r')
    v_scratch = cubit.vertex(cubit.get_id_from_name('vscratch'))
    v_Bottom_Astheno_OP = cubit.vertex(
        cubit.get_id_from_name('vBottom_Astheno_OP'))
    v_Bottom_Astheno_DP = cubit.vertex(
        cubit.get_id_from_name('vBottom_Astheno_DP'))
    #
    rcl.vertices_2_curve(v_Bottom_Litho_OP, v_Bottom_Astheno_OP,
                         'Edge_Astheno_OP')
    rcl.vertices_2_curve(v_Bottom_Litho_OP, v_scratch, 'Bottom_Litho_OP_PROTO')
    rcl.vertices_2_curve(v_Bottom_Litho_OP, v_Bathy_OP, 'Edge_Litho_OP')
    rcl.vertices_2_curve(v_Bottom_Astheno_OP, v_Bottom_Astheno_DP,
                         'Bottom_PROTO')
    rcl.vertices_2_curve(v_Bathy_DP, v_Bottom_Litho_DP, 'Edge_Litho_DP')
    rcl.vertices_2_curve(v_Bottom_Litho_DP, v_Bottom_Astheno_DP,
                         'Edge_Astheno_DP')
    ## Split des courbes
    rcl.double_split_desc('Bottom_Litho_OP_PROTO', 'Top_Litho_limit_DP')
    rcl.double_split_desc("Bottom_PROTO", "Top_Litho_limit_DP_1")
    rcl.double_split_desc("Bottom_PROTO_2", "Bottom_Litho_DP")
    rcl.double_split_desc("Backstop", "Top_Litho_limit_DP_2")
    rcl.double_split_desc("Top_Litho_OP", "Backstop_1")
    rcl.double_split_desc("Top_Litho_limit_DP_2_2", "Top_Litho_OP_2")
    if True:
        #    ## suppression des petits morceaux
        rcl.destroy_curve_desc("Top_Litho_limit_DP_1_1")
        rcl.destroy_curve_desc("Bottom_Litho_DP_1")
        rcl.destroy_curve_desc("Backstop_2")
        rcl.destroy_curve_desc("Bottom_Litho_OP_PROTO_2")
        rcl.destroy_curve_desc("Backstop_1_1")
        #    ## renommage des courbes
        rcl.rename_curve_desc(7, 'Edge_Litho_OP')
        rcl.rename_curve_desc(5, 'Edge_Astheno_OP')
        rcl.rename_curve_desc(9, 'Edge_Litho_DP')
        rcl.rename_curve_desc(10, 'Edge_Astheno_DP')
        rcl.rename_curve_desc("Top_Litho_limit_DP_2_1", 'Contact_OP_DP')
        rcl.rename_curve_desc("Top_Litho_limit_DP_2_2_1", 'Contact_Prism_DP')
        rcl.rename_curve_desc("Backstop_1_2", 'Contact_Prism_OP')
        rcl.rename_curve_desc("Top_Litho_OP_2_1", 'Top_Litho_DP')
        rcl.rename_curve_desc("Top_Litho_OP_2_2", 'Top_Prism')
        rcl.rename_curve_desc("Top_Litho_OP_1", 'Top_Litho_OP')
        rcl.rename_curve_desc("Bottom_PROTO_2_2", 'Bottom_Astheno_DP')
        rcl.rename_curve_desc("Bottom_Litho_DP_2", 'Bottom_Litho_DP')
        rcl.rename_curve_desc("Bottom_PROTO_1", 'Bottom_Astheno_OP')
        rcl.rename_curve_desc("Bottom_Litho_OP_PROTO_1", 'Bottom_Litho_OP')
        rcl.rename_curve_desc("Bottom_PROTO_2_1", 'Front_Litho_DP')
        rcl.rename_curve_desc("Top_Litho_limit_DP_1_2",
                              'Astheno_Litho_Contact')
        #    # creation des surfaces
        rcl.create_surface_desc(
            ["Edge_Astheno_DP", "Bottom_Astheno_DP", "Bottom_Litho_DP"])
        rcl.create_surface_desc([
            "Front_Litho_DP", "Bottom_Litho_DP", "Edge_Litho_DP",
            "Top_Litho_DP", "Contact_Prism_DP", "Contact_OP_DP",
            "Astheno_Litho_Contact"
        ])
        rcl.create_surface_desc([
            "Bottom_Astheno_OP", "Astheno_Litho_Contact", "Bottom_Litho_OP",
            "Edge_Astheno_OP"
        ])
        rcl.create_surface_desc([
            "Bottom_Litho_OP", "Edge_Litho_OP", "Top_Litho_OP",
            "Contact_Prism_OP", "Contact_OP_DP"
        ])
        rcl.create_surface_desc(
            ["Top_Prism", "Contact_Prism_DP", "Contact_Prism_OP"])
        #    # renomage des surfaces
        cubit.surface(1).entity_name('Astheno_DP')
        cubit.surface(2).entity_name('Litho_DP')
        cubit.surface(3).entity_name('Astheno_OP')
        cubit.surface(4).entity_name('Litho_OP')
        cubit.surface(5).entity_name('Prisme')
        # Fusion des surfaces
        cubit.cmd('delete vertex all')
        cubit.cmd('imprint all')
        cubit.cmd('merge all')
        cubit.cmd('stitch volume all')
        rcl.rename_curve_desc(45, 'Astheno_Litho_Contact')
        cubit.cmd('surface all scheme trimesh')
        cubit.cmd('curve all scheme default')
        cubit.cmd('surface all sizing function none')
        # nouveau decoupage des courbes
        rcl.curver_desc("Contact_Prism_DP", dx1)
        rcl.curver_desc("Contact_Prism_OP", dx1)
        rcl.curver_desc("Top_Prism", dx1)
        rcl.curver_desc("Bottom_Litho_DP", dx2)
        rcl.curver_desc("Bottom_Astheno_OP", dx2)
        rcl.curver_desc("Front_Litho_DP", dx2)
        rcl.curver_desc("Bottom_Astheno_DP", dx2)
        rcl.curver_desc("Edge_Astheno_OP", dx2)
        rcl.curver_desc("Edge_Litho_OP", dx2)
        rcl.curver_desc("Edge_Astheno_DP", dx2)
        rcl.curver_desc("Edge_Litho_DP", dx2)
        rcl.curver_desc("Contact_OP_DP", dx1)
        rcl.curver_start_end_desc("Bottom_Litho_OP", dx1, dx2, 'l')
        rcl.curver_start_end_desc("Top_Litho_OP", dx1, dx2, 'l')
        rcl.curver_start_end_desc("Top_Litho_DP", dx1, dx2, 'r')
        rcl.curver_start_end_desc("Astheno_Litho_Contact", dx1, dx2, 'l')
        # fabrication du mesh
        cubit.cmd('mesh surface all')
        cubit.cmd('surface all smooth scheme condition number beta 1.7 cpu 10')
        cubit.cmd('smooth surface all')
        cubit.cmd('surface 1 size auto factor 5')
        ## Fabrication de groupe et de nodeset
        for i, s in enumerate(cubit.get_entities("surface")):
            S = cubit.surface(s)
            cubit.cmd('block ' + str(i + 1) + ' surface ' + S.entity_name())
            cubit.cmd('block ' + str(i + 1) + ' name "' + S.entity_name() +
                      ' "')
        rcl.create_group_nodeset_desc(
            ['Astheno_Litho_Contact', 'Contact_OP_DP', 'Contact_Prism_DP'],
            "fault_top", 20)
        rcl.create_group_nodeset_desc(
            ['Top_Litho_OP', 'Top_Prism', 'Top_Litho_DP'], "ground_surface",
            20)
        rcl.create_group_nodeset_desc(['Bottom_Litho_OP'], "bottom_litho_OP",
                                      20)
        rcl.create_group_nodeset_desc(['Bottom_Litho_DP'], "bottom_litho_DP",
                                      20)
        rcl.create_group_nodeset_desc(['Edge_Litho_OP'], "edge_litho_OP", 20)
        rcl.create_group_nodeset_desc(['Edge_Litho_DP'], "edge_litho_DP", 20)
        rcl.create_group_nodeset_desc(['Front_Litho_DP'], "front_litho_DP", 20)
        rcl.create_group_nodeset_desc(['Contact_Prism_OP'], "contact_prism_OP",
                                      20, ['fault_top'])
        print 'ca chie'
        rcl.create_group_nodeset_desc(
            ['Bottom_Astheno_DP', 'Bottom_Astheno_OP'], "bottom_astheno", 20,
            ['front_litho_DP'])
        print 'ca chie 2'
        rcl.create_group_nodeset_desc(['Edge_Astheno_DP'], "edge_astheno_DP",
                                      20, ['edge_litho_DP'])
        rcl.create_group_nodeset_desc(['Edge_Astheno_OP'], "edge_astheno_OP",
                                      20, ['edge_litho_OP'])
        # ecriture fichier final
        cubit.cmd('export mesh "' + output_pathfile +
                  '" dimension 2 overwrite')
    return None
Пример #7
0
 def makeGeometry(self):
     for p in self.points:
         geo.createVertex(p[0],p[1],p[2])
     heap = [self.root]
     while not (len(heap) == 0):
         atual = heap.pop()
         lineID = geo.createLine(atual.initialPoint+1, atual.finalPoint+1)
         atual.index = lineID
         if atual.son1 is not None:
             heap.append(atual.son1)
         if atual.son2 is not None:
             heap.append(atual.son2) 
     heap = [self.root]
     count = 0
     while not (len(heap) == 0):
         count += 1
         if count < 15000:
             atual = heap.pop()
         else:
             break
         if atual.root is None:
             circleI = geo.createCircleNormal(atual.initialPoint+1, atual.radius, atual.index)
         else:
             circleI = atual.root.link
         if atual.nSplit > 0 and atual.nSplit < 6:
             ip = self.points[atual.initialPoint]
             fp = self.points[atual.finalPoint]
             lenght = geo.distance(ip, fp)
             t=(lenght-atual.getRadius()[1])/lenght
             ref = [(1-t)*ip[0]+t*fp[0],((1-t)*ip[1]+t*fp[1]),((1-t)*ip[2]+t*fp[2])]
             circleF = self.genArcFull(atual, atual.finalPoint+1, ref)
             if circleF == -1:
                 circleF = geo.createCircleNormal(atual.finalPoint+1, atual.radius, atual.index)
         else:
             circleF = geo.createCircleNormal(atual.finalPoint+1, atual.radius, atual.index)
         atual.circleI = circleI
         atual.circleF = circleF
         if atual.son1 is not None and atual.son2 is not None:
             self.genSons(atual)
             if atual.son1.son1 is not None:
                 heap.append(atual.son1.son1)
             if atual.son1.son2 is not None:
                 heap.append(atual.son1.son2) 
             if atual.son2.son1 is not None:
                 heap.append(atual.son2.son1)
             if atual.son2.son2 is not None:
                 heap.append(atual.son2.son2)
         else:
             if atual.son1 is not None:
                 atual.link = circleF#geo.copyCurve(circleF)
                 heap.append(atual.son1)
     self.genSurfaces()
     self.genVolumes()
     self.vol = cubit.get_entities("volume")[0]
     bb = geo.createBoudingBox(self.vol, self.root.radius)
     #cubit.cmd("brick x 20000 y 20000 z 20000")
     #cubit.cmd("create sphere radius 15100")
     #bb = cubit.get_last_id("volume")
     #cubit.cmd("move Volume %d location 0 0 0" % (self.vol))
     #print cubit.volume(bb).volume()
     #self.vol = geo.subtractVolumes(bb, self.vol)
     self.vol = bb
     cubit.cmd('Color Define "%s" RGB %f %f %f' % ("darkred", 0.75,0,0))
     geo.colorVolume(self.vol,'user "darkred"')
Пример #8
0
def makeGeometry(x, y):
    status = 0
    cubit.cmd("reset")
    cubit.cmd('open "circleGeom.trelis"')
    cubit.cmd("compress ids")
    num_base_vertex = len(cubit.get_entities("vertex"))

    x = numpy.array(x)
    y = numpy.array(y)
    target_surface = cubit.surface(1)
    vertex_on_surface = numpy.zeros(len(x), dtype=bool)
    for i in range(0, len(x)):
        vertex_on_surface[i] = target_surface.point_containment(
            [x[i], y[i], 0.])
        if vertex_on_surface[i] == True:
            cubit.cmd("create vertex " + str(x[i]) + " " + str(y[i]) +
                      " 0 on surface 1")

    nlcon = computeNonlinearConstraint(x, y)
    sys.stdout.write("Nonlinear Constraints: ")
    sys.stdout.write(str(nlcon))
    sys.stdout.write("\n")
    sys.stdout.flush()

    X = x[vertex_on_surface]
    Y = y[vertex_on_surface]
    num_active_pins = len(X)
    if num_active_pins == 0:
        # No pins on board, return with nonlinear constraint values
        status = 1
        return status, [], [], nlcon

    V = cubit.get_list_of_free_ref_entities("vertex")
    for i in range(0, len(V)):
        cubit.cmd("imprint volume all with vertex " + str(V[i]))
    cubit.cmd("delete free vertex all")
    cubit.cmd("compress ids")
    #for i in range(0,len(V)):
    #    cubit.cmd("nodeset 1 add vertex " + str(V[i]))
    cubit.cmd("surface all size 0.2")
    cubit.cmd("mesh surf all")
    cubit.cmd("surface all smooth scheme mean ratio cpu 0.1")
    cubit.cmd("smooth surf all")

    cubit.cmd("compress ids")

    V = numpy.zeros(num_active_pins, dtype=int)
    #N = numpy.zeros(num_active_pins, dtype=int)
    bc_xyz = [[] for i in range(0, num_active_pins)]
    cubit.cmd('create group "cf_crease_entities"')
    for i in range(0, num_active_pins):
        bc_xyz[i] = [X[i], Y[i], 0.]
        N = cubit.parse_cubit_list(
            "node", " at " + str(X[i]) + " " + str(Y[i]) + " 0.")
        for n in range(0, len(N)):
            nodeEdges = cubit.parse_cubit_list("edge", "in node " + str(N[n]))
            for e in range(0, len(nodeEdges)):
                cubit.cmd("cf_crease_entities add Edge " + str(nodeEdges[e]))

    EinC = cubit.parse_cubit_list("edge", " in curve 1")
    #for e in range(0,len(EinC)):
    #    cubit.cmd("cf_crease_entities add Edge " + str(EinC[e]))

    VinC = cubit.parse_cubit_list("node", " in curve 1")
    for n in range(0, len(VinC)):
        nxyz = cubit.get_nodal_coordinates(VinC[n])
        bc_xyz.append(list(nxyz))
        N = cubit.parse_cubit_list(
            "node", " at " + str(nxyz[0]) + " " + str(nxyz[1]) + " 0.")

        for n in range(0, len(N)):
            nodeEdges = cubit.parse_cubit_list("edge", "in node " + str(N[n]))
            for e in range(0, len(nodeEdges)):
                if nodeEdges[e] in EinC:
                    pass
                else:
                    cubit.cmd("cf_crease_entities add Edge " +
                              str(nodeEdges[e]))

    #V = cubit.get_entities("vertex")[num_base_vertex:]

    #cubit.cmd('create group "cf_crease_entities"')
    #bc_xyz = [[] for i in range(0,len(V))]
    #for i in range(0,len(V)):
    #    #ssID = cubit.get_next_sideset_id()
    #    bc_xyz[i] = list(cubit.vertex(V[i]).coordinates())
    #    cubit.parse_cubit_list("vertex", "at " + str(bc_)
    #    N = cubit.get_vertex_node(V[i])
    #    nodeEdges = cubit.parse_cubit_list('edge','in node ' + str(N))
    #    for e in range(0,len(nodeEdges)):
    #        #cubit.cmd("sideset " + str(ssID) + " add Edge " + str(nodeEdges[e]))
    #        cubit.cmd("cf_crease_entities add Edge " + str(nodeEdges[e]))
    #    #cubit.cmd("sideset " + str(ssID) + ' name "node_' + str(N) + '_edges"')

    cubit.cmd('save as "mesh.cub" overwrite')
    num_elem = len(cubit.get_entities("Face"))
    return status, bc_xyz, num_elem, nlcon
Пример #9
0
def makeGeometry(x, y):
    status = 0
    cubit.cmd("reset")
    cubit.cmd('open "pcb_geom.trelis"')
    cubit.cmd("compress ids")

    x = numpy.array(x)
    y = numpy.array(y)

    sys.stdout.write("PIN-X = " + str(x) + "\n")
    sys.stdout.flush()

    # Test to see if the vertex is contained on the target surface
    target_surface = cubit.surface(2)  # Target surface is id = 2
    vertex_on_surface = numpy.zeros(len(x), dtype=bool)
    for i in range(0, len(x)):
        vertex_on_surface[i] = target_surface.point_containment(
            [x[i], y[i], 0.])
    X = x[vertex_on_surface]
    Y = y[vertex_on_surface]

    # Compute Nonlinear Constraints
    nlcon = computeNonlinearConstraint(x, y)
    sys.stdout.write("Nonlinear Constraints: ")
    sys.stdout.write(str(nlcon))
    sys.stdout.write("\n")
    sys.stdout.flush()

    num_active_pins = len(X)
    sys.stdout.write("#" * 10 + "NUMBER OF ACTIVE PINS = " +
                     str(num_active_pins) + "#" * 10 + "\n")
    sys.stdout.flush()
    if num_active_pins == 0:
        # No pins on board, return with nonlinear constraint values
        status = 1
        return status, [], [], nlcon

    # Delete the target surface -- we don't need it anymore
    cubit.cmd("delete vol 2")
    cubit.cmd("compress ids")

    # Imprint circles on the geometry surface
    # Get initial curve ids
    C = cubit.get_entities("curve")
    for i in range(0, num_active_pins):
        cubit.cmd(
            "webcut volume all with cylinder radius 2.75 axis z center " +
            str(X[i]) + " " + str(Y[i]) + " 0.")
        #cubit.cmd("create curve arc radius 2.75 center location " + str(X[i]) + " " + str(Y[i]) + " 0 normal 0 0 1 start angle 0 stop angle 360 ")
    cubit.cmd("imprint all")
    cubit.cmd("merge all")
    cubit.cmd("stitch volume all")
    cubit.cmd("compress ids")
    #CF = cubit.get_list_of_free_ref_entities("curve")
    #for i in range(0,len(CF)):
    #    cubit.cmd("partition create surface all  curve " + str(CF[i]))
    #cubit.cmd("delete free curve all")
    cubit.cmd("compress ids")

    # Mesh the pin surfaces first
    S = cubit.get_entities("surface")
    for i in range(0, len(S)):
        if cubit.surface(S[i]).area() <= (1.1 * numpy.pi * (2.75**2)):
            cubit.cmd("surface " + str(S[i]) + " size 4")
            cubit.cmd("surface " + str(S[i]) + " scheme circle")
            cubit.cmd("mesh surface " + str(S[i]))
        else:
            board_surf_id = S[i]

    # Now mesh the board
    cubit.cmd("surface " + str(board_surf_id) + " size 10")
    cubit.cmd("mesh surface " + str(board_surf_id))

    # Smooth the surface mesh
    cubit.cmd("surface all smooth scheme mean ratio cpu 0.1")
    cubit.cmd("smooth surf all")

    # Set the BC edges to be creased to C^0
    cubit.cmd('create group "cf_crease_entities"')
    S_BC = cubit.get_entities("surface")
    for i in range(0, len(S_BC)):
        if S_BC[i] == board_surf_id:
            pass
        else:
            surf_edges = cubit.parse_cubit_list("edge",
                                                "in surface " + str(S_BC[i]))
            for e in range(0, len(surf_edges)):
                cubit.cmd("group 2 add edge " + str(surf_edges[e]))

    ### Prepare function return ###
    num_elem = len(cubit.get_entities("Face"))

    # Package the pin locations for function return
    bc_xyz = []
    for i in range(0, len(X)):
        bc_xyz.append([X[i], Y[i], 0.])

    # Save the cubit file
    cubit.cmd('save as "mesh.cub" overwrite')

    return status, bc_xyz, num_elem, nlcon
def geom_cubit_main(configfile):
    if not os.path.isfile(configfile) :
        raise Exception("ERR: CONFIG FILE DON'T EXIST !!!")
    #  READ CONFIGFILE
    cf = ConfigParser.ConfigParser()
    cf.read(configfile)
    experience_name = cf.get('Input','experience_name')
    bathyfile = cf.get('Input','bathyfile')
    slabfile = cf.get('Input','slabfile')
    left_extension=cf.getfloat('Parameters','left_extension') # (always positive)
    right_extension=cf.getfloat('Parameters','right_extension')
    down_limit=cf.getfloat('Parameters','down_limit') # (always positive)
    EET_OP=cf.getfloat('Parameters','EET_OP') #  Thickness of the OP Litho
    EET_DP=cf.getfloat('Parameters','EET_DP') #  Thickness of the DP Litho
    backstop_bool=cf.getboolean('Parameters','backstop_bool') # True or False
    x_backstop=cf.getfloat('Parameters','x_backstop')
    dip_backstop=cf.getfloat('Parameters','dip_backstop')
    output_path=cf.get('Output','output_path')
    output_file_prefix=cf.get('Output','output_file_prefix')
    output_pathfile = output_path + '/'  + output_file_prefix + '_'  + experience_name + '.exo'
    # =======================================================================
    #  PRIOR DESIGN
    # =======================================================================
    # Loading the BATHY and SLAB files
    XYbathy = np.loadtxt(bathyfile)
    XYslab = np.loadtxt(slabfile)
    # Creating the bottom of the slab
    XslabBot,YslabBot,_ = gcl.shift_thickness(XYslab[:,0],XYslab[:,1],EET_DP)
    # Creating the bounding points in a dictionnary
    outpts = gcl.make_bounding_points(XYbathy[:,0],XYbathy[:,1],XYslab[:,0],XYslab[:,1],EET_OP,EET_DP,down_limit,left_extension,right_extension)
    # Creating the backstop
    Xbackstop,Ybackstop = gcl.make_backstop(XYbathy[:,0],XYbathy[:,1],XYslab[:,0],XYslab[:,1],x_backstop,dip_backstop,dupdown=150)
    # Adding the 'Bottom_Litho_DP' point to the Litho_DP Bottom
    gcl.add_point_in_list(XslabBot,YslabBot,outpts['vBottom_Litho_DP'])
    # Changing the description concept : Bathy & Slab ==> OP & DP
    Xop,Yop,Xdp,Ydp = gcl.bathyslab_2_OPDPtop(XYbathy[:,0],XYbathy[:,1],XYslab[:,0],XYslab[:,1])
    # Adding the limit points of OP & DP
    Xop,Yop = gcl.add_point_in_list(Xop,Yop,outpts['vBathy_OP'])
    Xdp,Ydp = gcl.add_point_in_list(Xdp,Ydp,outpts['vBathy_DP'])
    # PLOT FOR SECURITY
    #plt.clf()
    #plt.axis('equal')
    #plt.plot(XYbathy[:,0],XYbathy[:,1],'+b')
    #plt.plot(XYslab[:,0],XYslab[:,1],'r+-')
    #plt.plot(XslabBot,YslabBot,'k+-')
    #plt.plot(Xbackstop,Ybackstop,'*-y')
    #for p in outpts.viewvalues():
    #    plt.plot(p[0],p[1],'*k')
    #plt.plot(Xop,Yop,'b-')
    #plt.plot(Xdp,Ydp,'r-')
    # =======================================================================
    #  CUBIT MESHING
    # =======================================================================
    # Initalisation
    cubit.cmd('reset')  
    cubit.cmd("#{Units('si')}")  
    # Chargement des courbes
    gcl.list_2_curve(Xop,Yop,'Top_Litho_OP')
    gcl.list_2_curve(Xdp,Ydp,'Top_Litho_limit_DP')
    gcl.list_2_curve(XslabBot,YslabBot,'Bottom_Litho_DP')
    gcl.list_2_curve(Xbackstop,Ybackstop,'Backstop')
    # Chargement des Points Isolés
    gcl.dico_2_listofvertices(outpts)
    ## fabrication de "courbes-segments" a partir de vertex
    v_Bottom_Litho_OP = cubit.vertex(cubit.get_id_from_name('vBottom_Litho_OP'))
    v_Bathy_DP = gcl.find_extrema(cubit.curve(cubit.get_id_from_name("Top_Litho_limit_DP")),'r')
    v_Bathy_OP = gcl.find_extrema(cubit.curve(cubit.get_id_from_name('Top_Litho_OP')),'l')
    v_Bottom_Litho_DP = gcl.find_extrema(cubit.curve(cubit.get_id_from_name("Bottom_Litho_DP")),'r')
    v_scratch = cubit.vertex(cubit.get_id_from_name('vscratch'))
    v_Bottom_Astheno_OP = cubit.vertex(cubit.get_id_from_name('vBottom_Astheno_OP'))
    v_Bottom_Astheno_DP = cubit.vertex(cubit.get_id_from_name('vBottom_Astheno_DP'))
    # 
    gcl.vertices_2_curve(v_Bottom_Litho_OP,v_Bottom_Astheno_OP,'Edge_Astheno_OP')
    gcl.vertices_2_curve(v_Bottom_Litho_OP,v_scratch,'Bottom_Litho_OP_PROTO')
    gcl.vertices_2_curve(v_Bottom_Litho_OP,v_Bathy_OP,'Edge_Litho_OP')
    gcl.vertices_2_curve(v_Bottom_Astheno_OP,v_Bottom_Astheno_DP,'Bottom_PROTO')
    gcl.vertices_2_curve(v_Bathy_DP,v_Bottom_Litho_DP,'Edge_Litho_DP')
    gcl.vertices_2_curve(v_Bottom_Litho_DP,v_Bottom_Astheno_DP,'Edge_Astheno_DP') 
    ## Split des courbes
    gcl.double_split_desc(2,6)
    gcl.double_split_desc(8,11)
    gcl.double_split_desc(16,3)
    gcl.double_split_desc(4,12)
    gcl.double_split_desc(1,23)
    gcl.double_split_desc(26,28)
    ## suppression des petits morceaux
    gcl.destroy_curve(cubit.curve(14))
    gcl.destroy_curve(cubit.curve(24))
    gcl.destroy_curve(cubit.curve(17))
    gcl.destroy_curve(cubit.curve(21))
    gcl.destroy_curve(cubit.curve(29))
    ## renommage des courbes
    gcl.rename_curve_desc(7,'Edge_Litho_OP')
    gcl.rename_curve_desc(5,'Edge_Astheno_OP')
    gcl.rename_curve_desc(9,'Edge_Litho_DP')
    gcl.rename_curve_desc(10,'Edge_Astheno_DP')
    gcl.rename_curve_desc(25,'Contact_OP_DP')
    gcl.rename_curve_desc(31,'Contact_Prism_DP')
    gcl.rename_curve_desc(30,'Contact_Prism_OP')
    gcl.rename_curve_desc(32,'Top_Litho_DP')
    gcl.rename_curve_desc(33,'Top_Prism')
    gcl.rename_curve_desc(27,'Top_Litho_OP')
    gcl.rename_curve_desc(20,'Bottom_Astheno_DP')
    gcl.rename_curve_desc(22,'Bottom_Litho_DP')
    gcl.rename_curve_desc(15,'Bottom_Astheno_OP')
    gcl.rename_curve_desc(13,'Bottom_Litho_OP')
    gcl.rename_curve_desc(19,'Front_Litho_DP')
    gcl.rename_curve_desc(18,'Astheno_Litho_Contact')
    # creation des surfaces
    gcl.create_surface_desc([10,20,22])
    gcl.create_surface_desc([19,18,25,31,32,9,22])
    gcl.create_surface_desc([13,18,15,5])
    gcl.create_surface_desc([13,7,27,30,25])
    gcl.create_surface_desc([30,31,33])
    # renomage des surfaces
    cubit.surface(1).entity_name('Astheno_DP')
    cubit.surface(2).entity_name('Litho_DP')
    cubit.surface(3).entity_name('Astheno_OP')
    cubit.surface(4).entity_name('Litho_OP')
    cubit.surface(5).entity_name('Prisme')
    # Fusion des surfaces
    cubit.cmd('delete vertex all')
    cubit.cmd('imprint all')
    cubit.cmd('merge all')
    cubit.cmd('stitch volume all')
    cubit.cmd('surface all scheme trimesh')
    cubit.cmd('curve all scheme default')
    cubit.cmd('surface all sizing function none')
    # nouveau decoupage des courbes
    dx1 = 4.0
    dx2 = 25.0
    dx3 = 8
    b1=1.1
    gcl.curver_desc("Contact_Prism_DP",dx1)
    gcl.curver_desc("Contact_Prism_OP",dx1)
    gcl.curver_desc("Top_Prism",dx1)
    gcl.curver_desc("Bottom_Litho_DP",dx2)
    gcl.curver_desc("Bottom_Astheno_OP",dx2)
    gcl.curver_desc("Front_Litho_DP",dx2)
    gcl.curver_desc("Bottom_Astheno_DP",dx2)
    gcl.curver_desc("Edge_Astheno_OP",dx2)
    gcl.curver_desc("Edge_Litho_OP",dx2)
    gcl.curver_desc("Edge_Astheno_DP",dx2)
    gcl.curver_desc("Edge_Litho_DP",dx2)
    gcl.curver_desc("Contact_OP_DP",dx1)
    gcl.curver_start_end_desc("Bottom_Litho_OP",dx1,dx2,'l')
    gcl.curver_start_end_desc("Top_Litho_OP",dx1,dx2,'l')
    gcl.curver_start_end_desc("Top_Litho_DP",dx1,dx2,'r')
    gcl.curver_start_end_desc("Astheno_Litho_Contact",dx1,dx2,'l')  
    # fabrication du mesh
    cubit.cmd('mesh surface all')
    cubit.cmd('surface all smooth scheme condition number beta 1.7 cpu 10')
    cubit.cmd('smooth surface all')
    cubit.cmd('surface 1 size auto factor 5')
    ## Fabrication de groupe et de nodeset
    for i,s in enumerate(cubit.get_entities("surface")):
        S = cubit.surface(s)
        cubit.cmd('block ' + str(i+1) + ' surface ' + S.entity_name())
        cubit.cmd('block ' + str(i+1) + ' name "' + S.entity_name() + ' "' )
    gcl.create_group_nodeset_desc(['Astheno_Litho_Contact','Contact_OP_DP','Contact_Prism_DP'],"fault_top",20)     
    gcl.create_group_nodeset_desc(['Top_Litho_OP','Top_Prism','Top_Litho_DP'],"ground_surface",20)     
    gcl.create_group_nodeset_desc(['Bottom_Litho_OP'],"bottom_litho_OP",20)     
    gcl.create_group_nodeset_desc(['Bottom_Litho_DP'],"bottom_litho_DP",20)     
    gcl.create_group_nodeset_desc(['Bottom_Astheno_DP','Bottom_Astheno_OP'],"bottom_astheno",20) 
    gcl.create_group_nodeset_desc(['Edge_Litho_OP'],"edge_litho_OP",20) 
    gcl.create_group_nodeset_desc(['Edge_Litho_DP'],"edge_litho_DP",20) 
    gcl.create_group_nodeset_desc(['Edge_Astheno_OP'],"edge_astheno_OP",20) 
    gcl.create_group_nodeset_desc(['Edge_Astheno_DP'],"edge_astheno_DP",20) 
    gcl.create_group_nodeset_desc(['Front_Litho_DP'],"front_litho_DP",20) 
    gcl.create_group_nodeset_desc(['Contact_Prism_OP'],"contact_prism_OP",20)
    # ecriture fichier final
    cubit.cmd('export mesh "' + output_pathfile + '" dimension 2 overwrite')
    return None