Skip to content

Commit 3b36a9c

Browse files
committed
Fail in parallel when we've confused NetGen
This might be useful in letting application code recover from such errors, and it's definitely useful in debugging unit tests where I've screwed something up.
1 parent 7a07148 commit 3b36a9c

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/mesh/mesh_netgen_interface.C

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ void NetGenMeshInterface::triangulate ()
128128
// Receive the mesh data rank 0 will send later, then fix it up
129129
// together
130130
MeshCommunication().broadcast(this->_mesh);
131+
132+
// If we got an empty mesh here then our tetrahedralization
133+
// failed.
134+
libmesh_error_msg_if (!this->_mesh.n_elem(),
135+
"NetGen failed to generate any tetrahedra");
136+
131137
this->_mesh.prepare_for_use();
132138
return;
133139
}
@@ -326,8 +332,17 @@ void NetGenMeshInterface::triangulate ()
326332

327333
const int n_elem = Ng_GetNE(ngmesh);
328334

329-
libmesh_error_msg_if (n_elem <= 0,
330-
"NetGen failed to generate any tetrahedra");
335+
// If Netgen fails us, we're likely to get n_elem <= 0. This is a
336+
// common enough failure from bad setups that I want to make sure
337+
// it's thrown in parallel so as to not desynchronize any unit tests
338+
// that trigger it. So we'll broadcast the empty mesh to indicate
339+
// the problem and enable throwing exceptions in parallel.
340+
if (n_elem <= 0)
341+
{
342+
this->_mesh.clear();
343+
MeshCommunication().broadcast(this->_mesh);
344+
libmesh_error_msg ("NetGen failed to generate any tetrahedra");
345+
}
331346

332347
const dof_id_type n_points = Ng_GetNP(ngmesh);
333348
const dof_id_type old_nodes = this->_mesh.n_nodes();

0 commit comments

Comments
 (0)