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_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testDofOwner (const ElemType elem_type)
 
void testDofOwnerOnEdge3 ()
 
void testDofOwnerOnQuad9 ()
 
void testDofOwnerOnTri6 ()
 
void testDofOwnerOnHex27 ()
 
void testBadElemFECombo ()
 
void testConstraintLoopDetection ()
 

Detailed Description

Definition at line 50 of file dof_map_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/6]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnEdge3  )

◆ CPPUNIT_TEST() [2/6]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnQuad9  )

◆ CPPUNIT_TEST() [3/6]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnTri6  )

◆ CPPUNIT_TEST() [4/6]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnHex27  )

◆ CPPUNIT_TEST() [5/6]

DofMapTest::CPPUNIT_TEST ( testBadElemFECombo  )

◆ CPPUNIT_TEST() [6/6]

DofMapTest::CPPUNIT_TEST ( testConstraintLoopDetection  )

◆ 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 76 of file dof_map_test.C.

77  {}

◆ tearDown()

void DofMapTest::tearDown ( )
inline

Definition at line 79 of file dof_map_test.C.

80  {}

◆ testBadElemFECombo()

void DofMapTest::testBadElemFECombo ( )
inline

Definition at line 125 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.

126  {
127  LOG_UNIT_TEST;
128 
130 
131  EquationSystems es(mesh);
132  System & sys = es.add_system<System> ("SimpleSystem");
133  sys.add_variable("u", SECOND);
134 
135  MeshTools::Generation::build_square (mesh,4,4,-1., 1.,-1., 1., QUAD4);
136 
137  // We need at least one element per processor to make sure
138  // everyone throws and we don't get out of sync before going on to
139  // future tests.
140  dof_id_type min_local_elem = mesh.n_local_elem();
141  mesh.comm().min(min_local_elem);
142 
143  if (!min_local_elem)
144  return;
145 
146  // We can't just CPPUNIT_ASSERT_THROW, because we want to make
147  // sure we were thrown from the right place with the right error
148  // message!
149  bool threw_desired_exception = false;
150  try {
151  es.init();
152  }
153  catch (libMesh::LogicError & e) {
154  std::regex msg_regex("only supports FEInterface::max_order");
155  CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
156  threw_desired_exception = true;
157  }
158  catch (...) {
159  CPPUNIT_ASSERT_MESSAGE("Unexpected exception type thrown", false);
160  }
161 
162  // If we have more than 4*4 processors, or a poor partitioner, we
163  // might not get an exception on every processor
164  mesh.comm().max(threw_desired_exception);
165 
166  CPPUNIT_ASSERT(threw_desired_exception);
167  }
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:96
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:1357
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 171 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.

172  {
173  LOG_UNIT_TEST;
175 
176  EquationSystems es(mesh);
177  System & sys = es.add_system<System> ("SimpleSystem");
178  sys.add_variable("u", FIRST);
179 
180  MyConstraint my_constraint(sys);
181  sys.attach_constraint_object(my_constraint);
182 
183  MeshTools::Generation::build_square (mesh,4,4,-1., 1.,-1., 1., QUAD4);
184 
185  // Tell the dof_map to check for constraint loops
186  DofMap & dof_map = sys.get_dof_map();
187  dof_map.set_error_on_constraint_loop(true);
188 
189  CPPUNIT_ASSERT_THROW_MESSAGE("Constraint loop not detected", es.init(), libMesh::LogicError);
190  }
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:241
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition: system.C:2209
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:96
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:1357
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:2374

◆ testDofOwner()

void DofMapTest::testDofOwner ( const ElemType  elem_type)
inline

Definition at line 82 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.

83  {
85 
87  System &sys = es.add_system<System> ("SimpleSystem");
88  sys.add_variable("u", THIRD, HIERARCHIC);
89 
90  const unsigned int n_elem_per_side = 3;
91  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
92  const unsigned int ymax = test_elem->dim() > 1;
93  const unsigned int zmax = test_elem->dim() > 2;
94  const unsigned int ny = ymax * n_elem_per_side;
95  const unsigned int nz = zmax * n_elem_per_side;
96 
98  n_elem_per_side,
99  ny,
100  nz,
101  0., 1.,
102  0., ymax,
103  0., zmax,
104  elem_type);
105 
106  es.init();
107 
108  DofMap & dof_map = sys.get_dof_map();
109  for (dof_id_type id = 0; id != dof_map.n_dofs(); ++id)
110  {
111  const processor_id_type pid = dof_map.dof_owner(id);
112  CPPUNIT_ASSERT(dof_map.first_dof(pid) <= id);
113  CPPUNIT_ASSERT(id < dof_map.end_dof(pid));
114  }
115  }
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:707
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
dof_id_type n_dofs(const unsigned int vn) const
Definition: dof_map.h:668
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:96
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:1357
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:2374
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 119 of file dof_map_test.C.

References libMesh::EDGE3.

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

◆ testDofOwnerOnHex27()

void DofMapTest::testDofOwnerOnHex27 ( )
inline

Definition at line 122 of file dof_map_test.C.

References libMesh::HEX27.

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

◆ testDofOwnerOnQuad9()

void DofMapTest::testDofOwnerOnQuad9 ( )
inline

Definition at line 120 of file dof_map_test.C.

References libMesh::QUAD9.

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

◆ testDofOwnerOnTri6()

void DofMapTest::testDofOwnerOnTri6 ( )
inline

Definition at line 121 of file dof_map_test.C.

References libMesh::TRI6.

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

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