17 #include <deal.II/base/vector_slice.h> 18 #include <deal.II/base/utilities.h> 19 #include <deal.II/lac/sparsity_pattern.h> 20 #include <deal.II/lac/sparsity_tools.h> 21 #include <deal.II/lac/full_matrix.h> 22 #include <deal.II/lac/dynamic_sparsity_pattern.h> 31 DEAL_II_NAMESPACE_OPEN
47 store_diagonal_first_in_row(false)
62 store_diagonal_first_in_row(false)
66 ExcMessage(
"This constructor can only be called if the provided argument " 67 "is the sparsity pattern for an empty matrix. This constructor can " 68 "not be used to copy-construct a non-empty sparsity pattern."));
77 const unsigned int max_per_row)
84 store_diagonal_first_in_row(m == n)
93 const std::vector<unsigned int> &row_lengths)
99 store_diagonal_first_in_row(m == n)
101 reinit (m, n, row_lengths);
107 const unsigned int max_per_row)
114 reinit (m, m, max_per_row);
120 const std::vector<unsigned int> &row_lengths)
127 reinit (m, m, row_lengths);
133 const unsigned int max_per_row,
170 original_last_before_side_diagonals
171 = (row > extra_off_diagonals ?
174 row-extra_off_diagonals) :
178 original_first_after_side_diagonals
179 = (row <
rows-extra_off_diagonals-1 ?
180 std::upper_bound (original_row_start,
182 row+extra_off_diagonals) :
190 next_free_slot = std::copy (original_row_start,
191 original_last_before_side_diagonals,
195 for (
size_type i=1; i<=std::min(row,extra_off_diagonals);
196 ++i, ++next_free_slot)
197 *next_free_slot = row-i;
198 for (
size_type i=1; i<=std::min(extra_off_diagonals,
rows-row-1);
199 ++i, ++next_free_slot)
200 *next_free_slot = row+i;
203 next_free_slot = std::copy (original_first_after_side_diagonals,
230 ExcMessage(
"This operator can only be called if the provided argument " 231 "is the sparsity pattern for an empty matrix. This operator can " 232 "not be used to copy a non-empty sparsity pattern."));
235 ExcMessage(
"This operator can only be called if the current object is " 246 const unsigned int max_per_row)
249 const std::vector<unsigned int> row_lengths (m, max_per_row);
250 reinit (m, n, row_lengths);
258 const VectorSlice<
const std::vector<unsigned int> > &row_lengths)
266 if ((m==0) || (n==0))
291 std::size_t vec_len = 0;
294 std::max(row_lengths[i], 1U) :
316 std::min (static_cast<size_type>(*std::max_element(row_lengths.begin(),
359 std::max(std::min(static_cast<size_type>(row_lengths[i-1]),n),
360 static_cast<size_type> (1U)) :
361 std::min(static_cast<size_type>(row_lengths[i-1]),n));
396 const std::size_t nonzero_elements
399 std_cxx11::bind(std::not_equal_to<size_type>(), std_cxx11::_1,
invalid_entry));
425 ? tmp_entries.begin()+1
426 : tmp_entries.begin(),
431 new_colnums[next_free_entry++] = tmp_entries[j];
435 next_row_start = next_free_entry;
453 (std::find (&new_colnums[
rowstart[line]+1],
454 &new_colnums[next_row_start],
456 &new_colnums[next_row_start]),
460 (std::adjacent_find(&new_colnums[
rowstart[line]+1],
461 &new_colnums[next_row_start]) ==
462 &new_colnums[next_row_start]),
467 Assert (next_free_entry == nonzero_elements,
485 template <
typename SparsityPatternType>
493 const bool do_diag_optimize = (dsp.n_rows() == dsp.n_cols());
494 std::vector<unsigned int> row_lengths (dsp.n_rows());
497 row_lengths[i] = dsp.row_length(i);
498 if (do_diag_optimize && !dsp.exists(i,i))
501 reinit (dsp.n_rows(), dsp.n_cols(), row_lengths);
507 for (
size_type row = 0; row<dsp.n_rows(); ++row)
510 typename SparsityPatternType::iterator col_num = dsp.begin (row),
511 end_row = dsp.end (row);
513 for (; col_num != end_row; ++col_num)
516 if ((col!=row) || !do_diag_optimize)
538 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
539 std::vector<unsigned int> row_lengths (dsp.
n_rows());
543 if (do_diag_optimize && !dsp.
exists(i,i))
553 for (
unsigned int index=0; index <
row_length; ++index)
556 if ((col!=row) || !do_diag_optimize)
569 template <
typename number>
575 std::vector<unsigned int> entries_per_row (matrix.m(), 0);
576 for (
size_type row=0; row<matrix.m(); ++row)
578 for (
size_type col=0; col<matrix.n(); ++col)
579 if (matrix(row,col) != 0)
580 ++entries_per_row[row];
581 if ((matrix.m() == matrix.n())
583 (matrix(row,row) == 0))
584 ++entries_per_row[row];
587 reinit (matrix.m(), matrix.n(), entries_per_row);
590 for (
size_type row=0; row<matrix.m(); ++row)
591 for (
size_type col=0; col<matrix.n(); ++col)
592 if (matrix(row,col) != 0)
603 const std::vector<unsigned int> &row_lengths)
605 reinit(m, n, make_slice(row_lengths));
681 = Utilities::lower_bound<const size_type *> (sorted_region_start,
720 template <
typename ForwardIterator>
723 ForwardIterator begin,
725 const bool indices_are_sorted)
727 if (indices_are_sorted ==
true)
731 ForwardIterator it =
begin;
732 bool has_larger_entries =
false;
740 has_larger_entries =
true;
743 if (has_larger_entries ==
false)
744 for ( ; it !=
end; ++it)
755 for (ForwardIterator p =
begin; p !=
end; ++p)
762 for (ForwardIterator it =
begin; it !=
end; ++it)
778 if (
colnums[k] == j)
return true;
802 std::pair<SparsityPattern::size_type, SparsityPattern::size_type>
822 return std::make_pair (row,col);
874 out <<
']' << std::endl;
895 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
903 unsigned int m = this->
n_rows();
904 unsigned int n = this->
n_cols();
905 out <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 " << n+2
906 <<
" " << m+2 <<
" \">\n" 907 "<style type=\"text/css\" >\n" 914 " <rect width=\"" << n+2 <<
"\" height=\"" << m+2 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n" 915 " <rect x=\"1\" y=\"1\" width=\"" << n <<
"\" height=\"" << m
916 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
921 for (; it!=
end; ++it)
923 out <<
" <rect class=\"pixel\" x=\"" << it->
column()+1
924 <<
"\" y=\"" << it->
row()+1
925 <<
"\" width=\".9\" height=\".9\"/>\n";
927 out <<
"</svg>" << std::endl;
943 if (static_cast<size_type>(std::abs(static_cast<int>(i-
colnums[j]))) > b)
944 b = std::abs(static_cast<signed int>(i-
colnums[j]));
967 out.write (reinterpret_cast<const char *>(&
rowstart[0]),
969 - reinterpret_cast<const char *>(&
rowstart[0]));
971 out.write (reinterpret_cast<const char *>(&
colnums[0]),
973 - reinterpret_cast<const char *>(&
colnums[0]));
1014 in.read (reinterpret_cast<char *>(&
rowstart[0]),
1016 - reinterpret_cast<char *>(&
rowstart[0]));
1021 in.read (reinterpret_cast<char *>(&
colnums[0]),
1023 - reinterpret_cast<char *>(&
colnums[0]));
1041 template void SparsityPattern::copy_from<SparsityPattern> (
const SparsityPattern &);
1045 template void SparsityPattern::add_entries<const SparsityPattern::size_type *> (
const size_type ,
1049 #ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER 1050 template void SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::const_iterator>
1052 std::vector<size_type>::const_iterator,
1053 std::vector<size_type>::const_iterator,
1056 template void SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>
1058 std::vector<size_type>::iterator,
1059 std::vector<size_type>::iterator,
1062 DEAL_II_NAMESPACE_CLOSE
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)
static ::ExceptionBase & ExcMatrixIsCompressed()
#define AssertDimension(dim1, dim2)
std::size_t n_nonzero_elements() const
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
static const size_type invalid_entry
std::size_t memory_consumption() const
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
void print_gnuplot(std::ostream &out) const
bool exists(const size_type i, const size_type j) const
#define AssertThrow(cond, exc)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
bool is_compressed() const
size_type bandwidth() const
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcMessage(std::string arg1)
void add(const size_type i, const size_type j)
#define Assert(cond, exc)
void print_svg(std::ostream &out) const
void print(std::ostream &out) const
SparsityPattern & operator=(const SparsityPattern &)
size_type max_entries_per_row() const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
unsigned int max_row_length
static ::ExceptionBase & ExcNotQuadratic()
types::global_dof_index size_type
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
size_type row_length(const size_type row) const
bool store_diagonal_first_in_row
static ::ExceptionBase & ExcEmptyObject()
void block_read(std::istream &in)
bool exists(const size_type i, const size_type j) const
unsigned int row_length(const size_type row) const
size_type row_position(const size_type i, const size_type j) const
static ::ExceptionBase & ExcInternalError()