55 , store_diagonal_first_in_row(false)
64 , 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)
82 , store_diagonal_first_in_row(m == n)
91 const std::vector<unsigned int> &row_lengths)
93 , store_diagonal_first_in_row(m == n)
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())),
355 const std::size_t nonzero_elements =
360 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
390 new_colnums[next_free_entry++] = tmp_entries[j];
394 next_row_start = next_free_entry;
411 (std::find(&new_colnums[
rowstart[line] + 1],
412 &new_colnums[next_row_start],
414 &new_colnums[next_row_start]),
417 (std::adjacent_find(&new_colnums[
rowstart[line] + 1],
418 &new_colnums[next_row_start]) ==
419 &new_colnums[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)
549template <
typename number>
556 const bool matrix_is_square = (
matrix.m() ==
matrix.n());
558 std::vector<unsigned int> entries_per_row(
matrix.m(), 0);
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];
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()) :
582 column_indices.resize(entries_per_row[row]);
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,
731template <
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)
767 for (ForwardIterator p =
begin; p !=
end; ++p)
774 for (ForwardIterator it =
begin; it !=
end; ++it)
816std::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 const unsigned int m = this->
n_rows();
917 const 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";
936 for (
const auto &entry : *
this)
938 out <<
" <rect class=\"pixel\" x=\"" << entry.column() + 1 <<
"\" y=\""
939 << entry.row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
941 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()));
1053SparsityPattern::add_entries<const SparsityPattern::size_type *>(
1058# ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
1061 std::vector<SparsityPattern::size_type>::const_iterator>(
1063 std::vector<size_type>::const_iterator,
1064 std::vector<size_type>::const_iterator,
1068SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1070 std::vector<size_type>::iterator,
1071 std::vector<size_type>::iterator,
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
void block_write(std::ostream &out) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
static ::ExceptionBase & ExcEmptyObject()
SparsityPattern & operator=(const SparsityPattern &)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
bool store_diagonal_first_in_row
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotQuadratic()
virtual void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths) override
size_type operator()(const size_type i, const size_type j) const
static ::ExceptionBase & ExcMessage(std::string arg1)
std::size_t memory_consumption() const
void block_read(std::istream &in)
#define AssertThrow(cond, exc)
std::size_t n_nonzero_elements() const
unsigned int max_row_length
void print_svg(std::ostream &out) const
void add(const size_type i, const size_type j)
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
unsigned int row_length(const size_type row) const
const IndexSet & row_index_set() const
static ::ExceptionBase & ExcNotCompressed()
std::unique_ptr< size_type[]> colnums
std::unique_ptr< std::size_t[]> rowstart
void print(std::ostream &out) const
size_type row_length(const size_type row) const
bool exists(const size_type i, const size_type j) const
void print_gnuplot(std::ostream &out) const
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
static const size_type invalid_entry
size_type bandwidth() const
bool is_compressed() const
size_type max_entries_per_row() const
size_type column_number(const size_type row, const size_type index) const
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
std::size_t memory_consumption() const
bool exists(const size_type i, const size_type j) const
size_type row_position(const size_type i, const size_type j) const
static ::ExceptionBase & ExcMatrixIsCompressed()
@ matrix
Contents is actually a matrix.
types::global_dof_index size_type
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
void copy(const T *begin, const T *end, U *dest)
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 > &)