16 #ifndef dealii_affine_constraints_h 17 #define dealii_affine_constraints_h 30 #include <boost/range/iterator_range.hpp> 46 template <
typename number>
48 template <
typename number>
53 template <
typename number>
54 class GlobalRowsFromLocal;
59 namespace AffineConstraintsImplementation
61 template <
class VectorType>
63 set_zero_all(
const std::vector<types::global_dof_index> &cm,
68 set_zero_all(
const std::vector<types::global_dof_index> &cm,
73 set_zero_all(
const std::vector<types::global_dof_index> &cm,
79 template <
typename number>
179 template <
typename number =
double>
288 can_store_line(
const size_type line_n)
const;
297 get_local_lines()
const;
347 add_lines(
const std::vector<bool> &lines);
362 add_lines(
const std::set<size_type> &lines);
400 const std::vector<std::pair<size_type, number>> &col_val_pairs);
462 const bool allow_different_local_lines =
false);
502 n_constraints()
const;
514 is_constrained(
const size_type line_n)
const;
528 is_identity_constrained(
const size_type line_n)
const;
537 are_identity_constrained(
const size_type line_n_1,
551 max_constraint_indirections()
const;
558 is_inhomogeneously_constrained(
const size_type index)
const;
566 has_inhomogeneities()
const;
572 const std::vector<std::pair<size_type, number>> *
573 get_constraint_entries(
const size_type line_n)
const;
580 get_inhomogeneity(
const size_type line_n)
const;
603 print(std::ostream &out)
const;
618 write_dot(std::ostream &)
const;
634 resolve_indices(std::vector<types::global_dof_index> &indices)
const;
711 template <
class VectorType>
721 template <
class VectorType>
737 template <
class VectorType>
745 template <
class BlockVectorType>
755 template <
class VectorType>
810 template <
class InVector,
class OutVector>
812 distribute_local_to_global(
const InVector & local_vector,
813 const std::vector<size_type> &local_dof_indices,
814 OutVector & global_vector)
const;
859 template <
typename VectorType>
862 const std::vector<size_type> &local_dof_indices,
885 template <
typename VectorType>
887 distribute_local_to_global(
889 const std::vector<size_type> &local_dof_indices_row,
890 const std::vector<size_type> &local_dof_indices_col,
898 template <
class VectorType>
900 distribute_local_to_global(
const size_type index,
932 template <
typename ForwardIteratorVec,
933 typename ForwardIteratorInd,
936 distribute_local_to_global(ForwardIteratorVec local_vector_begin,
937 ForwardIteratorVec local_vector_end,
938 ForwardIteratorInd local_indices_begin,
988 template <
typename MatrixType>
991 const std::vector<size_type> &local_dof_indices,
992 MatrixType & global_matrix)
const;
1021 template <
typename MatrixType>
1024 const std::vector<size_type> &row_indices,
1025 const std::vector<size_type> &col_indices,
1026 MatrixType & global_matrix)
const;
1044 template <
typename MatrixType>
1047 const std::vector<size_type> &row_indices,
1049 const std::vector<size_type> &column_indices,
1050 MatrixType & global_matrix)
const;
1068 template <
typename MatrixType,
typename VectorType>
1072 const std::vector<size_type> &local_dof_indices,
1073 MatrixType & global_matrix,
1075 bool use_inhomogeneities_for_rhs =
false)
const;
1130 template <
typename SparsityPatternType>
1132 add_entries_local_to_global(
1133 const std::vector<size_type> &local_dof_indices,
1134 SparsityPatternType & sparsity_pattern,
1135 const bool keep_constrained_entries =
true,
1141 template <
typename SparsityPatternType>
1143 add_entries_local_to_global(
1144 const std::vector<size_type> &row_indices,
1145 const std::vector<size_type> &col_indices,
1146 SparsityPatternType & sparsity_pattern,
1147 const bool keep_constrained_entries =
true,
1169 template <
typename ForwardIteratorVec,
1170 typename ForwardIteratorInd,
1173 get_dof_values(
const VectorType & global_vector,
1174 ForwardIteratorInd local_indices_begin,
1175 ForwardIteratorVec local_vector_begin,
1176 ForwardIteratorVec local_vector_end)
const;
1199 template <
class VectorType>
1216 using Entries = std::vector<std::pair<size_type, number>>;
1267 template <
class Archive>
1271 ar &index &entries &inhomogeneity;
1324 is_consistent_in_parallel(
const std::vector<IndexSet> &locally_owned_dofs,
1325 const IndexSet & locally_active_dofs,
1326 const MPI_Comm mpi_communicator,
1327 const bool verbose =
false)
const;
1348 <<
"The specified line " << arg1 <<
" does not exist.");
1359 <<
"The entry for the indices " << arg1 <<
" and " << arg2
1360 <<
" already exists, but the values " << arg3 <<
" (old) and " 1361 << arg4 <<
" (new) differ " 1362 <<
"by " << (arg4 - arg3) <<
".");
1371 <<
"You tried to constrain DoF " << arg1 <<
" to DoF " << arg2
1372 <<
", but that one is also constrained. This is not allowed!");
1380 <<
"Degree of freedom " << arg1
1381 <<
" is constrained from both object in a merge operation.");
1389 <<
"In the given argument a degree of freedom is constrained " 1390 <<
"to another DoF with number " << arg1
1391 <<
", which however is constrained by this object. This is not" 1400 <<
"The index set given to this constraints object indicates " 1401 <<
"constraints for degree of freedom " << arg1
1402 <<
" should not be stored by this object, but a constraint " 1403 <<
"is being added.");
1413 <<
"The index set given to this constraints object indicates " 1414 <<
"constraints using degree of freedom " << arg2
1415 <<
" should not be stored by this object, but a constraint " 1416 <<
"for degree of freedom " << arg1 <<
" uses it.");
1426 <<
"While distributing the constraint for DoF " << arg1
1427 <<
", it turns out that one of the processors " 1428 <<
"who own the " << arg2 <<
" degrees of freedom that x_" 1429 << arg1 <<
" is constrained against does not know about " 1430 <<
"the constraint on x_" << arg1
1431 <<
". Did you not initialize the AffineConstraints container " 1432 <<
"with the appropriate locally_relevant set so " 1433 <<
"that every processor who owns a DoF that constrains " 1434 <<
"another DoF also knows about this constraint?");
1501 calculate_line_index(
const size_type line_n)
const;
1507 template <
typename MatrixType,
typename VectorType>
1511 const std::vector<size_type> &local_dof_indices,
1512 MatrixType & global_matrix,
1514 bool use_inhomogeneities_for_rhs,
1515 std::integral_constant<bool, false>)
const;
1521 template <
typename MatrixType,
typename VectorType>
1525 const std::vector<size_type> &local_dof_indices,
1526 MatrixType & global_matrix,
1528 bool use_inhomogeneities_for_rhs,
1529 std::integral_constant<bool, true>)
const;
1535 template <
typename SparsityPatternType>
1537 add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
1538 SparsityPatternType & sparsity_pattern,
1539 const bool keep_constrained_entries,
1541 std::integral_constant<bool, false>)
const;
1547 template <
typename SparsityPatternType>
1549 add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
1550 SparsityPatternType & sparsity_pattern,
1551 const bool keep_constrained_entries,
1553 std::integral_constant<bool, true>)
const;
1563 make_sorted_row_list(
1564 const std::vector<size_type> & local_dof_indices,
1565 internals::GlobalRowsFromLocal<number> &global_rows)
const;
1575 make_sorted_row_list(
const std::vector<size_type> &local_dof_indices,
1576 std::vector<size_type> & active_dofs)
const;
1581 template <
typename MatrixScalar,
typename VectorScalar>
1583 resolve_vector_entry(
1585 const internals::GlobalRowsFromLocal<number> &global_rows,
1586 const Vector<VectorScalar> & local_vector,
1587 const std::vector<size_type> & local_dof_indices,
1593 template <
typename number>
1597 , local_lines(local_constraints)
1606 template <
typename number>
1616 template <
typename number>
1640 lines.emplace_back();
1641 lines.back().index = line_n;
1642 lines.back().inhomogeneity = 0.;
1646 template <
typename number>
1654 ExcMessage(
"Can't constrain a degree of freedom to itself"));
1659 ExcMessage(
"The current AffineConstraints does not contain the line " 1660 "for the current entry. Call AffineConstraints::add_line " 1661 "before calling this function."));
1674 for (
const auto &p : line_ptr->entries)
1675 if (p.first == column)
1677 Assert(std::abs(p.second - value) < 1.e-14,
1682 line_ptr->entries.emplace_back(column, value);
1685 template <
typename number>
1693 ExcMessage(
"call add_line() before calling set_inhomogeneity()"));
1696 line_ptr->inhomogeneity =
value;
1699 template <
typename number>
1700 template <
class VectorType>
1706 std::vector<size_type> constrained_lines(
lines.size());
1707 for (
unsigned int i = 0; i <
lines.size(); ++i)
1708 constrained_lines[i] =
lines[i].index;
1709 internal::AffineConstraintsImplementation::set_zero_all(constrained_lines,
1713 template <
typename number>
1717 return lines.size();
1720 template <
typename number>
1729 template <
typename number>
1747 template <
typename number>
1748 inline const std::vector<std::pair<types::global_dof_index, number>> *
1761 template <
typename number>
1775 template <
typename number>
1788 template <
typename number>
1795 template <
typename number>
1802 template <
typename number>
1803 template <
class VectorType>
1813 global_vector(index) +=
value;
1816 const ConstraintLine &position =
1818 for (
size_type j = 0; j < position.entries.size(); ++j)
1819 global_vector(position.entries[j].first) +=
1820 value * position.entries[j].second;
1824 template <
typename number>
1825 template <
typename ForwardIteratorVec,
1826 typename ForwardIteratorInd,
1830 ForwardIteratorVec local_vector_begin,
1831 ForwardIteratorVec local_vector_end,
1832 ForwardIteratorInd local_indices_begin,
1836 for (; local_vector_begin != local_vector_end;
1837 ++local_vector_begin, ++local_indices_begin)
1841 *local_indices_begin,
1845 const ConstraintLine &position =
1847 for (
size_type j = 0; j < position.entries.size(); ++j)
1849 (*local_vector_begin) * position.entries[j].second,
1850 position.entries[j].first,
1856 template <
typename number>
1857 template <
class InVector,
class OutVector>
1860 const InVector & local_vector,
1861 const std::vector<size_type> &local_dof_indices,
1862 OutVector & global_vector)
const 1864 Assert(local_vector.size() == local_dof_indices.size(),
1868 local_dof_indices.begin(),
1872 template <
typename number>
1873 template <
typename ForwardIteratorVec,
1874 typename ForwardIteratorInd,
1879 ForwardIteratorInd local_indices_begin,
1880 ForwardIteratorVec local_vector_begin,
1881 ForwardIteratorVec local_vector_end)
const 1884 for (; local_vector_begin != local_vector_end;
1885 ++local_vector_begin, ++local_indices_begin)
1888 *local_vector_begin = global_vector(*local_indices_begin);
1891 const ConstraintLine &position =
1893 typename VectorType::value_type
value = position.inhomogeneity;
1894 for (
size_type j = 0; j < position.entries.size(); ++j)
1895 value += (global_vector(position.entries[j].first) *
1896 position.entries[j].second);
1897 *local_vector_begin =
value;
1902 template <
typename MatrixType>
1904 template <
typename SparsityPatternType>
1906 template <
typename number>
1927 template <
typename MatrixType>
1945 template <
typename T>
1953 template <
typename T>
1961 template <
typename T>
1970 check_for_block_matrix(...);
1979 (
sizeof(check_for_block_matrix(static_cast<MatrixType *>(
nullptr))) ==
1984 template <
typename MatrixType>
1987 template <
typename number>
1988 template <
typename MatrixType>
1992 const std::vector<size_type> &local_dof_indices,
1993 MatrixType & global_matrix)
const 1997 Vector<typename MatrixType::value_type>
dummy(0);
2005 std::integral_constant<
bool, IsBlockMatrix<MatrixType>::value>());
2008 template <
typename number>
2009 template <
typename MatrixType,
typename VectorType>
2014 const std::vector<size_type> &local_dof_indices,
2015 MatrixType & global_matrix,
2017 bool use_inhomogeneities_for_rhs)
const 2027 use_inhomogeneities_for_rhs,
2028 std::integral_constant<
bool, IsBlockMatrix<MatrixType>::value>());
2031 template <
typename number>
2032 template <
typename SparsityPatternType>
2035 const std::vector<size_type> &local_dof_indices,
2036 SparsityPatternType & sparsity_pattern,
2037 const bool keep_constrained_entries,
2045 keep_constrained_entries,
const types::global_dof_index invalid_size_type
std::vector< ConstraintLine > lines
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
void set_zero(VectorType &vec) const
bool is_constrained(const size_type line_n) const
#define DeclException2(Exception2, type1, type2, outsequence)
bool can_store_line(const size_type line_n) const
Contents is actually a matrix.
typename internal::ProductTypeImpl< typename std::decay< T >::type, typename std::decay< U >::type >::type type
void add_entry(const size_type line_n, const size_type column, const number value)
static ::ExceptionBase & ExcColumnNotStoredHere(size_type arg1, size_type arg2)
bool operator<(const SynchronousIterators< Iterators > &a, const SynchronousIterators< Iterators > &b)
static ::ExceptionBase & ExcRowNotStoredHere(size_type arg1)
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
static ::ExceptionBase & ExcMatrixNotClosed()
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
static ::ExceptionBase & ExcMatrixIsClosed()
void serialize(Archive &ar, const unsigned int)
size_type n_constraints() const
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)
size_type index_within_set(const size_type global_index) const
#define DeclException0(Exception0)
#define DEAL_II_NAMESPACE_CLOSE
constexpr TableIndices< 2 > merge(const TableIndices< 2 > &previous_indices, const unsigned int new_index, const unsigned int position)
AffineConstraints(const IndexSet &local_constraints=IndexSet())
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
const types::global_dof_index * dummy()
size_type calculate_line_index(const size_type line_n) const
std::vector< std::pair< size_type, number > > Entries
const IndexSet & get_local_lines() const
static ::ExceptionBase & ExcLineInexistant(int arg1, int arg2)
std::vector< size_type > lines_cache
boost::iterator_range< const_iterator > LineRange
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line_n) const
bool is_inhomogeneously_constrained(const size_type index) const
unsigned 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
number get_inhomogeneity(const size_type line_n) const
#define DEAL_II_NAMESPACE_OPEN
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
bool is_element(const size_type index) const
void add_line(const size_type line_n)
void set_inhomogeneity(const size_type line_n, const number value)
#define DEAL_II_DEPRECATED
typename std::vector< ConstraintLine >::const_iterator const_iterator
T max(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcEntryAlreadyExists(size_type arg1, size_type arg2, number arg3, number arg4)
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
static ::ExceptionBase & ExcInternalError()