Reference documentation for deal.II version 9.0.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members

#include <deal.II/lac/constraint_matrix.h>

Inheritance diagram for ConstraintMatrix:
[legend]

Classes

struct  ConstraintLine
 

Public Types

enum  MergeConflictBehavior { no_conflicts_allowed, left_object_wins, right_object_wins }
 
typedef types::global_dof_index size_type
 
typedef std::vector< ConstraintLine >::const_iterator const_iterator
 
typedef boost::iterator_range< const_iteratorLineRange
 

Public Member Functions

 ConstraintMatrix (const IndexSet &local_constraints=IndexSet())
 
 ConstraintMatrix (const ConstraintMatrix &constraint_matrix)
 
 ConstraintMatrix (ConstraintMatrix &&constraint_matrix)=default
 
ConstraintMatrixoperator= (const ConstraintMatrix &)=delete
 
ConstraintMatrixoperator= (ConstraintMatrix &&constraint_matrix)=default
 
void copy_from (const ConstraintMatrix &other)
 
void reinit (const IndexSet &local_constraints=IndexSet())
 
bool can_store_line (const size_type line_index) const
 
const IndexSetget_local_lines () const
 
void add_selected_constraints (const ConstraintMatrix &constraints_in, const IndexSet &filter)
 
const LineRange get_lines () const
 
bool is_consistent_in_parallel (const std::vector< IndexSet > &locally_owned_dofs, const IndexSet &locally_active_dofs, const MPI_Comm mpi_communicator, const bool verbose=false) const
 
Adding constraints
void add_line (const size_type line)
 
void add_lines (const std::vector< bool > &lines)
 
void add_lines (const std::set< size_type > &lines)
 
void add_lines (const IndexSet &lines)
 
void add_entry (const size_type line, const size_type column, const double value)
 
void add_entries (const size_type line, const std::vector< std::pair< size_type, double > > &col_val_pairs)
 
void set_inhomogeneity (const size_type line, const double value)
 
void close ()
 
void merge (const ConstraintMatrix &other_constraints, const MergeConflictBehavior merge_conflict_behavior=no_conflicts_allowed, const bool allow_different_local_lines=false)
 
void shift (const size_type offset)
 
void clear ()
 
Querying constraints
size_type n_constraints () const
 
bool is_constrained (const size_type index) const
 
bool is_identity_constrained (const size_type index) const
 
bool are_identity_constrained (const size_type index1, const size_type index2) const
 
size_type max_constraint_indirections () const
 
bool is_inhomogeneously_constrained (const size_type index) const
 
bool has_inhomogeneities () const
 
const std::vector< std::pair< size_type, double > > * get_constraint_entries (const size_type line) const
 
double get_inhomogeneity (const size_type line) const
 
void print (std::ostream &out) const
 
void write_dot (std::ostream &) const
 
std::size_t memory_consumption () const
 
void resolve_indices (std::vector< types::global_dof_index > &indices) const
 
Eliminating constraints from linear systems after their creation
void condense (SparsityPattern &sparsity) const
 
void condense (BlockSparsityPattern &sparsity) const
 
void condense (DynamicSparsityPattern &sparsity) const
 
void condense (BlockDynamicSparsityPattern &sparsity) const
 
template<typename number >
void condense (SparseMatrix< number > &matrix) const
 
template<typename number >
void condense (BlockSparseMatrix< number > &matrix) const
 
template<class VectorType >
void condense (VectorType &vec) const
 
template<class VectorType >
void condense (const VectorType &vec_ghosted, VectorType &output) const
 
template<typename number , class VectorType >
void condense (SparseMatrix< number > &matrix, VectorType &vector) const
 
template<typename number , class BlockVectorType >
void condense (BlockSparseMatrix< number > &matrix, BlockVectorType &vector) const
 
template<class VectorType >
void set_zero (VectorType &vec) const
 
Eliminating constraints from linear systems during their creation
template<class InVector , class OutVector >
void distribute_local_to_global (const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
 
template<typename VectorType , typename LocalType >
void distribute_local_to_global (const Vector< LocalType > &local_vector, const std::vector< size_type > &local_dof_indices, VectorType &global_vector, const FullMatrix< LocalType > &local_matrix) const
 
template<typename VectorType , typename LocalType >
void distribute_local_to_global (const Vector< LocalType > &local_vector, const std::vector< size_type > &local_dof_indices_row, const std::vector< size_type > &local_dof_indices_col, VectorType &global_vector, const FullMatrix< LocalType > &local_matrix, bool diagonal=false) const
 
template<class VectorType >
void distribute_local_to_global (const size_type index, const double value, VectorType &global_vector) const
 
template<typename ForwardIteratorVec , typename ForwardIteratorInd , class VectorType >
void distribute_local_to_global (ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end, ForwardIteratorInd local_indices_begin, VectorType &global_vector) const
 
template<typename MatrixType >
void distribute_local_to_global (const FullMatrix< typename MatrixType::value_type > &local_matrix, const std::vector< size_type > &local_dof_indices, MatrixType &global_matrix) const
 
template<typename MatrixType >
void distribute_local_to_global (const FullMatrix< typename MatrixType::value_type > &local_matrix, const std::vector< size_type > &row_indices, const std::vector< size_type > &col_indices, MatrixType &global_matrix) const
 
template<typename MatrixType >
void distribute_local_to_global (const FullMatrix< typename MatrixType::value_type > &local_matrix, const std::vector< size_type > &row_indices, const ConstraintMatrix &column_constraint_matrix, const std::vector< size_type > &column_indices, MatrixType &global_matrix) const
 
template<typename MatrixType , typename VectorType >
void distribute_local_to_global (const FullMatrix< typename MatrixType::value_type > &local_matrix, const Vector< typename VectorType::value_type > &local_vector, const std::vector< size_type > &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, bool use_inhomogeneities_for_rhs=false) const
 
template<typename SparsityPatternType >
void add_entries_local_to_global (const std::vector< size_type > &local_dof_indices, SparsityPatternType &sparsity_pattern, const bool keep_constrained_entries=true, const Table< 2, bool > &dof_mask=default_empty_table) const
 
template<typename SparsityPatternType >
void add_entries_local_to_global (const std::vector< size_type > &row_indices, const std::vector< size_type > &col_indices, SparsityPatternType &sparsity_pattern, const bool keep_constrained_entries=true, const Table< 2, bool > &dof_mask=default_empty_table) const
 
template<typename ForwardIteratorVec , typename ForwardIteratorInd , class VectorType >
void get_dof_values (const VectorType &global_vector, ForwardIteratorInd local_indices_begin, ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end) const
 
Dealing with constraints after solving a linear system
template<class VectorType >
void distribute (VectorType &vec) const
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
void subscribe (const char *identifier=nullptr) const
 
void unsubscribe (const char *identifier=nullptr) const
 
unsigned int n_subscriptions () const
 
void list_subscribers () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Static Public Member Functions

static ::ExceptionBaseExcMatrixIsClosed ()
 
static ::ExceptionBaseExcMatrixNotClosed ()
 
static ::ExceptionBaseExcLineInexistant (size_type arg1)
 
static ::ExceptionBaseExcEntryAlreadyExists (size_type arg1, size_type arg2, double arg3, double arg4)
 
static ::ExceptionBaseExcDoFConstrainedToConstrainedDoF (int arg1, int arg2)
 
static ::ExceptionBaseExcDoFIsConstrainedFromBothObjects (size_type arg1)
 
static ::ExceptionBaseExcDoFIsConstrainedToConstrainedDoF (size_type arg1)
 
static ::ExceptionBaseExcRowNotStoredHere (size_type arg1)
 
static ::ExceptionBaseExcColumnNotStoredHere (size_type arg1, size_type arg2)
 
static ::ExceptionBaseExcIncorrectConstraint (int arg1, int arg2)
 
- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Private Member Functions

size_type calculate_line_index (const size_type line) const
 
template<typename MatrixType , typename VectorType >
void distribute_local_to_global (const FullMatrix< typename MatrixType::value_type > &local_matrix, const Vector< typename VectorType::value_type > &local_vector, const std::vector< size_type > &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, bool use_inhomogeneities_for_rhs, std::integral_constant< bool, false >) const
 
template<typename MatrixType , typename VectorType >
void distribute_local_to_global (const FullMatrix< typename MatrixType::value_type > &local_matrix, const Vector< typename VectorType::value_type > &local_vector, const std::vector< size_type > &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, bool use_inhomogeneities_for_rhs, std::integral_constant< bool, true >) const
 
template<typename SparsityPatternType >
void add_entries_local_to_global (const std::vector< size_type > &local_dof_indices, SparsityPatternType &sparsity_pattern, const bool keep_constrained_entries, const Table< 2, bool > &dof_mask, std::integral_constant< bool, false >) const
 
template<typename SparsityPatternType >
void add_entries_local_to_global (const std::vector< size_type > &local_dof_indices, SparsityPatternType &sparsity_pattern, const bool keep_constrained_entries, const Table< 2, bool > &dof_mask, std::integral_constant< bool, true >) const
 
void make_sorted_row_list (const std::vector< size_type > &local_dof_indices, internals::GlobalRowsFromLocal &global_rows) const
 
void make_sorted_row_list (const std::vector< size_type > &local_dof_indices, std::vector< size_type > &active_dofs) const
 
template<typename MatrixScalar , typename VectorScalar >
ProductType< VectorScalar, MatrixScalar >::type resolve_vector_entry (const size_type i, const internals::GlobalRowsFromLocal &global_rows, const Vector< VectorScalar > &local_vector, const std::vector< size_type > &local_dof_indices, const FullMatrix< MatrixScalar > &local_matrix) const
 

Static Private Member Functions

static bool check_zero_weight (const std::pair< size_type, double > &p)
 

Private Attributes

std::vector< ConstraintLinelines
 
std::vector< size_typelines_cache
 
IndexSet local_lines
 
bool sorted
 

Static Private Attributes

static const Table< 2, bool > default_empty_table = Table<2,bool>()
 

Detailed Description

This class implements dealing with linear (possibly inhomogeneous) constraints on degrees of freedom. The concept and origin of such constraints is extensively described in the Constraints on degrees of freedom module. The class is meant to deal with a limited number of constraints relative to the total number of degrees of freedom, for example a few per cent up to maybe 30 per cent; and with a linear combination of M other degrees of freedom where M is also relatively small (no larger than at most around the average number of entries per row of a linear system). It is not meant to describe full rank linear systems.

The algorithms used in the implementation of this class are described in some detail in the hp paper. There is also a significant amount of documentation on how to use this class in the Constraints on degrees of freedom module.

Description of constraints

Each "line" in objects of this class corresponds to one constrained degree of freedom, with the number of the line being i, entered by using add_line() or add_lines(). The entries in this line are pairs of the form (j,aij), which are added by add_entry() or add_entries(). The organization is essentially a SparsityPattern, but with only a few lines containing nonzero elements, and therefore no data wasted on the others. For each line, which has been added by the mechanism above, an elimination of the constrained degree of freedom of the form

\[ x_i = \sum_j a_{ij} x_j + b_i \]

is performed, where bi is optional and set by set_inhomogeneity(). Thus, if a constraint is formulated for instance as a zero mean value of several degrees of freedom, one of the degrees has to be chosen to be eliminated.

Note that the constraints are linear in the xi, and that there might be a constant (non-homogeneous) term in the constraint. This is exactly the form we need for hanging node constraints, where we need to constrain one degree of freedom in terms of others. There are other conditions of this form possible, for example for implementing mean value conditions as is done in the step-11 tutorial program. The name of the class stems from the fact that these constraints can be represented in matrix form as X x = b, and this object then describes the matrix X (and the vector b; originally, the ConstraintMatrix class was only meant to handle homogenous constraints where b=0, thus the name). The most frequent way to create/fill objects of this type is using the DoFTools::make_hanging_node_constraints() function. The use of these objects is first explained in step-6.

Objects of the present type are organized in lines (rows), but only those lines are stored where constraints are present. New constraints are added by adding new lines using the add_line() function, and then populating it using the add_entry() function to a given line, or add_entries() to add more than one entry at a time. The right hand side element, if nonzero, can be set using the set_inhomogeneity() function. After all constraints have been added, you need to call close(), which compresses the storage format and sorts the entries.

Note
Many of the algorithms this class implements are discussed in the hp_paper. The algorithms are also related to those shown in M. S. Shephard: Linear multipoint constraints applied via transformation as part of a direct stiffness assembly process. Int. J. Numer. Meth. Engrg., vol. 20 (1984), pp. 2107-2112., with the difference that the algorithms shown there completely eliminated constrained degrees of freedom, whereas we usually keep them as part of the linear system.
Author
Wolfgang Bangerth, Martin Kronbichler, 1998, 2004, 2008, 2009

Definition at line 137 of file constraint_matrix.h.

Member Typedef Documentation

◆ size_type

Declare the type for container size.

Definition at line 143 of file constraint_matrix.h.

◆ const_iterator

Typedef for the iterator type that is used in the LineRange container.

Definition at line 1196 of file constraint_matrix.h.

◆ LineRange

typedef boost::iterator_range<const_iterator> ConstraintMatrix::LineRange

Typedef for the return type used by get_lines().

Definition at line 1202 of file constraint_matrix.h.

Member Enumeration Documentation

◆ MergeConflictBehavior

An enum that describes what should happen if the two ConstraintMatrix objects involved in a call to the merge() function happen to have constraints on the same degrees of freedom.

Enumerator
no_conflicts_allowed 

Throw an exception if the two objects concerned have conflicting constraints on the same degree of freedom.

left_object_wins 

In an operation cm1.merge(cm2), if cm1 and cm2 have constraints on the same degree of freedom, take the one from cm1.

right_object_wins 

In an operation cm1.merge(cm2), if cm1 and cm2 have constraints on the same degree of freedom, take the one from cm2.

Definition at line 150 of file constraint_matrix.h.

Constructor & Destructor Documentation

◆ ConstraintMatrix() [1/3]

ConstraintMatrix::ConstraintMatrix ( const IndexSet local_constraints = IndexSet())
inlineexplicit

Constructor. The supplied IndexSet defines which indices might be constrained inside this ConstraintMatrix. In a calculation with a DoFHandler object based on parallel::distributed::Triangulation or parallel::shared::Triangulation, one should use the set of locally relevant dofs (see GlossLocallyRelevantDof).

The given IndexSet allows the ConstraintMatrix to save memory by just not caring about degrees of freedom that are not of importance to the current processor. Alternatively, if no such IndexSet is provided, internal data structures for all possible indices will be created, leading to memory consumption on every processor that is proportional to the overall size of the problem, not just proportional to the size of the portion of the overall problem that is handled by the current processor.

Definition at line 1524 of file constraint_matrix.h.

◆ ConstraintMatrix() [2/3]

ConstraintMatrix::ConstraintMatrix ( const ConstraintMatrix constraint_matrix)
inlineexplicit

Copy constructor

Definition at line 1539 of file constraint_matrix.h.

◆ ConstraintMatrix() [3/3]

ConstraintMatrix::ConstraintMatrix ( ConstraintMatrix &&  constraint_matrix)
default

Move constructor

Member Function Documentation

◆ operator=() [1/2]

ConstraintMatrix& ConstraintMatrix::operator= ( const ConstraintMatrix )
delete

Copy operator. Like for many other large objects, this operator is deleted to avoid its inadvertent use in places such as accidentally declaring a ConstraintMatrix object as a function argument by value, rather than by reference.

However, you can use the copy_from() function to explicitly copy ConstraintMatrix objects.

◆ operator=() [2/2]

ConstraintMatrix& ConstraintMatrix::operator= ( ConstraintMatrix &&  constraint_matrix)
default

Move assignment operator

◆ copy_from()

void ConstraintMatrix::copy_from ( const ConstraintMatrix other)

Copy the given object to the current one.

This function exists because operator=() is explicitly disabled.

Definition at line 57 of file constraint_matrix.cc.

◆ reinit()

void ConstraintMatrix::reinit ( const IndexSet local_constraints = IndexSet())

clear() the ConstraintMatrix object and supply an IndexSet with lines that may be constrained. This function is only relevant in the distributed case to supply a different IndexSet. Otherwise this routine is equivalent to calling clear(). See the constructor for details.

Definition at line 773 of file constraint_matrix.cc.

◆ can_store_line()

bool ConstraintMatrix::can_store_line ( const size_type  line_index) const
inline

Determines if we can store a constraint for the given line_index. This routine only matters in the distributed case and checks if the IndexSet allows storage of this line. Always returns true if not in the distributed case.

Definition at line 1729 of file constraint_matrix.h.

◆ get_local_lines()

const IndexSet & ConstraintMatrix::get_local_lines ( ) const
inline

Return the index set describing locally relevant lines if any are present. Note that if no local lines were given, this represents an empty IndexSet, whereas otherwise it contains the global problem size and the local range.

Definition at line 1738 of file constraint_matrix.h.

◆ add_selected_constraints()

void ConstraintMatrix::add_selected_constraints ( const ConstraintMatrix constraints_in,
const IndexSet filter 
)

This function copies the content of constraints_in with DoFs that are element of the IndexSet filter. Elements that are not present in the IndexSet are ignored. All DoFs will be transformed to local index space of the filter, both the constrained DoFs and the other DoFs these entries are constrained to. The local index space of the filter is a contiguous numbering of all (global) DoFs that are elements in the filter.

If, for example, the filter represents the range [10,20), and the constraint matrix constraints_in includes the global indices {7,13,14}, the indices {3,4} are added to the calling constraint matrix (since 13 and 14 are elements in the filter and element 13 is the fourth element in the index, and 14 is the fifth).

This function provides an easy way to create a ConstraintMatrix for certain vector components in a vector-valued problem from a full ConstraintMatrix, i.e. extracting a diagonal subblock from a larger ConstraintMatrix. The block is specified by the IndexSet argument.

Definition at line 266 of file constraint_matrix.cc.

◆ add_line()

void ConstraintMatrix::add_line ( const size_type  line)
inline

Add a new line to the matrix. If the line already exists, then the function simply returns without doing anything.

Definition at line 1551 of file constraint_matrix.h.

◆ add_lines() [1/3]

void ConstraintMatrix::add_lines ( const std::vector< bool > &  lines)

Call the first add_line() function for every index i for which lines[i] is true.

This function essentially exists to allow adding several constraints of the form xi=0 all at once, where the set of indices i for which these constraints should be added are given by the argument of this function. On the other hand, just as if the single- argument add_line() function were called repeatedly, the constraints can later be modified to include linear dependencies using the add_entry() function as well as inhomogeneities using set_inhomogeneity().

Definition at line 206 of file constraint_matrix.cc.

◆ add_lines() [2/3]

void ConstraintMatrix::add_lines ( const std::set< size_type > &  lines)

Call the first add_line() function for every index i that appears in the argument.

This function essentially exists to allow adding several constraints of the form xi=0 all at once, where the set of indices i for which these constraints should be added are given by the argument of this function. On the other hand, just as if the single- argument add_line() function were called repeatedly, the constraints can later be modified to include linear dependencies using the add_entry() function as well as inhomogeneities using set_inhomogeneity().

Definition at line 196 of file constraint_matrix.cc.

◆ add_lines() [3/3]

void ConstraintMatrix::add_lines ( const IndexSet lines)

Call the first add_line() function for every index i that appears in the argument.

This function essentially exists to allow adding several constraints of the form xi=0 all at once, where the set of indices i for which these constraints should be added are given by the argument of this function. On the other hand, just as if the single- argument add_line() function were called repeatedly, the constraints can later be modified to include linear dependencies using the add_entry() function as well as inhomogeneities using set_inhomogeneity().

Definition at line 216 of file constraint_matrix.cc.

◆ add_entry()

void ConstraintMatrix::add_entry ( const size_type  line,
const size_type  column,
const double  value 
)
inline

Add an entry to a given line. The list of lines is searched from the back to the front, so clever programming would add a new line (which is pushed to the back) and immediately afterwards fill the entries of that line. This way, no expensive searching is needed.

If an entry with the same indices as the one this function call denotes already exists, then this function simply returns provided that the value of the entry is the same. Thus, it does no harm to enter a constraint twice.

Definition at line 1584 of file constraint_matrix.h.

◆ add_entries()

void ConstraintMatrix::add_entries ( const size_type  line,
const std::vector< std::pair< size_type, double > > &  col_val_pairs 
)

Add a whole series of entries, denoted by pairs of column indices and values, to a line of constraints. This function is equivalent to calling the preceding function several times, but is faster.

Definition at line 226 of file constraint_matrix.cc.

◆ set_inhomogeneity()

void ConstraintMatrix::set_inhomogeneity ( const size_type  line,
const double  value 
)
inline

Set an inhomogeneity to the constraint line i, according to the discussion in the general class description.

Note
the line needs to be added with one of the add_line() calls first.

Definition at line 1627 of file constraint_matrix.h.

◆ close()

void ConstraintMatrix::close ( )

Close the filling of entries. Since the lines of a matrix of this type are usually filled in an arbitrary order and since we do not want to use associative constrainers to store the lines, we need to sort the lines and within the lines the columns before usage of the matrix. This is done through this function.

Also, zero entries are discarded, since they are not needed.

After closing, no more entries are accepted. If the object was already closed, then this function returns immediately.

This function also resolves chains of constraints. For example, degree of freedom 13 may be constrained to \(u_{13} = \frac{u_3}{2} + \frac{u_7}{2}\) while degree of freedom 7 is itself constrained as \(u_{7} = \frac{u_2}{2} + \frac{u_4}{2}\). Then, the resolution will be that \(u_{13} = \frac{u_3}{2} + \frac{u_2}{4} + \frac{u_4}{4}\). Note, however, that cycles in this graph of constraints are not allowed, i.e. for example \(u_4\) may not be constrained, directly or indirectly, to \(u_{13}\) again.

Definition at line 290 of file constraint_matrix.cc.

◆ merge()

void ConstraintMatrix::merge ( const ConstraintMatrix other_constraints,
const MergeConflictBehavior  merge_conflict_behavior = no_conflicts_allowed,
const bool  allow_different_local_lines = false 
)

Merge the constraints represented by the object given as argument into the constraints represented by this object. Both objects may or may not be closed (by having their function close() called before). If this object was closed before, then it will be closed afterwards as well. Note, however, that if the other argument is closed, then merging may be significantly faster.

Using the default value of the second arguments, the constraints in each of the two objects (the old one represented by this object and the argument) may not refer to the same degree of freedom, i.e. a degree of freedom that is constrained in one object may not be constrained in the second. If this is nevertheless the case, an exception is thrown. However, this behavior can be changed by providing a different value for the second argument.

By default, merging two ConstraintMatrix objects that are initialized with different IndexSet objects is not allowed. This behavior can be altered by setting allow_different_local_lines appropriately.

Merging a ConstraintMatrix that is initialized with an IndexSet and one that is not initialized with an IndexSet is not yet implemented.

Definition at line 579 of file constraint_matrix.cc.

◆ shift()

void ConstraintMatrix::shift ( const size_type  offset)

Shift all entries of this matrix down offset rows and over offset columns. If this object is initialized with an IndexSet, local_lines are shifted as well.

This function is useful if you are building block matrices, where all blocks are built by the same DoFHandler object, i.e. the matrix size is larger than the number of degrees of freedom. Since several matrix rows and columns correspond to the same degrees of freedom, you'd generate several constraint objects, then shift them, and finally merge() them together again.

Definition at line 721 of file constraint_matrix.cc.

◆ clear()

void ConstraintMatrix::clear ( )

Clear all entries of this matrix. Reset the flag determining whether new entries are accepted or not.

This function may be called also on objects which are empty or already cleared.

Definition at line 756 of file constraint_matrix.cc.

◆ n_constraints()

types::global_dof_index ConstraintMatrix::n_constraints ( ) const
inline

Return number of constraints stored in this matrix.

Definition at line 1643 of file constraint_matrix.h.

◆ is_constrained()

bool ConstraintMatrix::is_constrained ( const size_type  index) const
inline

Return whether the degree of freedom with number index is a constrained one.

Note that if close() was called before, then this function is significantly faster, since then the constrained degrees of freedom are sorted and we can do a binary search, while before close() was called, we have to perform a linear search through all entries.

Definition at line 1652 of file constraint_matrix.h.

◆ is_identity_constrained()

bool ConstraintMatrix::is_identity_constrained ( const size_type  index) const

Return whether the dof is constrained, and whether it is constrained to only one other degree of freedom with weight one. The function therefore returns whether the degree of freedom would simply be eliminated in favor of exactly one other degree of freedom.

The function returns false if either the degree of freedom is not constrained at all, or if it is constrained to more than one other degree of freedom, or if it is constrained to only one degree of freedom but with a weight different from one.

Definition at line 1186 of file constraint_matrix.cc.

◆ are_identity_constrained()

bool ConstraintMatrix::are_identity_constrained ( const size_type  index1,
const size_type  index2 
) const

Return whether the two given degrees of freedom are linked by an equality constraint that either constrains index1 to be so that index1=index2 or constrains index2 so that index2=index1.

Definition at line 1201 of file constraint_matrix.cc.

◆ max_constraint_indirections()

ConstraintMatrix::size_type ConstraintMatrix::max_constraint_indirections ( ) const

Return the maximum number of other dofs that one dof is constrained to. For example, in 2d a hanging node is constrained only to its two neighbors, so the returned value would be 2. However, for higher order elements and/or higher dimensions, or other types of constraints, this number is no more obvious.

The name indicates that within the system matrix, references to a constrained node are indirected to the nodes it is constrained to.

Definition at line 1233 of file constraint_matrix.cc.

◆ is_inhomogeneously_constrained()

bool ConstraintMatrix::is_inhomogeneously_constrained ( const size_type  index) const
inline

Return true in case the dof is constrained and there is a non- trivial inhomogeneous values set to the dof.

Definition at line 1664 of file constraint_matrix.h.

◆ has_inhomogeneities()

bool ConstraintMatrix::has_inhomogeneities ( ) const

Return false if all constraints in the ConstraintMatrix are homogeneous ones, and true if there is at least one inhomogeneity.

Definition at line 1248 of file constraint_matrix.cc.

◆ get_constraint_entries()

const std::vector< std::pair< types::global_dof_index, double > > * ConstraintMatrix::get_constraint_entries ( const size_type  line) const
inline

Return a pointer to the vector of entries if a line is constrained, and a zero pointer in case the dof is not constrained.

Definition at line 1683 of file constraint_matrix.h.

◆ get_inhomogeneity()

double ConstraintMatrix::get_inhomogeneity ( const size_type  line) const
inline

Return the value of the inhomogeneity stored in the constrained dof line. Unconstrained dofs also return a zero value.

Definition at line 1699 of file constraint_matrix.h.

◆ print()

void ConstraintMatrix::print ( std::ostream &  out) const

Print the constraints represented by the current object to the given stream.

For each constraint of the form

\[ x_{42} = 0.5 x_2 + 0.25 x_{14} + 2.75 \]

this function will write a sequence of lines that look like this:

42 2 : 0.5
42 14 : 0.25
42 : 2.75

The last line is only shown if the inhomogeneity (here: 2.75) is nonzero.

A block of lines such as the one above is repeated for each constrained degree of freedom.

Definition at line 1259 of file constraint_matrix.cc.

◆ write_dot()

void ConstraintMatrix::write_dot ( std::ostream &  out) const

Write the graph of constraints in 'dot' format. 'dot' is a program that can take a list of nodes and produce a graphical representation of the graph of constrained degrees of freedom and the degrees of freedom they are constrained to.

The output of this function can be used as input to the 'dot' program that can convert the graph into a graphical representation in postscript, png, xfig, and a number of other formats.

This function exists mostly for debugging purposes.

Definition at line 1296 of file constraint_matrix.cc.

◆ memory_consumption()

std::size_t ConstraintMatrix::memory_consumption ( ) const

Determine an estimate for the memory consumption (in bytes) of this object.

Definition at line 1318 of file constraint_matrix.cc.

◆ resolve_indices()

void ConstraintMatrix::resolve_indices ( std::vector< types::global_dof_index > &  indices) const

Add the constraint indices associated to the indices in the given vector. After a call to this function, the indices vector contains the initial elements and all the associated constrained indices. This function sorts the elements and suppresses duplicates.

Definition at line 1329 of file constraint_matrix.cc.

◆ condense() [1/10]

void ConstraintMatrix::condense ( SparsityPattern sparsity) const

Condense a sparsity pattern. The name of the function mimics the name of the function we use to condense linear systems, but it is a bit of a misnomer for the current context. This is because in the context of linear systems, we eliminate certain rows and columns of the linear system, i.e., we "reduce" or "condense" the linear system. On the other hand, in the current context, the functions does not remove nonzero entries from the sparsity pattern. Rather, it adds those nonzero entry locations to the sparsity pattern that will later be needed for the process of condensation of constrained degrees of freedom from a linear system.

Since this function adds new nonzero entries to the sparsity pattern, the given sparsity pattern must not be compressed. The constraint matrix (i.e., the current object) must be closed. The sparsity pattern is compressed at the end of the function.

Definition at line 787 of file constraint_matrix.cc.

◆ condense() [2/10]

void ConstraintMatrix::condense ( BlockSparsityPattern sparsity) const

Same function as above, but condenses square block sparsity patterns.

Definition at line 961 of file constraint_matrix.cc.

◆ condense() [3/10]

void ConstraintMatrix::condense ( DynamicSparsityPattern sparsity) const

Same function as above, but condenses square compressed sparsity patterns.

Definition at line 871 of file constraint_matrix.cc.

◆ condense() [4/10]

void ConstraintMatrix::condense ( BlockDynamicSparsityPattern sparsity) const

Same function as above, but condenses square compressed sparsity patterns.

Definition at line 1073 of file constraint_matrix.cc.

◆ condense() [5/10]

template<typename number >
void ConstraintMatrix::condense ( SparseMatrix< number > &  matrix) const

Condense a given matrix, i.e., eliminate the rows and columns of the matrix that correspond to constrained degrees of freedom.

See the general documentation of this class for more detailed information.

◆ condense() [6/10]

template<typename number >
void ConstraintMatrix::condense ( BlockSparseMatrix< number > &  matrix) const

Same function as above, but condenses square block sparse matrices.

◆ condense() [7/10]

template<class VectorType >
void ConstraintMatrix::condense ( VectorType &  vec) const

Condense the given vector in-place. The VectorType may be a Vector<float>, Vector<double>, BlockVector<...>, a PETSc or Trilinos vector wrapper class, or any other type having the same interface. Note that this function does not take any inhomogeneity into account and throws an exception in case there are any inhomogeneities. Use the function using both a matrix and vector for that case.

Note
This function does not work for MPI vectors. Use condense() with two vector arguments instead.

◆ condense() [8/10]

template<class VectorType >
void ConstraintMatrix::condense ( const VectorType &  vec_ghosted,
VectorType &  output 
) const

The function copies and condenses values from vec_ghosted into output. In a serial code it is equivalent to calling condense (vec). If called in parallel, vec_ghosted is supposed to contain ghost elements while output should not.

◆ condense() [9/10]

template<typename number , class VectorType >
void ConstraintMatrix::condense ( SparseMatrix< number > &  matrix,
VectorType &  vector 
) const

Condense a given matrix and a given vector by eliminating rows and columns of the linear system that correspond to constrained degrees of freedom. The sparsity pattern associated with the matrix needs to be condensed and compressed. This function is the appropriate choice for applying inhomogeneous constraints.

The constraint matrix object must be closed to call this function.

See the general documentation of this class for more detailed information.

◆ condense() [10/10]

template<typename number , class BlockVectorType >
void ConstraintMatrix::condense ( BlockSparseMatrix< number > &  matrix,
BlockVectorType &  vector 
) const

Same function as above, but condenses square block sparse matrices and vectors.

◆ set_zero()

template<class VectorType >
void ConstraintMatrix::set_zero ( VectorType &  vec) const

Set the values of all constrained DoFs in a vector to zero. The VectorType may be a Vector<float>, Vector<double>, BlockVector<...>, a PETSc or Trilinos vector wrapper class, or any other type having the same interface.

◆ distribute_local_to_global() [1/11]

template<class InVector , class OutVector >
void ConstraintMatrix::distribute_local_to_global ( const InVector &  local_vector,
const std::vector< size_type > &  local_dof_indices,
OutVector &  global_vector 
) const
inline

This function takes a vector of local contributions (local_vector) corresponding to the degrees of freedom indices given in local_dof_indices and distributes them to the global vector. In most cases, these local contributions will be the result of an integration over a cell or face of a cell. However, as long as local_vector and local_dof_indices have the same number of elements, this function is happy with whatever it is given.

In contrast to the similar function in the DoFAccessor class, this function also takes care of constraints, i.e. if one of the elements of local_dof_indices belongs to a constrained node, then rather than writing the corresponding element of local_vector into global_vector, the element is distributed to the entries in the global vector to which this particular degree of freedom is constrained.

Thus, by using this function to distribute local contributions to the global object, one saves the call to the condense function after the vectors and matrices are fully assembled. On the other hand, by consequence, the function does not only write into the entries enumerated by the local_dof_indices array, but also (possibly) others as necessary.

Note that this function will apply all constraints as if they were homogeneous. For correctly setting inhomogeneous constraints, use the similar function with a matrix argument or the function with both matrix and vector arguments.

Note
This function in itself is thread-safe, i.e., it works properly also when several threads call it simultaneously. However, the function call is only thread-safe if the underlying global vector allows for simultaneous access and the access is not to rows with the same global index at the same time. This needs to be made sure from the caller's site. There is no locking mechanism inside this method to prevent data races.
Parameters
[in]local_vectorVector of local contributions.
[in]local_dof_indicesLocal degrees of freedom indices corresponding to the vector of local contributions.
[out]global_vectorThe global vector to which all local contributions will be added.

Definition at line 1799 of file constraint_matrix.h.

◆ distribute_local_to_global() [2/11]

template<typename VectorType , typename LocalType >
void ConstraintMatrix::distribute_local_to_global ( const Vector< LocalType > &  local_vector,
const std::vector< size_type > &  local_dof_indices,
VectorType &  global_vector,
const FullMatrix< LocalType > &  local_matrix 
) const

This function takes a vector of local contributions (local_vector) corresponding to the degrees of freedom indices given in local_dof_indices and distributes them to the global vector. In most cases, these local contributions will be the result of an integration over a cell or face of a cell. However, as long as local_vector and local_dof_indices have the same number of elements, this function is happy with whatever it is given.

In contrast to the similar function in the DoFAccessor class, this function also takes care of constraints, i.e. if one of the elements of local_dof_indices belongs to a constrained node, then rather than writing the corresponding element of local_vector into global_vector, the element is distributed to the entries in the global vector to which this particular degree of freedom is constrained.

Thus, by using this function to distribute local contributions to the global object, one saves the call to the condense function after the vectors and matrices are fully assembled. On the other hand, by consequence, the function does not only write into the entries enumerated by the local_dof_indices array, but also (possibly) others as necessary. This includes writing into diagonal elements of the matrix if the corresponding degree of freedom is constrained.

The fourth argument local_matrix is intended to be used in case one wants to apply inhomogeneous constraints on the vector only. Such a situation could be where one wants to assemble of a right hand side vector on a problem with inhomogeneous constraints, but the global matrix has been assembled previously. A typical example of this is a time stepping algorithm where the stiffness matrix is assembled once, and the right hand side updated every time step. Note that, however, the entries in the columns of the local matrix have to be exactly the same as those that have been written into the global matrix. Otherwise, this function will not be able to correctly handle inhomogeneities.

Note
This function in itself is thread-safe, i.e., it works properly also when several threads call it simultaneously. However, the function call is only thread-safe if the underlying global vector allows for simultaneous access and the access is not to rows with the same global index at the same time. This needs to be made sure from the caller's site. There is no locking mechanism inside this method to prevent data races.

◆ distribute_local_to_global() [3/11]

template<typename VectorType , typename LocalType >
void ConstraintMatrix::distribute_local_to_global ( const Vector< LocalType > &  local_vector,
const std::vector< size_type > &  local_dof_indices_row,
const std::vector< size_type > &  local_dof_indices_col,
VectorType &  global_vector,
const FullMatrix< LocalType > &  local_matrix,
bool  diagonal = false 
) const

Same as the previous function, except that it uses two (possibly) different index sets to correctly handle inhomogeneities when the local matrix is computed from a combination of two neighboring elements, for example for an edge integral term in DG. Note that in the case that these two elements have different polynomial degree, the local matrix is rectangular.

local_dof_indices_row is the set of row indices and local_dof_indices_col is the set of column indices of the local matrix. diagonal=false says whether the two index sets are equal or not.

If both index sets are equal, diagonal must be set to true or we simply use the previous function. If both index sets are different (diagonal=false) the global_vector is modified to handle inhomogeneities but no entries from local_vector are added. Note that the edge integrals for inner edged for DG do not contribute any values to the right hand side.

◆ distribute_local_to_global() [4/11]

template<class VectorType >
void ConstraintMatrix::distribute_local_to_global ( const size_type  index,
const double  value,
VectorType &  global_vector 
) const
inline

Enter a single value into a result vector, obeying constraints.

Definition at line 1747 of file constraint_matrix.h.

◆ distribute_local_to_global() [5/11]

template<typename ForwardIteratorVec , typename ForwardIteratorInd , class VectorType >
void ConstraintMatrix::distribute_local_to_global ( ForwardIteratorVec  local_vector_begin,
ForwardIteratorVec  local_vector_end,
ForwardIteratorInd  local_indices_begin,
VectorType &  global_vector 
) const
inline

This function takes a pointer to a vector of local contributions (local_vector) corresponding to the degrees of freedom indices given in local_dof_indices and distributes them to the global vector. In most cases, these local contributions will be the result of an integration over a cell or face of a cell. However, as long as the entries in local_dof_indices indicate reasonable global vector entries, this function is happy with whatever it is given.

If one of the elements of local_dof_indices belongs to a constrained node, then rather than writing the corresponding element of local_vector into global_vector, the element is distributed to the entries in the global vector to which this particular degree of freedom is constrained.

Thus, by using this function to distribute local contributions to the global object, one saves the call to the condense function after the vectors and matrices are fully assembled. Note that this function completely ignores inhomogeneous constraints.

Note
This function in itself is thread-safe, i.e., it works properly also when several threads call it simultaneously. However, the function call is only thread-safe if the underlying global vector allows for simultaneous access and the access is not to rows with the same global index at the same time. This needs to be made sure from the caller's site. There is no locking mechanism inside this method to prevent data races.

Definition at line 1770 of file constraint_matrix.h.

◆ distribute_local_to_global() [6/11]

template<typename MatrixType >
void ConstraintMatrix::distribute_local_to_global ( const FullMatrix< typename MatrixType::value_type > &  local_matrix,
const std::vector< size_type > &  local_dof_indices,
MatrixType &  global_matrix 
) const
inline

This function takes a matrix of local contributions (local_matrix) corresponding to the degrees of freedom indices given in local_dof_indices and distributes them to the global matrix. In most cases, these local contributions will be the result of an integration over a cell or face of a cell. However, as long as local_matrix and local_dof_indices have the same number of elements, this function is happy with whatever it is given.

In contrast to the similar function in the DoFAccessor class, this function also takes care of constraints, i.e. if one of the elements of local_dof_indices belongs to a constrained node, then rather than writing the corresponding element of local_matrix into global_matrix, the element is distributed to the entries in the global matrix to which this particular degree of freedom is constrained.

With this scheme, we never write into rows or columns of constrained degrees of freedom. In order to make sure that the resulting matrix can still be inverted, we need to do something with the diagonal elements corresponding to constrained nodes. Thus, if a degree of freedom in local_dof_indices is constrained, we distribute the corresponding entries in the matrix, but also add the absolute value of the diagonal entry of the local matrix to the corresponding entry in the global matrix. Assuming the discretized operator is positive definite, this guarantees that the diagonal entry is always non-zero, positive, and of the same order of magnitude as the other entries of the matrix. On the other hand, when solving a source problem \(Au=f\) the exact value of the diagonal element is not important, since the value of the respective degree of freedom will be overwritten by the distribute() call later on anyway.

Note
The procedure described above adds an unforeseeable number of artificial eigenvalues to the spectrum of the matrix. Therefore, it is recommended to use the equivalent function with two local index vectors in such a case.

By using this function to distribute local contributions to the global object, one saves the call to the condense function after the vectors and matrices are fully assembled.

Note
This function in itself is thread-safe, i.e., it works properly also when several threads call it simultaneously. However, the function call is only thread-safe if the underlying global matrix allows for simultaneous access and the access is not to rows with the same global index at the same time. This needs to be made sure from the caller's site. There is no locking mechanism inside this method to prevent data races.

Definition at line 1925 of file constraint_matrix.h.

◆ distribute_local_to_global() [7/11]

template<typename MatrixType >
void ConstraintMatrix::distribute_local_to_global ( const FullMatrix< typename MatrixType::value_type > &  local_matrix,
const std::vector< size_type > &  row_indices,
const std::vector< size_type > &  col_indices,
MatrixType &  global_matrix 
) const

Does almost the same as the function above but can treat general rectangular matrices. The main difference to achieve this is that the diagonal entries in constrained rows are left untouched instead of being filled with arbitrary values.

Since the diagonal entries corresponding to eliminated degrees of freedom are not set, the result may have a zero eigenvalue, if applied to a square matrix. This has to be considered when solving the resulting problems. For solving a source problem \(Au=f\), it is possible to set the diagonal entry after building the matrix by a piece of code of the form

for (unsigned int i=0;i<matrix.m();++i)
if (constraints.is_constrained(i))
matrix.diag_element(i) = 1.;

The value of one which is used here is arbitrary, but in the context of Krylov space methods uncritical, since it corresponds to an invariant subspace. If the other matrix entries are smaller or larger by a factor close to machine accuracy, it may be advisable to adjust it.

For solving eigenvalue problems, this will only add one spurious zero eigenvalue (with a multiplicity that is possibly greater than one). Taking this into account, nothing else has to be changed.

◆ distribute_local_to_global() [8/11]

template<typename MatrixType >
void ConstraintMatrix::distribute_local_to_global ( const FullMatrix< typename MatrixType::value_type > &  local_matrix,
const std::vector< size_type > &  row_indices,
const ConstraintMatrix column_constraint_matrix,
const std::vector< size_type > &  column_indices,
MatrixType &  global_matrix 
) const

Does almost the same as the function above for general rectangular matrices but uses different ConstraintMatrix objects on the row and column indices. The convention is that row indices are constrained according to the calling ConstraintMatrix *this, whereas column indices are constrained according to the given ConstraintMatrix column_constraint_matrix. This function allows to handle the case where rows and columns of a matrix are represented by different function spaces with their own enumeration of indices, as e.g. in mixed finite element problems with separate DoFHandler objects or for flux matrices between different levels in multigrid methods.

Like the other method with separate slots for row and column indices, this method does not add diagonal entries to eliminated degrees of freedom. See there for a more elaborate description.

◆ distribute_local_to_global() [9/11]

template<typename MatrixType , typename VectorType >
void ConstraintMatrix::distribute_local_to_global ( const FullMatrix< typename MatrixType::value_type > &  local_matrix,
const Vector< typename VectorType::value_type > &  local_vector,
const std::vector< size_type > &  local_dof_indices,
MatrixType &  global_matrix,
VectorType &  global_vector,
bool  use_inhomogeneities_for_rhs = false 
) const
inline

This function simultaneously writes elements into matrix and vector, according to the constraints specified by the calling ConstraintMatrix. This function can correctly handle inhomogeneous constraints as well. For the parameter use_inhomogeneities_for_rhs see the documentation in Constraints on degrees of freedom module.

Note
This function in itself is thread-safe, i.e., it works properly also when several threads call it simultaneously. However, the function call is only thread-safe if the underlying global matrix and vector allow for simultaneous access and the access is not to rows with the same global index at the same time. This needs to be made sure from the caller's site. There is no locking mechanism inside this method to prevent data races.

Definition at line 1944 of file constraint_matrix.h.

◆ add_entries_local_to_global() [1/4]

template<typename SparsityPatternType >
void ConstraintMatrix::add_entries_local_to_global ( const std::vector< size_type > &  local_dof_indices,
SparsityPatternType &  sparsity_pattern,
const bool  keep_constrained_entries = true,
const Table< 2, bool > &  dof_mask = default_empty_table 
) const
inline

Do a similar operation as the distribute_local_to_global() function that distributes writing entries into a matrix for constrained degrees of freedom, except that here we don't write into a matrix but only allocate sparsity pattern entries.

As explained in the hp paper and in step-27, first allocating a sparsity pattern and later coming back and allocating additional entries for those matrix entries that will be written to due to the elimination of constrained degrees of freedom (using ConstraintMatrix::condense() ), can be a very expensive procedure. It is cheaper to allocate these entries right away without having to do a second pass over the sparsity pattern object. This function does exactly that.

Because the function only allocates entries in a sparsity pattern, all it needs to know are the degrees of freedom that couple to each other. Unlike the previous function, no actual values are written, so the second input argument is not necessary here.

The third argument to this function, keep_constrained_entries determines whether the function shall allocate entries in the sparsity pattern at all for entries that will later be set to zero upon condensation of the matrix. These entries are necessary if the matrix is built unconstrained, and only later condensed. They are not necessary if the matrix is built using the distribute_local_to_global() function of this class which distributes entries right away when copying a local matrix into a global object. The default of this argument is true, meaning to allocate the few entries that may later be set to zero.

By default, the function adds entries for all pairs of indices given in the first argument to the sparsity pattern (unless keep_constrained_entries is false). However, sometimes one would like to only add a subset of all of these pairs. In that case, the last argument can be used which specifies a boolean mask which of the pairs of indices should be considered. If the mask is false for a pair of indices, then no entry will be added to the sparsity pattern for this pair, irrespective of whether one or both of the indices correspond to constrained degrees of freedom.

This function is not typically called from user code, but is used in the DoFTools::make_sparsity_pattern() function when passed a constraint matrix object.

Note
This function in itself is thread-safe, i.e., it works properly also when several threads call it simultaneously. However, the function call is only thread-safe if the underlying global sparsity pattern allows for simultaneous access and the access is not to rows with the same global index at the same time. This needs to be made sure from the caller's site. There is no locking mechanism inside this method to prevent data races.

Definition at line 1965 of file constraint_matrix.h.

◆ add_entries_local_to_global() [2/4]

template<typename SparsityPatternType >
void ConstraintMatrix::add_entries_local_to_global ( const std::vector< size_type > &  row_indices,
const std::vector< size_type > &  col_indices,
SparsityPatternType &  sparsity_pattern,
const bool  keep_constrained_entries = true,
const Table< 2, bool > &  dof_mask = default_empty_table 
) const

Similar to the other function, but for non-quadratic sparsity patterns.

◆ get_dof_values()

template<typename ForwardIteratorVec , typename ForwardIteratorInd , class VectorType >
void ConstraintMatrix::get_dof_values ( const VectorType &  global_vector,
ForwardIteratorInd  local_indices_begin,
ForwardIteratorVec  local_vector_begin,
ForwardIteratorVec  local_vector_end 
) const
inline

This function imports values from a global vector (global_vector) by applying the constraints to a vector of local values, expressed in iterator format. In most cases, the local values will be identified by the local dof values on a cell. However, as long as the entries in local_dof_indices indicate reasonable global vector entries, this function is happy with whatever it is given.

If one of the elements of local_dof_indices belongs to a constrained node, then rather than writing the corresponding element of global_vector into local_vector, the constraints are resolved as the respective distribute function does, i.e., the local entry is constructed from the global entries to which this particular degree of freedom is constrained.

In contrast to the similar function get_dof_values in the DoFAccessor class, this function does not need the constrained values to be correctly set (i.e., distribute to be called).

Definition at line 1815 of file constraint_matrix.h.

◆ distribute()

template<class VectorType >
void ConstraintMatrix::distribute ( VectorType &  vec) const

Given a vector, set all constrained degrees of freedom to values so that the constraints are satisfied. For example, if the current object stores the constraint \(x_3=\frac 12 x_1 + \frac 12 x_2\), then this function will read the values of \(x_1\) and \(x_1\) from the given vector and set the element \(x_3\) according to this constraints. Similarly, if the current object stores the constraint \(x_{42}=208\), then this function will set the 42nd element of the given vector to 208.

Note
If this function is called with a parallel vector vec, then the vector must not contain ghost elements.

◆ get_lines()

const ConstraintMatrix::LineRange ConstraintMatrix::get_lines ( ) const

Return a range object containing (const) iterators to all line entries stored in the ConstraintMatrix. Such a range is useful to initialize range-based for loops as supported by C++11.

Returns
A range object for the half open range [this->begin(), this->end()) of line entries.

Definition at line 101 of file constraint_matrix.cc.

◆ is_consistent_in_parallel()

bool ConstraintMatrix::is_consistent_in_parallel ( const std::vector< IndexSet > &  locally_owned_dofs,
const IndexSet locally_active_dofs,
const MPI_Comm  mpi_communicator,
const bool  verbose = false 
) const

Check if the current object is consistent on all processors in a distributed computation.

This method checks if all processors agree on the constraints for their local lines as given by locally_active_dofs. This method is a collective operation and will return true only if all processors are consistent.

Please supply the owned DoFs per processor as returned by DoFHandler::locally_owned_dofs_per_processor() as locally_owned_dofs and the result of DoFTools::extract_locally_active_dofs() as locally_active_dofs. The former is used to determine ownership of the specific DoF, while the latter is used as the set of rows that need to be checked.

If verbose is set to true, additional debug information is written to std::cout.

Note
This method exchanges all constraint information of locally active lines and is as such slow for large computations and should probably only be used in debug mode. We do not check all lines returned by get_local_lines() but only the locally active ones, as we allow processors to not know about some locally relevant rows.
Returns
Whether all ConstraintMatrix objects are consistent. Returns the same value on all processors.

Definition at line 108 of file constraint_matrix.cc.

◆ calculate_line_index()

types::global_dof_index ConstraintMatrix::calculate_line_index ( const size_type  line) const
inlineprivate

Internal function to calculate the index of line line in the vector lines_cache using local_lines.

Definition at line 1714 of file constraint_matrix.h.

◆ check_zero_weight()

bool ConstraintMatrix::check_zero_weight ( const std::pair< size_type, double > &  p)
staticprivate

Return true if the weight of an entry (the second element of the pair) equals zero. This function is used to delete entries with zero weight.

Definition at line 68 of file constraint_matrix.cc.

◆ distribute_local_to_global() [10/11]

template<typename MatrixType , typename VectorType >
void ConstraintMatrix::distribute_local_to_global ( const FullMatrix< typename MatrixType::value_type > &  local_matrix,
const Vector< typename VectorType::value_type > &  local_vector,
const std::vector< size_type > &  local_dof_indices,
MatrixType &  global_matrix,
VectorType &  global_vector,
bool  use_inhomogeneities_for_rhs,
std::integral_constant< bool, false >   
) const
private

This function actually implements the local_to_global function for standard (non-block) matrices.

◆ distribute_local_to_global() [11/11]

template<typename MatrixType , typename VectorType >
void ConstraintMatrix::distribute_local_to_global ( const FullMatrix< typename MatrixType::value_type > &  local_matrix,
const Vector< typename VectorType::value_type > &  local_vector,
const std::vector< size_type > &  local_dof_indices,
MatrixType &  global_matrix,
VectorType &  global_vector,
bool  use_inhomogeneities_for_rhs,
std::integral_constant< bool, true >   
) const
private

This function actually implements the local_to_global function for block matrices.

◆ add_entries_local_to_global() [3/4]

template<typename SparsityPatternType >
void ConstraintMatrix::add_entries_local_to_global ( const std::vector< size_type > &  local_dof_indices,
SparsityPatternType &  sparsity_pattern,
const bool  keep_constrained_entries,
const Table< 2, bool > &  dof_mask,
std::integral_constant< bool, false >   
) const
private

This function actually implements the local_to_global function for standard (non-block) sparsity types.

◆ add_entries_local_to_global() [4/4]

template<typename SparsityPatternType >
void ConstraintMatrix::add_entries_local_to_global ( const std::vector< size_type > &  local_dof_indices,
SparsityPatternType &  sparsity_pattern,
const bool  keep_constrained_entries,
const Table< 2, bool > &  dof_mask,
std::integral_constant< bool, true >   
) const
private

This function actually implements the local_to_global function for block sparsity types.

◆ make_sorted_row_list() [1/2]

void ConstraintMatrix::make_sorted_row_list ( const std::vector< size_type > &  local_dof_indices,
internals::GlobalRowsFromLocal &  global_rows 
) const
private

Internal helper function for distribute_local_to_global function.

Creates a list of affected global rows for distribution, including the local rows where the entries come from. The list is sorted according to the global row indices.

◆ make_sorted_row_list() [2/2]

void ConstraintMatrix::make_sorted_row_list ( const std::vector< size_type > &  local_dof_indices,
std::vector< size_type > &  active_dofs 
) const
private

Internal helper function for add_entries_local_to_global function.

Creates a list of affected rows for distribution without any additional information, otherwise similar to the other make_sorted_row_list() function.

◆ resolve_vector_entry()

template<typename MatrixScalar , typename VectorScalar >
ProductType<VectorScalar,MatrixScalar>::type ConstraintMatrix::resolve_vector_entry ( const size_type  i,
const internals::GlobalRowsFromLocal &  global_rows,
const Vector< VectorScalar > &  local_vector,
const std::vector< size_type > &  local_dof_indices,
const FullMatrix< MatrixScalar > &  local_matrix 
) const
private

Internal helper function for distribute_local_to_global function.

Member Data Documentation

◆ lines

std::vector<ConstraintLine> ConstraintMatrix::lines
private

Store the lines of the matrix. Entries are usually appended in an arbitrary order and insertion into a vector is done best at the end, so the order is unspecified after all entries are inserted. Sorting of the entries takes place when calling the close() function.

We could, instead of using a vector, use an associative array, like a map to store the lines. This, however, would mean a much more fragmented heap since it allocates many small objects, and would additionally make usage of this matrix much slower.

Definition at line 1367 of file constraint_matrix.h.

◆ lines_cache

std::vector<size_type> ConstraintMatrix::lines_cache
private

A list of size_type that contains the position of the ConstraintLine of a constrained degree of freedom, or numbers::invalid_size_type if the degree of freedom is not constrained. The numbers::invalid_size_type return value returns thus whether there is a constraint line for a given degree of freedom index. Note that this class has no notion of how many degrees of freedom there really are, so if we check whether there is a constraint line for a given degree of freedom, then this vector may actually be shorter than the index of the DoF we check for.

This field exists since when adding a new constraint line we have to figure out whether it already exists. Previously, we would simply walk the unsorted list of constraint lines until we either hit the end or found it. This algorithm is O(N) if N is the number of constraints, which makes it O(N^2) when inserting all constraints. For large problems with many constraints, this could easily take 5-10 per cent of the total run time. With this field, we can save this time since we find any constraint in O(1) time or get to know that it a certain degree of freedom is not constrained.

To make things worse, traversing the list of existing constraints requires reads from many different places in memory. Thus, in large 3d applications, the add_line() function showed up very prominently in the overall compute time, mainly because it generated a lot of cache misses. This should also be fixed by using the O(1) algorithm to access the fields of this array.

The field is useful in a number of other contexts as well, e.g. when one needs random access to the constraints as in all the functions that apply constraints on the fly while add cell contributions into vectors and matrices.

Definition at line 1401 of file constraint_matrix.h.

◆ local_lines

IndexSet ConstraintMatrix::local_lines
private

This IndexSet is used to limit the lines to save in the ConstraintMatrix to a subset. This is necessary, because the lines_cache vector would become too big in a distributed calculation.

Definition at line 1408 of file constraint_matrix.h.

◆ sorted

bool ConstraintMatrix::sorted
private

Store whether the arrays are sorted. If so, no new entries can be added.

Definition at line 1413 of file constraint_matrix.h.

◆ default_empty_table

const Table< 2, bool > ConstraintMatrix::default_empty_table = Table<2,bool>()
staticprivate

Dummy table that serves as default argument for function add_entries_local_to_global().

Definition at line 1431 of file constraint_matrix.h.


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