39 , store_diagonal_first_in_row(false)
56 "This constructor can only be called if the provided argument "
57 "is the sparsity pattern for an empty matrix. This constructor can "
58 "not be used to copy-construct a non-empty sparsity pattern."));
67 const unsigned int max_per_row)
77 const std::vector<unsigned int> &row_lengths)
86 const unsigned int max_per_row)
95 const std::vector<unsigned int> &row_lengths)
104 const unsigned int max_per_row,
126 const size_type *
const original_row_start =
130 const size_type *
const original_row_end =
136 const size_type *
const original_last_before_side_diagonals =
137 (row > extra_off_diagonals ?
140 row - extra_off_diagonals) :
143 const size_type *
const original_first_after_side_diagonals =
144 (row <
rows - extra_off_diagonals - 1 ?
145 std::upper_bound(original_row_start,
147 row + extra_off_diagonals) :
155 next_free_slot = std::copy(original_row_start,
156 original_last_before_side_diagonals,
161 ++i, ++next_free_slot)
162 *next_free_slot = row - i;
164 ++i, ++next_free_slot)
165 *next_free_slot = row + i;
168 next_free_slot = std::copy(original_first_after_side_diagonals,
188 "This operator can only be called if the provided argument "
189 "is the sparsity pattern for an empty matrix. This operator can "
190 "not be used to copy a non-empty sparsity pattern."));
193 ExcMessage(
"This operator can only be called if the current object is "
210 if ((m == 0) || (n == 0))
235 std::size_t vec_len = 0;
253 (row_lengths.
empty() ?
256 *std::max_element(row_lengths.
begin(), row_lengths.
end())),
311 const std::vector<unsigned int> &row_lengths)
321 const unsigned int max_per_row)
324 const std::vector<unsigned int> row_lengths(m, max_per_row);
325 reinit(m, n, row_lengths);
348 const std::size_t nonzero_elements =
353 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
383 new_colnums[next_free_entry++] = tmp_entries[j];
387 next_row_start = next_free_entry;
404 (std::find(&new_colnums[
rowstart[line] + 1],
405 &new_colnums[next_row_start],
407 &new_colnums[next_row_start]),
410 (std::adjacent_find(&new_colnums[
rowstart[line] + 1],
411 &new_colnums[next_row_start]) ==
412 &new_colnums[next_row_start]),
424 colnums = std::move(new_colnums);
441 const bool do_diag_optimize = (sp.
n_rows() == sp.
n_cols());
442 std::vector<unsigned int> row_lengths(sp.
n_rows());
446 if (do_diag_optimize && !sp.
exists(i, i))
459 end_row = sp.
end(row);
461 for (; col_num != end_row; ++col_num)
464 if ((col != row) || !do_diag_optimize)
485 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
488 std::vector<unsigned int> row_lengths(dsp.
n_rows());
490 if (row_index_set.size() == 0)
495 if (do_diag_optimize && !dsp.
exists(i, i))
503 if (row_index_set.is_element(i))
506 if (do_diag_optimize && !dsp.
exists(i, i))
515 row_lengths[i] = do_diag_optimize ? 1 : 0;
526 for (
unsigned int index = 0; index <
row_length; ++index)
529 if ((col != row) || !do_diag_optimize)
542template <
typename number>
549 const bool matrix_is_square = (matrix.m() == matrix.n());
551 std::vector<unsigned int> entries_per_row(matrix.m(), 0);
552 for (
size_type row = 0; row < matrix.m(); ++row)
554 for (
size_type col = 0; col < matrix.n(); ++col)
555 if (matrix(row, col) != 0)
556 ++entries_per_row[row];
557 if (matrix_is_square && (matrix(row, row) == 0))
558 ++entries_per_row[row];
561 reinit(matrix.m(), matrix.n(), entries_per_row);
568 std::vector<size_type> column_indices;
569 column_indices.reserve(
570 entries_per_row.size() > 0 ?
571 *std::max_element(entries_per_row.begin(), entries_per_row.end()) :
573 for (
size_type row = 0; row < matrix.m(); ++row)
575 column_indices.resize(entries_per_row[row]);
578 for (
size_type col = 0; col < matrix.n(); ++col)
579 if (matrix(row, col) != 0)
581 column_indices[current_index] = col;
588 if (matrix_is_square && (col == row))
590 column_indices[current_index] = row;
598 add_entries(row, column_indices.begin(), column_indices.end(),
true);
648std::pair<SparsityPattern::size_type, SparsityPattern::size_type>
667 return std::make_pair(row, col);
778template <
typename ForwardIterator>
781 ForwardIterator begin,
783 const bool indices_are_sorted)
786 if (indices_are_sorted ==
true)
790 ForwardIterator it =
begin;
791 bool has_larger_entries =
false;
799 has_larger_entries =
true;
802 if (has_larger_entries ==
false)
803 for (; it !=
end; ++it)
816 for (ForwardIterator p =
begin; p !=
end; ++p)
823 for (ForwardIterator it =
begin; it !=
end; ++it)
833 const bool indices_are_sorted)
905 out <<
']' << std::endl;
926 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
936 const unsigned int m = this->
n_rows();
937 const unsigned int n = this->
n_cols();
939 <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 "
940 << n + 2 <<
" " << m + 2
942 "<style type=\"text/css\" >\n"
950 << n + 2 <<
"\" height=\"" << m + 2
951 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n"
952 " <rect x=\"1\" y=\"1\" width=\""
953 << n + 0.1 <<
"\" height=\"" << m + 0.1
954 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
956 for (
const auto &entry : *
this)
958 out <<
" <rect class=\"pixel\" x=\"" << entry.column() + 1 <<
"\" y=\""
959 << entry.row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
961 out <<
"</svg>" << std::endl;
976 out.write(
reinterpret_cast<const char *
>(
rowstart.get()),
978 reinterpret_cast<const char *
>(
rowstart.get()));
980 out.write(
reinterpret_cast<const char *
>(
colnums.get()),
982 reinterpret_cast<const char *
>(
colnums.get()));
1013 in.read(
reinterpret_cast<char *
>(
rowstart.get()),
1015 reinterpret_cast<char *
>(
rowstart.get()));
1020 in.read(
reinterpret_cast<char *
>(
colnums.get()),
1022 reinterpret_cast<char *
>(
colnums.get()));
1051# ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
1054 std::vector<SparsityPattern::size_type>::const_iterator>(
1056 std::vector<size_type>::const_iterator,
1057 std::vector<size_type>::const_iterator,
1061SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1063 std::vector<size_type>::iterator,
1064 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
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)
const 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 > &)