Salome HOME
Fix invalid Python dump of ExportUNV()
[modules/smesh.git] / bin / smesh_test.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2022  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import unittest
22
23 class TestMesh(unittest.TestCase):
24
25     def setUp(self):
26         import salome
27         salome.salome_init()
28
29     def processGuiEvents(self):
30         import salome
31         if salome.sg.hasDesktop():
32             salome.sg.updateObjBrowser();
33             import SalomePyQt
34             SalomePyQt.SalomePyQt().processEvents()
35
36     def test_mesh(self):
37         """Quick test for Mesh module"""
38
39         print()
40         print('Testing Mesh module')
41
42         # ==== Geometry part ====
43
44         from salome.geom import geomBuilder
45         geompy = geomBuilder.New()
46
47         # ---- create box
48         print('... Create box')
49         box = geompy.MakeBox(0., 0., 0., 100., 200., 300)
50         self.assertIsNotNone(box)
51         self.processGuiEvents()
52
53         # ==== Mesh part ====
54
55         import SMESH
56         from salome.smesh import smeshBuilder
57         smesh = smeshBuilder.New()
58         self.processGuiEvents()
59
60         # ---- create hypotheses 
61         print('... Create hypotheses')
62
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()
71
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()
80
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()
88
89         # ---- create algorithms
90         print('... Create algorithms')
91
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()
98
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()
105
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()
114
115         # ---- compute mesh
116         print('... Compute mesh')
117         self.assertEqual(smesh.Compute(mesh, box), True)
118         self.processGuiEvents()
119
120 if __name__ == '__main__':
121     unittest.main()