libMesh
distributed_mesh_test.C
Go to the documentation of this file.
1 // libmesh includes
2 #include <libmesh/distributed_mesh.h>
3 #include <libmesh/elem.h>
4 #include <libmesh/mesh_generation.h>
5 #include <libmesh/utility.h>
6 
7 // cppunit includes
8 #include "test_comm.h"
9 #include "libmesh_cppunit.h"
10 
11 // C++ includes
12 #include <regex>
13 
14 using namespace libMesh;
15 
16 
17 class DistributedMeshTest : public CppUnit::TestCase {
18 public:
19  LIBMESH_CPPUNIT_TEST_SUITE( DistributedMeshTest );
20 
21  CPPUNIT_TEST( testRemoteElemError );
22 
23  CPPUNIT_TEST_SUITE_END();
24 
25 private:
26 
27 public:
28  void setUp()
29  {}
30 
31  void tearDown()
32  {}
33 
35  {
36  LOG_UNIT_TEST;
37 
39 
40  // Build enough elements to be sure some will be remote on 2
41  // processors
43 
44 #ifdef LIBMESH_ENABLE_EXCEPTIONS
45  if (mesh.n_processors() > 1)
46  {
47  // We only expect a throw if we can get to a remote_elem to
48  // throw from, which can't happen if we're on 11+ procs
49  bool threw_expected_error = true;
50  try
51  {
52  for (const auto & elem : mesh.element_ptr_range())
53  {
54  threw_expected_error = false;
55  for (const Elem * neigh : elem->neighbor_ptr_range())
56  if (neigh && neigh->n_sides() != 2) // this should throw if not 2
57  CPPUNIT_ASSERT(false);
58  }
59  }
60  catch (libMesh::LogicError & e)
61  {
62  std::regex msg_regex("merely a shim");
63  CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
64  threw_expected_error = true;
65  }
66 
67  CPPUNIT_ASSERT(threw_expected_error);
68  }
69 #endif // LIBMESH_ENABLE_EXCEPTIONS
70  }
71 };
72 
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
CPPUNIT_TEST_SUITE_REGISTRATION(DistributedMeshTest)
The libMesh namespace provides an interface to certain functionality in the library.
processor_id_type n_processors() const
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
SimpleRange< NeighborPtrIter > neighbor_ptr_range()
Returns a range with all neighbors of an element, usable in range-based for loops.
Definition: elem.h:3503