Skip to content

Commit 083f7a0

Browse files
authored
Merge pull request #4128 from roystgnr/gmsh_physicals_fix
Don't let GMSH physicals overwrite each other
2 parents bf64b0b + 41aa571 commit 083f7a0

3 files changed

Lines changed: 218 additions & 8 deletions

File tree

src/mesh/gmsh_io.C

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,13 @@ void GmshIO::read_mesh(std::istream & in)
175175
// actually blocks of lower-dimensional elements.
176176
std::set<subdomain_id_type> lower_dimensional_blocks;
177177

178-
// Mapping from physical id -> (physical dim, physical name) pairs.
178+
// Mapping from (physical id, physical dim) -> physical name.
179179
// These can refer to either "sidesets" or "subdomains"; we need to
180180
// wait until the Mesh has been read to know which is which. Note
181-
// that we are using 'int' as the key here rather than
181+
// that we are using ptrdiff_t as the key here rather than
182182
// subdomain_id_type or boundary_id_type, since at this point, it
183183
// could be either.
184-
typedef std::pair<unsigned, std::string> GmshPhysical;
185-
std::map<int, GmshPhysical> gmsh_physicals;
184+
std::map<std::pair<std::ptrdiff_t, unsigned>, std::string> gmsh_physicals;
186185

187186
// map to hold the node numbers for translation
188187
// note the the nodes can be non-consecutive
@@ -267,7 +266,7 @@ void GmshIO::read_mesh(std::istream & in)
267266
phys_name.erase(std::remove(phys_name.begin(), phys_name.end(), '"'), phys_name.end());
268267

269268
// Record this ID for later assignment of subdomain/sideset names.
270-
gmsh_physicals[phys_id] = std::make_pair(phys_dim, phys_name);
269+
gmsh_physicals[std::make_pair(phys_id, phys_dim)] = phys_name;
271270

272271
// If 's' also contains the libmesh-specific string
273272
// "lower_dimensional_block", add this block ID to
@@ -790,9 +789,8 @@ void GmshIO::read_mesh(std::istream & in)
790789
for (const auto & pr : gmsh_physicals)
791790
{
792791
// Extract data
793-
int phys_id = pr.first;
794-
unsigned phys_dim = pr.second.first;
795-
const std::string & phys_name = pr.second.second;
792+
auto [phys_id, phys_dim] = pr.first;
793+
const std::string & phys_name = pr.second;
796794

797795
// If the physical's dimension matches the largest
798796
// dimension we've seen, it's a subdomain name.

tests/mesh/mesh_input.C

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public:
203203
CPPUNIT_TEST( testGoodSTL );
204204
CPPUNIT_TEST( testGoodSTLBinary );
205205

206+
CPPUNIT_TEST( testGmshBCIDOverlap );
207+
206208
#ifdef LIBMESH_HAVE_TETGEN
207209
CPPUNIT_TEST( testTetgenIO );
208210
#endif
@@ -1562,6 +1564,32 @@ public:
15621564
CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), dof_id_type(14));
15631565
}
15641566

1567+
void testGmshBCIDOverlap ()
1568+
{
1569+
LOG_UNIT_TEST;
1570+
1571+
Mesh mesh(*TestCommWorld);
1572+
1573+
GmshIO gmsh_io(mesh);
1574+
1575+
if (mesh.processor_id() == 0)
1576+
gmsh_io.read("meshes/bcid_overlap.msh");
1577+
MeshCommunication().broadcast(mesh);
1578+
1579+
CPPUNIT_ASSERT_EQUAL(mesh.get_boundary_info().get_sideset_name_map().size(),
1580+
std::size_t(2));
1581+
CPPUNIT_ASSERT_EQUAL(mesh.get_boundary_info().sideset_name(1),
1582+
std::string("srfBC4A"));
1583+
CPPUNIT_ASSERT_EQUAL(mesh.get_boundary_info().sideset_name(2),
1584+
std::string("srfBC4B"));
1585+
CPPUNIT_ASSERT_EQUAL(mesh.get_subdomain_name_map().size(),
1586+
std::size_t(2));
1587+
CPPUNIT_ASSERT_EQUAL(mesh.subdomain_name(1),
1588+
std::string("volBC3A"));
1589+
CPPUNIT_ASSERT_EQUAL(mesh.subdomain_name(2),
1590+
std::string("volBC3B"));
1591+
}
1592+
15651593
void testGoodSTL ()
15661594
{
15671595
LOG_UNIT_TEST;

tests/meshes/bcid_overlap.msh

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
$MeshFormat
2+
4.1 0 8
3+
$EndMeshFormat
4+
$PhysicalNames
5+
6
6+
1 1 "linD4A"
7+
1 2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
1 0.0 0.0 0.0 1.0 0.0 1.0 1 1 3 8 9 10
46+
2 0.0 0.0 0.0 1.0 0.0 1.0 1 1 3 2 -7 -8
47+
3 1.0 0.0 0.0 2.0 0.0 1.0 1 2 3 3 -1 -2
48+
4 1.0 0.0 0.0 2.0 0.0 1.0 1 2 3 18 4 -3
49+
5 0.0 0.0 0.0 1.0 1.0 0.0 0 3 14 15 16
50+
6 0.0 0.0 0.0 1.0 1.0 0.0 0 3 17 -16 -10
51+
7 0.0 0.0 0.0 1.0 1.0 1.0 0 3 14 11 12
52+
8 0.0 0.0 0.0 1.0 1.0 1.0 0 3 13 -12 -7
53+
9 0.0 0.0 0.0 0.0 1.0 1.0 0 3 -17 -9 13
54+
10 1.0 0.0 0.0 1.0 1.0 1.0 0 3 -2 -15 11
55+
11 1.0 0.0 0.0 2.0 1.0 0.0 0 3 19 20 21
56+
12 1.0 0.0 0.0 2.0 1.0 0.0 0 3 -15 -21 -18
57+
13 1.0 0.0 0.0 2.0 1.0 1.0 0 3 5 -1 -11
58+
14 1.0 0.0 0.0 2.0 1.0 1.0 0 3 6 -5 19
59+
15 2.0 0.0 0.0 2.0 1.0 1.0 0 3 4 -6 20
60+
1 0.0 0.0 0.0 1.0 1.0 1.0 1 1 8 1 2 9 6 10 8 5 7
61+
2 1.0 0.0 0.0 2.0 1.0 1.0 1 2 8 3 4 13 10 12 15 11 14
62+
$EndEntities
63+
$Nodes
64+
36 30 1 31
65+
0 1 0 1
66+
1
67+
1 0 1
68+
0 2 0 1
69+
2
70+
2 0 1
71+
0 3 0 1
72+
3
73+
1 0 0
74+
0 4 0 1
75+
4
76+
2 0 0
77+
0 5 0 1
78+
5
79+
2 1 0
80+
0 6 0 1
81+
6
82+
0 0 1
83+
0 7 0 1
84+
7
85+
0 0 0
86+
0 8 0 1
87+
8
88+
0 1 0
89+
0 9 0 1
90+
9
91+
1 1 0
92+
1 1 0 1
93+
11
94+
1.5 0 1
95+
1 2 0 1
96+
12
97+
1 0 0.5
98+
1 3 0 1
99+
13
100+
1.5 0 0.5
101+
1 4 0 1
102+
14
103+
2 0 0.5
104+
1 5 0 1
105+
15
106+
1.5 0.5 0.5
107+
1 6 0 1
108+
16
109+
2 0.5 0.5
110+
1 7 0 1
111+
17
112+
0.5 0 1
113+
1 8 0 1
114+
18
115+
0.5 0 0.5
116+
1 9 0 1
117+
19
118+
0 0 0.5
119+
1 10 0 1
120+
20
121+
0.5 0 0
122+
1 11 0 1
123+
21
124+
1 0.5 0.5
125+
1 12 0 1
126+
22
127+
0.5 0.5 0.5
128+
1 13 0 1
129+
23
130+
0 0.5 0.5
131+
1 14 0 1
132+
24
133+
0.5 1 0
134+
1 15 0 1
135+
25
136+
1 0.5 0
137+
1 16 0 1
138+
26
139+
0.5 0.5 0
140+
1 17 0 1
141+
27
142+
0 0.5 0
143+
1 18 0 1
144+
28
145+
1.5 0 0
146+
1 19 0 1
147+
29
148+
1.5 1 0
149+
1 20 0 1
150+
30
151+
2 0.5 0
152+
1 21 0 1
153+
31
154+
1.5 0.5 0
155+
2 1 0 0
156+
2 2 0 0
157+
2 3 0 0
158+
2 4 0 0
159+
3 1 0 0
160+
3 2 0 0
161+
$EndNodes
162+
$Elements
163+
8 12 94 135
164+
1 1 8 1
165+
94 1 2 11
166+
1 7 8 1
167+
100 6 1 17
168+
2 1 9 1
169+
115 3 6 7 18 19 20
170+
2 2 9 1
171+
116 1 6 3 17 18 12
172+
2 3 9 1
173+
117 1 3 2 12 13 11
174+
2 4 9 1
175+
118 2 3 4 13 28 14
176+
3 1 11 3
177+
130 6 3 7 8 18 20 19 23 27 26
178+
131 9 8 3 1 24 26 25 21 12 22
179+
132 6 3 8 1 18 26 23 17 22 12
180+
3 2 11 3
181+
133 3 2 9 1 13 15 25 12 21 11
182+
134 2 4 9 5 14 31 15 16 29 30
183+
135 2 3 9 4 13 25 15 14 31 28
184+
$EndElements

0 commit comments

Comments
 (0)