16 #include <deal.II/base/memory_consumption.h> 17 #include <deal.II/base/utilities.h> 19 #include <deal.II/lac/dynamic_sparsity_pattern.h> 20 #include <deal.II/lac/sparsity_pattern.h> 28 DEAL_II_NAMESPACE_OPEN
32 template <
typename ForwardIterator>
36 const bool indices_are_sorted)
44 if (indices_are_sorted ==
true && n_elements > 3)
52 for (; test1 !=
end; ++test, ++test1)
67 ForwardIterator my_it =
begin;
69 std::vector<size_type>::iterator it =
106 std::vector<size_type>::iterator it2 = it + (
end - my_it);
115 else if (*my_it == *it2)
142 ForwardIterator my_it =
begin;
146 if (stop_size >
entries.capacity())
150 std::vector<size_type>::iterator it, it2;
183 for (; my_it !=
end; ++my_it)
218 return entries.capacity() *
sizeof(
size_type) +
sizeof(
Line);
233 , have_entries(false)
241 "This constructor can only be called if the provided argument " 242 "is the sparsity pattern for an empty matrix. This constructor can " 243 "not be used to copy-construct a non-empty sparsity pattern."));
251 : have_entries(false)
261 : have_entries(false)
271 : have_entries(false)
287 "This operator can only be called if the provided argument " 288 "is the sparsity pattern for an empty matrix. This operator can " 289 "not be used to copy a non-empty sparsity pattern."));
292 ExcMessage(
"This operator can only be called if the current object is" 312 "The IndexSet argument to this function needs to either " 313 "be empty (indicating the complete set of rows), or have size " 314 "equal to the desired number of rows as specified by the " 315 "first argument to this function. (Of course, the number " 316 "of indices in this IndexSet may be less than the number " 317 "of rows, but the *size* of the IndexSet must be equal.)"));
320 lines.swap(new_lines);
334 return ((
rows == 0) && (
cols == 0));
346 for (
const auto &line :
lines)
348 m = std::max(m, static_cast<size_type>(line.entries.size()));
364 "The row IndexSet does not contain the index i. This sparsity pattern " 365 "object cannot know whether the entry (i, j) exists or not."));
378 return std::binary_search(
lines[rowindex].entries.begin(),
379 lines[rowindex].entries.end(),
406 for (std::vector<size_type>::const_iterator j =
407 lines[row].entries.begin();
408 j !=
lines[row].entries.end();
433 lines[rowindex].entries = std::vector<size_type>();
445 const auto end = rows.
end();
447 for (
auto it =
rows.begin(); it !=
end; ++it, ++view_row)
452 view.
lines[view_row].entries =
lines[rowindex].entries;
460 template <
typename SparsityPatternTypeLeft,
typename SparsityPatternTypeRight>
463 const SparsityPatternTypeLeft & sp_A,
464 const SparsityPatternTypeRight &sp_B)
466 Assert(sp_A.n_rows() == sp_B.n_rows(),
469 this->
reinit(sp_A.n_cols(), sp_B.n_cols());
476 std::vector<size_type> new_cols;
477 new_cols.reserve(sp_B.max_entries_per_row());
480 for (
size_type i = 0; i < sp_A.n_rows(); ++i)
483 new_cols.resize(sp_B.row_length(i));
485 const auto last_il = sp_B.end(i);
486 auto * col_ptr = new_cols.data();
487 for (
auto il = sp_B.begin(i); il != last_il; ++il)
488 *col_ptr++ = il->column();
490 std::sort(new_cols.begin(), new_cols.end());
493 const auto last_ik = sp_A.end(i);
494 for (
auto ik = sp_A.begin(i); ik != last_ik; ++ik)
495 this->
add_entries(ik->column(), new_cols.begin(), new_cols.end(),
true);
501 template <
typename SparsityPatternTypeLeft,
typename SparsityPatternTypeRight>
504 const SparsityPatternTypeLeft & left,
505 const SparsityPatternTypeRight &right)
507 Assert(left.n_cols() == right.n_rows(),
510 this->
reinit(left.n_rows(), right.n_cols());
512 typename SparsityPatternTypeLeft::iterator it_left = left.begin(),
513 end_left = left.end();
514 for (; it_left != end_left; ++it_left)
516 const unsigned int j = it_left->column();
522 typename SparsityPatternTypeRight::iterator it_right = right.begin(j),
523 end_right = right.end(j);
524 for (; it_right != end_right; ++it_right)
525 this->
add(it_left->row(), it_right->column());
538 for (
const auto entry :
lines[row].entries)
541 out <<
']' << std::endl;
557 for (
const auto entry :
lines[row].entries)
563 out << entry <<
" " << -
static_cast<signed int>(rowindex) << std::endl;
581 for (
const auto entry :
lines[row].entries)
582 if (static_cast<size_type>(
583 std::abs(static_cast<int>(rowindex - entry))) > b)
584 b = std::abs(static_cast<signed int>(rowindex - entry));
599 for (
const auto &line :
lines)
601 n += line.entries.size();
612 std::set<types::global_dof_index>
cols;
613 for (
const auto &line :
lines)
614 cols.insert(line.entries.begin(), line.entries.end());
629 std::vector<types::global_dof_index>
rows;
630 auto line =
lines.begin();
632 for (
const auto &row : locally_stored_rows)
634 if (line->entries.size() > 0)
654 for (
const auto &line :
lines)
668 ExcIndexRangeType<DynamicSparsityPattern::size_type>(row,
672 ExcIndexRangeType<DynamicSparsityPattern::size_type>(row,
682 const auto &
cols =
lines[local_row].entries;
685 if ((it !=
cols.end()) && (*it == col))
686 return (it -
cols.begin());
700 #ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER 703 std::vector<size_type>::iterator,
707 std::vector<size_type>::const_iterator,
708 std::vector<size_type>::const_iterator,
738 DEAL_II_NAMESPACE_CLOSE
Iterator lower_bound(Iterator first, Iterator last, const T &val)
const types::global_dof_index invalid_size_type
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
#define AssertDimension(dim1, dim2)
ElementIterator end() const
std::vector< Line > lines
std::vector< size_type > entries
void clear_row(const size_type row)
size_type nth_index_in_set(const unsigned int local_index) const
static ::ExceptionBase & ExcIO()
void add(const size_type i, const size_type j)
size_type max_entries_per_row() const
#define AssertIndexRange(index, range)
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
size_type memory_consumption() const
static ::ExceptionBase & ExcMessage(std::string arg1)
void compute_Tmmult_pattern(const SparsityPatternTypeLeft &left, const SparsityPatternTypeRight &right)
DynamicSparsityPattern get_view(const IndexSet &rows) const
#define Assert(cond, exc)
void add_entries(ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted)
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
size_type index_within_set(const size_type global_index) const
void print_gnuplot(std::ostream &out) const
void compute_mmult_pattern(const SparsityPatternTypeLeft &left, const SparsityPatternTypeRight &right)
size_type memory_consumption() const
size_type n_nonzero_elements() const
static ::ExceptionBase & ExcNotQuadratic()
unsigned int global_dof_index
types::global_dof_index size_type
DynamicSparsityPattern & operator=(const DynamicSparsityPattern &)
IndexSet nonempty_rows() const
void print(std::ostream &out) const
bool is_element(const size_type index) const
size_type bandwidth() const
bool exists(const size_type i, const size_type j) const
size_type column_index(const size_type row, const size_type col) const
size_type n_elements() const
IndexSet nonempty_cols() const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
static ::ExceptionBase & ExcInternalError()