16 #ifndef dealii__sparsity_pattern_h 17 #define dealii__sparsity_pattern_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/subscriptor.h> 26 #include <boost/version.hpp> 27 #if BOOST_VERSION >= 106400 28 # include <boost/serialization/array_wrapper.hpp> 30 # include <boost/serialization/array.hpp> 32 #include <boost/serialization/split_member.hpp> 38 DEAL_II_NAMESPACE_OPEN
45 template <
typename number>
class SparseILU;
60 namespace SparsityPatternTools
73 get_column_index_from_iterator (
const size_type i);
80 template <
typename value>
82 get_column_index_from_iterator (
const std::pair<size_type, value> &i);
89 template <
typename value>
91 get_column_index_from_iterator (
const std::pair<const size_type, value> &i);
247 const std::size_t index_within_sparsity);
422 const unsigned int max_per_row);
435 const std::vector<unsigned int> &row_lengths);
446 const unsigned int max_per_row);
456 const std::vector<unsigned int> &row_lengths);
481 const unsigned int max_per_row,
506 const unsigned int max_per_row);
525 const std::vector<unsigned int> &row_lengths);
533 const VectorSlice<
const std::vector<unsigned int> > &row_lengths);
626 template <
typename ForwardIterator>
629 const ForwardIterator
begin,
630 const ForwardIterator
end);
639 template <
typename SparsityPatternType>
640 void copy_from (
const SparsityPatternType &dsp);
650 template <
typename number>
677 template <
typename ForwardIterator>
679 ForwardIterator
begin,
681 const bool indices_are_sorted =
false);
859 std::pair<size_type, size_type>
889 const unsigned int index)
const;
929 void print (std::ostream &out)
const;
953 void print_svg (std::ostream &out)
const;
960 template <
class Archive>
961 void save (Archive &ar,
const unsigned int version)
const;
967 template <
class Archive>
968 void load (Archive &ar,
const unsigned int version);
970 BOOST_SERIALIZATION_SPLIT_MEMBER()
983 << "Upon entering a new entry to row " << arg1
984 << ": there was no free entry any more. " <<
std::endl
985 << "(Maximum number of entries for this row: "
986 << arg2 << "; maybe the matrix is already
compressed?)");
992 "The operation you attempted is only allowed after the
SparsityPattern "
993 "has been set up and
compress() was called.");
999 "The operation you attempted changes the structure of the
SparsityPattern "
1000 "and is not possible after
compress() has been called.");
1006 << "The iterators denote a range of " << arg1
1007 << " elements, but the given number of
rows was " << arg2);
1013 << "The number of partitions you gave is " << arg1
1014 << ", but must be greater than zero.");
1106 template <typename number> friend class
SparseILU;
1131 const std::size_t i)
1133 sparsity_pattern(sparsity_pattern),
1134 index_within_sparsity(i)
1142 sparsity_pattern(sparsity_pattern),
1143 index_within_sparsity(sparsity_pattern->
rowstart[sparsity_pattern->
rows])
1149 Accessor::is_valid_entry ()
const 1151 return (index_within_sparsity < sparsity_pattern->
rowstart[sparsity_pattern->
rows]
1153 sparsity_pattern->
colnums[index_within_sparsity]
1160 Accessor::row()
const 1164 const std::size_t *insert_point =
1165 std::upper_bound(sparsity_pattern->
rowstart,
1166 sparsity_pattern->
rowstart + sparsity_pattern->
rows + 1,
1167 index_within_sparsity);
1168 return insert_point - sparsity_pattern->
rowstart - 1;
1174 Accessor::column()
const 1178 return (sparsity_pattern->
colnums[index_within_sparsity]);
1184 Accessor::index()
const 1188 return index_within_sparsity - sparsity_pattern->
rowstart[row()];
1196 Accessor::operator == (
const Accessor &other)
const 1198 return (sparsity_pattern == other.sparsity_pattern &&
1199 index_within_sparsity == other.index_within_sparsity);
1206 Accessor::operator < (
const Accessor &other)
const 1208 Assert (sparsity_pattern == other.sparsity_pattern,
1211 return index_within_sparsity < other.index_within_sparsity;
1217 Accessor::advance ()
1221 ++index_within_sparsity;
1228 const std::size_t i)
1230 accessor(sparsity_pattern, i)
1237 Iterator::operator++ ()
1239 accessor.advance ();
1247 Iterator::operator++ (
int)
1249 const Iterator iter = *
this;
1250 accessor.advance ();
1258 Iterator::operator* ()
const 1267 Iterator::operator-> ()
const 1275 Iterator::operator == (
const Iterator &other)
const 1277 return (accessor == other.accessor);
1284 Iterator::operator != (
const Iterator &other)
const 1286 return ! (*
this == other);
1292 Iterator::operator < (
const Iterator &other)
const 1294 return accessor < other.accessor;
1300 Iterator::operator - (
const Iterator &other)
const 1302 Assert (accessor.sparsity_pattern == other.accessor.sparsity_pattern,
1305 return (*this)->index_within_sparsity - other->index_within_sparsity;
1396 const unsigned int index)
const 1416 template <
class Archive>
1432 template <
class Archive>
1485 namespace SparsityPatternTools
1494 get_column_index_from_iterator (
const size_type i)
1501 template <
typename value>
1504 get_column_index_from_iterator (
const std::pair<size_type, value> &i)
1511 template <
typename value>
1514 get_column_index_from_iterator (
const std::pair<const size_type, value> &i)
1523 template <
typename ForwardIterator>
1527 const ForwardIterator
begin,
1528 const ForwardIterator
end)
1538 std::vector<unsigned int> row_lengths;
1539 row_lengths.reserve(
n_rows);
1540 for (ForwardIterator i=
begin; i!=
end; ++i)
1541 row_lengths.push_back (std::distance (i->begin(), i->end())
1543 (is_square ? 1 : 0));
1552 typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
1553 for (ForwardIterator i=
begin; i!=
end; ++i, ++row)
1556 const inner_iterator end_of_row = i->end();
1557 for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
1560 = internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1563 if ((col!=row) || !is_square)
1575 DEAL_II_NAMESPACE_CLOSE
void block_write(std::ostream &out) const
types::global_dof_index size_type
const types::global_dof_index invalid_size_type
SparsityPatternIterators::Iterator iterator
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
std::size_t index_within_sparsity
static ::ExceptionBase & ExcMatrixIsCompressed()
#define DeclException2(Exception2, type1, type2, outsequence)
std::size_t n_nonzero_elements() const
bool operator==(const Accessor &) const
size_type operator()(const size_type i, const size_type j) const
types::global_dof_index size_type
static const size_type invalid_entry
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
bool operator!=(const Iterator &) const
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
bool operator<(const Accessor &) const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
bool is_compressed() const
bool operator<(const Iterator &) const
bool is_valid_entry() const
size_type bandwidth() const
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcNotCompressed()
#define DeclException1(Exception1, type1, outsequence)
void add(const size_type i, const size_type j)
int operator-(const Iterator &p) const
unsigned int global_dof_index
#define Assert(cond, exc)
void print_svg(std::ostream &out) const
size_type column_number(const size_type row, const unsigned int index) const
#define DeclExceptionMsg(Exception, defaulttext)
void print(std::ostream &out) const
SparsityPattern & operator=(const SparsityPattern &)
size_type max_entries_per_row() const
void load(Archive &ar, const unsigned int version)
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
bool operator==(const Iterator &) const
const Accessor & operator*() const
SparsityPatternIterators::Iterator const_iterator
static ::ExceptionBase & ExcIteratorPastEnd()
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
unsigned int max_row_length
types::global_dof_index size_type
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
bool operator==(const SparsityPattern &) const
bool stores_only_added_elements() const
bool store_diagonal_first_in_row
const SparsityPattern * sparsity_pattern
static ::ExceptionBase & ExcEmptyObject()
Iterator(const SparsityPattern *sp, const std::size_t index_within_sparsity)
void block_read(std::istream &in)
Accessor(const SparsityPattern *matrix, const std::size_t index_within_sparsity)
static ::ExceptionBase & ExcIteratorRange(int arg1, int arg2)
const Accessor * operator->() const
void save(Archive &ar, const unsigned int version) 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()