]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Run all SMESH tests at once: all tests pass in 2min instead of 1h20min
authorvsr <vsr@opencascade.com>
Wed, 31 Oct 2018 11:48:24 +0000 (14:48 +0300)
committervsr <vsr@opencascade.com>
Wed, 31 Oct 2018 11:48:24 +0000 (14:48 +0300)
doc/salome/examples/CMakeLists.txt
doc/salome/examples/creating_meshes_ex06.py
doc/salome/examples/modifying_meshes_ex09.py
doc/salome/examples/modifying_meshes_ex23.py
doc/salome/examples/tests.py.in [new file with mode: 0644]
doc/salome/examples/use_existing_faces.py

index 7aa40fe8d158de56875b8a332c5cbeabf97b6229..bfdc0a4f691bad71966bf81773db7d1e51651a3a 100644 (file)
 
 INCLUDE(tests.set)
 
+SET(TEST_REINIT_SALOME "False")
+SALOME_CONFIGURE_FILE(tests.py.in tests.py)
+
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
-FOREACH(test ${GOOD_TESTS})
-  GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
-  ADD_TEST(NAME ${testname}
-           COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
-  SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
-ENDFOREACH()
+IF(SMESH_JOIN_TESTS)
+  ADD_TEST(NAME SMESH_examples COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py tests.py)
+ELSE(SMESH_JOIN_TESTS)
+  FOREACH(test ${GOOD_TESTS})
+    GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
+    ADD_TEST(NAME ${testname}
+             COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
+    SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
+  ENDFOREACH()
+ENDIF(SMESH_JOIN_TESTS)
 
 # install Python scripts
 SALOME_INSTALL_SCRIPTS("${EXAMPLES_TESTS}" ${SALOME_INSTALL_DOC}/examples/SMESH)
index 3cc4dc1023d98decd129ae2f8b66bf58b4ed444f..20b8a043446a54a3dc776bd14da8e30e976c769e 100644 (file)
@@ -58,24 +58,19 @@ geompy.addToStudy(blocks, "cylinder:blocks")
 # Build geometric groups
 # ----------------------
 
-def group(name, shape, type, base=None, direction=None):
-    t = geompy.ShapeType[type]
-    g = geompy.CreateGroup(shape, t)
-
-    geompy.addToStudyInFather(shape, g, name)
-
-    if base!=None:
-        l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
-        geompy.UnionIDs(g, l)
-
-    return g
-
-group_a = group("baseA", blocks, "FACE", base, direction)
-
-base_b  = geompy.MakeVertex(0, 0, height)
-group_b = group("baseB", blocks, "FACE", base_b, direction)
-
-group_1     = group("limit", blocks, "SOLID")
+group_a = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
+geompy.addToStudyInFather(blocks, group_a, "baseA")
+items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base, GEOM.ST_ON)
+geompy.UnionIDs(group_a, items)
+
+base_b = geompy.MakeVertex(0, 0, height)
+group_b = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
+geompy.addToStudyInFather(blocks, group_b, "baseB")
+items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base_b, GEOM.ST_ON)
+geompy.UnionIDs(group_b, items)
+
+group_1 = geompy.CreateGroup(blocks, geompy.ShapeType["SOLID"])
+geompy.addToStudyInFather(blocks, group_1, "limit")
 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
 geompy.UnionIDs(group_1, group_1_all)
 group_1_box = geompy.GetBlockNearPoint(blocks, base)
@@ -86,22 +81,34 @@ geompy.DifferenceList(group_1, [group_1_box])
 
 smesh.UpdateStudy()
 
-def discretize(x, y, z,  nbSeg, shape=blocks):
-    vert = geompy.MakeVertex( x, y, z )
-    edge = geompy.GetEdgeNearPoint( shape, vert )
-    algo = hexa.Segment( edge )
-    algo.NumberOfSegments( nbSeg )
-    algo.Propagation()
-
 hexa = smesh.Mesh(blocks)
 
 hexa_1d = hexa.Segment()
 hexa_1d.NumberOfSegments(1)
 
-discretize(+radius        , +radius,        0,   5)
-discretize(-radius        , +radius,        0,   8)
-discretize((radius+size)/2,       0,        0,  10)
-discretize(        +radius,       0, height/2,  20)
+vertex = geompy.MakeVertex(+radius, +radius, 0)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(5)
+algo.Propagation()
+
+vertex = geompy.MakeVertex(-radius, +radius, 0)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(8)
+algo.Propagation()
+
+vertex = geompy.MakeVertex((radius+size)/2, 0, 0)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(10)
+algo.Propagation()
+
+vertex = geompy.MakeVertex(+radius, 0, height/2)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(20)
+algo.Propagation()
 
 hexa.Quadrangle()
 hexa.Hexahedron()
index 401fda8d6edc6feb88305aeb0e666a8eb185d1a1..057a5d6a2d1852974bf0ff11a9c409b2d90a5509 100644 (file)
@@ -1,37 +1,36 @@
 # Add Polygon
 
-import math
-
 import salome
 salome.salome_init()
 
 import SMESH, SALOMEDS
 from salome.smesh import smeshBuilder
-smesh =  smeshBuilder.New()
-
+smesh = smeshBuilder.New()
 
 # create an empty mesh structure
 mesh = smesh.Mesh() 
 
 # a method to build a polygonal mesh element with <nb_vert> angles:
-def MakePolygon (a_mesh, x0, y0, z0, radius, nb_vert):
+def MakePolygon (a_mesh, x0, y0, z0, radius, nb_vert, smesh_builder):
+    import math
+
     al = 2.0 * math.pi / nb_vert
     node_ids = []
 
     # Create nodes for a polygon
     for ii in range(nb_vert):
-        nid = mesh.AddNode(x0 + radius * math.cos(ii*al),
-                           y0 + radius * math.sin(ii*al),
-                                                     z0)
+        nid = smesh_builder.AddNode(x0 + radius * math.cos(ii*al),
+                                    y0 + radius * math.sin(ii*al),
+                                    z0)
         node_ids.append(nid)
         pass
 
     # Create a polygon
-    return mesh.AddPolygonalFace(node_ids)
+    return smesh_builder.AddPolygonalFace(node_ids)
 
 # Create three polygons
-f1 = MakePolygon(mesh, 0, 0,  0, 30, 13)
-f2 = MakePolygon(mesh, 0, 0, 10, 21,  9)
-f3 = MakePolygon(mesh, 0, 0, 20, 13,  6)
+f1 = MakePolygon(mesh, 0, 0,  0, 30, 13, smesh_builder=mesh)
+f2 = MakePolygon(mesh, 0, 0, 10, 21,  9, smesh_builder=mesh)
+f3 = MakePolygon(mesh, 0, 0, 20, 13,  6, smesh_builder=mesh)
 
 salome.sg.updateObjBrowser()
index ac8556262d0f21cf97065a290c274e701dc88e93..65b57ff36d2e552d080817eb967d90412d982c14 100644 (file)
@@ -44,8 +44,8 @@ for ii in range(len(Wire_polyline_edges)):
 # Mesh
 
 # Mesh the given shape with the given 1d hypothesis
-def Mesh1D(shape1d, nbSeg, name):
-  mesh1d_tool = smesh.Mesh(shape1d, name)
+def Mesh1D(shape1d, nbSeg, name, smesh_builder):
+  mesh1d_tool = smesh_builder.Mesh(shape1d, name)
   algo = mesh1d_tool.Segment()
   hyp  = algo.NumberOfSegments(nbSeg)
   isDone = mesh1d_tool.Compute()
@@ -53,8 +53,8 @@ def Mesh1D(shape1d, nbSeg, name):
   return mesh1d_tool
 
 # Create a mesh with six nodes, seven edges and two quadrangle faces
-def MakeQuadMesh2(mesh_name):
-  quad_1 = smesh.Mesh(name = mesh_name)
+def MakeQuadMesh2(mesh_name, smesh_builder):
+  quad_1 = smesh_builder.Mesh(name = mesh_name)
   
   # six nodes
   n1 = quad_1.AddNode(0, 20, 10)
@@ -79,19 +79,19 @@ def MakeQuadMesh2(mesh_name):
   return [quad_1, [1,2,3,4,5,6,7], [8,9]]
 
 # Path meshes
-Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight")
-Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")
-Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline")
-Edge_Circle_mesh   = Mesh1D(Edge_Circle  , 8, "Edge_Circle")
+Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight", smesh_builder=smesh)
+Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr", smesh_builder=smesh)
+Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline", smesh_builder=smesh)
+Edge_Circle_mesh   = Mesh1D(Edge_Circle  , 8, "Edge_Circle"  , smesh_builder=smesh)
 
 # Initial meshes (to be extruded)
-[quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1")
-[quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2")
-[quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3")
-[quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4")
-[quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5")
-[quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6")
-[quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7")
+[quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1", smesh_builder=smesh)
+[quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2", smesh_builder=smesh)
+[quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3", smesh_builder=smesh)
+[quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4", smesh_builder=smesh)
+[quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5", smesh_builder=smesh)
+[quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6", smesh_builder=smesh)
+[quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7", smesh_builder=smesh)
 
 # ExtrusionAlongPath
 # IDsOfElements, PathMesh, PathShape, NodeStart,
diff --git a/doc/salome/examples/tests.py.in b/doc/salome/examples/tests.py.in
new file mode 100644 (file)
index 0000000..ffcdad1
--- /dev/null
@@ -0,0 +1,35 @@
+DIR='@CMAKE_CURRENT_SOURCE_DIR@'
+TESTS='@GOOD_TESTS@'
+REINIT_SALOME=@TEST_REINIT_SALOME@
+
+import os
+import unittest
+import salome
+
+class MyTest(unittest.TestCase):
+    def setUp(self):
+        if REINIT_SALOME:
+            salome.salome_init()
+    def tearDown(self):
+        if REINIT_SALOME:
+            salome.salome_close()
+    pass
+
+if __name__ == "__main__":
+    tests = TESTS.split(';')
+    for test in tests:
+        file_name = os.path.basename(test)
+        if os.path.isabs(test):
+            file_path = file_name
+        else:
+            file_path = os.path.join(DIR, file_name)
+        case_name = 'test_' + file_name[:-3]
+        code = """
+def func(self):
+  with open('{}') as f:
+    exec(f.read())
+"""
+        exec(code.format(file_path))
+        setattr(MyTest, case_name, func)
+
+    unittest.main()
index 1af8322e308f5279bf3f5201be1573152f1c1c13..0ef132b66f6d5dbb92da95c9c0ed156314d2b64b 100644 (file)
@@ -12,26 +12,25 @@ from salome.smesh import smeshBuilder
 smesh =  smeshBuilder.New()
 import salome_notebook
 
-import numpy as np
-
 # define my 2D algorithm
-def my2DMeshing( geomFace ):
+def my2DMeshing(geomFace, geom_builder, smesh_builder):
+    import numpy as np
 
     # find gravity center of geomFace
-    gcXYZ = geompy.PointCoordinates( geompy.MakeCDG( geomFace ))
+    gcXYZ = geom_builder.PointCoordinates( geom_builder.MakeCDG( geomFace ))
 
     # define order and orientation of edges
     sortedEdges = []
-    geomEdges = geompy.SubShapeAll( geomFace, geompy.ShapeType["EDGE"])
+    geomEdges = geom_builder.SubShapeAll( geomFace, geom_builder.ShapeType["EDGE"])
     sortedEdges.append(( geomEdges.pop(0), True ))
     while geomEdges:
         prevEdge_rev = sortedEdges[ -1 ]
-        prevVV = geompy.SubShapeAll( prevEdge_rev[0], geompy.ShapeType["VERTEX"])
+        prevVV = geom_builder.SubShapeAll( prevEdge_rev[0], geom_builder.ShapeType["VERTEX"])
         prevV2 = prevVV[ prevEdge_rev[1] ]
         found = False
         for iE in range( len( geomEdges )):
-            v1,v2 = geompy.SubShapeAll( geomEdges[ iE ], geompy.ShapeType["VERTEX"])
-            same1,same2 = [( geompy.MinDistance( prevV2, v ) < 1e-7 ) for v in [v1,v2] ]
+            v1,v2 = geom_builder.SubShapeAll( geomEdges[ iE ], geom_builder.ShapeType["VERTEX"])
+            same1,same2 = [( geom_builder.MinDistance( prevV2, v ) < 1e-7 ) for v in [v1,v2] ]
             if not same1 and not same2: continue
             sortedEdges.append(( geomEdges.pop( iE ), same1 ))
             found = True
@@ -42,10 +41,10 @@ def my2DMeshing( geomFace ):
     # put nodes on edges in a right order
     nodes = []
     for edge, isForward in sortedEdges:
-        v1,v2 = geompy.SubShapeAll( edge, geompy.ShapeType["VERTEX"])
-        edgeNodes = mesh.GetSubMeshNodesId( v2,   all=False ) + \
-                    mesh.GetSubMeshNodesId( edge, all=False ) + \
-                    mesh.GetSubMeshNodesId( v1,   all=False )
+        v1,v2 = geom_builder.SubShapeAll( edge, geom_builder.ShapeType["VERTEX"])
+        edgeNodes = smesh_builder.GetSubMeshNodesId( v2,   all=False ) + \
+                    smesh_builder.GetSubMeshNodesId( edge, all=False ) + \
+                    smesh_builder.GetSubMeshNodesId( v1,   all=False )
         if not isForward: edgeNodes.reverse()
         nodes.extend( edgeNodes[:-1] )
 
@@ -54,23 +53,23 @@ def my2DMeshing( geomFace ):
     r2 = 1 - r1
     nodesInside = []
     for n in nodes:
-        nXYZ = mesh.GetNodeXYZ( n )
+        nXYZ = smesh_builder.GetNodeXYZ( n )
         newXYZ = np.add( np.multiply( r1, gcXYZ ), np.multiply( r2, nXYZ ))
-        nodesInside.append( mesh.AddNode( newXYZ[0], newXYZ[1], newXYZ[2] ))
-        mesh.SetNodeOnFace( nodesInside[-1], geomFace, 0, 0 )
+        nodesInside.append( smesh_builder.AddNode( newXYZ[0], newXYZ[1], newXYZ[2] ))
+        smesh_builder.SetNodeOnFace( nodesInside[-1], geomFace, 0, 0 )
 
     # find out orientation of faces to create
     #    geomFace normal
-    faceNorm = geompy.GetNormal( geomFace )
-    v1,v2 = [ geompy.PointCoordinates( v ) \
-              for v in geompy.SubShapeAll( faceNorm, geompy.ShapeType["VERTEX"]) ]
+    faceNorm = geom_builder.GetNormal( geomFace )
+    v1,v2 = [ geom_builder.PointCoordinates( v ) \
+              for v in geom_builder.SubShapeAll( faceNorm, geom_builder.ShapeType["VERTEX"]) ]
     faceNormXYZ = np.subtract( v2, v1 )
     outDirXYZ   = np.subtract( v1, [ 50, 50, 50 ] )
     if np.dot( faceNormXYZ, outDirXYZ ) < 0: # reversed face
         faceNormXYZ = np.multiply( -1., faceNormXYZ )
     #   mesh face normal
-    e1 = np.subtract( mesh.GetNodeXYZ( nodes[0] ), mesh.GetNodeXYZ( nodes[1] ))
-    e2 = np.subtract( mesh.GetNodeXYZ( nodes[0] ), mesh.GetNodeXYZ( nodesInside[0] ))
+    e1 = np.subtract( smesh_builder.GetNodeXYZ( nodes[0] ), smesh_builder.GetNodeXYZ( nodes[1] ))
+    e2 = np.subtract( smesh_builder.GetNodeXYZ( nodes[0] ), smesh_builder.GetNodeXYZ( nodesInside[0] ))
     meshNorm = np.cross( e1, e2 )
     #   faces orientation
     reverse = ( np.dot( faceNormXYZ, meshNorm ) < 0 )
@@ -81,16 +80,16 @@ def my2DMeshing( geomFace ):
         n1, n2, n3, n4 = nodes[iN-1], nodes[iN-2], nodesInside[iN-2], nodesInside[iN-1]
         iN -= 1
         if reverse:
-            f = mesh.AddFace( [n1, n2, n3, n4] )
+            f = smesh_builder.AddFace( [n1, n2, n3, n4] )
         else:
-            f = mesh.AddFace( [n4, n3, n2, n1] )
+            f = smesh_builder.AddFace( [n4, n3, n2, n1] )
         # new faces must be assigned to geometry to allow 3D algorithm finding them
-        mesh.SetMeshElementOnShape( f, geomFace )
+        smesh_builder.SetMeshElementOnShape( f, geomFace )
 
     if reverse:
         nodesInside.reverse()
-    polygon = mesh.AddPolygonalFace( nodesInside )
-    mesh.SetMeshElementOnShape( polygon, geomFace )
+    polygon = smesh_builder.AddPolygonalFace( nodesInside )
+    smesh_builder.SetMeshElementOnShape( polygon, geomFace )
 
     return
 
@@ -111,8 +110,8 @@ mesh.Compute()
 mesh.Quadrangle()
 mesh.UseExistingFaces(f1) # UseExistingFaces() allows using my2DMeshing();
 mesh.UseExistingFaces(f2) # assign UseExistingFaces() BEFORE calling my2DMeshing()!
-my2DMeshing( f1 )
-my2DMeshing( f2 )
+my2DMeshing(f1, geom_builder=geompy, smesh_builder=mesh)
+my2DMeshing(f2, geom_builder=geompy, smesh_builder=mesh)
 assert mesh.Compute()
 
 # compute 3D mesh