40 , store_diagonal_first_in_row(false)
57 "This constructor can only be called if the provided argument "
58 "is the sparsity pattern for an empty matrix. This constructor can "
59 "not be used to copy-construct a non-empty sparsity pattern."));
68 const unsigned int max_per_row)
78 const std::vector<unsigned int> &row_lengths)
87 const unsigned int max_per_row)
96 const std::vector<unsigned int> &row_lengths)
105 const unsigned int max_per_row,
127 const size_type *
const original_row_start =
131 const size_type *
const original_row_end =
137 const size_type *
const original_last_before_side_diagonals =
138 (row > extra_off_diagonals ?
141 row - extra_off_diagonals) :
144 const size_type *
const original_first_after_side_diagonals =
145 (row <
rows - extra_off_diagonals - 1 ?
146 std::upper_bound(original_row_start,
148 row + extra_off_diagonals) :
156 next_free_slot =
std::copy(original_row_start,
157 original_last_before_side_diagonals,
162 ++i, ++next_free_slot)
163 *next_free_slot = row - i;
165 ++i, ++next_free_slot)
166 *next_free_slot = row + i;
169 next_free_slot =
std::copy(original_first_after_side_diagonals,
189 "This operator can only be called if the provided argument "
190 "is the sparsity pattern for an empty matrix. This operator can "
191 "not be used to copy a non-empty sparsity pattern."));
194 ExcMessage(
"This operator can only be called if the current object is "
211 if ((m == 0) || (n == 0))
236 std::size_t vec_len = 0;
254 (row_lengths.
empty() ?
257 *std::max_element(row_lengths.
begin(), row_lengths.
end())),
312 const std::vector<unsigned int> &row_lengths)
322 const unsigned int max_per_row)
325 const std::vector<unsigned int> row_lengths(m, max_per_row);
326 reinit(m, n, row_lengths);
349 const std::size_t nonzero_elements =
354 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
384 new_colnums[next_free_entry++] = tmp_entries[j];
388 next_row_start = next_free_entry;
405 (std::find(&new_colnums[
rowstart[line] + 1],
406 &new_colnums[next_row_start],
408 &new_colnums[next_row_start]),
411 (std::adjacent_find(&new_colnums[
rowstart[line] + 1],
412 &new_colnums[next_row_start]) ==
413 &new_colnums[next_row_start]),
425 colnums = std::move(new_colnums);
442 const bool do_diag_optimize = (sp.
n_rows() == sp.
n_cols());
443 std::vector<unsigned int> row_lengths(sp.
n_rows());
447 if (do_diag_optimize && !sp.
exists(i, i))
460 end_row = sp.
end(row);
462 for (; col_num != end_row; ++col_num)
465 if ((col != row) || !do_diag_optimize)
486 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
489 std::vector<unsigned int> row_lengths(dsp.
n_rows());
491 if (row_index_set.size() == 0)
496 if (do_diag_optimize && !dsp.
exists(i, i))
504 if (row_index_set.is_element(i))
507 if (do_diag_optimize && !dsp.
exists(i, i))
516 row_lengths[i] = do_diag_optimize ? 1 : 0;
527 for (
unsigned int index = 0; index <
row_length; ++index)
530 if ((col != row) || !do_diag_optimize)
543 template <
typename number>
550 const bool matrix_is_square = (
matrix.m() ==
matrix.n());
552 std::vector<unsigned int> entries_per_row(
matrix.m(), 0);
556 if (
matrix(row, col) != 0)
557 ++entries_per_row[row];
558 if (matrix_is_square && (
matrix(row, row) == 0))
559 ++entries_per_row[row];
569 std::vector<size_type> column_indices;
570 column_indices.reserve(
571 entries_per_row.size() > 0 ?
572 *std::max_element(entries_per_row.begin(), entries_per_row.end()) :
576 column_indices.resize(entries_per_row[row]);
580 if (
matrix(row, col) != 0)
582 column_indices[current_index] = col;
589 if (matrix_is_square && (col == row))
591 column_indices[current_index] = row;
599 add_entries(row, column_indices.begin(), column_indices.end(),
true);
649 std::pair<SparsityPattern::size_type, SparsityPattern::size_type>
668 return std::make_pair(row, col);
683 std::abs(
static_cast<int>(i -
colnums[j]))) >
b)
684 b = std::abs(
static_cast<signed int>(i -
colnums[j]));
740 Utilities::lower_bound<const size_type *>(sorted_region_start,
779 template <
typename ForwardIterator>
782 ForwardIterator
begin,
784 const bool indices_are_sorted)
787 if (indices_are_sorted ==
true)
791 ForwardIterator it =
begin;
792 bool has_larger_entries =
false;
800 has_larger_entries =
true;
803 if (has_larger_entries ==
false)
804 for (; it !=
end; ++it)
817 for (ForwardIterator p =
begin; p !=
end; ++p)
824 for (ForwardIterator it =
begin; it !=
end; ++it)
834 const bool indices_are_sorted)
906 out <<
']' << std::endl;
927 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
937 const unsigned int m = this->
n_rows();
938 const unsigned int n = this->
n_cols();
940 <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 "
941 << n + 2 <<
" " << m + 2
943 "<style type=\"text/css\" >\n"
951 << n + 2 <<
"\" height=\"" << m + 2
952 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n"
953 " <rect x=\"1\" y=\"1\" width=\""
954 << n + 0.1 <<
"\" height=\"" << m + 0.1
955 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
957 for (
const auto &entry : *
this)
959 out <<
" <rect class=\"pixel\" x=\"" << entry.column() + 1 <<
"\" y=\""
960 << entry.row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
962 out <<
"</svg>" << std::endl;
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()),
1023 reinterpret_cast<char *
>(
colnums.get()));
1047 SparsityPattern::add_entries<const SparsityPattern::size_type *>(
1052 # ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
1055 std::vector<SparsityPattern::size_type>::const_iterator>(
1057 std::vector<size_type>::const_iterator,
1058 std::vector<size_type>::const_iterator,
1062 SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1064 std::vector<size_type>::iterator,
1065 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)
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
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
virtual void add_entries(const ArrayView< const std::pair< size_type, size_type >> &entries)
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
types::global_dof_index size_type
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 & ExcInternalError()
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcEmptyObject()
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcMatrixIsCompressed()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcNotQuadratic()
#define AssertThrow(cond, exc)
@ 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 * begin(VectorType &V)
VectorType::value_type * end(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