17 #ifndef dealii__constraint_matrix_h 18 #define dealii__constraint_matrix_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/index_set.h> 23 #include <deal.II/base/subscriptor.h> 24 #include <deal.II/base/template_constraints.h> 25 #include <deal.II/base/thread_local_storage.h> 27 #include <deal.II/lac/vector.h> 36 DEAL_II_NAMESPACE_OPEN
38 template<
int dim,
class T>
class Table;
51 class GlobalRowsFromLocal;
213 bool can_store_line (
const size_type line_index)
const;
221 const IndexSet &get_local_lines()
const;
254 void add_line (
const size_type line);
268 void add_lines (
const std::vector<bool> &lines);
282 void add_lines (
const std::set<size_type> &lines);
296 void add_lines (
const IndexSet &lines);
309 void add_entry (
const size_type line,
310 const size_type column,
318 void add_entries (
const size_type line,
319 const std::vector<std::pair<size_type,double> > &col_val_pairs);
327 void set_inhomogeneity (
const size_type line,
382 void shift (
const size_type offset);
406 size_type n_constraints ()
const;
417 bool is_constrained (
const size_type index)
const;
430 bool is_identity_constrained (
const size_type index)
const;
438 bool are_identity_constrained (
const size_type index1,
439 const size_type index2)
const;
451 size_type max_constraint_indirections ()
const;
457 bool is_inhomogeneously_constrained (
const size_type index)
const;
464 bool has_inhomogeneities ()
const;
470 const std::vector<std::pair<size_type,double> > *
471 get_constraint_entries (
const size_type line)
const;
477 double get_inhomogeneity (
const size_type line)
const;
487 void print (std::ostream &)
const;
501 void write_dot (std::ostream &)
const;
507 std::size_t memory_consumption ()
const;
515 void resolve_indices(std::vector<types::global_dof_index> &indices)
const;
570 template<
typename number>
576 template <
typename number>
590 template <
class VectorType>
591 void condense (VectorType &vec)
const;
599 template <
class VectorType>
600 void condense (
const VectorType &vec_ghosted,
601 VectorType &output)
const;
615 template<
typename number,
class VectorType>
617 VectorType &vector)
const;
623 template <
typename number,
class BlockVectorType>
625 BlockVectorType &vector)
const;
633 template <
class VectorType>
634 void set_zero (VectorType &vec)
const;
687 template <
class InVector,
class OutVector>
689 distribute_local_to_global (
const InVector &local_vector,
690 const std::vector<size_type> &local_dof_indices,
691 OutVector &global_vector)
const;
736 template <
typename VectorType,
typename LocalType>
739 const std::vector<size_type> &local_dof_indices,
740 VectorType &global_vector,
746 template <
class VectorType>
748 distribute_local_to_global (
const size_type index,
750 VectorType &global_vector)
const;
780 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
783 distribute_local_to_global (ForwardIteratorVec local_vector_begin,
784 ForwardIteratorVec local_vector_end,
785 ForwardIteratorInd local_indices_begin,
786 VectorType &global_vector)
const;
835 template <
typename MatrixType>
838 const std::vector<size_type> &local_dof_indices,
839 MatrixType &global_matrix)
const;
868 template <
typename MatrixType>
871 const std::vector<size_type> &row_indices,
872 const std::vector<size_type> &col_indices,
873 MatrixType &global_matrix)
const;
891 template <
typename MatrixType,
typename VectorType>
895 const std::vector<size_type> &local_dof_indices,
896 MatrixType &global_matrix,
897 VectorType &global_vector,
898 bool use_inhomogeneities_for_rhs =
false)
const;
953 template <
typename SparsityPatternType>
955 add_entries_local_to_global (
const std::vector<size_type> &local_dof_indices,
956 SparsityPatternType &sparsity_pattern,
957 const bool keep_constrained_entries =
true,
963 template <
typename SparsityPatternType>
965 add_entries_local_to_global (
const std::vector<size_type> &row_indices,
966 const std::vector<size_type> &col_indices,
967 SparsityPatternType &sparsity_pattern,
968 const bool keep_constrained_entries =
true,
990 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
993 get_dof_values (
const VectorType &global_vector,
994 ForwardIteratorInd local_indices_begin,
995 ForwardIteratorVec local_vector_begin,
996 ForwardIteratorVec local_vector_end)
const;
1019 template <
class VectorType>
1020 void distribute (VectorType &vec)
const;
1045 <<
"The specified line " << arg1
1046 <<
" does not exist.");
1053 size_type, size_type,
double,
double,
1054 <<
"The entry for the indices " << arg1 <<
" and " 1055 << arg2 <<
" already exists, but the values " 1056 << arg3 <<
" (old) and " << arg4 <<
" (new) differ " 1057 <<
"by " << (arg4-arg3) <<
".");
1065 <<
"You tried to constrain DoF " << arg1
1066 <<
" to DoF " << arg2
1067 <<
", but that one is also constrained. This is not allowed!");
1075 <<
"Degree of freedom " << arg1
1076 <<
" is constrained from both object in a merge operation.");
1084 <<
"In the given argument a degree of freedom is constrained " 1085 <<
"to another DoF with number " << arg1
1086 <<
", which however is constrained by this object. This is not" 1095 <<
"The index set given to this constraint matrix indicates " 1096 <<
"constraints for degree of freedom " << arg1
1097 <<
" should not be stored by this object, but a constraint " 1098 <<
"is being added.");
1108 <<
"The index set given to this constraint matrix indicates " 1109 <<
"constraints using degree of freedom " << arg2
1110 <<
" should not be stored by this object, but a constraint " 1111 <<
"for degree of freedom " << arg1 <<
" uses it.");
1120 <<
"While distributing the constraint for DoF " 1121 << arg1 <<
", it turns out that one of the processors " 1122 <<
"who own the " << arg2
1123 <<
" degrees of freedom that x_" << arg1
1124 <<
" is constrained against does not know about " 1125 <<
"the constraint on x_" << arg1
1126 <<
". Did you not initialize the ConstraintMatrix " 1127 <<
"with the appropriate locally_relevant set so " 1128 <<
"that every processor who owns a DoF that constrains " 1129 <<
"another DoF also knows about this constraint?");
1142 typedef std::vector<std::pair<size_type,double> >
Entries;
1184 std::size_t memory_consumption ()
const;
1250 size_type calculate_line_index (
const size_type line)
const;
1256 static bool check_zero_weight (
const std::pair<size_type, double> &p);
1268 template <
typename MatrixType,
typename VectorType>
1272 const std::vector<size_type> &local_dof_indices,
1273 MatrixType &global_matrix,
1274 VectorType &global_vector,
1275 bool use_inhomogeneities_for_rhs,
1282 template <
typename MatrixType,
typename VectorType>
1286 const std::vector<size_type> &local_dof_indices,
1287 MatrixType &global_matrix,
1288 VectorType &global_vector,
1289 bool use_inhomogeneities_for_rhs,
1296 template <
typename SparsityPatternType>
1298 add_entries_local_to_global (
const std::vector<size_type> &local_dof_indices,
1299 SparsityPatternType &sparsity_pattern,
1300 const bool keep_constrained_entries,
1308 template <
typename SparsityPatternType>
1310 add_entries_local_to_global (
const std::vector<size_type> &local_dof_indices,
1311 SparsityPatternType &sparsity_pattern,
1312 const bool keep_constrained_entries,
1324 make_sorted_row_list (
const std::vector<size_type> &local_dof_indices,
1325 internals::GlobalRowsFromLocal &global_rows)
const;
1335 make_sorted_row_list (
const std::vector<size_type> &local_dof_indices,
1336 std::vector<size_type> &active_dofs)
const;
1341 template <
typename LocalType>
1343 resolve_vector_entry (
const size_type i,
1344 const internals::GlobalRowsFromLocal &global_rows,
1346 const std::vector<size_type> &local_dof_indices,
1364 local_lines (local_constraints),
1397 ExcInternalError());
1412 lines.back().line = line;
1413 lines.back().inhomogeneity = 0.;
1422 const size_type column,
1427 ExcMessage (
"Can't constrain a degree of freedom to itself"));
1435 ExcInternalError());
1437 ExcColumnNotStoredHere(line, column));
1439 Assert (line_ptr->line == line, ExcInternalError());
1440 for (ConstraintLine::Entries::const_iterator
1441 p=line_ptr->entries.begin();
1442 p != line_ptr->entries.end(); ++p)
1443 if (p->first == column)
1445 Assert (std::fabs(p->second - value) < 1.e-14,
1446 ExcEntryAlreadyExists(line, column, p->second, value));
1450 line_ptr->entries.push_back (std::make_pair(column,value));
1463 ExcMessage(
"call add_line() before calling set_inhomogeneity()"));
1466 line_ptr->inhomogeneity = value;
1475 return lines.size();
1512 const std::vector<std::pair<types::global_dof_index,double> > *
1551 ExcRowNotStoredHere(line));
1575 template <
class VectorType>
1578 const size_type index,
1580 VectorType &global_vector)
const 1585 global_vector(index) += value;
1590 for (size_type j=0; j<position.
entries.size(); ++j)
1591 global_vector(position.
entries[j].first)
1592 += value * position.
entries[j].second;
1597 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
1601 ForwardIteratorVec local_vector_begin,
1602 ForwardIteratorVec local_vector_end,
1603 ForwardIteratorInd local_indices_begin,
1604 VectorType &global_vector)
const 1607 for ( ; local_vector_begin != local_vector_end;
1608 ++local_vector_begin, ++local_indices_begin)
1611 global_vector(*local_indices_begin) += *local_vector_begin;
1616 for (size_type j=0; j<position.
entries.size(); ++j)
1617 global_vector(position.
entries[j].first)
1618 += *local_vector_begin * position.
entries[j].second;
1624 template <
class InVector,
class OutVector>
1628 const InVector &local_vector,
1629 const std::vector<size_type> &local_dof_indices,
1630 OutVector &global_vector)
const 1632 Assert (local_vector.size() == local_dof_indices.size(),
1633 ExcDimensionMismatch(local_vector.size(), local_dof_indices.size()));
1635 local_dof_indices.begin(), global_vector);
1640 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
1644 ForwardIteratorInd local_indices_begin,
1645 ForwardIteratorVec local_vector_begin,
1646 ForwardIteratorVec local_vector_end)
const 1649 for ( ; local_vector_begin != local_vector_end;
1650 ++local_vector_begin, ++local_indices_begin)
1653 *local_vector_begin = global_vector(*local_indices_begin);
1658 typename VectorType::value_type value = position.
inhomogeneity;
1659 for (size_type j=0; j<position.
entries.size(); ++j)
1660 value += (global_vector(position.
entries[j].first) *
1662 *local_vector_begin = value;
1690 template <
typename MatrixType>
1708 template <
typename T>
1715 template <
typename T>
1722 template <
typename T>
1729 static no_type check_for_block_matrix (...);
1737 static const bool value = (
sizeof(check_for_block_matrix
1745 template <
typename MatrixType>
1749 template <
typename MatrixType>
1754 const std::vector<size_type> &local_dof_indices,
1755 MatrixType &global_matrix)
const 1761 global_matrix, dummy,
false,
1768 template <
typename MatrixType,
typename VectorType>
1774 const std::vector<size_type> &local_dof_indices,
1775 MatrixType &global_matrix,
1776 VectorType &global_vector,
1777 bool use_inhomogeneities_for_rhs)
const 1782 global_matrix, global_vector, use_inhomogeneities_for_rhs,
1789 template <
typename SparsityPatternType>
1794 SparsityPatternType &sparsity_pattern,
1795 const bool keep_constrained_entries,
1801 keep_constrained_entries, dof_mask,
1806 DEAL_II_NAMESPACE_CLOSE
const types::global_dof_index invalid_size_type
#define DeclException2(Exception2, type1, type2, outsequence)
std::vector< size_type > lines_cache
void get_dof_values(const VectorType &global_vector, ForwardIteratorInd local_indices_begin, ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end) const
::ExceptionBase & ExcMessage(std::string arg1)
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
const IndexSet & get_local_lines() const
types::global_dof_index size_type
std::vector< std::pair< size_type, double > > Entries
void add_line(const size_type line)
#define DeclException1(Exception1, type1, outsequence)
void add_entry(const size_type line, const size_type column, const double value)
unsigned int global_dof_index
bool is_inhomogeneously_constrained(const size_type index) const
#define Assert(cond, exc)
size_type index_within_set(const size_type global_index) const
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
ConstraintMatrix(const IndexSet &local_constraints=IndexSet())
size_type n_constraints() const
#define DeclException0(Exception0)
static const Table< 2, bool > default_empty_table
size_type calculate_line_index(const size_type line) const
bool can_store_line(const size_type line_index) const
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
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
bool is_element(const size_type index) 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 set_inhomogeneity(const size_type line, const double value)
std::vector< ConstraintLine > lines
bool is_constrained(const size_type index) const