16#ifndef dealii_sparsity_pattern_h
17#define dealii_sparsity_pattern_h
29#include <boost/version.hpp>
30#if BOOST_VERSION >= 106400
31# include <boost/serialization/array_wrapper.hpp>
33# include <boost/serialization/array.hpp>
35#include <boost/serialization/split_member.hpp>
50template <
typename number>
52template <
typename number>
54template <
typename number>
56template <
typename number>
71 namespace SparsityPatternTools
91 template <
typename value>
100 template <
typename value>
220 "The instance of this class was initialized"
221 " without SparsityPattern object, which"
222 " means that it is a dummy accessor that can"
223 " not do any operations.");
406 const std::vector<unsigned int> &row_lengths);
618 std::pair<size_type, size_type>
634 print(std::ostream &out)
const;
667 template <
class Archive>
669 save(Archive &ar,
const unsigned int version)
const;
676 template <
class Archive>
678 load(Archive &ar,
const unsigned int version);
686 template <
class Archive>
688 serialize(Archive &archive,
const unsigned int version);
692 BOOST_SERIALIZATION_SPLIT_MEMBER()
708 "The operation you attempted is only allowed after the SparsityPattern "
709 "has been set up and compress() was called.");
717 <<
"Upon entering a new entry to row " << arg1
718 <<
": there was no free entry any more. " << std::endl
719 <<
"(Maximum number of entries for this row: " << arg2
720 <<
"; maybe the matrix is already compressed?)");
728 "The operation you attempted changes the structure of the SparsityPattern "
729 "and is not possible after compress() has been called.");
815 template <
typename number>
817 template <
typename number>
819 template <
typename number>
821 template <
typename number>
938 const unsigned int max_per_row);
951 const std::vector<unsigned int> &row_lengths);
971 const std::vector<unsigned int> &row_lengths);
996 const unsigned int max_per_row,
1114 template <
typename ForwardIterator>
1118 const ForwardIterator
begin,
1119 const ForwardIterator
end);
1149 template <
typename number>
1159 template <
typename ForwardIterator>
1162 ForwardIterator
begin,
1163 ForwardIterator
end,
1164 const bool indices_are_sorted =
false);
1270 template <
class Archive>
1272 save(Archive &ar,
const unsigned int version)
const;
1278 template <
class Archive>
1280 load(Archive &ar,
const unsigned int version);
1287 template <
class Archive>
1293 BOOST_SERIALIZATION_SPLIT_MEMBER()
1308 <<
"The iterators denote a range of " << arg1
1309 <<
" elements, but the given number of rows was " << arg2);
1315 <<
"The number of partitions you gave is " << arg1
1316 <<
", but must be greater than zero.");
1325 template <
typename number>
1327 template <
typename number>
1329 template <
typename number>
1331 template <
typename number>
1353 const std::size_t i)
1354 : container(sparsity_pattern)
1361 : container(sparsity_pattern)
1362 , linear_index(container->rowstart[container->rows])
1367 inline Accessor::Accessor()
1368 : container(nullptr)
1375 Accessor::is_valid_entry()
const
1377 Assert(container !=
nullptr, DummyAccessor());
1378 return (linear_index < container->rowstart[container->rows] &&
1385 Accessor::row()
const
1389 const std::size_t *insert_point =
1390 std::upper_bound(container->rowstart.get(),
1391 container->rowstart.get() + container->rows + 1,
1393 return insert_point - container->rowstart.get() - 1;
1399 Accessor::column()
const
1403 return (container->colnums[linear_index]);
1409 Accessor::index()
const
1413 return linear_index - container->rowstart[row()];
1423 return linear_index;
1431 return (container == other.container && linear_index == other.linear_index);
1439 Assert(container !=
nullptr, DummyAccessor());
1440 Assert(other.container !=
nullptr, DummyAccessor());
1443 return linear_index < other.linear_index;
1451 Assert(container !=
nullptr, DummyAccessor());
1452 Assert(linear_index < container->rowstart[container->rows],
1459 const std::size_t linear_index)
1464 inline Iterator::Iterator(
const Accessor &accessor)
1490 return {
nullptr, 0};
1558 const unsigned int index)
const
1582template <
class Archive>
1587 ar &boost::serialization::base_object<const Subscriptor>(*
this);
1597template <
class Archive>
1602 ar &boost::serialization::base_object<Subscriptor>(*
this);
1615template <
class Archive>
1620 ar &boost::serialization::base_object<const SparsityPatternBase>(*
this);
1626template <
class Archive>
1631 ar &boost::serialization::base_object<SparsityPatternBase>(*
this);
1671 namespace SparsityPatternTools
1686 template <
typename value>
1695 template <
typename value>
1706template <
typename ForwardIterator>
1710 const ForwardIterator
begin,
1711 const ForwardIterator
end)
1721 std::vector<unsigned int> row_lengths;
1722 row_lengths.reserve(
n_rows);
1723 for (ForwardIterator i =
begin; i !=
end; ++i)
1724 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1725 (is_square ? 1 : 0));
1734 using inner_iterator =
1735 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1736 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1739 const inner_iterator end_of_row = i->end();
1740 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
1746 if ((col != row) || !is_square)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
void load(Archive &ar, const unsigned int version)
static ::ExceptionBase & ExcInvalidIterator()
void block_write(std::ostream &out) const
bool stores_only_added_elements() const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
void serialize(Archive &archive, const unsigned int version)
static ::ExceptionBase & DummyAccessor()
SparsityPattern & operator=(const SparsityPattern &)
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
SparsityPatternBase::size_type size_type
#define DeclException2(Exception2, type1, type2, outsequence)
~SparsityPattern() override=default
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
bool store_diagonal_first_in_row
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
virtual void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths) override
size_type operator()(const size_type i, const size_type j) const
void save(Archive &ar, const unsigned int version) const
std::size_t memory_consumption() const
bool operator==(const SparsityPattern &) const
void block_read(std::istream &in)
static ::ExceptionBase & ExcIteratorRange(int arg1, int arg2)
void serialize(Archive &archive, const unsigned int version)
void save(Archive &ar, const unsigned int version) const
std::size_t n_nonzero_elements() const
bool operator==(const SparsityPatternBase &) const
unsigned int max_row_length
Iterator(const SparsityPatternBase *sp, const std::size_t linear_index)
void print_svg(std::ostream &out) const
void add(const size_type i, const size_type j)
SparsityPatternIterators::Iterator iterator
types::global_dof_index size_type
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
unsigned int row_length(const size_type row) const
static ::ExceptionBase & ExcNotCompressed()
std::unique_ptr< size_type[]> colnums
std::unique_ptr< std::size_t[]> rowstart
void print(std::ostream &out) const
types::global_dof_index size_type
size_type get_column_index_from_iterator(const size_type i)
types::global_dof_index size_type
size_type global_index() const
bool operator==(const Accessor &) const
bool exists(const size_type i, const size_type j) const
size_type column_number(const size_type row, const unsigned int index) const
iterator begin(const size_type r) const
virtual void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths)=0
void print_gnuplot(std::ostream &out) const
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
static const size_type invalid_entry
size_type bandwidth() const
bool is_compressed() const
size_type max_entries_per_row() const
void load(Archive &ar, const unsigned int version)
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
~SparsityPatternBase() override=default
const SparsityPatternBase * container
std::size_t memory_consumption() const
size_type get_column_index_from_iterator(const std::pair< const size_type, value > &i)
SparsityPatternIterators::Iterator const_iterator
Iterator(const Accessor &accessor)
bool operator<(const Accessor &) const
Accessor(const SparsityPatternBase *matrix)
Accessor(const SparsityPatternBase *matrix, const std::size_t linear_index)
size_type row_position(const size_type i, const size_type j) const
iterator end(const size_type r) const
static ::ExceptionBase & ExcMatrixIsCompressed()
bool is_valid_entry() const
@ matrix
Contents is actually a matrix.
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
const types::global_dof_index invalid_size_type
unsigned int global_dof_index
bool operator<(const SynchronousIterators< Iterators > &a, const SynchronousIterators< Iterators > &b)
void advance(std::tuple< I1, I2 > &t, const unsigned int n)