libMesh
Loading...
Searching...
No Matches
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 (testGhostConstraintSendList)
 
 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 testGhostConstraintSendList ()
 
void testArrayDofIndicesWithType (const FEType &fe_type)
 
void testArrayDofIndices ()
 

Detailed Description

Definition at line 106 of file dof_map_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/8]

DofMapTest::CPPUNIT_TEST ( testArrayDofIndices  )

◆ CPPUNIT_TEST() [2/8]

DofMapTest::CPPUNIT_TEST ( testBadElemFECombo  )

◆ CPPUNIT_TEST() [3/8]

DofMapTest::CPPUNIT_TEST ( testConstraintLoopDetection  )

◆ CPPUNIT_TEST() [4/8]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnEdge3  )

◆ CPPUNIT_TEST() [5/8]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnHex27  )

◆ CPPUNIT_TEST() [6/8]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnQuad9  )

◆ CPPUNIT_TEST() [7/8]

DofMapTest::CPPUNIT_TEST ( testDofOwnerOnTri6  )

◆ CPPUNIT_TEST() [8/8]

DofMapTest::CPPUNIT_TEST ( testGhostConstraintSendList  )

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

139 {}

◆ tearDown()

void DofMapTest::tearDown ( )
inline

Definition at line 141 of file dof_map_test.C.

142 {}

◆ testArrayDofIndices()

void DofMapTest::testArrayDofIndices ( )
inline

Definition at line 369 of file dof_map_test.C.

370 {
371 LOG_UNIT_TEST;
372 for (int i = 1; i < 3; ++i)
373 {
378 }
379 }
void testArrayDofIndicesWithType(const FEType &fe_type)

References libMesh::HIERARCHIC, libMesh::L2_LAGRANGE, libMesh::LAGRANGE, libMesh::MONOMIAL, and testArrayDofIndicesWithType().

◆ testArrayDofIndicesWithType()

void DofMapTest::testArrayDofIndicesWithType ( const FEType &  fe_type)
inline

Definition at line 341 of file dof_map_test.C.

342 {
343 Mesh mesh(*TestCommWorld);
345 auto & sys = es.add_system<System>("SimpleSystem");
346 const auto last_var = sys.add_variable_array({"u0", "u1"}, fe_type);
347 MeshTools::Generation::build_square (mesh,1,1,-1., 1.,-1., 1., QUAD9);
348 es.init();
349 auto & dof_map = sys.get_dof_map();
350 const auto * const elem = mesh.query_elem_ptr(0);
351 if (elem)
352 {
353 std::vector<dof_id_type> array_dofs, work_dofs, dofs;
354 dof_map.array_dof_indices(elem, array_dofs, last_var);
355 // Make sure there are no duplicates
356 std::sort(array_dofs.begin(), array_dofs.end());
357 auto it = std::unique(array_dofs.begin(), array_dofs.end());
358 array_dofs.erase(it, array_dofs.end());
359 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(dof_map.n_dofs()), array_dofs.size());
360 dof_map.dof_indices(elem, work_dofs, last_var);
361 dofs = work_dofs;
362 dof_map.dof_indices(elem, work_dofs, last_var - 1);
363 dofs.insert(dofs.end(), work_dofs.begin(), work_dofs.end());
364 std::sort(dofs.begin(), dofs.end());
365 CPPUNIT_ASSERT(array_dofs == dofs);
366 }
367 }
This is the EquationSystems class.
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:51
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
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:1386
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.

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.

Referenced by testArrayDofIndices().

◆ testBadElemFECombo()

void DofMapTest::testBadElemFECombo ( )
inline

Definition at line 187 of file dof_map_test.C.

188 {
189 LOG_UNIT_TEST;
190
191 Mesh mesh(*TestCommWorld);
192
194 System & sys = es.add_system<System> ("SimpleSystem");
195 sys.add_variable("u", SECOND);
196
197 MeshTools::Generation::build_square (mesh,4,4,-1., 1.,-1., 1., QUAD4);
198
199 // We need at least one element per processor to make sure
200 // everyone throws and we don't get out of sync before going on to
201 // future tests.
202 dof_id_type min_local_elem = mesh.n_local_elem();
203 mesh.comm().min(min_local_elem);
204
205 if (!min_local_elem)
206 return;
207
208 // We can't just CPPUNIT_ASSERT_THROW, because we want to make
209 // sure we were thrown from the right place with the right error
210 // message!
211 bool threw_desired_exception = false;
212 try {
213 es.init();
214 }
215 catch (libMesh::LogicError & e) {
216 std::regex msg_regex("only supports FEInterface::max_order");
217 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
218 threw_desired_exception = true;
219 }
220 catch (...) {
221 CPPUNIT_ASSERT_MESSAGE("Unexpected exception type thrown", false);
222 }
223
224 // If we have more than 4*4 processors, or a poor partitioner, we
225 // might not get an exception on every processor
226 mesh.comm().max(threw_desired_exception);
227
228 CPPUNIT_ASSERT(threw_desired_exception);
229 }
void max(const T &r, T &o, Request &req) const
void min(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()...
dof_id_type n_local_elem() const
Definition mesh_base.h:694
const Parallel::Communicator & comm() const
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:1344
uint8_t dof_id_type
Definition id_types.h:67

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

◆ testConstraintLoopDetection()

void DofMapTest::testConstraintLoopDetection ( )
inline

Definition at line 233 of file dof_map_test.C.

234 {
235 LOG_UNIT_TEST;
236 Mesh mesh(*TestCommWorld);
237
239 System & sys = es.add_system<System> ("SimpleSystem");
240 sys.add_variable("u", FIRST);
241
242 MyConstraint my_constraint(sys);
243 sys.attach_constraint_object(my_constraint);
244
245 MeshTools::Generation::build_square (mesh,4,4,-1., 1.,-1., 1., QUAD4);
246
247 // Tell the dof_map to check for constraint loops
248 DofMap & dof_map = sys.get_dof_map();
249 dof_map.set_error_on_constraint_loop(true);
250
251 CPPUNIT_ASSERT_THROW_MESSAGE("Constraint loop not detected", es.init(), libMesh::LogicError);
252 }
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
void set_error_on_constraint_loop(bool error_on_constraint_loop)
Definition dof_map.C:235
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
Definition system.C:2007
const DofMap & get_dof_map() const
Definition system.h:2417

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.

◆ testDofOwner()

void DofMapTest::testDofOwner ( const ElemType  elem_type)
inline

Definition at line 144 of file dof_map_test.C.

145 {
146 Mesh mesh(*TestCommWorld);
147
149 System &sys = es.add_system<System> ("SimpleSystem");
150 sys.add_variable("u", THIRD, HIERARCHIC);
151
152 const unsigned int n_elem_per_side = 3;
153 const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
154 const unsigned int ymax = test_elem->dim() > 1;
155 const unsigned int zmax = test_elem->dim() > 2;
156 const unsigned int ny = ymax * n_elem_per_side;
157 const unsigned int nz = zmax * n_elem_per_side;
158
160 n_elem_per_side,
161 ny,
162 nz,
163 0., 1.,
164 0., ymax,
165 0., zmax,
166 elem_type);
167
168 es.init();
169
170 DofMap & dof_map = sys.get_dof_map();
171 for (dof_id_type id = 0; id != dof_map.n_dofs(); ++id)
172 {
173 const processor_id_type pid = dof_map.dof_owner(id);
174 CPPUNIT_ASSERT(dof_map.first_dof(pid) <= id);
175 CPPUNIT_ASSERT(id < dof_map.end_dof(pid));
176 }
177 }
dof_id_type first_dof(const processor_id_type proc) const
dof_id_type end_dof(const processor_id_type proc) const
processor_id_type dof_owner(const dof_id_type dof) const
Definition dof_map.h:822
dof_id_type n_dofs(const unsigned int vn) const
Definition dof_map.h:783
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition elem.C:382
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 processor_id_type
Definition id_types.h:104

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.

Referenced by testDofOwnerOnEdge3(), testDofOwnerOnHex27(), testDofOwnerOnQuad9(), and testDofOwnerOnTri6().

◆ testDofOwnerOnEdge3()

void DofMapTest::testDofOwnerOnEdge3 ( )
inline

Definition at line 181 of file dof_map_test.C.

181{ LOG_UNIT_TEST; testDofOwner(EDGE3); }
void testDofOwner(const ElemType elem_type)

References libMesh::EDGE3, and testDofOwner().

◆ testDofOwnerOnHex27()

void DofMapTest::testDofOwnerOnHex27 ( )
inline

Definition at line 184 of file dof_map_test.C.

184{ LOG_UNIT_TEST; testDofOwner(HEX27); }

References libMesh::HEX27, and testDofOwner().

◆ testDofOwnerOnQuad9()

void DofMapTest::testDofOwnerOnQuad9 ( )
inline

Definition at line 182 of file dof_map_test.C.

182{ LOG_UNIT_TEST; testDofOwner(QUAD9); }

References libMesh::QUAD9, and testDofOwner().

◆ testDofOwnerOnTri6()

void DofMapTest::testDofOwnerOnTri6 ( )
inline

Definition at line 183 of file dof_map_test.C.

183{ LOG_UNIT_TEST; testDofOwner(TRI6); }

References testDofOwner(), and libMesh::TRI6.

◆ testGhostConstraintSendList()

void DofMapTest::testGhostConstraintSendList ( )
inline

Definition at line 256 of file dof_map_test.C.

257 {
258 LOG_UNIT_TEST;
259
260 if (TestCommWorld->size() == 1)
261 return;
262
263 ReplicatedMesh mesh(*TestCommWorld);
264 mesh.partitioner() = std::make_unique<GhostDofConstraintPartitioner>();
265
266 // Build this four-element line:
267 //
268 // node: 0 ----- 1 ----- 2 ----- 3 ----- 4
269 // elem: 0 1 2 3
270 // owner: 0 0 0 remote
271 //
272 // Node 3 remains owned by processor 0, so its DOF is ghosted on the
273 // processor owning element 3. Node 0 is too distant to be ghosted by
274 // the ordinary element-neighbor send-list construction.
276 const processor_id_type ghost_dof_processor = mesh.elem_ref(3).processor_id();
277 mesh.node_ref(3).processor_id() = 0;
278
280 // The default route should not ghost dependencies of constrained ghost DOFs.
281 System & default_sys = es.add_system<System>("DefaultSystem");
282 default_sys.add_variable("u", FIRST);
283 // The enabled route should add those dependencies to the send list.
284 System & ghost_sys = es.add_system<System>("GhostSystem");
285 ghost_sys.add_variable("u", FIRST);
286
287 GhostDofConstraint default_constraint(default_sys);
288 default_sys.attach_constraint_object(default_constraint);
289 GhostDofConstraint ghost_constraint(ghost_sys);
290 ghost_sys.attach_constraint_object(ghost_constraint);
291
292 // Enable the new behavior only for GhostSystem so DefaultSystem provides
293 // a control route using the original send-list behavior.
294 DofMap & ghost_dof_map = ghost_sys.get_dof_map();
295 ghost_dof_map.ghost_constraints_needed();
296 es.init();
297
298 // Only the processor owning element 3 has the constrained DOF as a ghost
299 // supported by one of its local elements.
300 if (mesh.processor_id() == ghost_dof_processor)
301 {
302 const Elem & local_elem = mesh.elem_ref(3);
303 CPPUNIT_ASSERT_EQUAL(mesh.processor_id(), local_elem.processor_id());
304
305 auto verify_send_list = [&local_elem](System & sys, const bool dependency_is_ghosted)
306 {
307 DofMap & dof_map = sys.get_dof_map();
308 const dof_id_type ghost_constrained_dof =
309 sys.get_mesh().node_ref(3).dof_number(sys.number(), 0, 0);
310 const dof_id_type dependency_dof =
311 sys.get_mesh().node_ref(0).dof_number(sys.number(), 0, 0);
312
313 CPPUNIT_ASSERT(!dof_map.local_index(ghost_constrained_dof));
314 CPPUNIT_ASSERT(!dof_map.local_index(dependency_dof));
315
316 // Verify that the nonlocal constrained DOF is supported by this
317 // processor's local element, making it a constrained ghost DOF.
318 std::vector<dof_id_type> local_dofs;
319 dof_map.dof_indices(&local_elem, local_dofs);
320 CPPUNIT_ASSERT(std::find(local_dofs.begin(), local_dofs.end(), ghost_constrained_dof) !=
321 local_dofs.end());
322
323 const auto & send_list = dof_map.get_send_list();
324 // The constrained DOF is always ghosted because the local element
325 // uses it; its distant dependency is ghosted only when requested.
326 CPPUNIT_ASSERT(std::binary_search(send_list.begin(), send_list.end(),
327 ghost_constrained_dof));
328 // This assertion is false for the control route and true for the
329 // route with ghost constraint dependency expansion enabled.
330 CPPUNIT_ASSERT_EQUAL(dependency_is_ghosted,
331 std::binary_search(send_list.begin(), send_list.end(),
332 dependency_dof));
333 };
334
335 verify_send_list(default_sys, false);
336 verify_send_list(ghost_sys, true);
337 }
338 }
const std::vector< dof_id_type > & get_send_list() const
Definition dof_map.h:540
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition dof_map.C:2203
bool local_index(dof_id_type dof_index) const
Definition dof_map.h:974
void ghost_constraints_needed()
Sets _need_ghost_constraints to true regardless of the requirements by static condensation.
Definition dof_map.h:2573
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
processor_id_type processor_id() const
Definition dof_object.h:895
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual const Node & node_ref(const dof_id_type i) const
Definition mesh_base.h:742
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each partitioning.
Definition mesh_base.h:165
virtual const Elem & elem_ref(const dof_id_type i) const
Definition mesh_base.h:785
processor_id_type processor_id() const
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
unsigned int number() const
Definition system.h:2393
const MeshBase & get_mesh() const
Definition system.h:2401
Communicator * TestCommWorld
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.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::System::attach_constraint_object(), libMesh::MeshTools::Generation::build_line(), libMesh::DofMap::dof_indices(), libMesh::DofObject::dof_number(), libMesh::EDGE2, libMesh::MeshBase::elem_ref(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::DofMap::get_send_list(), libMesh::DofMap::ghost_constraints_needed(), libMesh::EquationSystems::init(), libMesh::DofMap::local_index(), mesh, libMesh::MeshBase::node_ref(), libMesh::System::number(), libMesh::MeshBase::partitioner(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), and TestCommWorld.


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