1#include <libmesh/libmesh.h>
2#include <libmesh/distributed_mesh.h>
3#include <libmesh/elem.h>
4#include <libmesh/cell_c0polyhedron.h>
5#include <libmesh/face_c0polygon.h>
6#include <libmesh/face_polygon.h>
7#include <libmesh/mesh.h>
8#include <libmesh/mesh_generation.h>
9#include <libmesh/mesh_tools.h>
10#include <libmesh/replicated_mesh.h>
36# ifdef LIBMESH_ENABLE_AMR
51# ifdef LIBMESH_ENABLE_AMR
73#ifdef LIBMESH_ENABLE_EXCEPTIONS
78#ifdef LIBMESH_ENABLE_AMR
83# ifdef LIBMESH_ENABLE_AMR
91 std::unique_ptr<UnstructuredMesh>
new_mesh (
bool is_replicated)
106 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n));
111 CPPUNIT_ASSERT_EQUAL(bbox.
min()(0),
Real(-1.0));
112 CPPUNIT_ASSERT_EQUAL(bbox.
max()(0),
Real(2.0));
116 for (
auto & elem :
mesh.element_ptr_range())
117 CPPUNIT_ASSERT(elem->has_affine_map());
124 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n + 4 + 2 * (n - 1) + ((n - 1) / 2)));
126 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n));
128 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n*2));
135 cast_int<dof_id_type>((n+1)*(n+1)));
140 cast_int<dof_id_type>((2*n+1)*(2*n+1)));
144 cast_int<dof_id_type>((2*n+1)*(2*n+1) - n*n));
148 cast_int<dof_id_type>((2*n+1)*(2*n+1) + 2*n*n));
152 cast_int<dof_id_type>(4 + 2*n*n + (n - 1) + 2*n + 2 * (n%2)));
155 CPPUNIT_ASSERT(
false);
161 CPPUNIT_ASSERT(bbox.
min()(0) <=
Real(-2.0));
162 CPPUNIT_ASSERT(bbox.
max()(0) >=
Real(3.0));
163 CPPUNIT_ASSERT(bbox.
min()(1) <=
Real(-4.0));
164 CPPUNIT_ASSERT(bbox.
max()(1) >=
Real(5.0));
169 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
min()(0),
172 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
max()(0),
175 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
min()(1),
178 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
max()(1),
186 for (
auto & elem :
mesh.element_ptr_range())
187 CPPUNIT_ASSERT(elem->has_affine_map());
192 MeshTools::Generation::build_cube (
mesh, n, n, n, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, type);
195 const dof_id_type grid_nodes = cast_int<dof_id_type>((n+1)*(n+1)*(n+1));
197 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n*n));
199 CPPUNIT_ASSERT(
mesh.
n_nodes() <= grid_nodes + cast_int<dof_id_type>(n*n*n));
206 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n*n*24));
211 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n*n*2));
213 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n*n*6));
216 CPPUNIT_ASSERT_EQUAL(
mesh.
n_elem(), cast_int<dof_id_type>(n*n*n));
227 cast_int<dof_id_type>((n+1)*(n+1)*(n+1) + n*n*n + 3*(n+1)*n*n));
232 cast_int<dof_id_type>((n+1)*(n+1)*(n+1)));
236 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) + 14*n*n*n + 4*3*(n+1)*n*n));
241 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1)));
246 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) - n*n*n - 3*(n+1)*n*n));
249 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) + 2*(n+1)*n*n));
253 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) + 2*(2*n+1)*n*n));
257 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) - n*n*n - 2*(n+1)*n*n));
261 cast_int<dof_id_type>((n+1)*(n+1)*(n+1) + n*n*n));
265 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) + 8*n*n*n - 3*(n+1)*n*n));
270 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) + 8*n*n*n));
273 cast_int<dof_id_type>((2*n+1)*(2*n+1)*(2*n+1) + 14*n*n*n + 4*3*(n+1)*n*n +
274 36*n*n*n + 4*3*(n+1)*n*n));
284 CPPUNIT_ASSERT(bbox.
min()(0) <=
Real(-2.0));
285 CPPUNIT_ASSERT(bbox.
max()(0) >=
Real(3.0));
286 CPPUNIT_ASSERT(bbox.
min()(1) <=
Real(-4.0));
287 CPPUNIT_ASSERT(bbox.
max()(1) >=
Real(5.0));
288 CPPUNIT_ASSERT(bbox.
min()(2) <=
Real(-6.0));
289 CPPUNIT_ASSERT(bbox.
max()(2) >=
Real(7.0));
296 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
min()(0),
299 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
max()(0),
302 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
min()(1),
305 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
max()(1),
308 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
min()(2),
311 LIBMESH_ASSERT_FP_EQUAL(nodal_bbox.
max()(2),
318 for (
auto & elem :
mesh.element_ptr_range())
321 CPPUNIT_ASSERT_EQUAL(elem->n_sides(), 6u);
322 CPPUNIT_ASSERT(elem->n_sub_elem() > 0);
323 CPPUNIT_ASSERT(elem->volume() > 0);
335 int n_neighbor_links = 0;
336 for (
auto & elem :
mesh.active_local_element_ptr_range())
337 for (
auto s : elem->side_index_range())
348 CPPUNIT_ASSERT(ns < neigh->n_sides());
354 CPPUNIT_ASSERT_EQUAL(n_neighbor_links,
355 static_cast<int>(2 * 3 * (n-1) * n * n));
368 for (
auto & elem :
mesh.element_ptr_range())
369 CPPUNIT_ASSERT(elem->has_affine_map());
387 for (
int is_replicated = 0; is_replicated != 2; ++is_replicated)
389 for (
int skip_renumber = 0 ; skip_renumber != 2; ++skip_renumber)
391 std::unique_ptr<UnstructuredMesh>
mesh =
394 (this->*f)(*
mesh, n, type);
443 for (
int is_replicated = 0; is_replicated != 2; ++is_replicated)
445 std::unique_ptr<UnstructuredMesh> mesh_ptr =
new_mesh(is_replicated);
458 auto p = std::make_shared<C0Polygon>(3);
462 return std::shared_ptr<Polygon>(std::move(p));
465 std::vector<std::shared_ptr<Polygon>> faces =
466 { tri(0,1,2), tri(0,1,3), tri(1,2,3), tri(0,2,3) };
468 std::unique_ptr<Node> mid_elem_node;
469 std::unique_ptr<Elem> poly =
470 std::make_unique<C0Polyhedron>(faces, mid_elem_node);
490 int poly_to_tet = 0, tet_to_poly = 0;
491 for (
const Elem * elem :
mesh.active_local_element_ptr_range())
492 for (
auto s : elem->side_index_range())
503 CPPUNIT_ASSERT_EQUAL(neigh->
type(),
TET4);
508 else if (elem->type() ==
TET4)
522 CPPUNIT_ASSERT_EQUAL(1, poly_to_tet);
523 CPPUNIT_ASSERT_EQUAL(1, tet_to_poly);
535#ifdef LIBMESH_ENABLE_EXCEPTIONS
void ErrorVector unsigned int
CPPUNIT_TEST(buildSquareQuad9)
CPPUNIT_TEST(buildLineEdge2)
std::unique_ptr< UnstructuredMesh > new_mesh(bool is_replicated)
void testBuildLine(UnstructuredMesh &mesh, unsigned int n, ElemType type)
CPPUNIT_TEST(buildLineEdge3)
LIBMESH_CPPUNIT_TEST_SUITE(MeshGenerationTest)
The goal of this test is to verify proper operation of MeshGeneration functions, as well as to indire...
CPPUNIT_TEST(buildCubePrism6)
CPPUNIT_TEST(buildCubePyramid13)
CPPUNIT_TEST(buildCubeTet4)
CPPUNIT_TEST(buildCubePrism18)
void testBuildSphere(unsigned int n_ref, ElemType type)
CPPUNIT_TEST(buildCubeHex20)
void buildCubeC0Polyhedron()
CPPUNIT_TEST(buildCubePrism15)
CPPUNIT_TEST(buildSphereEdge3)
CPPUNIT_TEST(buildCubeC0Polyhedron)
CPPUNIT_TEST(buildSphereEdge2)
CPPUNIT_TEST(buildLineEdge4)
void testBuildCube(UnstructuredMesh &mesh, unsigned int n, ElemType type)
CPPUNIT_TEST(buildCubeHex8)
CPPUNIT_TEST(buildSquareTri6)
CPPUNIT_TEST(buildSphereHex8)
CPPUNIT_TEST(buildSquareC0PolygonEven)
CPPUNIT_TEST(buildSquareTri3)
CPPUNIT_TEST(buildSquareQuad8)
void buildCubePyramid14()
CPPUNIT_TEST(buildCubeHex27)
CPPUNIT_TEST(buildSphereTri3)
void buildCubePyramid13()
CPPUNIT_TEST(buildCubeTet14)
void testBuildSquare(UnstructuredMesh &mesh, unsigned int n, ElemType type)
void polyhedronTetNeighbor()
void tester(Builder f, unsigned int n, ElemType type)
CPPUNIT_TEST(buildCubePrism21)
void buildSquareC0PolygonOdd()
CPPUNIT_TEST(buildSphereQuad4)
CPPUNIT_TEST(buildCubePyramid5)
void buildSquareC0PolygonEven()
CPPUNIT_TEST(buildSquareTri7)
CPPUNIT_TEST(buildCubePyramid14)
CPPUNIT_TEST(buildCubePrism20)
CPPUNIT_TEST(polyhedronTetNeighbor)
CPPUNIT_TEST(buildCubeTet10)
CPPUNIT_TEST(buildSquareC0PolygonOdd)
CPPUNIT_TEST(buildSphereHex27)
CPPUNIT_TEST(buildSquareQuad4)
void(MeshGenerationTest::* Builder)(UnstructuredMesh &, unsigned int, ElemType)
Defines a Cartesian bounding box by the two corner extremum.
const Point & max() const
const Point & min() const
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
This is the base class from which all geometric element types are derived.
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
static const unsigned int type_to_n_sides_map[INVALID_ELEM]
This array maps the integer representation of the ElemType enum to the number of sides on the element...
virtual bool is_remote() const
static constexpr unsigned int type_to_n_nodes_map[INVALID_ELEM]
This array maps the integer representation of the ElemType enum to the number of nodes in the element...
virtual ElemType type() const =0
const Elem * neighbor_ptr(unsigned int i) const
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual dof_id_type n_elem() const =0
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
virtual dof_id_type n_nodes() const =0
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.
virtual Node * add_node(Node *n)=0
Add Node n to the end of the vertex array.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
The UnstructuredMesh class is derived from the MeshBase class.
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(MeshGenerationTest)
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real