1 #include <libmesh/boundary_info.h> 2 #include <libmesh/elem.h> 3 #include <libmesh/mesh.h> 4 #include <libmesh/mesh_generation.h> 5 #include <libmesh/mesh_netgen_interface.h> 6 #include <libmesh/mesh_tetgen_interface.h> 7 #include <libmesh/mesh_tet_interface.h> 8 #include <libmesh/mesh_tools.h> 9 #include <libmesh/parallel_implementation.h> 29 (
mesh, xmin, xmax, ymin, ymax, zmin, zmax);
32 return (xmax-xmin)*(ymax-ymin)*(zmax-zmin)/6;
47 #ifdef LIBMESH_HAVE_NETGEN 49 CPPUNIT_TEST( testNetGen );
50 CPPUNIT_TEST( testNetGenError );
51 CPPUNIT_TEST( testNetGenTets );
52 CPPUNIT_TEST( testNetGenFlippedTris );
53 CPPUNIT_TEST( testNetGenHole );
55 #ifdef LIBMESH_ENABLE_AMR 56 CPPUNIT_TEST( testNetGenSphereShell );
71 #ifdef LIBMESH_HAVE_TETGEN 80 CPPUNIT_TEST_SUITE_END();
92 Real expected_volume = 0)
94 #ifdef LIBMESH_ENABLE_EXCEPTIONS 98 bool threw_desired_exception =
false;
100 this->testTetInterfaceBase(
mesh, tetinterface, expected_n_elem,
101 expected_n_nodes, expected_volume);
104 std::regex msg_regex(re);
105 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
106 threw_desired_exception =
true;
108 catch (CppUnit::Exception & e) {
112 CPPUNIT_ASSERT_MESSAGE(
"Unexpected exception type thrown",
false);
114 CPPUNIT_ASSERT(threw_desired_exception);
123 Real expected_volume = 0)
128 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), expected_n_elem);
131 CPPUNIT_ASSERT_EQUAL(
mesh.
n_nodes(), expected_n_nodes);
133 if (expected_volume != 0)
138 for (
const auto & elem :
mesh.element_ptr_range())
140 CPPUNIT_ASSERT_EQUAL(elem->type(),
TET4);
143 CPPUNIT_ASSERT(!elem->is_flipped());
151 std::unique_ptr<UnstructuredMesh> holemesh =
152 std::make_unique<Mesh>(*TestCommWorld);
155 -2, 2, -2, 2, -2, 2);
157 const Real hole_volume =
158 build_octahedron(*holemesh,
false, -1, 1, -1, 1, -1, 1);
161 std::make_unique<std::vector<std::unique_ptr<UnstructuredMesh>>>();
163 holes->push_back(std::move(holemesh));
167 const Real expected_volume =
169 this->testTetInterfaceBase(
mesh, triangulator, 32, 14,
174 #ifdef LIBMESH_ENABLE_AMR 178 std::unique_ptr<UnstructuredMesh> holemesh =
179 std::make_unique<Mesh>(*TestCommWorld);
186 std::make_unique<std::vector<std::unique_ptr<UnstructuredMesh>>>();
188 holes->push_back(std::move(holemesh));
197 this->testTetInterfaceBase(
mesh, triangulator);
204 bool flip_tris =
false)
208 const Real expected_volume =
209 build_octahedron(
mesh, flip_tris, -1, 1, -1, 1, -0.1, 0.1);
211 this->testTetInterfaceBase(
mesh, triangulator, 4,
218 bool flip_tris =
false)
220 const Real expected_volume =
221 build_octahedron(
mesh, flip_tris, -1, 1, -1, 1, -0.1, 0.1);
224 for (
auto elem :
mesh.element_ptr_range())
226 Point center = elem->vertex_average();
234 this->testExceptionBase(
"element with a null neighbor",
mesh, triangulator,
252 auto add_tet = [&
mesh](std::array<dof_id_type,4> nodes)
271 this->testTetInterfaceBase(
mesh, triangulator, 4,
276 #ifdef LIBMESH_HAVE_TETGEN 283 testTrisToTets(
mesh, tet_tet);
293 testTrisToTetsError(
mesh, tet_tet);
319 #endif // LIBMESH_HAVE_TETGEN 322 #ifdef LIBMESH_HAVE_NETGEN 329 testTrisToTets(
mesh, net_tet);
339 testTrisToTetsError(
mesh, net_tet);
349 testTetsToTets(
mesh, net_tet);
359 testTrisToTets(
mesh, net_tet,
true);
369 testHole(
mesh, net_tet);
373 #ifdef LIBMESH_ENABLE_AMR 380 testSphereShell(
mesh, net_tet);
489 #endif // LIBMESH_HAVE_NETGEN Class TetGenMeshInterface provides an interface for tetrahedralization of meshes using the TetGen lib...
virtual Node *& set_node(const unsigned int i)
Real & desired_volume()
Sets and/or gets the desired tetrahedron volume.
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
static constexpr Real TOLERANCE
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.
CPPUNIT_TEST_SUITE_REGISTRATION(MeshTetTest)
The libMesh namespace provides an interface to certain functionality in the library.
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.
This is the MeshBase class.
void testSphereShell(UnstructuredMesh &mesh, MeshTetInterface &triangulator)
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 testTetsToTets(MeshBase &mesh, MeshTetInterface &triangulator)
void testNetGenSphereShell()
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
The UnstructuredMesh class is derived from the MeshBase class.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
void testTrisToTets(UnstructuredMesh &mesh, MeshTetInterface &triangulator, bool flip_tris=false)
void testNetGenFlippedTris()
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
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
virtual void triangulate()=0
This is the main public interface for this function.
void testHole(UnstructuredMesh &mesh, MeshTetInterface &triangulator)
virtual dof_id_type n_elem() const =0
virtual const Node * node_ptr(const dof_id_type i) const =0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Point defines a location in LIBMESH_DIM dimensional Real space.
virtual dof_id_type n_nodes() const =0
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)
Class MeshTetInterface provides an abstract interface for tetrahedralization of meshes by subclasses...