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 26 of file spatial_dimension_test.C.

Member Function Documentation

MeshSpatialDimensionTest::CPPUNIT_TEST ( test1D  )
MeshSpatialDimensionTest::CPPUNIT_TEST ( test2D  )
MeshSpatialDimensionTest::CPPUNIT_TEST_SUITE ( MeshSpatialDimensionTest  )

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

MeshSpatialDimensionTest::CPPUNIT_TEST_SUITE_END ( )
void MeshSpatialDimensionTest::setUp ( )

Definition at line 41 of file spatial_dimension_test.C.

42  {
43  }
void MeshSpatialDimensionTest::tearDown ( )

Definition at line 45 of file spatial_dimension_test.C.

46  {
47  }
void MeshSpatialDimensionTest::test1D ( )

Definition at line 49 of file spatial_dimension_test.C.

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

50  {
51  // 1.) Test that build_line() produces a Mesh with spatial_dimension==1
53  MeshTools::Generation::build_line (mesh, /*n_elem=*/2, /*xmin=*/0., /*xmax=*/1., EDGE2);
54  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
55  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.spatial_dimension());
56 
57  // 2.) Move the nodes in the y-direction, test that spatial_dimension==2
58  // The spatial dimension is updated during prepare_for_use().
59  for (auto & node : mesh.node_ptr_range())
60  (*node)(1) = (*node)(0) * (*node)(0);
61 
63  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
64  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
65 
66 
67  // 3.) Move nodes back to zero, check that spatial_dimension is *not* decreased
68  for (auto & node : mesh.node_ptr_range())
69  (*node)(1) = 0.;
70 
72  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
73  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
74 
75 
76  // 4.) Move z-coordinate of nodes, check that spatial_dimension is now 3.
77 #if LIBMESH_DIM == 3
78  for (auto & node : mesh.node_ptr_range())
79  (*node)(2) = (*node)(0) * (*node)(0);
80 
82  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), mesh.mesh_dimension());
83  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
84 #endif
85  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
MeshBase & mesh
virtual SimpleRange< node_iterator > node_ptr_range()=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
unsigned int spatial_dimension() const
Definition: mesh_base.C:157
unsigned int mesh_dimension() const
Definition: mesh_base.C:148
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.
void MeshSpatialDimensionTest::test2D ( )

Definition at line 89 of file spatial_dimension_test.C.

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

90  {
91  // 1.) Test that build_cube() produces a Mesh with spatial_dimension==2
94  /*nx=*/2, /*ny=*/2,
95  /*xmin=*/0., /*xmax=*/1.,
96  /*ymin=*/0., /*ymax=*/1.,
97  QUAD4);
98  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
99 
100  // 2.) Move the nodes in the z-direction, test that spatial_dimension==3
101  // The spatial dimension is updated during prepare_for_use().
102  for (auto & node : mesh.node_ptr_range())
103  (*node)(2) =
104  (*node)(0) * (*node)(0) +
105  (*node)(1) * (*node)(1);
106 
108  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
109  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
110 
111 
112  // 3.) Move nodes back to zero, check that spatial_dimension is *not* decreased
113  for (auto & node : mesh.node_ptr_range())
114  (*node)(2) = 0.;
115 
117  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
118  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), mesh.spatial_dimension());
119 
120  // 4.) The user is allowed to set the spatial dimension, make sure
121  // that's honored if it's consistent.
124  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
125  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
126 
127  // 5.) If the user sets a spatial dimension that's not big enough, make sure that
128  // prepare_for_use() increases it.
131  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.mesh_dimension());
132  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), mesh.spatial_dimension());
133  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
void set_spatial_dimension(unsigned char d)
Sets the "spatial dimension" of the Mesh.
Definition: mesh_base.C:164
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.
virtual SimpleRange< node_iterator > node_ptr_range()=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
unsigned int spatial_dimension() const
Definition: mesh_base.C:157
unsigned int mesh_dimension() const
Definition: mesh_base.C:148

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