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> 41 template<
int dim,
class T>
class Table;
58 class GlobalRowsFromLocal;
210 bool can_store_line (
const size_type line_index)
const;
218 const IndexSet &get_local_lines()
const;
251 void add_line (
const size_type line);
266 void add_lines (
const std::vector<bool> &lines);
281 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;
626 template<
typename number>
635 template<
typename number>
641 template <
typename number>
660 template <
class VectorType>
661 void condense (
const VectorType &uncondensed,
673 template <
class VectorType>
674 void condense (VectorType &vec)
const;
689 template<
typename number,
class VectorType>
691 const VectorType &uncondensed_vector,
700 template<
typename number,
class VectorType>
702 VectorType &vector)
const;
708 template <
typename number,
class BlockVectorType>
710 BlockVectorType &vector)
const;
718 template <
class VectorType>
719 void set_zero (VectorType &vec)
const;
766 template <
class InVector,
class OutVector>
768 distribute_local_to_global (
const InVector &local_vector,
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,
819 VectorType &global_vector,
825 template <
class VectorType>
827 distribute_local_to_global (
const size_type index,
829 VectorType &global_vector)
const;
859 template <
typename ForwardIteratorVec,
typename ForwardIteratorInd,
862 distribute_local_to_global (ForwardIteratorVec local_vector_begin,
863 ForwardIteratorVec local_vector_end,
864 ForwardIteratorInd local_indices_begin,
865 VectorType &global_vector)
const;
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,
945 VectorType &global_vector,
946 bool use_inhomogeneities_for_rhs =
false)
const;
1000 template <
typename SparsityType>
1002 add_entries_local_to_global (
const std::vector<size_type> &local_dof_indices,
1003 SparsityType &sparsity_pattern,
1004 const bool keep_constrained_entries =
true,
1010 template <
typename SparsityType>
1012 add_entries_local_to_global (
const std::vector<size_type> &row_indices,
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,
1040 get_dof_values (
const VectorType &global_vector,
1041 ForwardIteratorInd local_indices_begin,
1042 ForwardIteratorVec local_vector_begin,
1043 ForwardIteratorVec local_vector_end)
const;
1066 template <
class VectorType>
1067 void distribute (
const VectorType &condensed,
1068 VectorType &uncondensed)
const;
1079 template <
class VectorType>
1080 void distribute (VectorType &vec)
const;
1105 <<
"The specified line " << arg1
1106 <<
" does not exist.");
1113 size_type, size_type,
double,
double,
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;
1231 std::size_t memory_consumption ()
const;
1297 size_type calculate_line_index (
const size_type line)
const;
1303 static bool check_zero_weight (
const std::pair<size_type, double> &p);
1315 template <
typename MatrixType,
typename VectorType>
1319 const std::vector<size_type> &local_dof_indices,
1320 MatrixType &global_matrix,
1321 VectorType &global_vector,
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,
1335 VectorType &global_vector,
1336 bool use_inhomogeneities_for_rhs,
1343 template <
typename SparsityType>
1345 add_entries_local_to_global (
const std::vector<size_type> &local_dof_indices,
1346 SparsityType &sparsity_pattern,
1347 const bool keep_constrained_entries,
1355 template <
typename SparsityType>
1357 add_entries_local_to_global (
const std::vector<size_type> &local_dof_indices,
1358 SparsityType &sparsity_pattern,
1359 const bool keep_constrained_entries,
1371 make_sorted_row_list (
const std::vector<size_type> &local_dof_indices,
1382 make_sorted_row_list (
const std::vector<size_type> &local_dof_indices,
1383 std::vector<size_type> &active_dofs)
const;
1389 resolve_vector_entry (
const size_type i,
1392 const std::vector<size_type> &local_dof_indices,
1404 local_lines (local_constraints),
1452 lines.back().line = line;
1453 lines.back().inhomogeneity = 0.;
1462 const size_type column,
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>
1616 const size_type index,
1618 VectorType &global_vector)
const 1623 global_vector(index) += value;
1628 for (size_type j=0; j<position.
entries.size(); ++j)
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,
1642 VectorType &global_vector)
const 1645 for ( ; local_vector_begin != local_vector_end;
1646 ++local_vector_begin, ++local_indices_begin)
1649 global_vector(*local_indices_begin) += *local_vector_begin;
1654 for (size_type j=0; j<position.
entries.size(); ++j)
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;
1697 for (size_type j=0; j<position.
entries.size(); ++j)
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,
1733 VectorType &global_vector,
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
#define DeclException2(Exception2, type1, type2, outsequence)
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...
const IndexSet & get_local_lines() const
static const Table< 2, bool > default_empty_table
types::global_dof_index size_type
std::vector< std::pair< size_type, double > > Entries
void add_line(const size_type line)
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
#define DeclException1(Exception1, type1, outsequence)
void add_entry(const size_type line, const size_type column, const double value)
unsigned int global_dof_index
#define Assert(cond, exc)
ConstraintMatrix(const IndexSet &local_constraints=IndexSet())
bool is_inhomogeneously_constrained(const size_type index) const
#define DeclException0(Exception0)
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
size_type n_constraints() const
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void set_inhomogeneity(const size_type line, const double value)
std::vector< ConstraintLine > lines
::ExceptionBase & ExcInternalError()
bool is_element(const types::global_dof_index index) const
void get_dof_values(const VectorType &global_vector, ForwardIteratorInd local_indices_begin, ForwardIteratorVec local_vector_begin, ForwardIteratorVec local_vector_end) const