libMesh
Public Member Functions | List of all members
MeshTetTest Class Reference
Inheritance diagram for MeshTetTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (MeshTetTest)
 The goal of this test is to verify proper operation of the interfaces to tetrahedralization libraries. More...
 
 CPPUNIT_TEST (testNetGen)
 
 CPPUNIT_TEST (testNetGenError)
 
 CPPUNIT_TEST (testNetGenTets)
 
 CPPUNIT_TEST (testNetGenFlippedTris)
 
 CPPUNIT_TEST (testNetGenHole)
 
 CPPUNIT_TEST (testNetGenSphereShell)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testExceptionBase (const char *re, MeshBase &mesh, MeshTetInterface &tetinterface, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
 
void testTetInterfaceBase (MeshBase &mesh, MeshTetInterface &triangulator, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
 
void testHole (UnstructuredMesh &mesh, MeshTetInterface &triangulator)
 
void testSphereShell (UnstructuredMesh &mesh, MeshTetInterface &triangulator)
 
void testTrisToTets (UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
 
void testTrisToTetsError (UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
 
void testTetsToTets (MeshBase &mesh, MeshTetInterface &triangulator)
 
void testTetGen ()
 
void testTetGenError ()
 
void testNetGen ()
 
void testNetGenError ()
 
void testNetGenTets ()
 
void testNetGenFlippedTris ()
 
void testNetGenHole ()
 
void testNetGenSphereShell ()
 

Detailed Description

Definition at line 38 of file mesh_tet_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/6]

MeshTetTest::CPPUNIT_TEST ( testNetGen  )

◆ CPPUNIT_TEST() [2/6]

MeshTetTest::CPPUNIT_TEST ( testNetGenError  )

◆ CPPUNIT_TEST() [3/6]

MeshTetTest::CPPUNIT_TEST ( testNetGenTets  )

◆ CPPUNIT_TEST() [4/6]

MeshTetTest::CPPUNIT_TEST ( testNetGenFlippedTris  )

◆ CPPUNIT_TEST() [5/6]

MeshTetTest::CPPUNIT_TEST ( testNetGenHole  )

◆ CPPUNIT_TEST() [6/6]

MeshTetTest::CPPUNIT_TEST ( testNetGenSphereShell  )

◆ CPPUNIT_TEST_SUITE_END()

MeshTetTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

MeshTetTest::LIBMESH_CPPUNIT_TEST_SUITE ( MeshTetTest  )

The goal of this test is to verify proper operation of the interfaces to tetrahedralization libraries.

◆ setUp()

void MeshTetTest::setUp ( )
inline

Definition at line 83 of file mesh_tet_test.C.

83 {}

◆ tearDown()

void MeshTetTest::tearDown ( )
inline

Definition at line 85 of file mesh_tet_test.C.

85 {}

◆ testExceptionBase()

void MeshTetTest::testExceptionBase ( const char *  re,
MeshBase mesh,
MeshTetInterface tetinterface,
dof_id_type  expected_n_elem = DofObject::invalid_id,
dof_id_type  expected_n_nodes = DofObject::invalid_id,
Real  expected_volume = 0 
)
inline

Definition at line 87 of file mesh_tet_test.C.

References mesh.

93  {
94 #ifdef LIBMESH_ENABLE_EXCEPTIONS
95  // We can't just CPPUNIT_ASSERT_THROW, because we want to make
96  // sure we were thrown from the right place with the right error
97  // message!
98  bool threw_desired_exception = false;
99  try {
100  this->testTetInterfaceBase(mesh, tetinterface, expected_n_elem,
101  expected_n_nodes, expected_volume);
102  }
103  catch (libMesh::LogicError & e) {
104  std::regex msg_regex(re);
105  CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
106  threw_desired_exception = true;
107  }
108  catch (CppUnit::Exception & e) {
109  throw e;
110  }
111  catch (...) {
112  CPPUNIT_ASSERT_MESSAGE("Unexpected exception type thrown", false);
113  }
114  CPPUNIT_ASSERT(threw_desired_exception);
115 #endif
116  }
void testTetInterfaceBase(MeshBase &mesh, MeshTetInterface &triangulator, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...

◆ testHole()

void MeshTetTest::testHole ( UnstructuredMesh mesh,
MeshTetInterface triangulator 
)
inline

Definition at line 148 of file mesh_tet_test.C.

References libMesh::MeshTetInterface::attach_hole_list(), libMesh::MeshTools::Generation::build_cube(), mesh, libMesh::Real, and libMesh::MeshTools::volume().

150  {
151  std::unique_ptr<UnstructuredMesh> holemesh =
152  std::make_unique<Mesh>(*TestCommWorld);
153 
155  -2, 2, -2, 2, -2, 2);
156 
157  const Real hole_volume =
158  build_octahedron(*holemesh, false, -1, 1, -1, 1, -1, 1);
159 
160  auto holes =
161  std::make_unique<std::vector<std::unique_ptr<UnstructuredMesh>>>();
162 
163  holes->push_back(std::move(holemesh));
164 
165  triangulator.attach_hole_list(std::move(holes));
166 
167  const Real expected_volume =
168  MeshTools::volume(mesh) - hole_volume;
169  this->testTetInterfaceBase(mesh, triangulator, 32, 14,
170  expected_volume);
171  }
MeshBase & mesh
void testTetInterfaceBase(MeshBase &mesh, MeshTetInterface &triangulator, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
Find the total volume of a mesh (interpreting that as area for dim = 2, or total arc length for dim =...
Definition: mesh_tools.C:985
void attach_hole_list(std::unique_ptr< std::vector< std::unique_ptr< UnstructuredMesh >>> holes)
Attaches a vector of Mesh pointers defining holes which will be meshed around.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

◆ testNetGen()

void MeshTetTest::testNetGen ( )
inline

Definition at line 323 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

324  {
325  LOG_UNIT_TEST;
326 
328  NetGenMeshInterface net_tet(mesh);
329  testTrisToTets(mesh, net_tet);
330  }
Class NetGenMeshInterface provides an interface for tetrahedralization of meshes using the NetGen lib...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
void testTrisToTets(UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testNetGenError()

void MeshTetTest::testNetGenError ( )
inline

Definition at line 333 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

334  {
335  LOG_UNIT_TEST;
336 
338  NetGenMeshInterface net_tet(mesh);
339  testTrisToTetsError(mesh, net_tet);
340  }
Class NetGenMeshInterface provides an interface for tetrahedralization of meshes using the NetGen lib...
void testTrisToTetsError(UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testNetGenFlippedTris()

void MeshTetTest::testNetGenFlippedTris ( )
inline

Definition at line 353 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

354  {
355  LOG_UNIT_TEST;
356 
358  NetGenMeshInterface net_tet(mesh);
359  testTrisToTets(mesh, net_tet, true);
360  }
Class NetGenMeshInterface provides an interface for tetrahedralization of meshes using the NetGen lib...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
void testTrisToTets(UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testNetGenHole()

void MeshTetTest::testNetGenHole ( )
inline

Definition at line 363 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

364  {
365  LOG_UNIT_TEST;
366 
368  NetGenMeshInterface net_tet(mesh);
369  testHole(mesh, net_tet);
370  }
Class NetGenMeshInterface provides an interface for tetrahedralization of meshes using the NetGen lib...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
void testHole(UnstructuredMesh &mesh, MeshTetInterface &triangulator)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testNetGenSphereShell()

void MeshTetTest::testNetGenSphereShell ( )
inline

Definition at line 374 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

375  {
376  LOG_UNIT_TEST;
377 
379  NetGenMeshInterface net_tet(mesh);
380  testSphereShell(mesh, net_tet);
381  }
Class NetGenMeshInterface provides an interface for tetrahedralization of meshes using the NetGen lib...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
void testSphereShell(UnstructuredMesh &mesh, MeshTetInterface &triangulator)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testNetGenTets()

void MeshTetTest::testNetGenTets ( )
inline

Definition at line 343 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

344  {
345  LOG_UNIT_TEST;
346 
348  NetGenMeshInterface net_tet(mesh);
349  testTetsToTets(mesh, net_tet);
350  }
Class NetGenMeshInterface provides an interface for tetrahedralization of meshes using the NetGen lib...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
void testTetsToTets(MeshBase &mesh, MeshTetInterface &triangulator)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testSphereShell()

void MeshTetTest::testSphereShell ( UnstructuredMesh mesh,
MeshTetInterface triangulator 
)
inline

Definition at line 175 of file mesh_tet_test.C.

References libMesh::MeshTetInterface::attach_hole_list(), libMesh::MeshTools::Generation::build_sphere(), libMesh::MeshTetInterface::desired_volume(), mesh, and libMesh::TET4.

177  {
178  std::unique_ptr<UnstructuredMesh> holemesh =
179  std::make_unique<Mesh>(*TestCommWorld);
180 
181  MeshTools::Generation::build_sphere (*holemesh, 1, 2, TET4);
182 
184 
185  auto holes =
186  std::make_unique<std::vector<std::unique_ptr<UnstructuredMesh>>>();
187 
188  holes->push_back(std::move(holemesh));
189 
190  triangulator.attach_hole_list(std::move(holes));
191 
192  // Netgen can't seem to triangulate this without inserting points,
193  // so let MeshNetgenInterface know that we're allowed to insert
194  // points
195  triangulator.desired_volume() = 1000;
196 
197  this->testTetInterfaceBase(mesh, triangulator);
198  }
void build_sphere(UnstructuredMesh &mesh, const Real rad=1, const unsigned int nr=2, const ElemType type=INVALID_ELEM, const unsigned int n_smooth=2, const bool flat=true)
Meshes a spherical or mapped-spherical domain.
Real & desired_volume()
Sets and/or gets the desired tetrahedron volume.
MeshBase & mesh
void testTetInterfaceBase(MeshBase &mesh, MeshTetInterface &triangulator, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
void attach_hole_list(std::unique_ptr< std::vector< std::unique_ptr< UnstructuredMesh >>> holes)
Attaches a vector of Mesh pointers defining holes which will be meshed around.

◆ testTetGen()

void MeshTetTest::testTetGen ( )
inline

Definition at line 277 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

278  {
279  LOG_UNIT_TEST;
280 
282  TetGenMeshInterface tet_tet(mesh);
283  testTrisToTets(mesh, tet_tet);
284  }
Class TetGenMeshInterface provides an interface for tetrahedralization of meshes using the TetGen lib...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
void testTrisToTets(UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testTetGenError()

void MeshTetTest::testTetGenError ( )
inline

Definition at line 287 of file mesh_tet_test.C.

References mesh, and TestCommWorld.

288  {
289  LOG_UNIT_TEST;
290 
292  TetGenMeshInterface tet_tet(mesh);
293  testTrisToTetsError(mesh, tet_tet);
294  }
Class TetGenMeshInterface provides an interface for tetrahedralization of meshes using the TetGen lib...
void testTrisToTetsError(UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testTetInterfaceBase()

void MeshTetTest::testTetInterfaceBase ( MeshBase mesh,
MeshTetInterface triangulator,
dof_id_type  expected_n_elem = DofObject::invalid_id,
dof_id_type  expected_n_nodes = DofObject::invalid_id,
Real  expected_volume = 0 
)
inline

Definition at line 119 of file mesh_tet_test.C.

References libMesh::DofObject::invalid_id, mesh, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::TET4, libMesh::TOLERANCE, libMesh::MeshTetInterface::triangulate(), and libMesh::MeshTools::volume().

124  {
125  triangulator.triangulate();
126 
127  if (expected_n_elem != DofObject::invalid_id)
128  CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), expected_n_elem);
129 
130  if (expected_n_nodes != DofObject::invalid_id)
131  CPPUNIT_ASSERT_EQUAL(mesh.n_nodes(), expected_n_nodes);
132 
133  if (expected_volume != 0)
134  LIBMESH_ASSERT_FP_EQUAL(MeshTools::volume(mesh),
135  expected_volume,
137 
138  for (const auto & elem : mesh.element_ptr_range())
139  {
140  CPPUNIT_ASSERT_EQUAL(elem->type(), TET4);
141 
142  // Make sure we're not getting any inverted elements
143  CPPUNIT_ASSERT(!elem->is_flipped());
144  }
145  }
static constexpr Real TOLERANCE
MeshBase & mesh
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
Find the total volume of a mesh (interpreting that as area for dim = 2, or total arc length for dim =...
Definition: mesh_tools.C:985
virtual void triangulate()=0
This is the main public interface for this function.
virtual dof_id_type n_elem() const =0
virtual dof_id_type n_nodes() const =0

◆ testTetsToTets()

void MeshTetTest::testTetsToTets ( MeshBase mesh,
MeshTetInterface triangulator 
)
inline

Definition at line 240 of file mesh_tet_test.C.

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::Elem::build(), mesh, libMesh::MeshBase::node_ptr(), libMesh::MeshBase::prepare_for_use(), libMesh::Real, libMesh::Elem::set_node(), libMesh::TET4, and libMesh::MeshTools::volume().

242  {
243  // An asymmetric octahedron, so we hopefully have an unambiguous
244  // choice of shortest diagonal for a Delaunay algorithm to pick.
245  mesh.add_point(Point(0,0,-0.1), 0);
246  mesh.add_point(Point(1,0,0), 1);
247  mesh.add_point(Point(0,1,0), 2);
248  mesh.add_point(Point(-1,0,0), 3);
249  mesh.add_point(Point(0,-1,0), 4);
250  mesh.add_point(Point(0,0,0.1), 5);
251 
252  auto add_tet = [&mesh](std::array<dof_id_type,4> nodes)
253  {
254  auto elem = mesh.add_elem(Elem::build(TET4));
255  elem->set_node(0, mesh.node_ptr(nodes[0]));
256  elem->set_node(1, mesh.node_ptr(nodes[1]));
257  elem->set_node(2, mesh.node_ptr(nodes[2]));
258  elem->set_node(3, mesh.node_ptr(nodes[3]));
259  };
260 
261  // Split along a different diagonal to start
262  add_tet({1,3,4,5});
263  add_tet({1,3,5,2});
264  add_tet({1,3,2,0});
265  add_tet({1,3,0,4});
266 
268 
269  const Real expected_volume = MeshTools::volume(mesh);
270 
271  this->testTetInterfaceBase(mesh, triangulator, /* n_elem = */ 4,
272  /* n_nodes = */ 6, expected_volume);
273  }
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2558
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:759
MeshBase & mesh
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
void testTetInterfaceBase(MeshBase &mesh, MeshTetInterface &triangulator, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
Find the total volume of a mesh (interpreting that as area for dim = 2, or total arc length for dim =...
Definition: mesh_tools.C:985
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Node * node_ptr(const dof_id_type i) const =0
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ testTrisToTets()

void MeshTetTest::testTrisToTets ( UnstructuredMesh mesh,
MeshTetInterface triangulator,
bool  flip_tris = false 
)
inline

Definition at line 202 of file mesh_tet_test.C.

References mesh, and libMesh::Real.

205  {
206  // An asymmetric octahedron, so we hopefully have an unambiguous
207  // choice of shortest diagonal for a Delaunay algorithm to pick.
208  const Real expected_volume =
209  build_octahedron(mesh, flip_tris, -1, 1, -1, 1, -0.1, 0.1);
210 
211  this->testTetInterfaceBase(mesh, triangulator, /* n_elem = */ 4,
212  /* n_nodes = */ 6, expected_volume);
213  }
MeshBase & mesh
void testTetInterfaceBase(MeshBase &mesh, MeshTetInterface &triangulator, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ testTrisToTetsError()

void MeshTetTest::testTrisToTetsError ( UnstructuredMesh mesh,
MeshTetInterface triangulator,
bool  flip_tris = false 
)
inline

Definition at line 216 of file mesh_tet_test.C.

References libMesh::MeshBase::delete_elem(), mesh, libMesh::MeshBase::prepare_for_use(), and libMesh::Real.

219  {
220  const Real expected_volume =
221  build_octahedron(mesh, flip_tris, -1, 1, -1, 1, -0.1, 0.1);
222 
223  // Remove one tri, breaking the mesh
224  for (auto elem : mesh.element_ptr_range())
225  {
226  Point center = elem->vertex_average();
227  if (center(0) > 0 &&
228  center(1) > 0 &&
229  center(2) > 0)
230  mesh.delete_elem(elem);
231  }
233 
234  this->testExceptionBase("element with a null neighbor", mesh, triangulator,
235  /* n_elem = */ 4, /* n_nodes = */ 6,
236  expected_volume);
237  }
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:759
MeshBase & mesh
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void testExceptionBase(const char *re, MeshBase &mesh, MeshTetInterface &tetinterface, dof_id_type expected_n_elem=DofObject::invalid_id, dof_id_type expected_n_nodes=DofObject::invalid_id, Real expected_volume=0)
Definition: mesh_tet_test.C:87

The documentation for this class was generated from the following file: