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 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
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()
def saveMesh3D(self): cubit.cmd("brick x 5000 y 5000 z 5000") cubit.cmd("create cylinder height 4000 radius 500") cubit.cmd("subtract body 2 from body 1") volID = cubit.get_last_id("volume") self.vol = volID self.mesh() nNodes = cubit.get_node_count() meshFile = open(folder+"mesh3D2.xml", 'w') meshFile.write('<mesh celltype="tetrahedron" dim="3">\n') meshFile.write(' <nodes size="%d">\n' % (nNodes)) for x in range(0, nNodes): coords = cubit.get_nodal_coordinates(x+1) meshFile.write(' <node id="%d" x="%f" y="%f" z="%f"/>\n' % (x,coords[0],coords[1],coords[2])) meshFile.write(' </nodes>\n') nTets = cubit.get_tet_count() meshFile.write(' <elements size="%d">\n' % (nTets)) for x in range(0, nTets): nodes = cubit.get_connectivity("tet", x+1) meshFile.write(' <element id="%d" v0="%d" v1="%d" v2="%d" v3="%d"/>\n' % (x,nodes[0]-1,nodes[1]-1,nodes[2]-1,nodes[3]-1)) meshFile.write(' </elements>\n') meshFile.write(' <element_data type="fiber_transversely_isotropic">\n') for x in range(0, nTets): meshFile.write(' <element id="%d">\n' %(x)) meshFile.write(' <fiber>1.000000,0.000000,0.000000</fiber>\n') meshFile.write(' </element>\n') meshFile.write(' </element_data>\n') meshFile.write(' <boundary celltype="triangle" dim="2">\n') bsurfs = [10, 11, 12] ec = 0 for x in range(0, len(bsurfs)): tris = cubit.get_surface_tris(bsurfs[x]) surf = cubit.surface(bsurfs[x]) for y in range(0, len(tris)): cp = cubit.get_center_point("tri", tris[y]) norm = surf.normal_at([cp[0],cp[1],cp[2]]) #cubit.cmd("create curve location %f %f %f direction %f %f %f length %f" % (cp[0],cp[1],cp[2],norm[0],norm[1],norm[2],200)) nodes = cubit.get_connectivity("tri", tris[y]) element = [nodes[0]-1, nodes[1]-1, nodes[2]-1] meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d" nx="%f" ny="%f" nz="%f"/>\n' % (ec,1.0,element[0],element[1],element[2],norm[0],norm[1],norm[2])) ec = ec+1 meshFile.write(' </boundary>\n') meshFile.write('</mesh>\n') meshFile.write('<poisson>\n') meshFile.write(' <neumann>\n') meshFile.write(' <node id="1" marker="1" value="0.5" />\n') meshFile.write(' </neumann>\n') meshFile.write('</poisson>\n') #meshFile.write('<electrophysiology>\n') #meshFile.write(' <stimuli number="1">\n') #bb = cubit.get_bounding_box("volume", self.vol) #x0 = bb[0] #x1 = 0.8*x0 + 0.2*bb[1] #y0 = bb[3] #y1 = 0.8*y0 + 0.2*bb[4] #z0 = bb[6] #z1 = 0.8*z0 + 0.2*bb[7] #meshFile.write(' <stim start="0.00" duration="4.00" value="-35.7140" x0="%f" x1="%f" y0="%f" y1="%f" z0="%f" z1="%f" />\n' % (x0,x1,y0,y1,z0,z1)) #meshFile.write(' </stimuli>\n') #meshFile.write('</electrophysiology>\n') meshFile.close()
def saveMesh(self): nNodes = cubit.get_node_count() nTets = cubit.get_tet_count() meshFile = open(folder+"Cubo.xml", 'w') meshFile.write('<mesh celltype="tetrahedron" dim="3">\n') meshFile.write(' <nodes size="%d">\n' % (nNodes)) for x in range(0, nNodes): coords = cubit.get_nodal_coordinates(x+1) meshFile.write(' <node id="%d" x="%f" y="%f" z="%f"/>\n' % (x,coords[0],coords[1],coords[2])) meshFile.write(' </nodes>\n') meshFile.write(' <elements size="%d">\n' % (nTets)) for x in range(0, nTets): nodes = cubit.get_connectivity("tet", x+1) meshFile.write(' <element id="%d" v0="%d" v1="%d" v2="%d" v3="%d"/>\n' % (x,nodes[0]-1,nodes[1]-1,nodes[2]-1,nodes[3]-1)) meshFile.write(' </elements>\n') meshFile.write(' <element_data type="fiber_transversely_isotropic">\n') for x in range(0, nTets): meshFile.write(' <element id="%d">\n' %(x)) meshFile.write(' <fiber>1.000000,0.000000,0.000000</fiber>\n') meshFile.write(' </element>\n') meshFile.write(' </element_data>\n') meshFile.write(' <boundary celltype="triangle" dim="2">\n') bsurfs = cubit.get_relatives("volume", self.vol, "surface") ec = 0 for x in range(0, len(bsurfs)): #for x in range(6, len(bsurfs)): #if x is not 16 and x is not 14: tris = cubit.get_surface_tris(bsurfs[x]) surf = cubit.surface(bsurfs[x]) for y in range(0, len(tris)): cp = cubit.get_center_point("tri", tris[y]) norm = surf.normal_at([cp[0],cp[1],cp[2]]) #cubit.cmd("create curve location %f %f %f direction %f %f %f length %f" % (cp[0],cp[1],cp[2],norm[0],norm[1],norm[2],200)) nodes = cubit.get_connectivity("tri", tris[y]) element = [nodes[0]-1, nodes[1]-1, nodes[2]-1] meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d" nx="%f" ny="%f" nz="%f"/>\n' % (ec,1.0,element[0],element[1],element[2],norm[0],norm[1],norm[2])) ec = ec+1 meshFile.write(' </boundary>\n') #meshFile.write(' <boundary celltype="triangle" dim="2">\n') #surfs = cubit.get_relatives("volume", self.vol, "surface") #ec = 0 #for x in range(0, 2): # tris = cubit.get_surface_tris(surfs[x]) # for y in range(0, len(tris)): # nodes = cubit.get_connectivity("tri", tris[y]) # element = [nodes[0]-1, nodes[1]-1, nodes[2]-1] # ec = ec+1 # meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec,x,element[0],element[1],element[2])) #meshFile.write(' <element id="%d" marker="%d" v0="%d" v1="%d" v2="%d"/>\n' % (ec+1,2,element[0],element[1],element[2])) #meshFile.write(' </boundary>\n') meshFile.write('</mesh>\n') meshFile.write('<poisson>\n') meshFile.write(' <neumann>\n') #meshFile.write(' <node id="0" marker="0" value="-1.0" />\n') meshFile.write(' <node id="1" marker="1" value="0.05"/>\n') meshFile.write(' </neumann>\n') #meshFile.write(' <dirichlet>\n') #meshFile.write(' <node id="2" marker="2" value="0.0" />\n') #meshFile.write(' </dirichlet>\n') meshFile.write('</poisson>\n') #meshFile.write('<electrophysiology>\n') #meshFile.write(' <stimuli number="1">\n') #bb = cubit.get_bounding_box("volume", self.vol) #x0 = bb[0] #x1 = 0.8*x0 + 0.2*bb[1] #y0 = bb[3] #y1 = 0.8*y0 + 0.2*bb[4] #z0 = bb[6] #z1 = 0.8*z0 + 0.2*bb[7] #meshFile.write(' <stim start="0.00" duration="4.00" value="-35.7140" x0="%f" x1="%f" y0="%f" y1="%f" z0="%f" z1="%f" />\n' % (x0,x1,y0,y1,z0,z1)) #meshFile.write(' </stimuli>\n') #meshFile.write('</electrophysiology>\n') meshFile.close()
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
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