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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (DofMapTest)
 
 CPPUNIT_TEST (testDofOwnerOnEdge3)
 
 CPPUNIT_TEST (testDofOwnerOnQuad9)
 
 CPPUNIT_TEST (testDofOwnerOnTri6)
 
 CPPUNIT_TEST (testDofOwnerOnHex27)
 
 CPPUNIT_TEST (testBadElemFECombo)
 
 CPPUNIT_TEST (testConstraintLoopDetection)
 
 CPPUNIT_TEST (testArrayDofIndices)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testDofOwner (const ElemType elem_type)
 
void testDofOwnerOnEdge3 ()
 
void testDofOwnerOnQuad9 ()
 
void testDofOwnerOnTri6 ()
 
void testDofOwnerOnHex27 ()
 
void testBadElemFECombo ()
 
void testConstraintLoopDetection ()
 
void testArrayDofIndicesWithType (const FEType &fe_type)
 
void testArrayDofIndices ()
 

Detailed Description

Definition at line 50 of file dof_map_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/7]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnEdge3  )

◆ CPPUNIT_TEST() [2/7]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnQuad9  )

◆ CPPUNIT_TEST() [3/7]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnTri6  )

◆ CPPUNIT_TEST() [4/7]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnHex27  )

◆ CPPUNIT_TEST() [5/7]

DofMapTest::CPPUNIT_TEST ( testBadElemFECombo  )

◆ CPPUNIT_TEST() [6/7]

DofMapTest::CPPUNIT_TEST ( testConstraintLoopDetection  )

◆ CPPUNIT_TEST() [7/7]

DofMapTest::CPPUNIT_TEST ( testArrayDofIndices  )

◆ CPPUNIT_TEST_SUITE_END()

DofMapTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

DofMapTest::LIBMESH_CPPUNIT_TEST_SUITE ( DofMapTest  )

◆ setUp()

void DofMapTest::setUp ( )
inline

Definition at line 78 of file dof_map_test.C.

79  {}

◆ tearDown()

void DofMapTest::tearDown ( )
inline

Definition at line 81 of file dof_map_test.C.

82  {}

◆ testArrayDofIndices()

void DofMapTest::testArrayDofIndices ( )
inline

Definition at line 223 of file dof_map_test.C.

References libMesh::HIERARCHIC, libMesh::L2_LAGRANGE, libMesh::LAGRANGE, and libMesh::MONOMIAL.

224  {
225  LOG_UNIT_TEST;
226  for (int i = 1; i < 3; ++i)
227  {
232  }
233  }
void testArrayDofIndicesWithType(const FEType &fe_type)
Definition: dof_map_test.C:195

◆ testArrayDofIndicesWithType()

void DofMapTest::testArrayDofIndicesWithType ( const FEType fe_type)
inline

Definition at line 195 of file dof_map_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable_array(), libMesh::MeshTools::Generation::build_square(), libMesh::EquationSystems::init(), mesh, libMesh::QUAD9, libMesh::MeshBase::query_elem_ptr(), and TestCommWorld.

196  {
198  EquationSystems es(mesh);
199  auto & sys = es.add_system<System>("SimpleSystem");
200  const auto last_var = sys.add_variable_array({"u0", "u1"}, fe_type);
201  MeshTools::Generation::build_square (mesh,1,1,-1., 1.,-1., 1., QUAD9);
202  es.init();
203  auto & dof_map = sys.get_dof_map();
204  const auto * const elem = mesh.query_elem_ptr(0);
205  if (elem)
206  {
207  std::vector<dof_id_type> array_dofs, work_dofs, dofs;
208  dof_map.array_dof_indices(elem, array_dofs, last_var);
209  // Make sure there are no duplicates
210  std::sort(array_dofs.begin(), array_dofs.end());
211  auto it = std::unique(array_dofs.begin(), array_dofs.end());
212  array_dofs.erase(it, array_dofs.end());
213  CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(dof_map.n_dofs()), array_dofs.size());
214  dof_map.dof_indices(elem, work_dofs, last_var);
215  dofs = work_dofs;
216  dof_map.dof_indices(elem, work_dofs, last_var - 1);
217  dofs.insert(dofs.end(), work_dofs.begin(), work_dofs.end());
218  std::sort(dofs.begin(), dofs.end());
219  CPPUNIT_ASSERT(array_dofs == dofs);
220  }
221  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
unsigned int add_variable_array(const std::vector< std::string > &vars, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds variables vars to the list of variables for this system.
Definition: system.C:1382
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.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:97
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ testBadElemFECombo()

void DofMapTest::testBadElemFECombo ( )
inline

Definition at line 127 of file dof_map_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshTools::Generation::build_square(), libMesh::ParallelObject::comm(), libMesh::EquationSystems::init(), TIMPI::Communicator::max(), mesh, TIMPI::Communicator::min(), libMesh::MeshBase::n_local_elem(), libMesh::QUAD4, libMesh::SECOND, and TestCommWorld.

128  {
129  LOG_UNIT_TEST;
130 
132 
133  EquationSystems es(mesh);
134  System & sys = es.add_system<System> ("SimpleSystem");
135  sys.add_variable("u", SECOND);
136 
137  MeshTools::Generation::build_square (mesh,4,4,-1., 1.,-1., 1., QUAD4);
138 
139  // We need at least one element per processor to make sure
140  // everyone throws and we don't get out of sync before going on to
141  // future tests.
142  dof_id_type min_local_elem = mesh.n_local_elem();
143  mesh.comm().min(min_local_elem);
144 
145  if (!min_local_elem)
146  return;
147 
148  // We can't just CPPUNIT_ASSERT_THROW, because we want to make
149  // sure we were thrown from the right place with the right error
150  // message!
151  bool threw_desired_exception = false;
152  try {
153  es.init();
154  }
155  catch (libMesh::LogicError & e) {
156  std::regex msg_regex("only supports FEInterface::max_order");
157  CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
158  threw_desired_exception = true;
159  }
160  catch (...) {
161  CPPUNIT_ASSERT_MESSAGE("Unexpected exception type thrown", false);
162  }
163 
164  // If we have more than 4*4 processors, or a poor partitioner, we
165  // might not get an exception on every processor
166  mesh.comm().max(threw_desired_exception);
167 
168  CPPUNIT_ASSERT(threw_desired_exception);
169  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
const Parallel::Communicator & comm() const
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.
dof_id_type n_local_elem() const
Definition: mesh_base.h:548
void min(const T &r, T &o, Request &req) const
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:97
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1342
void max(const T &r, T &o, Request &req) const
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
uint8_t dof_id_type
Definition: id_types.h:67

◆ testConstraintLoopDetection()

void DofMapTest::testConstraintLoopDetection ( )
inline

Definition at line 173 of file dof_map_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::System::attach_constraint_object(), libMesh::MeshTools::Generation::build_square(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), mesh, libMesh::QUAD4, libMesh::DofMap::set_error_on_constraint_loop(), and TestCommWorld.

174  {
175  LOG_UNIT_TEST;
177 
178  EquationSystems es(mesh);
179  System & sys = es.add_system<System> ("SimpleSystem");
180  sys.add_variable("u", FIRST);
181 
182  MyConstraint my_constraint(sys);
183  sys.attach_constraint_object(my_constraint);
184 
185  MeshTools::Generation::build_square (mesh,4,4,-1., 1.,-1., 1., QUAD4);
186 
187  // Tell the dof_map to check for constraint loops
188  DofMap & dof_map = sys.get_dof_map();
189  dof_map.set_error_on_constraint_loop(true);
190 
191  CPPUNIT_ASSERT_THROW_MESSAGE("Constraint loop not detected", es.init(), libMesh::LogicError);
192  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
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.
void set_error_on_constraint_loop(bool error_on_constraint_loop)
Definition: dof_map.C:234
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition: system.C:1987
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:97
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1342
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
const DofMap & get_dof_map() const
Definition: system.h:2375

◆ testDofOwner()

void DofMapTest::testDofOwner ( const ElemType  elem_type)
inline

Definition at line 84 of file dof_map_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::DofMap::dof_owner(), libMesh::DofMapBase::end_dof(), libMesh::DofMapBase::first_dof(), libMesh::System::get_dof_map(), libMesh::HIERARCHIC, libMesh::EquationSystems::init(), mesh, libMesh::DofMap::n_dofs(), TestCommWorld, and libMesh::THIRD.

85  {
87 
89  System &sys = es.add_system<System> ("SimpleSystem");
90  sys.add_variable("u", THIRD, HIERARCHIC);
91 
92  const unsigned int n_elem_per_side = 3;
93  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
94  const unsigned int ymax = test_elem->dim() > 1;
95  const unsigned int zmax = test_elem->dim() > 2;
96  const unsigned int ny = ymax * n_elem_per_side;
97  const unsigned int nz = zmax * n_elem_per_side;
98 
100  n_elem_per_side,
101  ny,
102  nz,
103  0., 1.,
104  0., ymax,
105  0., zmax,
106  elem_type);
107 
108  es.init();
109 
110  DofMap & dof_map = sys.get_dof_map();
111  for (dof_id_type id = 0; id != dof_map.n_dofs(); ++id)
112  {
113  const processor_id_type pid = dof_map.dof_owner(id);
114  CPPUNIT_ASSERT(dof_map.first_dof(pid) <= id);
115  CPPUNIT_ASSERT(id < dof_map.end_dof(pid));
116  }
117  }
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map_base.h:191
This is the EquationSystems class.
processor_id_type dof_owner(const dof_id_type dof) const
Definition: dof_map.h:815
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
dof_id_type n_dofs(const unsigned int vn) const
Definition: dof_map.h:776
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
uint8_t processor_id_type
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:97
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1342
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map_base.h:185
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
const DofMap & get_dof_map() const
Definition: system.h:2375
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
uint8_t dof_id_type
Definition: id_types.h:67

◆ testDofOwnerOnEdge3()

void DofMapTest::testDofOwnerOnEdge3 ( )
inline

Definition at line 121 of file dof_map_test.C.

References libMesh::EDGE3.

121 { LOG_UNIT_TEST; testDofOwner(EDGE3); }
void testDofOwner(const ElemType elem_type)
Definition: dof_map_test.C:84

◆ testDofOwnerOnHex27()

void DofMapTest::testDofOwnerOnHex27 ( )
inline

Definition at line 124 of file dof_map_test.C.

References libMesh::HEX27.

124 { LOG_UNIT_TEST; testDofOwner(HEX27); }
void testDofOwner(const ElemType elem_type)
Definition: dof_map_test.C:84

◆ testDofOwnerOnQuad9()

void DofMapTest::testDofOwnerOnQuad9 ( )
inline

Definition at line 122 of file dof_map_test.C.

References libMesh::QUAD9.

122 { LOG_UNIT_TEST; testDofOwner(QUAD9); }
void testDofOwner(const ElemType elem_type)
Definition: dof_map_test.C:84

◆ testDofOwnerOnTri6()

void DofMapTest::testDofOwnerOnTri6 ( )
inline

Definition at line 123 of file dof_map_test.C.

References libMesh::TRI6.

123 { LOG_UNIT_TEST; testDofOwner(TRI6); }
void testDofOwner(const ElemType elem_type)
Definition: dof_map_test.C:84

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