1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2021 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 class TestMesh(unittest.TestCase):
29 def processGuiEvents(self):
31 if salome.sg.hasDesktop():
32 salome.sg.updateObjBrowser();
34 SalomePyQt.SalomePyQt().processEvents()
37 """Quick test for Mesh module"""
40 print('Testing Mesh module')
42 # ==== Geometry part ====
44 from salome.geom import geomBuilder
45 geompy = geomBuilder.New()
48 print('... Create box')
49 box = geompy.MakeBox(0., 0., 0., 100., 200., 300)
50 self.assertIsNotNone(box)
51 self.processGuiEvents()
56 from salome.smesh import smeshBuilder
57 smesh = smeshBuilder.New()
58 lib = 'StdMeshersEngine'
59 self.processGuiEvents()
61 # ---- create hypotheses
62 print('... Create hypotheses')
64 # **** create local length
65 print('...... Local Length')
66 local_length = smesh.CreateHypothesis('LocalLength', lib)
67 self.assertIsNotNone(local_length)
68 local_length.SetLength(100)
69 self.assertEqual(local_length.GetName(), 'LocalLength')
70 self.assertEqual(local_length.GetLength(), 100)
71 self.processGuiEvents()
73 # **** create number of segments
74 print('...... Number Of Segments')
75 nb_segments= smesh.CreateHypothesis('NumberOfSegments', lib)
76 self.assertIsNotNone(nb_segments)
77 nb_segments.SetNumberOfSegments(7)
78 self.assertEqual(nb_segments.GetName(), 'NumberOfSegments')
79 self.assertEqual(nb_segments.GetNumberOfSegments(), 7)
80 self.processGuiEvents()
82 # **** create max element area
83 print('...... Max Element Area')
84 max_area = smesh.CreateHypothesis('MaxElementArea', lib)
85 max_area.SetMaxElementArea(2500)
86 self.assertEqual(max_area.GetName(), 'MaxElementArea')
87 self.assertEqual(max_area.GetMaxElementArea(), 2500)
88 self.processGuiEvents()
90 # ---- create algorithms
91 print('... Create algorithms')
93 # **** create regular 1d
94 print('...... Regular 1D')
95 regular = smesh.CreateHypothesis('Regular_1D', lib)
96 listHyp = regular.GetCompatibleHypothesis()
97 self.assertEqual(regular.GetName(), 'Regular_1D')
98 self.processGuiEvents()
100 # **** create mefisto 2d
101 print('...... Mefisto 2D')
102 mefisto = smesh.CreateHypothesis( 'MEFISTO_2D', lib )
103 listHyp = mefisto.GetCompatibleHypothesis()
104 self.assertEqual(mefisto.GetName(), 'MEFISTO_2D')
105 self.processGuiEvents()
107 # ---- create mesh on box
108 print('... Create mesh on box')
109 mesh = smesh.CreateMesh(box)
110 self.assertEqual(mesh.AddHypothesis(box, regular)[0], SMESH.HYP_OK)
111 self.assertEqual(mesh.AddHypothesis(box, mefisto)[0], SMESH.HYP_OK)
112 self.assertEqual(mesh.AddHypothesis(box, nb_segments)[0], SMESH.HYP_OK)
113 self.assertEqual(mesh.AddHypothesis(box, max_area)[0], SMESH.HYP_OK)
114 self.processGuiEvents()
117 print('... Compute mesh')
118 self.assertEqual(smesh.Compute(mesh, box), True)
119 self.processGuiEvents()
121 if __name__ == '__main__':