1#include <libmesh/equation_systems.h>
2#include <libmesh/mesh.h>
3#include <libmesh/mesh_generation.h>
4#include <libmesh/elem.h>
5#include <libmesh/dof_map.h>
6#include <libmesh/partitioner.h>
7#include <libmesh/replicated_mesh.h>
19#ifdef LIBMESH_ENABLE_CONSTRAINTS
38 constraint_row[1] = 1.0;
44 constraint_row[0] = 1.0;
74 constraint_row[dependency_dof] = 1.;
83 std::unique_ptr<Partitioner>
clone()
const override
85 return std::make_unique<GhostDofConstraintPartitioner>(*
this);
96 for (
auto & elem :
mesh.active_element_ptr_range())
97 elem->processor_id() = 0;
119#if defined(LIBMESH_ENABLE_EXCEPTIONS)
123#if defined(LIBMESH_ENABLE_CONSTRAINTS) && defined(LIBMESH_ENABLE_EXCEPTIONS) && LIBMESH_DIM > 1
127#if defined(LIBMESH_ENABLE_CONSTRAINTS)
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;
174 CPPUNIT_ASSERT(dof_map.
first_dof(pid) <=
id);
175 CPPUNIT_ASSERT(
id < dof_map.
end_dof(pid));
186#if defined(LIBMESH_ENABLE_EXCEPTIONS)
211 bool threw_desired_exception =
false;
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;
221 CPPUNIT_ASSERT_MESSAGE(
"Unexpected exception type thrown",
false);
228 CPPUNIT_ASSERT(threw_desired_exception);
232#if defined(LIBMESH_ENABLE_CONSTRAINTS) && defined(LIBMESH_ENABLE_EXCEPTIONS)
255#if defined(LIBMESH_ENABLE_CONSTRAINTS)
264 mesh.
partitioner() = std::make_unique<GhostDofConstraintPartitioner>();
305 auto verify_send_list = [&local_elem](
System & sys,
const bool dependency_is_ghosted)
313 CPPUNIT_ASSERT(!dof_map.
local_index(ghost_constrained_dof));
314 CPPUNIT_ASSERT(!dof_map.
local_index(dependency_dof));
318 std::vector<dof_id_type> local_dofs;
320 CPPUNIT_ASSERT(std::find(local_dofs.begin(), local_dofs.end(), ghost_constrained_dof) !=
326 CPPUNIT_ASSERT(std::binary_search(send_list.begin(), send_list.end(),
327 ghost_constrained_dof));
330 CPPUNIT_ASSERT_EQUAL(dependency_is_ghosted,
331 std::binary_search(send_list.begin(), send_list.end(),
335 verify_send_list(default_sys,
false);
336 verify_send_list(ghost_sys,
true);
349 auto & dof_map = sys.get_dof_map();
353 std::vector<dof_id_type> array_dofs, work_dofs, dofs;
354 dof_map.array_dof_indices(elem, array_dofs, last_var);
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);
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);
372 for (
int i = 1; i < 3; ++i)
CPPUNIT_TEST(testDofOwnerOnQuad9)
void testConstraintLoopDetection()
void testGhostConstraintSendList()
CPPUNIT_TEST(testBadElemFECombo)
CPPUNIT_TEST(testConstraintLoopDetection)
CPPUNIT_TEST(testGhostConstraintSendList)
CPPUNIT_TEST(testDofOwnerOnEdge3)
LIBMESH_CPPUNIT_TEST_SUITE(DofMapTest)
CPPUNIT_TEST(testDofOwnerOnHex27)
void testBadElemFECombo()
void testDofOwnerOnTri6()
void testArrayDofIndicesWithType(const FEType &fe_type)
CPPUNIT_TEST(testDofOwnerOnTri6)
void testDofOwner(const ElemType elem_type)
CPPUNIT_TEST(testArrayDofIndices)
void testArrayDofIndices()
void testDofOwnerOnEdge3()
void testDofOwnerOnHex27()
void testDofOwnerOnQuad9()
virtual bool partitions_from_scratch() const override
void _do_partition(MeshBase &mesh, const unsigned int n) override
This is the actual partitioning method which must be overridden in derived classes.
std::unique_ptr< Partitioner > clone() const override
GhostDofConstraint(System &sys)
void constrain() override
MyConstraint(System &sys)
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
dof_id_type first_dof(const processor_id_type proc) const
dof_id_type end_dof(const processor_id_type proc) const
This class handles the numbering of degrees of freedom on a mesh.
processor_id_type dof_owner(const dof_id_type dof) const
const std::vector< dof_id_type > & get_send_list() const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
bool local_index(dof_id_type dof_index) const
void ghost_constraints_needed()
Sets _need_ghost_constraints to true regardless of the requirements by static condensation.
dof_id_type n_dofs(const unsigned int vn) const
void add_constraint_row(const dof_id_type dof_number, const DofConstraintRow &constraint_row, const Number constraint_rhs, const bool forbid_constraint_overwrite)
Adds a copy of the user-defined row to the constraint matrix, using an inhomogeneous right-hand-side ...
void set_error_on_constraint_loop(bool error_on_constraint_loop)
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
processor_id_type processor_id() const
This is the base class from which all geometric element types are derived.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
This is the EquationSystems class.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
This is the MeshBase class.
virtual const Node & node_ref(const dof_id_type i) const
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each partitioning.
dof_id_type n_local_elem() const
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
virtual const Elem & elem_ref(const dof_id_type i) const
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
The Partitioner class provides a uniform interface for partitioning algorithms.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Abstract base class to be used for system constraints.
Manages consistently variables, degrees of freedom, and coefficient vectors.
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.
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.
void attach_constraint_object(Constraint &constrain)
Register a user object for imposing constraints.
const DofMap & get_dof_map() const
unsigned int number() const
const MeshBase & get_mesh() const
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(DofMapTest)
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
std::map< dof_id_type, Real, std::less< dof_id_type >, Threads::scalable_allocator< std::pair< const dof_id_type, Real > > > DofConstraintRow
A row of the Dof constraint matrix.
uint8_t processor_id_type