1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2024 CEA, EDF, 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 self.processGuiEvents()
60 # ---- create hypotheses
61 print('... Create hypotheses')
63 # **** create local length
64 print('...... Local Length')
65 local_length = smesh.CreateHypothesis('LocalLength')
66 self.assertIsNotNone(local_length)
67 local_length.SetLength(100)
68 self.assertEqual(local_length.GetName(), 'LocalLength')
69 self.assertEqual(local_length.GetLength(), 100)
70 self.processGuiEvents()
72 # **** create number of segments
73 print('...... Number Of Segments')
74 nb_segments = smesh.CreateHypothesis('NumberOfSegments')
75 self.assertIsNotNone(nb_segments)
76 nb_segments.SetNumberOfSegments(7)
77 self.assertEqual(nb_segments.GetName(), 'NumberOfSegments')
78 self.assertEqual(nb_segments.GetNumberOfSegments(), 7)
79 self.processGuiEvents()
81 # **** create max element area
82 print('...... Max Element Area')
83 max_area = smesh.CreateHypothesis('MaxElementArea')
84 max_area.SetMaxElementArea(2500)
85 self.assertEqual(max_area.GetName(), 'MaxElementArea')
86 self.assertEqual(max_area.GetMaxElementArea(), 2500)
87 self.processGuiEvents()
89 # ---- create algorithms
90 print('... Create algorithms')
92 # **** create regular 1d
93 print('...... Regular 1D')
94 regular = smesh.CreateHypothesis('Regular_1D')
95 self.assertTrue(len(regular.GetCompatibleHypothesis()) > 0)
96 self.assertEqual(regular.GetName(), 'Regular_1D')
97 self.processGuiEvents()
99 # **** create quadrangle mapping
100 print('...... Quadrangle_2D')
101 quad = smesh.CreateHypothesis('Quadrangle_2D')
102 self.assertTrue(len(quad.GetCompatibleHypothesis()) > 0)
103 self.assertEqual(quad.GetName(), 'Quadrangle_2D')
104 self.processGuiEvents()
106 # ---- create mesh on box
107 print('... Create mesh on box')
108 mesh = smesh.CreateMesh(box)
109 self.assertEqual(mesh.AddHypothesis(box, regular)[0], SMESH.HYP_OK)
110 self.assertEqual(mesh.AddHypothesis(box, quad)[0], SMESH.HYP_OK)
111 self.assertEqual(mesh.AddHypothesis(box, nb_segments)[0], SMESH.HYP_OK)
112 self.assertEqual(mesh.AddHypothesis(box, max_area)[0], SMESH.HYP_OK)
113 self.processGuiEvents()
116 print('... Compute mesh')
117 self.assertEqual(smesh.Compute(mesh, box), True)
118 self.processGuiEvents()
120 if __name__ == '__main__':