18 #ifndef __deal2__constraint_matrix_h
19 #define __deal2__constraint_matrix_h
21 #include <deal.II/base/config.h>
23 #include <deal.II/base/index_set.h>
24 #include <deal.II/base/subscriptor.h>
25 #include <deal.II/base/template_constraints.h>
26 #include <deal.II/base/thread_local_storage.h>
28 #include <deal.II/lac/vector.h>
36 #include <boost/scoped_ptr.hpp>
39 DEAL_II_NAMESPACE_OPEN
41 template<
int dim,
class T>
class Table;
58 class GlobalRowsFromLocal;
319 const std::vector<std::pair<size_type,double> > &col_val_pairs);
470 const std::vector<std::pair<size_type,double> > *
487 void print (std::ostream &)
const;
515 void resolve_indices(std::vector<types::global_dof_index> &indices)
const;
626 template<
typename number>
635 template<
typename number>
641 template <
typename number>
660 template <
class VectorType>
673 template <
class VectorType>
689 template<
typename number,
class VectorType>
700 template<
typename number,
class VectorType>
708 template <
typename number,
class BlockVectorType>
710 BlockVectorType &vector)
const;
718 template <
class VectorType>
766 template <
class InVector,
class OutVector>
769 const std::vector<size_type> &local_dof_indices,
770 OutVector &global_vector)
const;
815 template <
typename VectorType>
818 const std::vector<size_type> &local_dof_indices,
825 template <
class VectorType>
859 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
863 ForwardIteratorVec local_vector_end,
864 ForwardIteratorInd local_indices_begin,
908 template <
typename MatrixType>
911 const std::vector<size_type> &local_dof_indices,
912 MatrixType &global_matrix)
const;
917 template <
typename MatrixType>
920 const std::vector<size_type> &row_indices,
921 const std::vector<size_type> &col_indices,
922 MatrixType &global_matrix)
const;
939 template <
typename MatrixType,
typename VectorType>
943 const std::vector<size_type> &local_dof_indices,
944 MatrixType &global_matrix,
946 bool use_inhomogeneities_for_rhs =
false)
const;
1000 template <
typename SparsityType>
1003 SparsityType &sparsity_pattern,
1004 const bool keep_constrained_entries =
true,
1010 template <
typename SparsityType>
1013 const std::vector<size_type> &col_indices,
1014 SparsityType &sparsity_pattern,
1015 const bool keep_constrained_entries =
true,
1037 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
1041 ForwardIteratorInd local_indices_begin,
1042 ForwardIteratorVec local_vector_begin,
1043 ForwardIteratorVec local_vector_end)
const;
1066 template <
class VectorType>
1079 template <
class VectorType>
1105 <<
"The specified line " << arg1
1106 <<
" does not exist.");
1114 <<
"The entry for the indices " << arg1 <<
" and "
1115 << arg2 <<
" already exists, but the values "
1116 << arg3 <<
" (old) and " << arg4 <<
" (new) differ "
1117 <<
"by " << (arg4-arg3) <<
".");
1125 <<
"You tried to constrain DoF " << arg1
1126 <<
" to DoF " << arg2
1127 <<
", but that one is also constrained. This is not allowed!");
1135 <<
"Degree of freedom " << arg1
1136 <<
" is constrained from both object in a merge operation.");
1144 <<
"In the given argument a degree of freedom is constrained "
1145 <<
"to another DoF with number " << arg1
1146 <<
", which however is constrained by this object. This is not"
1155 <<
"The index set given to this constraint matrix indicates "
1156 <<
"constraints for degree of freedom " << arg1
1157 <<
" should not be stored by this object, but a constraint "
1158 <<
"is being added.");
1167 <<
"While distributing the constraint for DoF "
1168 << arg1 <<
", it turns out that one of the processors "
1169 <<
"who own the " << arg2
1170 <<
" degrees of freedom that x_" << arg1
1171 <<
" is constrained against does not know about "
1172 <<
"the constraint on x_" << arg1
1173 <<
". Did you not initialize the ConstraintMatrix "
1174 <<
"with the appropriate locally_relevant set so "
1175 <<
"that every processor who owns a DoF that constrains "
1176 <<
"another DoF also knows about this constraint?");
1189 typedef std::vector<std::pair<size_type,double> >
Entries;
1315 template <
typename MatrixType,
typename VectorType>
1319 const std::vector<size_type> &local_dof_indices,
1320 MatrixType &global_matrix,
1322 bool use_inhomogeneities_for_rhs,
1329 template <
typename MatrixType,
typename VectorType>
1333 const std::vector<size_type> &local_dof_indices,
1334 MatrixType &global_matrix,
1336 bool use_inhomogeneities_for_rhs,
1343 template <
typename SparsityType>
1346 SparsityType &sparsity_pattern,
1347 const bool keep_constrained_entries,
1355 template <
typename SparsityType>
1358 SparsityType &sparsity_pattern,
1359 const bool keep_constrained_entries,
1383 std::vector<size_type> &active_dofs)
const;
1392 const std::vector<size_type> &local_dof_indices,
1404 local_lines (local_constraints),
1419 lines (constraint_matrix.lines),
1420 lines_cache (constraint_matrix.lines_cache),
1421 local_lines (constraint_matrix.local_lines),
1422 sorted (constraint_matrix.sorted)
1452 lines.back().line = line;
1453 lines.back().inhomogeneity = 0.;
1467 ExcMessage (
"Can't constrain a degree of freedom to itself"));
1478 for (ConstraintLine::Entries::const_iterator
1480 p != line_ptr->
entries.end(); ++p)
1481 if (p->first == column)
1483 Assert (std::fabs(p->second - value) < 1.e-14,
1484 ExcEntryAlreadyExists(line, column, p->second, value));
1488 line_ptr->
entries.push_back (std::make_pair(column,value));
1501 ExcMessage(
"call add_line() before calling set_inhomogeneity()"));
1504 line_ptr->inhomogeneity = value;
1513 return lines.size();
1550 const std::vector<std::pair<types::global_dof_index,double> > *
1589 ExcRowNotStoredHere(line));
1613 template <
class VectorType>
1623 global_vector(index) += value;
1629 global_vector(position.
entries[j].first)
1630 += value * position.
entries[j].second;
1635 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
1639 ForwardIteratorVec local_vector_begin,
1640 ForwardIteratorVec local_vector_end,
1641 ForwardIteratorInd local_indices_begin,
1645 for ( ; local_vector_begin != local_vector_end;
1646 ++local_vector_begin, ++local_indices_begin)
1649 global_vector(*local_indices_begin) += *local_vector_begin;
1655 global_vector(position.
entries[j].first)
1656 += *local_vector_begin * position.
entries[j].second;
1662 template <
class InVector,
class OutVector>
1666 const InVector &local_vector,
1667 const std::vector<size_type> &local_dof_indices,
1668 OutVector &global_vector)
const
1670 Assert (local_vector.size() == local_dof_indices.size(),
1673 local_dof_indices.begin(), global_vector);
1678 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
1682 ForwardIteratorInd local_indices_begin,
1683 ForwardIteratorVec local_vector_begin,
1684 ForwardIteratorVec local_vector_end)
const
1687 for ( ; local_vector_begin != local_vector_end;
1688 ++local_vector_begin, ++local_indices_begin)
1691 *local_vector_begin = global_vector(*local_indices_begin);
1696 typename VectorType::value_type value = position.
inhomogeneity;
1698 value += (global_vector(position.
entries[j].first) *
1700 *local_vector_begin = value;
1707 template <
typename MatrixType>
1712 const std::vector<size_type> &local_dof_indices,
1713 MatrixType &global_matrix)
const
1719 global_matrix, dummy,
false,
1725 template <
typename MatrixType,
typename VectorType>
1731 const std::vector<size_type> &local_dof_indices,
1732 MatrixType &global_matrix,
1734 bool use_inhomogeneities_for_rhs)
const
1739 global_matrix, global_vector, use_inhomogeneities_for_rhs,
1745 template <
typename SparsityType>
1750 SparsityType &sparsity_pattern,
1751 const bool keep_constrained_entries,
1757 keep_constrained_entries, dof_mask,
1762 DEAL_II_NAMESPACE_CLOSE
const types::global_dof_index invalid_size_type
double get_inhomogeneity(const size_type line) const
types::global_dof_index index_within_set(const types::global_dof_index global_index) const
std::vector< size_type > lines_cache
bool can_store_line(const size_type line_index) const
bool is_constrained(const size_type index) const
types::global_dof_index size() const
const std::vector< std::pair< size_type, double > > * get_constraint_entries(const size_type line) const
::ExceptionBase & ExcMessage(std::string arg1)
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
void add_entries(const size_type line, const std::vector< std::pair< size_type, double > > &col_val_pairs)
const IndexSet & get_local_lines() const
size_type max_constraint_indirections() const
bool has_inhomogeneities() const
static const Table< 2, bool > default_empty_table
types::global_dof_index size_type
DeclException1(ExcLineInexistant, size_type,<< "The specified line "<< arg1<< " does not exist.")
std::vector< std::pair< size_type, double > > Entries
bool are_identity_constrained(const size_type index1, const size_type index2) const
void add_line(const size_type line)
void write_dot(std::ostream &) const
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
DeclException0(ExcMatrixIsClosed)
void add_entry(const size_type line, const size_type column, const double value)
unsigned int global_dof_index
#define Assert(cond, exc)
void condense(const SparsityPattern &uncondensed, SparsityPattern &condensed) const
ConstraintMatrix(const IndexSet &local_constraints=IndexSet())
bool operator<(const ConstraintLine &) const
bool is_inhomogeneously_constrained(const size_type index) const
bool operator==(const ConstraintLine &) const
void add_entries_local_to_global(const std::vector< size_type > &local_dof_indices, SparsityType &sparsity_pattern, const bool keep_constrained_entries=true, const Table< 2, bool > &dof_mask=default_empty_table) const
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
size_type calculate_line_index(const size_type line) const
DeclException4(ExcEntryAlreadyExists, size_type, size_type, double, double,<< "The entry for the indices "<< arg1<< " and "<< arg2<< " already exists, but the values "<< arg3<< " (old) and "<< arg4<< " (new) differ "<< "by "<< (arg4-arg3)<< ".")
void add_lines(const std::vector< bool > &lines)
static bool check_zero_weight(const std::pair< size_type, double > &p)
void print(std::ostream &) const
std::size_t memory_consumption() const
void merge(const ConstraintMatrix &other_constraints, const MergeConflictBehavior merge_conflict_behavior=no_conflicts_allowed)
std::size_t memory_consumption() const
DeclException2(ExcDoFConstrainedToConstrainedDoF, int, int,<< "You tried to constrain DoF "<< arg1<< " to DoF "<< arg2<< ", but that one is also constrained. This is not allowed!")
void shift(const size_type offset)
void set_zero(VectorType &vec) const
void resolve_indices(std::vector< types::global_dof_index > &indices) const
size_type n_constraints() const
void distribute(const VectorType &condensed, VectorType &uncondensed) const
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void reinit(const IndexSet &local_constraints=IndexSet())
void add_selected_constraints(const ConstraintMatrix &constraints_in, const IndexSet &filter)
void set_inhomogeneity(const size_type line, const double value)
std::vector< ConstraintLine > lines
::ExceptionBase & ExcInternalError()
void make_sorted_row_list(const std::vector< size_type > &local_dof_indices, internals::GlobalRowsFromLocal &global_rows) const
bool is_element(const types::global_dof_index index) const
double resolve_vector_entry(const size_type i, const internals::GlobalRowsFromLocal &global_rows, const Vector< double > &local_vector, const std::vector< size_type > &local_dof_indices, const FullMatrix< double > &local_matrix) const
void get_dof_values(const VectorType &global_vector, ForwardIteratorInd local_indices_begin, ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end) const
bool is_identity_constrained(const size_type index) const