39 , store_diagonal_first_in_row(false)
55 "This constructor can only be called if the provided argument "
56 "is the sparsity pattern for an empty matrix. This constructor can "
57 "not be used to copy-construct a non-empty sparsity pattern."));
66 const unsigned int max_per_row)
76 const std::vector<unsigned int> &row_lengths)
85 const unsigned int max_per_row)
94 const std::vector<unsigned int> &row_lengths)
103 const unsigned int max_per_row,
125 const size_type *
const original_row_start =
129 const size_type *
const original_row_end =
135 const size_type *
const original_last_before_side_diagonals =
136 (row > extra_off_diagonals ?
139 row - extra_off_diagonals) :
142 const size_type *
const original_first_after_side_diagonals =
143 (row <
rows - extra_off_diagonals - 1 ?
144 std::upper_bound(original_row_start,
146 row + extra_off_diagonals) :
154 next_free_slot = std::copy(original_row_start,
155 original_last_before_side_diagonals,
160 ++i, ++next_free_slot)
161 *next_free_slot = row - i;
163 ++i, ++next_free_slot)
164 *next_free_slot = row + i;
167 next_free_slot = std::copy(original_first_after_side_diagonals,
186 "This operator can only be called if the provided argument "
187 "is the sparsity pattern for an empty matrix. This operator can "
188 "not be used to copy a non-empty sparsity pattern."));
191 ExcMessage(
"This operator can only be called if the current object is "
208 if ((m == 0) || (n == 0))
233 std::size_t vec_len = 0;
251 (row_lengths.
empty() ?
254 *std::max_element(row_lengths.
begin(), row_lengths.
end())),
309 const std::vector<unsigned int> &row_lengths)
319 const unsigned int max_per_row)
322 const std::vector<unsigned int> row_lengths(m, max_per_row);
323 reinit(m, n, row_lengths);
342 std::size_t next_free_entry = 0, next_row_start = 0,
row_length = 0;
346 const std::size_t nonzero_elements =
351 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
381 new_colnums[next_free_entry++] = tmp_entries[j];
385 next_row_start = next_free_entry;
402 (std::find(&new_colnums[
rowstart[line] + 1],
403 &new_colnums[next_row_start],
405 &new_colnums[next_row_start]),
408 (std::adjacent_find(&new_colnums[
rowstart[line] + 1],
409 &new_colnums[next_row_start]) ==
410 &new_colnums[next_row_start]),
422 colnums = std::move(new_colnums);
439 const bool do_diag_optimize = (sp.
n_rows() == sp.
n_cols());
440 std::vector<unsigned int> row_lengths(sp.
n_rows());
444 if (do_diag_optimize && !sp.
exists(i, i))
457 end_row = sp.
end(row);
459 for (; col_num != end_row; ++col_num)
462 if ((col != row) || !do_diag_optimize)
483 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
486 std::vector<unsigned int> row_lengths(dsp.
n_rows());
488 if (row_index_set.size() == 0)
493 if (do_diag_optimize && !dsp.
exists(i, i))
501 if (row_index_set.is_element(i))
504 if (do_diag_optimize && !dsp.
exists(i, i))
513 row_lengths[i] = do_diag_optimize ? 1 : 0;
524 for (
unsigned int index = 0; index <
row_length; ++index)
527 if ((col != row) || !do_diag_optimize)
540template <
typename number>
547 const bool matrix_is_square = (matrix.m() == matrix.n());
549 std::vector<unsigned int> entries_per_row(matrix.m(), 0);
550 for (
size_type row = 0; row < matrix.m(); ++row)
552 for (
size_type col = 0; col < matrix.n(); ++col)
553 if (matrix(row, col) != 0)
554 ++entries_per_row[row];
555 if (matrix_is_square && (matrix(row, row) == 0))
556 ++entries_per_row[row];
559 reinit(matrix.m(), matrix.n(), entries_per_row);
566 std::vector<size_type> column_indices;
567 column_indices.reserve(
568 entries_per_row.size() > 0 ?
569 *std::max_element(entries_per_row.begin(), entries_per_row.end()) :
571 for (
size_type row = 0; row < matrix.m(); ++row)
573 column_indices.resize(entries_per_row[row]);
576 for (
size_type col = 0; col < matrix.n(); ++col)
577 if (matrix(row, col) != 0)
579 column_indices[current_index] = col;
586 if (matrix_is_square && (col == row))
588 column_indices[current_index] = row;
596 add_entries(row, column_indices.begin(), column_indices.end(),
true);
655 Utilities::lower_bound<const size_type *>(sorted_region_start,
684std::pair<SparsityPattern::size_type, SparsityPattern::size_type>
703 return std::make_pair(row, col);
794template <
typename ForwardIterator>
797 ForwardIterator begin,
799 const bool indices_are_sorted)
802 if (indices_are_sorted ==
true)
806 ForwardIterator it =
begin;
807 bool has_larger_entries =
false;
815 has_larger_entries =
true;
818 if (has_larger_entries ==
false)
819 for (; it !=
end; ++it)
832 for (ForwardIterator p =
begin; p !=
end; ++p)
839 for (ForwardIterator it =
begin; it !=
end; ++it)
849 const bool indices_are_sorted)
932 out <<
']' << std::endl;
953 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
963 const unsigned int m = this->
n_rows();
964 const unsigned int n = this->
n_cols();
966 <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 "
967 << n + 2 <<
" " << m + 2
969 "<style type=\"text/css\" >\n"
977 << n + 2 <<
"\" height=\"" << m + 2
978 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n"
979 " <rect x=\"1\" y=\"1\" width=\""
980 << n + 0.1 <<
"\" height=\"" << m + 0.1
981 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
983 for (
const auto &entry : *
this)
985 out <<
" <rect class=\"pixel\" x=\"" << entry.column() + 1 <<
"\" y=\""
986 << entry.row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
988 out <<
"</svg>" << std::endl;
1003 out.write(
reinterpret_cast<const char *
>(
rowstart.get()),
1005 reinterpret_cast<const char *
>(
rowstart.get()));
1007 out.write(
reinterpret_cast<const char *
>(
colnums.get()),
1009 reinterpret_cast<const char *
>(
colnums.get()));
1040 in.read(
reinterpret_cast<char *
>(
rowstart.get()),
1042 reinterpret_cast<char *
>(
rowstart.get()));
1047 in.read(
reinterpret_cast<char *
>(
colnums.get()),
1049 reinterpret_cast<char *
>(
colnums.get()));
1073SparsityPattern::add_entries<const SparsityPattern::size_type *>(
1078# ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
1081 std::vector<SparsityPattern::size_type>::const_iterator>(
1083 std::vector<size_type>::const_iterator,
1084 std::vector<size_type>::const_iterator,
1088SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1090 std::vector<size_type>::iterator,
1091 std::vector<size_type>::iterator,
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
const IndexSet & row_index_set() const
size_type row_length(const size_type row) const
size_type column_number(const size_type row, const size_type index) const
bool exists(const size_type i, const size_type j) const
virtual void resize(const size_type rows, const size_type cols)
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
void block_write(std::ostream &out) const
void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths)
void print_svg(std::ostream &out) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
size_type bandwidth() const
void print_gnuplot(std::ostream &out) const
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
bool is_compressed() const
SparsityPattern & operator=(const SparsityPattern &)
std::size_t n_nonzero_elements() const
bool exists(const size_type i, const size_type j) const
std::unique_ptr< size_type[]> colnums
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
static constexpr size_type invalid_entry
size_type row_position(const size_type i, const size_type j) const
std::unique_ptr< std::size_t[]> rowstart
void print(std::ostream &out) const
void add(const size_type i, const size_type j)
bool store_diagonal_first_in_row
size_type max_entries_per_row() const
unsigned int max_row_length
size_type operator()(const size_type i, const size_type j) const
unsigned int row_length(const size_type row) const
std::size_t memory_consumption() const
bool operator==(const SparsityPattern &) const
void block_read(std::istream &in)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcEmptyObject()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMatrixIsCompressed()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
constexpr types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)