-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_salome_mesh_utilities.py
208 lines (169 loc) · 7.01 KB
/
test_salome_mesh_utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# _ __ _ ___ _ ___ _ _
# | |/ /_ _ __ _| |_ ___ __/ __| __ _| |___ _ __ ___| _ \ |_ _ __ _(_)_ _
# | ' <| '_/ _` | _/ _ (_-<__ \/ _` | / _ \ ' \/ -_) _/ | || / _` | | ' \
# |_|\_\_| \__,_|\__\___/__/___/\__,_|_\___/_|_|_\___|_| |_|\_,_\__, |_|_||_|
# |___/
# License: BSD License ; see LICENSE
#
# Main authors: Philipp Bucher (https://github.com/philbucher)
#
# set up testing environment (before anything else)
import initialize_testing_environment
# python imports
import os
import shutil
import unittest
# plugin imports
from kratos_salome_plugin import salome_utilities
from kratos_salome_plugin import salome_mesh_utilities
# tests imports
import testing_utilities
# salome imports
import salome
import GEOM
import SMESH
class TestSalomeMeshUtilities(testing_utilities.SalomeTestCaseWithBox):
def test_IsMesh(self):
meshes = [
self.mesh_tetra
]
not_meshes = [
self.mesh_tetra.GetMesh(),
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1,
self.box,
self.face_1,
self.group_faces,
self.group_tetra_0D_elements,
self.group_hexa_ball_elements,
self.group_tetra_f1_nodes,
self.group_tetra_f1_faces,
self.group_hexa_edges
]
for mesh in meshes:
self.assertTrue(salome_mesh_utilities.IsMesh(mesh))
for not_mesh in not_meshes:
self.assertFalse(salome_mesh_utilities.IsMesh(not_mesh))
def test_IsMeshProxy(self):
meshes = [
self.mesh_tetra.GetMesh()
]
not_meshes = [
self.mesh_tetra,
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1,
self.box,
self.face_1,
self.group_faces,
self.group_tetra_0D_elements,
self.group_hexa_ball_elements,
self.group_tetra_f1_nodes,
self.group_tetra_f1_faces,
self.group_hexa_edges
]
for mesh in meshes:
self.assertTrue(salome_mesh_utilities.IsMeshProxy(mesh))
for not_mesh in not_meshes:
self.assertFalse(salome_mesh_utilities.IsMeshProxy(not_mesh))
def test_IsSubMeshProxy(self):
sub_meshes = [
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1
]
not_sub_meshes = [
self.mesh_tetra,
self.mesh_tetra.GetMesh(),
self.box,
self.face_1,
self.group_faces,
self.group_tetra_0D_elements,
self.group_hexa_ball_elements,
self.group_tetra_f1_nodes,
self.group_tetra_f1_faces,
self.group_hexa_edges
]
for sub_mesh in sub_meshes:
self.assertTrue(salome_mesh_utilities.IsSubMeshProxy(sub_mesh))
for not_sub_mesh in not_sub_meshes:
self.assertFalse(salome_mesh_utilities.IsSubMeshProxy(not_sub_mesh))
def test_IsMeshGroup(self):
mesh_groups = [
self.group_tetra_0D_elements, # type "SMESH._objref_SMESH_Group"
self.group_hexa_ball_elements, # type "SMESH._objref_SMESH_Group"
self.group_tetra_f1_nodes, # type "SMESH._objref_SMESH_GroupOnGeom"
self.group_tetra_f1_faces, # type "SMESH._objref_SMESH_GroupOnGeom"
self.group_hexa_edges # "SMESH._objref_SMESH_GroupOnFilter"
]
not_mesh_groups = [
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1,
self.mesh_tetra,
self.mesh_tetra.GetMesh(),
self.box,
self.face_1,
self.group_faces
]
for mesh_group in mesh_groups:
self.assertTrue(salome_mesh_utilities.IsMeshGroup(mesh_group))
for not_mesh_group in not_mesh_groups:
self.assertFalse(salome_mesh_utilities.IsMeshGroup(not_mesh_group))
def test_IsAnyMesh(self):
mesh_groups = [
self.group_tetra_0D_elements,
self.group_hexa_ball_elements,
self.group_tetra_f1_nodes,
self.group_tetra_f1_faces,
self.group_hexa_edges,
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1,
self.mesh_tetra,
self.mesh_tetra.GetMesh()
]
not_mesh_groups = [
self.box,
self.face_1,
self.group_faces
]
for mesh_group in mesh_groups:
self.assertTrue(salome_mesh_utilities.IsAnyMesh(mesh_group))
for not_mesh_group in not_mesh_groups:
self.assertFalse(salome_mesh_utilities.IsAnyMesh(not_mesh_group))
def test_DoMeshesBelongToSameMainMesh(self):
self.assertTrue(salome_mesh_utilities.DoMeshesBelongToSameMainMesh([])) # empty input should return True
meshes_same_main_mesh = [
self.mesh_tetra.GetMesh(),
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1,
self.sub_mesh_tetra_e_2,
self.group_tetra_f1_faces,
self.group_tetra_0D_elements
]
meshes_not_same_main_mesh = [
self.mesh_hexa.GetMesh(),
self.sub_mesh_tetra_f_1,
self.sub_mesh_tetra_g_1,
self.sub_mesh_tetra_e_2,
self.group_tetra_f1_faces,
self.group_tetra_0D_elements
]
meshes_not_meshes = [
self.mesh_hexa.GetMesh(),
self.box
]
mesh_identifiers_same_main_mesh = [salome_utilities.GetSalomeID(mesh) for mesh in meshes_same_main_mesh]
mesh_identifiers_not_same_main_mesh = [salome_utilities.GetSalomeID(mesh) for mesh in meshes_not_same_main_mesh]
identifiers_not_meshes = [salome_utilities.GetSalomeID(mesh) for mesh in meshes_not_meshes]
self.assertTrue(salome_mesh_utilities.DoMeshesBelongToSameMainMesh(mesh_identifiers_same_main_mesh))
self.assertFalse(salome_mesh_utilities.DoMeshesBelongToSameMainMesh(mesh_identifiers_not_same_main_mesh))
with self.assertRaisesRegex(Exception, 'Object with identifier "0:1:1:1" is not a mesh! Name: "main_box" , Type:'):
salome_mesh_utilities.DoMeshesBelongToSameMainMesh(identifiers_not_meshes)
def test_EntityTypeToString(self):
self.assertEqual("Tetra", salome_mesh_utilities.EntityTypeToString(SMESH.Entity_Tetra))
self.assertEqual("Quadrangle", salome_mesh_utilities.EntityTypeToString(SMESH.Entity_Quadrangle))
def test_EntityTypeFromString(self):
self.assertEqual(SMESH.Entity_Tetra, salome_mesh_utilities.EntityTypeFromString("Tetra"))
self.assertEqual(SMESH.Entity_Quadrangle, salome_mesh_utilities.EntityTypeFromString("Quadrangle"))
with self.assertRaisesRegex(Exception, 'The requested entity type "WeirdGeometry" is not available!\nOnly the following entity types are available:\n'):
salome_mesh_utilities.EntityTypeFromString("WeirdGeometry")
if __name__ == '__main__':
unittest.main()