17 #ifndef __deal2__chunk_sparsity_pattern_h
18 #define __deal2__chunk_sparsity_pattern_h
21 #include <deal.II/base/config.h>
23 #include <deal.II/base/subscriptor.h>
24 #include <deal.II/base/vector_slice.h>
26 #include <deal.II/lac/sparsity_pattern.h>
70 const unsigned int row);
81 unsigned int row ()
const;
92 unsigned int column ()
const;
166 const unsigned int row);
297 const size_type max_chunks_per_row,
306 const size_type max_chunks_per_row,
320 const std::vector<size_type> &row_lengths,
329 const std::vector<size_type> &row_lengths,
342 const size_type max_per_row,
353 const std::vector<size_type> &row_lengths,
361 const std::vector<size_type> &row_lengths,
385 void reinit (
const size_type m,
387 const size_type max_per_row,
394 void reinit (
const size_type m,
396 const size_type max_per_row,
417 void reinit (
const size_type m,
419 const std::vector<size_type> &row_lengths,
426 void reinit (
const size_type m,
428 const std::vector<size_type > &row_lengths,
435 void reinit (
const size_type m,
437 const VectorSlice<
const std::vector<size_type> > &row_lengths,
444 void reinit (
const size_type m,
446 const VectorSlice<
const std::vector<size_type> > &row_lengths,
540 template <
typename ForwardIterator>
543 const ForwardIterator
begin,
544 const ForwardIterator
end,
551 template <
typename ForwardIterator>
554 const ForwardIterator
begin,
555 const ForwardIterator
end,
565 template <
typename SparsityType>
573 template <
typename SparsityType>
585 template <
typename number>
593 template <
typename number>
615 template <
typename Sparsity>
617 const unsigned int n,
618 const Sparsity &sparsity_pattern_for_chunks,
646 void add (
const size_type i,
662 inline size_type
n_rows ()
const;
668 inline size_type
n_cols ()
const;
673 bool exists (
const size_type i,
674 const size_type j)
const;
679 size_type
row_length (
const size_type row)
const;
731 iterator
begin () const;
736 iterator
end () const;
746 iterator
begin (const
unsigned int r) const;
756 iterator
end (const
unsigned int r) const;
790 void print (
std::ostream &out) const;
820 << "The provided number is
invalid here: " << arg1);
826 << "The given index " << arg1
827 << " should be less than " << arg2 << ".");
833 << "Upon entering a new entry to row " << arg1
834 << ": there was no free entry any more. " <<
std::endl
835 << "(Maximum number of entries for this row: "
836 << arg2 << "; maybe the matrix is already compressed?)");
858 << "The iterators denote a range of " << arg1
859 << " elements, but the given number of
rows was " << arg2);
869 << "The number of partitions you gave is " << arg1
870 << ", but must be greater than zero.");
876 << "The array has size " << arg1 << " but should have size "
923 const unsigned int row)
926 reduced_accessor(row==sparsity_pattern->
n_rows() ?
930 chunk_row (row==sparsity_pattern->
n_rows() ? 0 :
951 Accessor::is_valid_entry ()
const
953 return reduced_accessor.is_valid_entry()
955 sparsity_pattern->
get_chunk_size()*reduced_accessor.row()+chunk_row <
956 sparsity_pattern->
n_rows()
958 sparsity_pattern->
get_chunk_size()*reduced_accessor.column()+chunk_col <
959 sparsity_pattern->
n_cols();
966 Accessor::row()
const
970 return sparsity_pattern->
get_chunk_size()*reduced_accessor.row() +
978 Accessor::column()
const
982 return sparsity_pattern->
get_chunk_size()*reduced_accessor.column() +
990 Accessor::reduced_index()
const
994 return reduced_accessor.index_within_sparsity;
1002 Accessor::operator == (
const Accessor &other)
const
1007 return (reduced_accessor == other.reduced_accessor &&
1008 chunk_row == other.chunk_row &&
1009 chunk_col == other.chunk_col);
1016 Accessor::operator < (
const Accessor &other)
const
1021 if (chunk_row != other.chunk_row)
1023 if (reduced_accessor.index_within_sparsity ==
1024 reduced_accessor.sparsity_pattern->n_nonzero_elements())
1026 if (other.reduced_accessor.index_within_sparsity ==
1027 reduced_accessor.sparsity_pattern->n_nonzero_elements())
1031 global_row = sparsity_pattern->
get_chunk_size()*reduced_accessor.row()
1034 other.reduced_accessor.row()+other.chunk_row;
1035 if (global_row < other_global_row)
1037 else if (global_row > other_global_row)
1041 return (reduced_accessor.index_within_sparsity <
1042 other.reduced_accessor.index_within_sparsity ||
1043 (reduced_accessor.index_within_sparsity ==
1044 other.reduced_accessor.index_within_sparsity &&
1045 chunk_col < other.chunk_col));
1051 Accessor::advance ()
1053 const unsigned int chunk_size = sparsity_pattern->
get_chunk_size();
1054 Assert (chunk_row < chunk_size && chunk_col < chunk_size,
1056 Assert (reduced_accessor.row() * chunk_size + chunk_row <
1057 sparsity_pattern->
n_rows()
1059 reduced_accessor.column() * chunk_size + chunk_col <
1060 sparsity_pattern->
n_cols(),
1062 if (chunk_size == 1)
1064 reduced_accessor.advance();
1071 if (chunk_col == chunk_size
1073 reduced_accessor.column() * chunk_size + chunk_col ==
1074 sparsity_pattern->
n_cols())
1076 const unsigned int reduced_row = reduced_accessor.row();
1078 if (reduced_accessor.index_within_sparsity + 1 ==
1079 reduced_accessor.sparsity_pattern->rowstart[reduced_row+1])
1086 if (chunk_row == chunk_size ||
1087 (reduced_row * chunk_size + chunk_row ==
1088 sparsity_pattern->
n_rows()))
1091 reduced_accessor.advance();
1096 reduced_accessor.index_within_sparsity =
1097 reduced_accessor.sparsity_pattern->rowstart[reduced_row];
1102 reduced_accessor.advance();
1112 const unsigned int row)
1114 accessor(sparsity_pattern, row)
1121 Iterator::operator++ ()
1123 accessor.advance ();
1131 Iterator::operator++ (
int)
1133 const Iterator iter = *
this;
1134 accessor.advance ();
1142 Iterator::operator* ()
const
1151 Iterator::operator-> ()
const
1159 Iterator::operator == (
const Iterator &other)
const
1161 return (accessor == other.accessor);
1168 Iterator::operator != (
const Iterator &other)
const
1170 return ! (accessor == other.accessor);
1176 Iterator::operator < (
const Iterator &other)
const
1178 return accessor < other.accessor;
1217 return iterator(this, r+1);
1266 template <
typename ForwardIterator>
1271 const ForwardIterator
begin,
1272 const ForwardIterator
end,
1273 const size_type chunk_size,
1276 copy_from (n_rows, n_cols, begin, end, chunk_size);
1281 template <
typename ForwardIterator>
1285 const ForwardIterator
begin,
1286 const ForwardIterator
end,
1287 const size_type chunk_size)
1289 Assert (static_cast<size_type>(std::distance (begin, end)) == n_rows,
1290 ExcIteratorRange (std::distance (begin, end), n_rows));
1296 const bool is_square = (n_rows ==
n_cols);
1297 std::vector<size_type> row_lengths;
1298 row_lengths.reserve(n_rows);
1299 for (ForwardIterator i=begin; i!=
end; ++i)
1300 row_lengths.push_back (std::distance (i->begin(), i->end())
1302 (is_square ? 1 : 0));
1303 reinit (n_rows, n_cols, row_lengths, chunk_size);
1307 typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
1308 for (ForwardIterator i=begin; i!=
end; ++i, ++row)
1310 const inner_iterator end_of_row = i->end();
1311 for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
1314 = internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1315 Assert (col < n_cols, ExcInvalidIndex(col,n_cols));
1328 DEAL_II_NAMESPACE_CLOSE
bool optimize_diagonal() const DEAL_II_DEPRECATED
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end, const size_type chunk_size)
void block_write(std::ostream &out) const
void create_from(const unsigned int m, const unsigned int n, const Sparsity &sparsity_pattern_for_chunks, const unsigned int chunk_size, const bool optimize_diagonal=true)
std::size_t memory_consumption() const
Iterator(const ChunkSparsityPattern *sp, const unsigned int row)
void print_gnuplot(std::ostream &out) const
ChunkSparsityPattern & operator=(const ChunkSparsityPattern &)
bool is_compressed() const
bool exists(const size_type i, const size_type j) const
std::size_t reduced_index() const
ChunkSparsityPatternIterators::Iterator const_iterator
void block_read(std::istream &in)
bool operator==(const Accessor &) const
const Accessor * operator->() const
const ChunkSparsityPattern * sparsity_pattern
void add(const size_type i, const size_type j)
size_type n_nonzero_elements() const
SparsityPattern sparsity_pattern
DeclException2(ExcInvalidIndex, int, int,<< "The given index "<< arg1<< " should be less than "<< arg2<< ".")
bool stores_only_added_elements() const
size_type get_chunk_size() const
Iterator is invalid, probably due to an error.
unsigned int global_dof_index
size_type row_length(const size_type row) const
ChunkSparsityPatternIterators::Iterator iterator
#define Assert(cond, exc)
::ExceptionBase & ExcEmptyObject()
bool operator<(const Accessor &) const
::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
::ExceptionBase & ExcInvalidConstructorCall()
void print(std::ostream &out) const
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
bool operator<(const Iterator &) const
types::global_dof_index size_type
Accessor(const ChunkSparsityPattern *matrix, const unsigned int row)
::ExceptionBase & ExcIteratorPastEnd()
bool operator==(const Iterator &) const
bool store_diagonal_first_in_row
DeclException0(ExcNotCompressed)
size_type bandwidth() const
static const size_type invalid_entry
size_type max_entries_per_row() const
bool is_valid_entry() const
::ExceptionBase & ExcInvalidIterator()
bool operator!=(const Iterator &) const
::ExceptionBase & ExcInternalError()
DeclException1(ExcInvalidNumber, int,<< "The provided number is invalid here: "<< arg1)
SparsityPatternIterators::Accessor reduced_accessor
void reinit(const size_type m, const size_type n, const size_type max_per_row, const size_type chunk_size)
const Accessor & operator*() const
unsigned int column() const
static const size_type invalid_entry