-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_meshes.py
More file actions
223 lines (165 loc) · 6.9 KB
/
test_meshes.py
File metadata and controls
223 lines (165 loc) · 6.9 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import gmsh
import assembly_mesh_plugin
from tests.sample_assemblies import (
generate_nested_spheres,
generate_touching_boxes,
generate_nested_boxes,
generate_simple_nested_boxes,
generate_test_cross_section,
generate_assembly,
generate_subshape_assembly,
generate_materials_assembly,
)
def test_simple_assembly():
"""
Tests to make sure that the most basic assembly works correctly with tagging.
"""
# Create the basic assembly
assy = generate_simple_nested_boxes()
# Create a mesh that has all the faces tagged as physical groups
assy.saveToGmsh(mesh_path="tagged_mesh.msh")
gmsh.initialize()
gmsh.open("tagged_mesh.msh")
# Make sure that there are physical groups for the volumes
physical_groups = gmsh.model.getPhysicalGroups(3)
assert len(physical_groups) > 0, "There should be some physical groups for volumes"
# Check the solids for the correct tags
for group in physical_groups:
# Get the name for the current volume
cur_name = gmsh.model.getPhysicalName(3, group[1])
assert cur_name in ["shell", "insert"]
# Check to make sure there are physical groups for the surfaces
physical_groups = gmsh.model.getPhysicalGroups(2)
assert len(physical_groups) > 0, "There should be some physical groups for surfaces"
# Check the surfaces for the correct tags
for group in physical_groups:
# Get the name for this group
cur_name = gmsh.model.getPhysicalName(2, group[1])
# Skip any groups that are not tagged explicitly
if "_surface_" in cur_name:
continue
assert cur_name in ["shell_inner-right", "insert_outer-right", "in_contact"]
def test_subshape_assembly():
"""
Tests whether subshapes in assemblies get exported to physical groups in the resulting mesh.
"""
# Generate a simple assembly with a subshape
assy = generate_subshape_assembly()
# Create a mesh that has all the faces tagged as physical groups
assy.saveToGmsh(mesh_path="tagged_subshape_mesh.msh")
gmsh.initialize()
gmsh.open("tagged_subshape_mesh.msh")
# Make sure that there are physical groups for the volumes
physical_groups = gmsh.model.getPhysicalGroups(3)
assert len(physical_groups) > 0, "There should be some physical groups for volumes"
# Check the solids/volumes for the correct tags
for group in physical_groups:
# Get the name for the current volume
cur_name = gmsh.model.getPhysicalName(3, group[1])
assert cur_name in ["cube_1"]
# Check to make sure there are physical groups for the surfaces
physical_groups = gmsh.model.getPhysicalGroups(2)
assert len(physical_groups) > 0, "There should be some physical groups for surfaces"
# Check the surfaces for the correct tags
for group in physical_groups:
# Get the name for this group
cur_name = gmsh.model.getPhysicalName(2, group[1])
# Skip any groups that are not tagged explicitly
if "_surface_" in cur_name:
continue
assert cur_name in ["cube_1_cube_1_top_face"]
def test_imprinted_assembly():
# Create the basic assembly
assy = generate_simple_nested_boxes()
assy.assemblyToImprintedGmsh("tagged_imprinted_mesh.msh")
gmsh.initialize()
gmsh.open("tagged_imprinted_mesh.msh")
# Make sure that there are physical groups for the volumes
physical_groups = gmsh.model.getPhysicalGroups(3)
assert len(physical_groups) > 0, "There should be some physical groups for volumes"
# Check the solids for the correct tags
for group in physical_groups:
# Get the name for the current volume
cur_name = gmsh.model.getPhysicalName(3, group[1])
assert cur_name in ["shell", "insert"]
# Check to make sure there are physical groups for the surfaces
physical_groups = gmsh.model.getPhysicalGroups(2)
assert len(physical_groups) > 0, "There should be some physical groups for surfaces"
# Check the surfaces for the correct tags
for group in physical_groups:
# Get the name for this group
cur_name = gmsh.model.getPhysicalName(2, group[1])
# Skip any groups that are not tagged explicitly
if "_surface_" in cur_name:
continue
assert cur_name in ["shell_inner-right", "insert_outer-right", "in_contact"]
def test_nested_sphere_assembly():
"""
Tests to make sure the the nested sphere example works.
"""
def _check_physical_groups():
# Make sure that there are physical groups for the volumes
physical_groups = gmsh.model.getPhysicalGroups(3)
assert (
len(physical_groups) == 2
), "There should be two physical groups for volumes"
# Check the solids for the correct tags
for group in physical_groups:
# Get the name for the current volume
cur_name = gmsh.model.getPhysicalName(3, group[1])
assert cur_name in ["inner_sphere", "middle_sphere"]
# Make sure we can retrieve the physical groups
inner_sphere_volume = gmsh.model.getEntitiesForPhysicalName("inner_sphere")
middle_sphere_volume = gmsh.model.getEntitiesForPhysicalName("middle_sphere")
# Create a basic assembly
assy = generate_nested_spheres()
#
# Go through the entire process with an imprinted assembly.
#
gmsh = assy.getGmsh(imprint=True)
gmsh.model.mesh.generate(3)
# Ensure that there are physical groups and that they have the right names
_check_physical_groups()
#
# Go othrough the entire process again with a non-imprinted assembly.
#
gmsh = assy.getGmsh(imprint=False)
gmsh.model.mesh.generate(3)
# Ensure that there are physical groups
_check_physical_groups()
def test_mesh_materials():
"""
Tests to make sure that assembly materials are preserved in the mesh data.
"""
# Create the basic assembly with materials
assy = generate_materials_assembly()
#
# Imprinted assembly
#
gmsh = assy.getGmsh(imprint=True)
gmsh.model.mesh.generate(3)
phys_groups = gmsh.model.getPhysicalGroups(3)
# Make sure we got the correct names
name = gmsh.model.getPhysicalName(3, 1)
assert name == "cube_1"
name = gmsh.model.getPhysicalName(3, 2)
assert name == "mat:copper"
name = gmsh.model.getPhysicalName(3, 3)
assert name == "cube_2"
name = gmsh.model.getPhysicalName(3, 4)
assert name == "mat:steel"
#
# Non-imprinted assembly
#
gmsh = assy.getGmsh(imprint=False)
gmsh.model.mesh.generate(3)
phys_groups = gmsh.model.getPhysicalGroups(3)
# Make sure we got the correct names
name = gmsh.model.getPhysicalName(3, 1)
assert name == "cube_1"
name = gmsh.model.getPhysicalName(3, 2)
assert name == "mat:copper"
name = gmsh.model.getPhysicalName(3, 3)
assert name == "cube_2"
name = gmsh.model.getPhysicalName(3, 4)
assert name == "mat:steel"