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

Public Member Functions

 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()

MeshSpatialDimensionTest::CPPUNIT_TEST_SUITE ( MeshSpatialDimensionTest  )

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

◆ CPPUNIT_TEST_SUITE_END()

MeshSpatialDimensionTest::CPPUNIT_TEST_SUITE_END ( )

◆ 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.

40  {
41  // 1.) Test that build_line() produces a Mesh with spatial_dimension==1
43  MeshTools::Generation::build_line (mesh, /*n_elem=*/2, /*xmin=*/0., /*xmax=*/1., EDGE2);
44  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
45  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.spatial_dimension());
46 
47  // 2.) Move the nodes in the y-direction, test that spatial_dimension==2
48  // The spatial dimension is updated during prepare_for_use().
49  for (auto & node : mesh.node_ptr_range())
50  (*node)(1) = (*node)(0) * (*node)(0);
51 
53  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
54  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
55 
56 
57  // 3.) Move nodes back to zero, check that spatial_dimension is *not* decreased
58  for (auto & node : mesh.node_ptr_range())
59  (*node)(1) = 0.;
60 
62  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
63  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
64 
65 
66  // 4.) Move z-coordinate of nodes, check that spatial_dimension is now 3.
67 #if LIBMESH_DIM == 3
68  for (auto & node : mesh.node_ptr_range())
69  (*node)(2) = (*node)(0) * (*node)(0);
70 
72  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
73  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
74 #endif
75  }

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

◆ test2D()

void MeshSpatialDimensionTest::test2D ( )
inline

Definition at line 79 of file spatial_dimension_test.C.

80  {
81  // 1.) Test that build_cube() produces a Mesh with spatial_dimension==2
84  /*nx=*/2, /*ny=*/2,
85  /*xmin=*/0., /*xmax=*/1.,
86  /*ymin=*/0., /*ymax=*/1.,
87  QUAD4);
88  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
89 
90  // 2.) Move the nodes in the z-direction, test that spatial_dimension==3
91  // The spatial dimension is updated during prepare_for_use().
92  for (auto & node : mesh.node_ptr_range())
93  (*node)(2) =
94  (*node)(0) * (*node)(0) +
95  (*node)(1) * (*node)(1);
96 
98  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
99  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
100 
101 
102  // 3.) Move nodes back to zero, check that spatial_dimension is *not* decreased
103  for (auto & node : mesh.node_ptr_range())
104  (*node)(2) = 0.;
105 
107  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
108  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
109 
110  // 4.) The user is allowed to set the spatial dimension, make sure
111  // that's honored if it's consistent.
114  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
115  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
116 
117  // 5.) If the user sets a spatial dimension that's not big enough, make sure that
118  // prepare_for_use() increases it.
121  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
122  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
123  }

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


The documentation for this class was generated from the following file:
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::mesh_dimension
unsigned int mesh_dimension() const
Definition: mesh_base.C:135
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::MeshTools::Generation::build_square
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.
Definition: mesh_generation.C:1501
libMesh::MeshBase::node_ptr_range
virtual SimpleRange< node_iterator > node_ptr_range()=0
libMesh::MeshTools::Generation::build_line
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.
Definition: mesh_generation.C:1480
libMesh::QUAD4
Definition: enum_elem_type.h:41
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::MeshBase::spatial_dimension
unsigned int spatial_dimension() const
Definition: mesh_base.C:159
libMesh::MeshBase::prepare_for_use
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:318
libMesh::MeshBase::set_spatial_dimension
void set_spatial_dimension(unsigned char d)
Sets the "spatial dimension" of the Mesh.
Definition: mesh_base.C:166
libMesh::EDGE2
Definition: enum_elem_type.h:35