Skip to content

Commit d47009f

Browse files
Merge pull request #766 from baagaard-usgs/add-orphan-vertices-check
Add check for orphan vertices in check of mesh topology
2 parents 868a6b3 + dfe0e62 commit d47009f

File tree

8 files changed

+141
-3
lines changed

8 files changed

+141
-3
lines changed

libsrc/pylith/meshio/MeshIOPetsc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pylith::meshio::MeshIOPetsc::_read(void) {
144144
err = PetscObjectSetOptionsPrefix((PetscObject) dmMesh, _prefix.c_str());PYLITH_CHECK_ERROR(err);
145145
} // if
146146
err = DMPlexDistributeSetDefault(dmMesh, PETSC_FALSE);PYLITH_CHECK_ERROR(err);
147-
err = DMSetFromOptions(dmMesh);PYLITH_CHECK_ERROR(err);
147+
err = DMSetFromOptions(dmMesh);PYLITH_CHECK_ERROR_MSG(err, "Error creating mesh with MeshIOPetsc.");
148148

149149
_MeshIOPetsc::fixMaterialLabel(&dmMesh);
150150
_MeshIOPetsc::fixBoundaryLabels(&dmMesh);

libsrc/pylith/topology/MeshOps.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pylith::topology::MeshOps::checkTopology(const Mesh& mesh) {
376376

377377
_MeshOps::Events::logger.eventBegin(_MeshOps::Events::checkTopologySkeleton);
378378
err = DMPlexCheckSkeleton(dmMesh, cellHeight);PYLITH_CHECK_ERROR_MSG(err, "Error in topology of mesh cells.");
379+
err = DMPlexCheckOrphanVertices(dmMesh);PYLITH_CHECK_ERROR_MSG(err, "Mesh contains vertices not connected to cells.");
379380
_MeshOps::Events::logger.eventEnd(_MeshOps::Events::checkTopologySkeleton);
380381

381382
/* Other check functions that we are not using:

tests/libtests/meshio/TestMeshIOAscii.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,23 @@ pylith::meshio::TestMeshIOAscii::testRead(void) {
9494
_checkVals();
9595

9696
PYLITH_METHOD_END;
97-
} // testRead3DIndexOne
97+
} // testRead
98+
99+
100+
// ----------------------------------------------------------------------
101+
// Test read() with error.
102+
void
103+
pylith::meshio::TestMeshIOAscii::testReadError(void) {
104+
PYLITH_METHOD_BEGIN;
105+
assert(_io);
106+
107+
// Read mesh
108+
delete _mesh;_mesh = new pylith::topology::Mesh;
109+
_io->setFilename(_data->filename.c_str());
110+
CHECK_THROWS_AS(_io->read(_mesh), std::runtime_error);
111+
112+
PYLITH_METHOD_END;
113+
} // testRead
98114

99115

100116
// End of file

tests/libtests/meshio/TestMeshIOAscii.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public:
3737
/// Test read().
3838
void testRead(void);
3939

40+
/// Test read() with known errors.
41+
void testReadError(void);
42+
4043
// PROTECTED METHODS ////////////////////////////////////////////////
4144
protected:
4245

tests/libtests/meshio/TestMeshIOAscii_Cases.cc

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class pylith::meshio::TestMeshIOAscii_Cases {
3535

3636
static TestMeshIO_Data* Hex3D_Index1(void);
3737

38+
static TestMeshIO_Data* Tri_OrphanVertex(void);
39+
40+
static TestMeshIO_Data* Hex_OrphanVertex(void);
41+
3842
}; // TestMeshIOAscii_Cases
3943

4044
// ------------------------------------------------------------------------------------------------
@@ -55,10 +59,17 @@ TEST_CASE("TestMeshIOAscii::Hex3D::testWriteRead", "[TestMeshIOAscii][testWriteR
5559
TEST_CASE("TestMeshIOAscii::Quad2D_Comments::testRead", "[TestMeshIOAscii][testRead]") {
5660
pylith::meshio::TestMeshIOAscii(pylith::meshio::TestMeshIOAscii_Cases::Quad2D_Comments()).testRead();
5761
}
58-
TEST_CASE("TestMeshIOAscii::Hex3D_Index1::testReas", "[TestMeshIOAscii][testRead]") {
62+
TEST_CASE("TestMeshIOAscii::Hex3D_Index1::testRead", "[TestMeshIOAscii][testRead]") {
5963
pylith::meshio::TestMeshIOAscii(pylith::meshio::TestMeshIOAscii_Cases::Hex3D_Index1()).testRead();
6064
}
6165

66+
TEST_CASE("TestMeshIOAscii::Tri_OrphanVertex::testReadError", "[TestMeshIOAscii][testReadError]") {
67+
pylith::meshio::TestMeshIOAscii(pylith::meshio::TestMeshIOAscii_Cases::Tri_OrphanVertex()).testReadError();
68+
}
69+
TEST_CASE("TestMeshIOAscii::Hex_OrphanVertex::testReadError", "[TestMeshIOAscii][testReadError]") {
70+
pylith::meshio::TestMeshIOAscii(pylith::meshio::TestMeshIOAscii_Cases::Hex_OrphanVertex()).testReadError();
71+
}
72+
6273
// ------------------------------------------------------------------------------------------------
6374
pylith::meshio::TestMeshIO_Data*
6475
pylith::meshio::TestMeshIOAscii_Cases::Quad2D(void) {
@@ -368,4 +379,26 @@ pylith::meshio::TestMeshIOAscii_Cases::Hex3D_Index1(void) {
368379
} // Hex3D_Index1
369380

370381

382+
// ------------------------------------------------------------------------------------------------
383+
pylith::meshio::TestMeshIO_Data*
384+
pylith::meshio::TestMeshIOAscii_Cases::Tri_OrphanVertex(void) {
385+
TestMeshIO_Data* data = new TestMeshIO_Data();assert(data);
386+
387+
data->filename = "data/tri_orphan_vertex.mesh";
388+
389+
return data;
390+
} // Hex3D_Index1
391+
392+
393+
// ------------------------------------------------------------------------------------------------
394+
pylith::meshio::TestMeshIO_Data*
395+
pylith::meshio::TestMeshIOAscii_Cases::Hex_OrphanVertex(void) {
396+
TestMeshIO_Data* data = new TestMeshIO_Data();assert(data);
397+
398+
data->filename = "data/hex_orphan_vertex.mesh";
399+
400+
return data;
401+
} // Hex3D_Index1
402+
403+
371404
// End of file

tests/libtests/meshio/data/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dist_noinst_DATA = \
6161
noembed_tet.msh \
6262
nosplit_tri.msh \
6363
tri3.mesh \
64+
tri_orphan_vertex.mesh \
6465
tri3_vertex_t10.vtk \
6566
tri3_cell_t10.vtk \
6667
quad4.mesh \
@@ -70,6 +71,7 @@ dist_noinst_DATA = \
7071
tet4_vertex_t10.vtk \
7172
tet4_cell_t10.vtk \
7273
hex8.mesh \
74+
hex_orphan_vertex.mesh \
7375
hex8_vertex_t10.vtk \
7476
hex8_cell_t10.vtk \
7577
tri3_mat_vertex_t10.vtk \
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Mesh with an orphan vertex (verify topology check fails).
2+
mesh = {
3+
dimension = 3
4+
use-index-zero = true
5+
vertices = {
6+
dimension = 3
7+
count = 12
8+
coordinates = {
9+
0 -1.0 -1.0 -1.0
10+
1 -1.0 1.0 -1.0
11+
2 0.0 -1.0 -1.0
12+
3 0.0 1.0 -1.0
13+
4 1.0 -1.0 -1.0
14+
5 1.0 1.0 -1.0
15+
6 -1.0 -1.0 1.0
16+
7 -1.0 1.0 1.0
17+
8 0.0 -1.0 1.0
18+
9 0.0 1.0 1.0
19+
10 1.0 -1.0 1.0
20+
11 1.0 1.0 1.0
21+
}
22+
}
23+
cells = {
24+
count = 1
25+
num-corners = 8
26+
simplices = {
27+
0 0 2 3 1 6 8 9 7
28+
}
29+
material-ids = {
30+
0 1
31+
}
32+
}
33+
group = {
34+
name = fault
35+
type = vertices
36+
count = 4
37+
indices = {
38+
2 3 8 9
39+
}
40+
}
41+
group = {
42+
name = front
43+
type = vertices
44+
count = 4
45+
indices = {
46+
0 1 6 7
47+
}
48+
}
49+
group = {
50+
name = top
51+
type = vertices
52+
count = 6
53+
indices = {
54+
6 7 8 9 10 11
55+
}
56+
}
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Mesh with an orphan vertex (verify topology check fails).
2+
mesh = {
3+
dimension = 2
4+
use-index-zero = true
5+
vertices = {
6+
dimension = 2
7+
count = 4
8+
coordinates = {
9+
0 -1.0 0.0
10+
1 0.0 -1.0
11+
2 0.0 1.0
12+
3 1.0 0.0
13+
}
14+
}
15+
cells = {
16+
count = 1
17+
num-corners = 3
18+
simplices = {
19+
0 0 1 2
20+
}
21+
material-ids = {
22+
0 1
23+
1 0
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)