31template <
typename ForwardIterator>
35 const bool indices_are_sorted)
43 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)
237 "This constructor can only be called if the provided argument "
238 "is the sparsity pattern for an empty matrix. This constructor can "
239 "not be used to copy-construct a non-empty sparsity pattern."));
275 "This operator can only be called if the provided argument "
276 "is the sparsity pattern for an empty matrix. This operator can "
277 "not be used to copy a non-empty sparsity pattern."));
280 ExcMessage(
"This operator can only be called if the current object is "
299 "The IndexSet argument to this function needs to either "
300 "be empty (indicating the complete set of rows), or have size "
301 "equal to the desired number of rows as specified by the "
302 "first argument to this function. (Of course, the number "
303 "of indices in this IndexSet may be less than the number "
304 "of rows, but the *size* of the IndexSet must be equal.)"));
306 std::vector<Line> new_lines(
rowset.size() == 0 ?
n_rows() :
308 lines.swap(new_lines);
322 return ((
rows == 0) && (
cols == 0));
334 for (
const auto &line :
lines)
348 const bool indices_are_sorted)
363 "The row IndexSet does not contain the index i. This sparsity pattern "
364 "object cannot know whether the entry (i, j) exists or not."));
377 return std::binary_search(
lines[rowindex].entries.begin(),
378 lines[rowindex].entries.end(),
400 rowset.size() == 0 ? row :
rowset.nth_index_in_set(row);
404 if (rowindex != row_entry)
405 add(row_entry, rowindex);
422 rowset.size() == 0 ? row :
rowset.index_within_set(row);
425 lines[rowindex].entries = std::vector<size_type>();
434 view.
reinit(
rows.n_elements(), this->n_cols());
439 for (
auto it =
rows.begin(); it !=
end; ++it, ++view_row)
442 rowset.size() == 0 ? *it :
rowset.index_within_set(*it);
444 view.
lines[view_row].entries =
lines[rowindex].entries;
452template <
typename SparsityPatternTypeLeft,
typename SparsityPatternTypeRight>
455 const SparsityPatternTypeLeft &sp_A,
456 const SparsityPatternTypeRight &sp_B)
458 Assert(sp_A.n_rows() == sp_B.n_rows(),
461 this->
reinit(sp_A.n_cols(), sp_B.n_cols());
468 std::vector<size_type> new_cols;
469 new_cols.reserve(sp_B.max_entries_per_row());
472 for (
size_type i = 0; i < sp_A.n_rows(); ++i)
475 new_cols.resize(sp_B.row_length(i));
477 const auto last_il = sp_B.end(i);
478 auto *col_ptr = new_cols.data();
479 for (
auto il = sp_B.begin(i); il != last_il; ++il)
480 *col_ptr++ = il->column();
482 std::sort(new_cols.begin(), new_cols.end());
485 const auto last_ik = sp_A.end(i);
486 for (
auto ik = sp_A.begin(i); ik != last_ik; ++ik)
487 this->
add_entries(ik->column(), new_cols.begin(), new_cols.end(),
true);
493template <
typename SparsityPatternTypeLeft,
typename SparsityPatternTypeRight>
496 const SparsityPatternTypeLeft &left,
497 const SparsityPatternTypeRight &right)
499 Assert(left.n_cols() == right.n_rows(),
502 this->
reinit(left.n_rows(), right.n_cols());
504 typename SparsityPatternTypeLeft::iterator it_left = left.begin(),
505 end_left = left.end();
506 for (; it_left != end_left; ++it_left)
508 const unsigned int j = it_left->column();
514 typename SparsityPatternTypeRight::iterator it_right = right.begin(j),
515 end_right = right.end(j);
516 for (; it_right != end_right; ++it_right)
517 this->
add(it_left->row(), it_right->column());
528 out <<
'[' << (
rowset.size() == 0 ? row :
rowset.nth_index_in_set(row));
530 for (
const auto entry :
lines[row].entries)
533 out <<
']' << std::endl;
547 rowset.size() == 0 ? row :
rowset.nth_index_in_set(row);
549 for (
const auto entry :
lines[row].entries)
555 out << entry <<
" " << -
static_cast<signed int>(rowindex) << std::endl;
571 rowset.size() == 0 ? row :
rowset.nth_index_in_set(row);
573 for (
const auto entry :
lines[row].entries)
575 std::abs(
static_cast<int>(rowindex - entry))) > b)
576 b =
std::abs(
static_cast<signed int>(rowindex - entry));
591 for (
const auto &line :
lines)
593 n += line.entries.size();
604 std::set<types::global_dof_index>
cols;
605 for (
const auto &line :
lines)
606 cols.insert(line.entries.begin(), line.entries.end());
621 std::vector<types::global_dof_index>
rows;
622 auto line =
lines.begin();
624 for (
const auto row : locally_stored_rows)
626 if (line->entries.size() > 0)
646 for (
const auto &line :
lines)
664 rowset.size() != 0u ?
rowset.index_within_set(row) : row;
668 const auto &
cols =
lines[local_row].entries;
671 if ((it !=
cols.end()) && (*it == col))
672 return (it -
cols.begin());
686#ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
689 std::vector<size_type>::iterator,
693 std::vector<size_type>::const_iterator,
694 std::vector<size_type>::const_iterator,
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
IndexSet nonempty_cols() const
DynamicSparsityPattern get_view(const IndexSet &rows) const
types::global_dof_index size_type
size_type memory_consumption() const
void compute_mmult_pattern(const SparsityPatternTypeLeft &left, const SparsityPatternTypeRight &right)
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
size_type column_index(const size_type row, const size_type col) const
DynamicSparsityPattern & operator=(const DynamicSparsityPattern &)
std::vector< Line > lines
void print(std::ostream &out) const
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
void clear_row(const size_type row)
size_type max_entries_per_row() const
void print_gnuplot(std::ostream &out) const
size_type bandwidth() const
void compute_Tmmult_pattern(const SparsityPatternTypeLeft &left, const SparsityPatternTypeRight &right)
size_type n_nonzero_elements() const
bool exists(const size_type i, const size_type j) const
void add(const size_type i, const size_type j)
IndexSet nonempty_rows() const
size_type n_elements() const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
virtual void resize(const size_type rows, const size_type cols)
#define DEAL_II_NAMESPACE_OPEN
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
IndexSet complete_index_set(const IndexSet::size_type N)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
constexpr types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
void add_entries(ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted)
std::vector< size_type > entries
size_type memory_consumption() const