55 , store_diagonal_first_in_row(false)
69 "This constructor can only be called if the provided argument " 70 "is the sparsity pattern for an empty matrix. This constructor can " 71 "not be used to copy-construct a non-empty sparsity pattern."));
80 const unsigned int max_per_row)
91 const std::vector<unsigned int> &row_lengths)
101 const unsigned int max_per_row)
104 reinit(m, m, max_per_row);
110 const std::vector<unsigned int> &row_lengths)
113 reinit(m, m, row_lengths);
119 const unsigned int max_per_row,
141 const size_type *
const original_row_start =
145 const size_type *
const original_row_end =
151 const size_type *
const original_last_before_side_diagonals =
152 (row > extra_off_diagonals ?
155 row - extra_off_diagonals) :
158 const size_type *
const original_first_after_side_diagonals =
159 (row <
rows - extra_off_diagonals - 1 ?
160 std::upper_bound(original_row_start,
162 row + extra_off_diagonals) :
170 next_free_slot =
std::copy(original_row_start,
171 original_last_before_side_diagonals,
176 ++i, ++next_free_slot)
177 *next_free_slot = row - i;
179 ++i, ++next_free_slot)
180 *next_free_slot = row + i;
183 next_free_slot =
std::copy(original_first_after_side_diagonals,
203 "This operator can only be called if the provided argument " 204 "is the sparsity pattern for an empty matrix. This operator can " 205 "not be used to copy a non-empty sparsity pattern."));
208 ExcMessage(
"This operator can only be called if the current object is " 219 const unsigned int max_per_row)
222 const std::vector<unsigned int> row_lengths(m, max_per_row);
223 reinit(m, n, row_lengths);
239 if ((m == 0) || (n == 0))
264 std::size_t vec_len = 0;
282 (row_lengths.
size() == 0 ?
285 *std::max_element(row_lengths.
begin(), row_lengths.
end())),
317 static_cast<size_type>(1
U)) :
318 std::min(static_cast<size_type>(row_lengths[i - 1]), n));
319 Assert((rowstart[rows] == vec_len) ||
320 ((vec_len == 1) && (rowstart[rows] == 0)),
355 const std::size_t nonzero_elements =
360 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
371 for (
size_type j = rowstart[line]; j < rowstart[line + 1];
390 new_colnums[next_free_entry++] = tmp_entries[j];
393 rowstart[line] = next_row_start;
394 next_row_start = next_free_entry;
403 (row_length != 0 && new_colnums[rowstart[line]] == line),
410 Assert((rowstart[line] == next_row_start) ||
411 (std::find(&new_colnums[rowstart[line] + 1],
412 &new_colnums[next_row_start],
413 new_colnums[rowstart[line]]) ==
414 &new_colnums[next_row_start]),
416 Assert((rowstart[line] == next_row_start) ||
417 (std::adjacent_find(&new_colnums[rowstart[line] + 1],
418 &new_colnums[next_row_start]) ==
419 &new_colnums[next_row_start]),
427 rowstart[
rows] = next_row_start;
431 colnums = std::move(new_colnums);
448 const bool do_diag_optimize = (sp.
n_rows() == sp.
n_cols());
449 std::vector<unsigned int> row_lengths(sp.
n_rows());
453 if (do_diag_optimize && !sp.
exists(i, i))
466 end_row = sp.
end(row);
468 for (; col_num != end_row; ++col_num)
471 if ((col != row) || !do_diag_optimize)
492 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
495 std::vector<unsigned int> row_lengths(dsp.
n_rows());
497 if (row_index_set.size() == 0)
502 if (do_diag_optimize && !dsp.
exists(i, i))
510 if (row_index_set.is_element(i))
513 if (do_diag_optimize && !dsp.
exists(i, i))
522 row_lengths[i] = do_diag_optimize ? 1 : 0;
533 for (
unsigned int index = 0; index <
row_length; ++index)
536 if ((col != row) || !do_diag_optimize)
549 template <
typename number>
556 const bool matrix_is_square = (matrix.
m() == matrix.
n());
558 std::vector<unsigned int> entries_per_row(matrix.
m(), 0);
559 for (
size_type row = 0; row < matrix.
m(); ++row)
561 for (
size_type col = 0; col < matrix.
n(); ++col)
562 if (
matrix(row, col) != 0)
563 ++entries_per_row[row];
564 if (matrix_is_square && (
matrix(row, row) == 0))
565 ++entries_per_row[row];
568 reinit(matrix.
m(), matrix.
n(), entries_per_row);
575 std::vector<size_type> column_indices;
576 column_indices.reserve(
577 entries_per_row.size() > 0 ?
578 *std::max_element(entries_per_row.begin(), entries_per_row.end()) :
580 for (
size_type row = 0; row < matrix.
m(); ++row)
582 column_indices.resize(entries_per_row[row]);
585 for (
size_type col = 0; col < matrix.
n(); ++col)
586 if (
matrix(row, col) != 0)
588 column_indices[current_index] = col;
595 if (matrix_is_square && (col == row))
597 column_indices[current_index] = row;
605 add_entries(row, column_indices.begin(), column_indices.end(),
true);
616 const std::vector<unsigned int> &row_lengths)
692 Utilities::lower_bound<const size_type *>(sorted_region_start,
695 if ((p != &
colnums[rowstart[i + 1]]) && (*p == j))
731 template <
typename ForwardIterator>
734 ForwardIterator
begin,
736 const bool indices_are_sorted)
738 if (indices_are_sorted ==
true)
742 ForwardIterator it =
begin;
743 bool has_larger_entries =
false;
751 has_larger_entries =
true;
754 if (has_larger_entries ==
false)
755 for (; it !=
end; ++it)
757 if (store_diagonal_first_in_row && *it == row)
759 Assert(k <= rowstart[row + 1],
761 rowstart[row + 1] - rowstart[row]));
767 for (ForwardIterator p = begin; p !=
end; ++p)
774 for (ForwardIterator it = begin; it !=
end; ++it)
809 return k - rowstart[i];
816 std::pair<SparsityPatternBase::size_type, SparsityPatternBase::size_type>
835 return std::make_pair(row, col);
887 out <<
']' << std::endl;
908 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
916 unsigned int m = this->
n_rows();
917 unsigned int n = this->
n_cols();
919 <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 " 920 << n + 2 <<
" " << m + 2
922 "<style type=\"text/css\" >\n" 930 << n + 2 <<
"\" height=\"" << m + 2
931 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n" 932 " <rect x=\"1\" y=\"1\" width=\"" 933 << n + 0.1 <<
"\" height=\"" << m + 0.1
934 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
937 for (; it !=
end; ++it)
939 out <<
" <rect class=\"pixel\" x=\"" << it->column() + 1 <<
"\" y=\"" 940 << it->row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
942 out <<
"</svg>" << std::endl;
956 if (static_cast<size_type>(
957 std::abs(static_cast<int>(i -
colnums[j]))) > b)
958 b = std::abs(static_cast<signed int>(i -
colnums[j]));
977 out.write(reinterpret_cast<const char *>(
rowstart.get()),
979 reinterpret_cast<const char *>(
rowstart.get()));
981 out.write(reinterpret_cast<const char *>(
colnums.get()),
983 reinterpret_cast<const char *>(
colnums.get()));
1014 in.read(reinterpret_cast<char *>(
rowstart.get()),
1016 reinterpret_cast<char *>(
rowstart.get()));
1021 in.read(reinterpret_cast<char *>(colnums.get()),
1022 reinterpret_cast<char *>(colnums.get() +
max_vec_len) -
1023 reinterpret_cast<char *>(colnums.get()));
1054 SparsityPattern::add_entries<const SparsityPattern::size_type *>(
1059 # ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER 1062 std::vector<SparsityPattern::size_type>::const_iterator>(
1064 std::vector<size_type>::const_iterator,
1065 std::vector<size_type>::const_iterator,
1069 SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1071 std::vector<size_type>::iterator,
1072 std::vector<size_type>::iterator,
Iterator lower_bound(Iterator first, Iterator last, const T &val)
void block_write(std::ostream &out) const
const types::global_dof_index invalid_size_type
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
#define AssertDimension(dim1, dim2)
unsigned int max_row_length
static ::ExceptionBase & ExcMatrixIsCompressed()
Contents is actually a matrix.
size_type operator()(const size_type i, const size_type j) const
static ::ExceptionBase & ExcIO()
size_type column_number(const size_type row, const size_type index) const
std::size_t memory_consumption() const
#define AssertIndexRange(index, range)
size_type row_position(const size_type i, const size_type j) const
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
size_type bandwidth() const
#define AssertThrow(cond, exc)
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
std::unique_ptr< std::size_t[]> rowstart
void print_gnuplot(std::ostream &out) const
static ::ExceptionBase & ExcNotCompressed()
size_type max_entries_per_row() const
virtual void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths) override
static ::ExceptionBase & ExcMessage(std::string arg1)
SparsityPatternBase::size_type size_type
#define Assert(cond, exc)
const IndexSet & row_index_set() const
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
std::size_t memory_consumption() const
void add(const size_type i, const size_type j)
#define DEAL_II_NAMESPACE_CLOSE
SparsityPattern & operator=(const SparsityPattern &)
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
std::size_t n_nonzero_elements() const
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
bool exists(const size_type i, const size_type j) const
std::unique_ptr< size_type[]> colnums
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
bool is_compressed() const
size_type row_length(const size_type row) const
bool store_diagonal_first_in_row
#define DEAL_II_NAMESPACE_OPEN
T min(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcEmptyObject()
void block_read(std::istream &in)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
static const size_type invalid_entry
bool exists(const size_type i, const size_type j) const
unsigned int row_length(const size_type row) const
void copy(const T *begin, const T *end, U *dest)
T max(const T &t, const MPI_Comm &mpi_communicator)
void print(std::ostream &out) const
void print_svg(std::ostream &out) const
static ::ExceptionBase & ExcInternalError()