1 # CEA/LGLS-LETR 2008, Francis KLOSS (OCC)
2 # =======================================
4 # Procedure that take a triangulation and split all triangles in 4 others triangles
12 # Path for ".med" files
15 # Name of the shape and the mesh
18 # Add a node and needed edges
19 # ---------------------------
21 def node(m, f, n1, n2, lnv):
22 x1, y1, z1 = m.GetNodeXYZ(n1)
23 x2, y2, z2 = m.GetNodeXYZ(n2)
29 i = m.AddNode(x, y, z)
31 in1 = m.GetShapeID(n1)
32 in2 = m.GetShapeID(n2)
34 if (in1==f) or (in2==f):
35 m.SetNodeOnFace(i, f, 0, 0)
38 e1 = m.AddEdge([ n1, i ])
39 e2 = m.AddEdge([ i , n2 ])
46 m.SetMeshElementOnShape(e1, e)
47 m.SetMeshElementOnShape(e2, e)
48 m.SetNodeOnEdge(i, e, 0)
52 # Add a triangle and associate to the CAD face
53 # --------------------------------------------
55 def triangle(m, f, n1, n2, n3):
56 i = m.AddFace([ n1, n2, n3 ])
57 m.SetMeshElementOnShape(i, f)
59 # Split all triangles in 4 triangles
60 # ----------------------------------
62 def SplitTrianglesIn4(m):
64 triangles = m.GetElementsByType(smesh.FACE)
67 m.RemoveElements(m.GetElementsByType(smesh.EDGE))
69 # Get the list of nodes (ids) associated with the CAD vertices
72 for v in geompy.SubShapeAll(shape, geompy.ShapeType["VERTEX"]):
73 lnv = lnv + m.GetSubMeshNodesId(v, True)
75 # Split every triangle
77 noeud_1, noeud_2, noeud_3 = m.GetElemNodes(t)
79 face = m.GetShapeIDForElem(t)
81 noeud_12 = node(m, face, noeud_1, noeud_2, lnv)
82 noeud_23 = node(m, face, noeud_2, noeud_3, lnv)
83 noeud_13 = node(m, face, noeud_1, noeud_3, lnv)
85 triangle(m, face, noeud_1 , noeud_12, noeud_13)
86 triangle(m, face, noeud_2 , noeud_23, noeud_12)
87 triangle(m, face, noeud_3 , noeud_13, noeud_23)
88 triangle(m, face, noeud_12, noeud_23, noeud_13)
90 # Remove all initial triangles
91 m.RemoveElements(triangles)
93 # Merge all identical nodes
94 m.MergeNodes(m.FindCoincidentNodes(0.0001))
99 x0 = 0.0 ; y0 = 0.0 ; z0 = 0.0
100 x1 = 1.0 ; y1 = 0.0 ; z1 = 0.0
101 x2 = 1.0 ; y2 = 1.0 ; z2 = 0.0
102 x3 = 0.0 ; y3 = 1.0 ; z3 = 0.0
104 P0 = geompy.MakeVertex(x0, y0, z0)
105 P1 = geompy.MakeVertex(x1, y1, z1)
106 P2 = geompy.MakeVertex(x2, y2, z2)
107 P3 = geompy.MakeVertex(x3, y3, z3)
109 square = geompy.MakeQuad4Vertices(P0, P1, P2, P3)
110 geompy.addToStudy(square, name)
112 # Refine edges and create group of mesh
113 # -------------------------------------
115 def refine(m, p1, p2, n, k, name):
118 g = geompy.CreateGroup(s, geompy.ShapeType["EDGE"])
119 e = geompy.GetEdge(s, p1, p2)
120 i = geompy.GetSubShapeID(s, e)
121 geompy.AddObject(g, i)
125 a.NumberOfSegments(n, k)
130 MyMesh = smesh.Mesh(square)
132 refine(MyMesh, P1, P2, 8, 7, "Droite")
133 refine(MyMesh, P3, P0, 9, 10, "Gauche")
134 refine(MyMesh, P0, P1, 7, 9, "Bas" )
135 refine(MyMesh, P2, P3, 12, 14, "Haut" )
137 algo2D = MyMesh.Triangle()
138 algo2D.MaxElementArea(0.07)
142 MyMesh.ExportMED(path+"110_triangles.med", 0)
147 MyMesh.MoveNode( 37, 0.05 , 0.368967 , 0 )
148 MyMesh.MoveNode( 38, 0.34 , 0.0762294, 0 )
149 MyMesh.MoveNode( 40, 0.8 , 0.42 , 0 )
150 MyMesh.MoveNode( 42, 0.702662, 0.74 , 0 )
151 MyMesh.MoveNode( 46, 0.4 , 0.374656 , 0 )
152 MyMesh.MoveNode( 47, 0.13 , 0.63 , 0 )
153 MyMesh.MoveNode( 49, 0.222187, 0.3 , 0 )
154 MyMesh.MoveNode( 54, 0.557791, 0.05 , 0 )
155 MyMesh.MoveNode( 55, 0.7 , 0.2 , 0 )
156 MyMesh.MoveNode( 56, 0.73 , 0.52 , 0 )
157 MyMesh.MoveNode( 58, 0.313071, 0.31 , 0 )
158 MyMesh.MoveNode( 59, 0.8 , 0.56 , 0 )
159 MyMesh.MoveNode( 62, 0.592703, 0.95 , 0 )
160 MyMesh.MoveNode( 63, 0.28 , 0.5 , 0 )
161 MyMesh.MoveNode( 65, 0.49 , 0.93 , 0 )
162 MyMesh.MoveNode( 68, 0.501038, 0.65 , 0 )
163 MyMesh.MoveNode( 69, 0.37 , 0.63 , 0 )
164 MyMesh.MoveNode( 70, 0.597025, 0.52 , 0 )
165 MyMesh.MoveNode( 72, 0.899 , 0.878589 , 0 )
166 MyMesh.MoveNode( 73, 0.92 , 0.85 , 0 )
167 MyMesh.MoveNode( 74, 0.820851, 0.75 , 0 )
170 MyMesh.ExportMED(path+"110_triangles_2.med", 0)
172 # First mesh refining
173 # -------------------
175 SplitTrianglesIn4(MyMesh)
177 NbCells2 = NbCells1*4
178 print("Mesh with "+str(NbCells2)+" cells computed.")
180 MyMesh.ExportMED(path+str(NbCells2)+"_triangles.med", 0)
182 # Second mesh refining
183 # --------------------
185 SplitTrianglesIn4(MyMesh)
187 NbCells3 = NbCells2*4
188 print("Mesh with "+str(NbCells3)+" cells computed.")
190 MyMesh.ExportMED(path+str(NbCells3)+"_triangles.med",0)
192 # Third mesh refining
193 # -------------------
195 SplitTrianglesIn4(MyMesh)
197 NbCells4 = NbCells3*4
198 print("Mesh with "+str(NbCells4)+" cells computed.")
200 MyMesh.ExportMED(path+str(NbCells4)+"_triangles.med", 0)
202 # Update the object browser
203 # -------------------------
205 salome.sg.updateObjBrowser(1)