16 #ifndef dealii_affine_constraints_h 17 #define dealii_affine_constraints_h 19 #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/table.h> 25 #include <deal.II/base/template_constraints.h> 27 #include <deal.II/lac/vector.h> 28 #include <deal.II/lac/vector_element_access.h> 30 #include <boost/range/iterator_range.hpp> 36 DEAL_II_NAMESPACE_OPEN
44 template <
typename number>
46 template <
typename number>
51 template <
typename number>
52 class GlobalRowsFromLocal;
56 template <
typename number>
155 template <
typename number =
double>
264 can_store_line(
const size_type line_index)
const;
273 get_local_lines()
const;
323 add_lines(
const std::vector<bool> &lines);
338 add_lines(
const std::set<size_type> &lines);
376 const std::vector<std::pair<size_type, number>> &col_val_pairs);
385 set_inhomogeneity(
const size_type line,
const number value);
438 const bool allow_different_local_lines =
false);
478 n_constraints()
const;
490 is_constrained(
const size_type index)
const;
504 is_identity_constrained(
const size_type index)
const;
513 are_identity_constrained(
const size_type index1,
527 max_constraint_indirections()
const;
534 is_inhomogeneously_constrained(
const size_type index)
const;
542 has_inhomogeneities()
const;
548 const std::vector<std::pair<size_type, number>> *
549 get_constraint_entries(
const size_type line)
const;
556 get_inhomogeneity(
const size_type line)
const;
579 print(std::ostream &out)
const;
594 write_dot(std::ostream &)
const;
601 memory_consumption()
const;
610 resolve_indices(std::vector<types::global_dof_index> &indices)
const;
688 template <
class VectorType>
690 condense(VectorType &vec)
const;
698 template <
class VectorType>
700 condense(
const VectorType &vec_ghosted, VectorType &output)
const;
714 template <
class VectorType>
722 template <
class BlockVectorType>
732 template <
class VectorType>
734 set_zero(VectorType &vec)
const;
787 template <
class InVector,
class OutVector>
789 distribute_local_to_global(
const InVector & local_vector,
790 const std::vector<size_type> &local_dof_indices,
791 OutVector & global_vector)
const;
836 template <
typename VectorType>
839 const std::vector<size_type> &local_dof_indices,
840 VectorType & global_vector,
862 template <
typename VectorType>
864 distribute_local_to_global(
866 const std::vector<size_type> &local_dof_indices_row,
867 const std::vector<size_type> &local_dof_indices_col,
868 VectorType & global_vector,
870 bool diagonal =
false)
const;
875 template <
class VectorType>
877 distribute_local_to_global(
const size_type index,
879 VectorType & global_vector)
const;
909 template <
typename ForwardIteratorVec,
910 typename ForwardIteratorInd,
913 distribute_local_to_global(ForwardIteratorVec local_vector_begin,
914 ForwardIteratorVec local_vector_end,
915 ForwardIteratorInd local_indices_begin,
916 VectorType & global_vector)
const;
965 template <
typename MatrixType>
968 const std::vector<size_type> &local_dof_indices,
969 MatrixType & global_matrix)
const;
998 template <
typename MatrixType>
1001 const std::vector<size_type> &row_indices,
1002 const std::vector<size_type> &col_indices,
1003 MatrixType & global_matrix)
const;
1021 template <
typename MatrixType>
1024 const std::vector<size_type> &row_indices,
1026 const std::vector<size_type> &column_indices,
1027 MatrixType & global_matrix)
const;
1045 template <
typename MatrixType,
typename VectorType>
1049 const std::vector<size_type> &local_dof_indices,
1050 MatrixType & global_matrix,
1051 VectorType & global_vector,
1052 bool use_inhomogeneities_for_rhs =
false)
const;
1107 template <
typename SparsityPatternType>
1109 add_entries_local_to_global(
1110 const std::vector<size_type> &local_dof_indices,
1111 SparsityPatternType & sparsity_pattern,
1112 const bool keep_constrained_entries =
true,
1118 template <
typename SparsityPatternType>
1120 add_entries_local_to_global(
1121 const std::vector<size_type> &row_indices,
1122 const std::vector<size_type> &col_indices,
1123 SparsityPatternType & sparsity_pattern,
1124 const bool keep_constrained_entries =
true,
1146 template <
typename ForwardIteratorVec,
1147 typename ForwardIteratorInd,
1150 get_dof_values(
const VectorType & global_vector,
1151 ForwardIteratorInd local_indices_begin,
1152 ForwardIteratorVec local_vector_begin,
1153 ForwardIteratorVec local_vector_end)
const;
1176 template <
class VectorType>
1178 distribute(VectorType &vec)
const;
1193 using Entries = std::vector<std::pair<size_type, number>>;
1239 memory_consumption()
const;
1244 template <
class Archive>
1248 ar &index &entries &inhomogeneity;
1301 is_consistent_in_parallel(
const std::vector<IndexSet> &locally_owned_dofs,
1302 const IndexSet & locally_active_dofs,
1303 const MPI_Comm mpi_communicator,
1304 const bool verbose =
false)
const;
1325 <<
"The specified line " << arg1 <<
" does not exist.");
1336 <<
"The entry for the indices " << arg1 <<
" and " << arg2
1337 <<
" already exists, but the values " << arg3 <<
" (old) and " 1338 << arg4 <<
" (new) differ " 1339 <<
"by " << (arg4 - arg3) <<
".");
1348 <<
"You tried to constrain DoF " << arg1 <<
" to DoF " << arg2
1349 <<
", but that one is also constrained. This is not allowed!");
1357 <<
"Degree of freedom " << arg1
1358 <<
" is constrained from both object in a merge operation.");
1366 <<
"In the given argument a degree of freedom is constrained " 1367 <<
"to another DoF with number " << arg1
1368 <<
", which however is constrained by this object. This is not" 1377 <<
"The index set given to this constraint matrix indicates " 1378 <<
"constraints for degree of freedom " << arg1
1379 <<
" should not be stored by this object, but a constraint " 1380 <<
"is being added.");
1390 <<
"The index set given to this constraint matrix indicates " 1391 <<
"constraints using degree of freedom " << arg2
1392 <<
" should not be stored by this object, but a constraint " 1393 <<
"for degree of freedom " << arg1 <<
" uses it.");
1403 <<
"While distributing the constraint for DoF " << arg1
1404 <<
", it turns out that one of the processors " 1405 <<
"who own the " << arg2 <<
" degrees of freedom that x_" 1406 << arg1 <<
" is constrained against does not know about " 1407 <<
"the constraint on x_" << arg1
1408 <<
". Did you not initialize the AffineConstraints container " 1409 <<
"with the appropriate locally_relevant set so " 1410 <<
"that every processor who owns a DoF that constrains " 1411 <<
"another DoF also knows about this constraint?");
1478 calculate_line_index(
const size_type line)
const;
1485 check_zero_weight(
const std::pair<size_type, number> &p);
1491 template <
typename MatrixType,
typename VectorType>
1495 const std::vector<size_type> &local_dof_indices,
1496 MatrixType & global_matrix,
1497 VectorType & global_vector,
1498 bool use_inhomogeneities_for_rhs,
1499 std::integral_constant<bool, false>)
const;
1505 template <
typename MatrixType,
typename VectorType>
1509 const std::vector<size_type> &local_dof_indices,
1510 MatrixType & global_matrix,
1511 VectorType & global_vector,
1512 bool use_inhomogeneities_for_rhs,
1513 std::integral_constant<bool, true>)
const;
1519 template <
typename SparsityPatternType>
1521 add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
1522 SparsityPatternType & sparsity_pattern,
1523 const bool keep_constrained_entries,
1525 std::integral_constant<bool, false>)
const;
1531 template <
typename SparsityPatternType>
1533 add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
1534 SparsityPatternType & sparsity_pattern,
1535 const bool keep_constrained_entries,
1537 std::integral_constant<bool, true>)
const;
1547 make_sorted_row_list(
1548 const std::vector<size_type> & local_dof_indices,
1549 internals::GlobalRowsFromLocal<number> &global_rows)
const;
1559 make_sorted_row_list(
const std::vector<size_type> &local_dof_indices,
1560 std::vector<size_type> & active_dofs)
const;
1565 template <
typename MatrixScalar,
typename VectorScalar>
1566 typename ProductType<VectorScalar, MatrixScalar>::type
1567 resolve_vector_entry(
1569 const internals::GlobalRowsFromLocal<number> &global_rows,
1570 const Vector<VectorScalar> & local_vector,
1571 const std::vector<size_type> & local_dof_indices,
1577 template <
typename number>
1581 , local_lines(local_constraints)
1590 template <
typename number>
1600 template <
typename number>
1624 lines.emplace_back();
1625 lines.back().index = line;
1626 lines.back().inhomogeneity = 0.;
1630 template <
typename number>
1638 ExcMessage(
"Can't constrain a degree of freedom to itself"));
1643 ExcMessage(
"The current AffineConstraints does not contain the line " 1644 "for the current entry. Call AffineConstraints::add_line " 1645 "before calling this function."));
1658 for (
const auto &p : line_ptr->entries)
1659 if (p.first == column)
1661 Assert(std::abs(p.second - value) < 1.e-14,
1666 line_ptr->entries.emplace_back(column, value);
1669 template <
typename number>
1677 ExcMessage(
"call add_line() before calling set_inhomogeneity()"));
1680 line_ptr->inhomogeneity = value;
1683 template <
typename number>
1687 return lines.size();
1690 template <
typename number>
1699 template <
typename number>
1717 template <
typename number>
1718 inline const std::vector<std::pair<types::global_dof_index, number>> *
1731 template <
typename number>
1745 template <
typename number>
1758 template <
typename number>
1765 template <
typename number>
1772 template <
typename number>
1773 template <
class VectorType>
1778 VectorType & global_vector)
const 1783 global_vector(index) += value;
1789 global_vector(position.
entries[j].first) +=
1790 value * position.
entries[j].second;
1794 template <
typename number>
1795 template <
typename ForwardIteratorVec,
1796 typename ForwardIteratorInd,
1800 ForwardIteratorVec local_vector_begin,
1801 ForwardIteratorVec local_vector_end,
1802 ForwardIteratorInd local_indices_begin,
1803 VectorType & global_vector)
const 1806 for (; local_vector_begin != local_vector_end;
1807 ++local_vector_begin, ++local_indices_begin)
1810 internal::ElementAccess<VectorType>::add(*local_vector_begin,
1811 *local_indices_begin,
1818 internal::ElementAccess<VectorType>::add(
1819 (*local_vector_begin) * position.
entries[j].second,
1826 template <
typename number>
1827 template <
class InVector,
class OutVector>
1830 const InVector & local_vector,
1831 const std::vector<size_type> &local_dof_indices,
1832 OutVector & global_vector)
const 1834 Assert(local_vector.size() == local_dof_indices.size(),
1838 local_dof_indices.begin(),
1842 template <
typename number>
1843 template <
typename ForwardIteratorVec,
1844 typename ForwardIteratorInd,
1848 const VectorType & global_vector,
1849 ForwardIteratorInd local_indices_begin,
1850 ForwardIteratorVec local_vector_begin,
1851 ForwardIteratorVec local_vector_end)
const 1854 for (; local_vector_begin != local_vector_end;
1855 ++local_vector_begin, ++local_indices_begin)
1858 *local_vector_begin = global_vector(*local_indices_begin);
1863 typename VectorType::value_type value = position.
inhomogeneity;
1865 value += (global_vector(position.
entries[j].first) *
1867 *local_vector_begin = value;
1872 template <
typename MatrixType>
1874 template <
typename SparsityPatternType>
1876 template <
typename number>
1897 template <
typename MatrixType>
1915 template <
typename T>
1923 template <
typename T>
1931 template <
typename T>
1940 check_for_block_matrix(...);
1948 static const bool value =
1949 (
sizeof(check_for_block_matrix((MatrixType *)
nullptr)) ==
sizeof(yes_type));
1953 template <
typename MatrixType>
1956 template <
typename number>
1957 template <
typename MatrixType>
1961 const std::vector<size_type> &local_dof_indices,
1962 MatrixType & global_matrix)
const 1966 Vector<typename MatrixType::value_type> dummy(0);
1974 std::integral_constant<
bool, IsBlockMatrix<MatrixType>::value>());
1977 template <
typename number>
1978 template <
typename MatrixType,
typename VectorType>
1983 const std::vector<size_type> &local_dof_indices,
1984 MatrixType & global_matrix,
1985 VectorType & global_vector,
1986 bool use_inhomogeneities_for_rhs)
const 1996 use_inhomogeneities_for_rhs,
1997 std::integral_constant<
bool, IsBlockMatrix<MatrixType>::value>());
2000 template <
typename number>
2001 template <
typename SparsityPatternType>
2004 const std::vector<size_type> &local_dof_indices,
2005 SparsityPatternType & sparsity_pattern,
2006 const bool keep_constrained_entries,
2014 keep_constrained_entries,
2019 DEAL_II_NAMESPACE_CLOSE
const types::global_dof_index invalid_size_type
std::vector< ConstraintLine > lines
size_type calculate_line_index(const size_type line) const
#define DeclException2(Exception2, type1, type2, outsequence)
void add_entry(const size_type line, const size_type column, const number value)
TableIndices< 2 > merge(const TableIndices< 2 > &previous_indices, const unsigned int new_index, const unsigned int position)
static::ExceptionBase & ExcColumnNotStoredHere(size_type arg1, size_type arg2)
types::global_dof_index size_type
number get_inhomogeneity(const size_type line) const
static::ExceptionBase & ExcRowNotStoredHere(size_type arg1)
bool is_constrained(const size_type index) const
static::ExceptionBase & ExcMatrixNotClosed()
static::ExceptionBase & ExcMatrixIsClosed()
void add_line(const size_type line)
unsigned long long int global_dof_index
void get_dof_values(const VectorType &global_vector, ForwardIteratorInd local_indices_begin, ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end) const
void serialize(Archive &ar, const unsigned int)
static::ExceptionBase & ExcMessage(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
#define Assert(cond, exc)
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
#define DeclException0(Exception0)
AffineConstraints(const IndexSet &local_constraints=IndexSet())
static::ExceptionBase & ExcLineInexistant(int arg1, int arg2)
bool can_store_line(const size_type line_index) const
std::vector< size_type > lines_cache
boost::iterator_range< const_iterator > LineRange
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=Table< 2, bool >()) const
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
size_type index_within_set(const size_type global_index) const
std::vector< std::pair< size_type, number >> Entries
void set_inhomogeneity(const size_type line, const number value)
bool is_element(const size_type index) const
const IndexSet & get_local_lines() const
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line) const
typename std::vector< ConstraintLine >::const_iterator const_iterator
static::ExceptionBase & ExcEntryAlreadyExists(size_type arg1, size_type arg2, number arg3, number arg4)
bool is_inhomogeneously_constrained(const size_type index) const
static::ExceptionBase & ExcInternalError()
size_type n_constraints() const