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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (MeshSpatialDimensionTest)
 This unit test tests a few basic things with the new Mesh::spatial_dimension() implementation. More...
 
 CPPUNIT_TEST (test1D)
 
 CPPUNIT_TEST (test2D)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void test1D ()
 
void test2D ()
 

Detailed Description

Definition at line 12 of file spatial_dimension_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/2]

MeshSpatialDimensionTest::CPPUNIT_TEST ( test1D  )

◆ CPPUNIT_TEST() [2/2]

MeshSpatialDimensionTest::CPPUNIT_TEST ( test2D  )

◆ CPPUNIT_TEST_SUITE_END()

MeshSpatialDimensionTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

MeshSpatialDimensionTest::LIBMESH_CPPUNIT_TEST_SUITE ( MeshSpatialDimensionTest  )

This unit test tests a few basic things with the new Mesh::spatial_dimension() implementation.

◆ setUp()

void MeshSpatialDimensionTest::setUp ( )
inline

Definition at line 31 of file spatial_dimension_test.C.

32  {
33  }

◆ tearDown()

void MeshSpatialDimensionTest::tearDown ( )
inline

Definition at line 35 of file spatial_dimension_test.C.

36  {
37  }

◆ test1D()

void MeshSpatialDimensionTest::test1D ( )
inline

Definition at line 39 of file spatial_dimension_test.C.

References libMesh::MeshTools::Generation::build_line(), libMesh::EDGE2, mesh, libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::prepare_for_use(), libMesh::MeshBase::spatial_dimension(), and TestCommWorld.

40  {
41  LOG_UNIT_TEST;
42 
43  // 1.) Test that build_line() produces a Mesh with spatial_dimension==1
45  MeshTools::Generation::build_line (mesh, /*n_elem=*/2, /*xmin=*/0., /*xmax=*/1., EDGE2);
46  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
47  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.spatial_dimension());
48 
49  // 2.) Move the nodes in the y-direction, test that spatial_dimension==2
50  // The spatial dimension is updated during prepare_for_use().
51  for (auto & node : mesh.node_ptr_range())
52  (*node)(1) = (*node)(0) * (*node)(0);
53 
55  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
56  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
57 
58 
59  // 3.) Move nodes back to zero, check that spatial_dimension is *not* decreased
60  for (auto & node : mesh.node_ptr_range())
61  (*node)(1) = 0.;
62 
64  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
65  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
66 
67 
68  // 4.) Move z-coordinate of nodes, check that spatial_dimension is now 3.
69 #if LIBMESH_DIM == 3
70  for (auto & node : mesh.node_ptr_range())
71  (*node)(2) = (*node)(0) * (*node)(0);
72 
74  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
75  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
76 #endif
77  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
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
unsigned int spatial_dimension() const
Definition: mesh_base.C:543
unsigned int mesh_dimension() const
Definition: mesh_base.C:372
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.

◆ test2D()

void MeshSpatialDimensionTest::test2D ( )
inline

Definition at line 81 of file spatial_dimension_test.C.

References libMesh::MeshTools::Generation::build_square(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::prepare_for_use(), libMesh::QUAD4, libMesh::MeshBase::set_spatial_dimension(), libMesh::MeshBase::spatial_dimension(), and TestCommWorld.

82  {
83  LOG_UNIT_TEST;
84 
85  // 1.) Test that build_cube() produces a Mesh with spatial_dimension==2
88  /*nx=*/2, /*ny=*/2,
89  /*xmin=*/0., /*xmax=*/1.,
90  /*ymin=*/0., /*ymax=*/1.,
91  QUAD4);
92  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
93 
94  // 2.) Move the nodes in the z-direction, test that spatial_dimension==3
95  // The spatial dimension is updated during prepare_for_use().
96  for (auto & node : mesh.node_ptr_range())
97  (*node)(2) =
98  (*node)(0) * (*node)(0) +
99  (*node)(1) * (*node)(1);
100 
102  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
103  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
104 
105 
106  // 3.) Move nodes back to zero, check that spatial_dimension is *not* decreased
107  for (auto & node : mesh.node_ptr_range())
108  (*node)(2) = 0.;
109 
111  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
112  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
113 
114  // 4.) The user is allowed to set the spatial dimension, make sure
115  // that's honored if it's consistent.
118  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
119  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
120 
121  // 5.) If the user sets a spatial dimension that's not big enough, make sure that
122  // prepare_for_use() increases it.
125  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
126  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
127  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
void set_spatial_dimension(unsigned char d)
Sets the "spatial dimension" of the Mesh.
Definition: mesh_base.C:550
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
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
unsigned int spatial_dimension() const
Definition: mesh_base.C:543
unsigned int mesh_dimension() const
Definition: mesh_base.C:372

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