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/std_cxx14/memory.h> 23 #include <deal.II/base/subscriptor.h> 27 #include <boost/version.hpp> 28 #if BOOST_VERSION >= 106400 29 # include <boost/serialization/array_wrapper.hpp> 31 # include <boost/serialization/array.hpp> 33 #include <boost/serialization/split_member.hpp> 39 DEAL_II_NAMESPACE_OPEN
47 template <
typename number>
class SparseILU;
62 namespace SparsityPatternTools
75 get_column_index_from_iterator (
const size_type i);
82 template <
typename value>
84 get_column_index_from_iterator (
const std::pair<size_type, value> &i);
91 template <
typename value>
93 get_column_index_from_iterator (
const std::pair<const size_type, value> &i);
249 const std::size_t index_within_sparsity);
424 const unsigned int max_per_row);
437 const std::vector<unsigned int> &row_lengths);
448 const unsigned int max_per_row);
458 const std::vector<unsigned int> &row_lengths);
483 const unsigned int max_per_row,
508 const unsigned int max_per_row);
527 const std::vector<unsigned int> &row_lengths);
535 const VectorSlice<
const std::vector<unsigned int> > &row_lengths);
628 template <
typename ForwardIterator>
631 const ForwardIterator
begin,
632 const ForwardIterator
end);
653 template <
typename number>
680 template <
typename ForwardIterator>
682 ForwardIterator
begin,
684 const bool indices_are_sorted =
false);
862 std::pair<size_type, size_type>
892 const unsigned int index)
const;
932 void print (std::ostream &out)
const;
956 void print_svg (std::ostream &out)
const;
963 template <
class Archive>
964 void save (Archive &ar,
const unsigned int version)
const;
970 template <
class Archive>
971 void load (Archive &ar,
const unsigned int version);
973 BOOST_SERIALIZATION_SPLIT_MEMBER()
986 << "Upon entering a new entry to row " << arg1
987 << ": there was no free entry any more. " <<
std::endl
988 << "(Maximum number of entries for this row: "
989 << arg2 << "; maybe the matrix is already
compressed?)");
995 "The operation you attempted is only allowed after the
SparsityPattern "
996 "has been set up and
compress() was called.");
1002 "The operation you attempted changes the structure of the
SparsityPattern "
1003 "and is not possible after
compress() has been called.");
1009 << "The iterators denote a range of " << arg1
1010 << " elements, but the given number of
rows was " << arg2);
1016 << "The number of partitions you gave is " << arg1
1017 << ", but must be greater than zero.");
1109 template <typename number> friend class
SparseILU;
1134 const std::size_t i)
1136 sparsity_pattern(sparsity_pattern),
1137 index_within_sparsity(i)
1145 sparsity_pattern(sparsity_pattern),
1146 index_within_sparsity(sparsity_pattern->
rowstart[sparsity_pattern->
rows])
1152 Accessor::is_valid_entry ()
const 1154 return (index_within_sparsity < sparsity_pattern->
rowstart[sparsity_pattern->
rows]
1156 sparsity_pattern->
colnums[index_within_sparsity]
1163 Accessor::row()
const 1167 const std::size_t *insert_point =
1168 std::upper_bound(sparsity_pattern->
rowstart.get(),
1169 sparsity_pattern->
rowstart.get() + sparsity_pattern->
rows + 1,
1170 index_within_sparsity);
1171 return insert_point - sparsity_pattern->
rowstart.get() - 1;
1177 Accessor::column()
const 1181 return (sparsity_pattern->
colnums[index_within_sparsity]);
1187 Accessor::index()
const 1191 return index_within_sparsity - sparsity_pattern->
rowstart[row()];
1199 Accessor::operator == (
const Accessor &other)
const 1201 return (sparsity_pattern == other.sparsity_pattern &&
1202 index_within_sparsity == other.index_within_sparsity);
1209 Accessor::operator < (
const Accessor &other)
const 1211 Assert (sparsity_pattern == other.sparsity_pattern,
1214 return index_within_sparsity < other.index_within_sparsity;
1220 Accessor::advance ()
1224 ++index_within_sparsity;
1231 const std::size_t i)
1233 accessor(sparsity_pattern, i)
1240 Iterator::operator++ ()
1242 accessor.advance ();
1250 Iterator::operator++ (
int)
1252 const Iterator iter = *
this;
1253 accessor.advance ();
1270 Iterator::operator-> ()
const 1278 Iterator::operator == (
const Iterator &other)
const 1280 return (accessor == other.accessor);
1287 Iterator::operator != (
const Iterator &other)
const 1289 return ! (*
this == other);
1295 Iterator::operator < (
const Iterator &other)
const 1297 return accessor < other.accessor;
1305 Assert (accessor.sparsity_pattern == other.accessor.sparsity_pattern,
1308 return (*this)->index_within_sparsity - other->index_within_sparsity;
1399 const unsigned int index)
const 1423 template <
class Archive>
1439 template <
class Archive>
1487 namespace SparsityPatternTools
1496 get_column_index_from_iterator (
const size_type i)
1503 template <
typename value>
1506 get_column_index_from_iterator (
const std::pair<size_type, value> &i)
1513 template <
typename value>
1516 get_column_index_from_iterator (
const std::pair<const size_type, value> &i)
1525 template <
typename ForwardIterator>
1529 const ForwardIterator
begin,
1530 const ForwardIterator
end)
1540 std::vector<unsigned int> row_lengths;
1541 row_lengths.reserve(
n_rows);
1542 for (ForwardIterator i=
begin; i!=
end; ++i)
1543 row_lengths.push_back (std::distance (i->begin(), i->end())
1545 (is_square ? 1 : 0));
1554 typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
1555 for (ForwardIterator i=
begin; i!=
end; ++i, ++row)
1558 const inner_iterator end_of_row = i->end();
1559 for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
1562 = internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1565 if ((col!=row) || !is_square)
1577 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)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
~SparsityPattern()=default
bool is_compressed() const
bool operator<(const Iterator &) const
bool is_valid_entry() const
size_type bandwidth() const
std::unique_ptr< size_type[]> colnums
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
std::unique_ptr< std::size_t[]> rowstart
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
SymmetricTensor< rank_, dim, typename ProductType< Number, OtherNumber >::type > operator-(const SymmetricTensor< rank_, dim, Number > &left, const SymmetricTensor< rank_, dim, OtherNumber > &right)
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()