15#ifndef dealii_sparsity_pattern_h
16#define dealii_sparsity_pattern_h
30#include <boost/version.hpp>
31#if BOOST_VERSION >= 106400
32# include <boost/serialization/array_wrapper.hpp>
34# include <boost/serialization/array.hpp>
36#include <boost/serialization/split_member.hpp>
50template <
typename number>
52template <
typename number>
54template <
typename number>
56template <
typename number>
72 namespace SparsityPatternTools
92 template <
typename value>
101 template <
typename value>
221 "The instance of this class was initialized"
222 " without SparsityPattern object, which"
223 " means that it is a dummy accessor that can"
224 " not do any operations.");
476 const unsigned int max_per_row);
489 const std::vector<unsigned int> &row_lengths);
509 const std::vector<unsigned int> &row_lengths);
534 const unsigned int max_per_row,
566 const std::vector<unsigned int> &row_lengths);
671 template <
typename ForwardIterator>
675 const ForwardIterator
begin,
676 const ForwardIterator
end);
706 template <
typename number>
725 template <
typename ForwardIterator>
728 ForwardIterator
begin,
730 const bool indices_are_sorted =
false);
735 const bool indices_are_sorted =
false)
override;
796 std::pair<size_type, size_type>
934 print(std::ostream &out)
const;
995 template <
class Archive>
997 save(Archive &ar,
const unsigned int version)
const;
1003 template <
class Archive>
1005 load(Archive &ar,
const unsigned int version);
1012 template <
class Archive>
1018 BOOST_SERIALIZATION_SPLIT_MEMBER()
1036 <<
"The iterators denote a range of " << arg1
1037 <<
" elements, but the given number of rows was " << arg2);
1043 <<
"The number of partitions you gave is " << arg1
1044 <<
", but must be greater than zero.");
1052 <<
"Upon entering a new entry to row " << arg1
1053 <<
": there was no free entry any more. " << std::endl
1054 <<
"(Maximum number of entries for this row: " << arg2
1055 <<
"; maybe the matrix is already compressed?)");
1063 "The operation you attempted changes the structure of the SparsityPattern "
1064 "and is not possible after compress() has been called.");
1072 "The operation you attempted is only allowed after the SparsityPattern "
1073 "has been set up and compress() was called.");
1154 template <
typename number>
1156 template <
typename number>
1158 template <
typename number>
1160 template <
typename number>
1184 const std::size_t i)
1185 : container(sparsity_pattern)
1192 : container(sparsity_pattern)
1193 , linear_index(container->rowstart[container->rows])
1198 inline Accessor::Accessor()
1199 : container(nullptr)
1206 Accessor::is_valid_entry()
const
1208 Assert(container !=
nullptr, DummyAccessor());
1209 return (linear_index < container->rowstart[container->rows] &&
1216 Accessor::row()
const
1220 const std::size_t *insert_point =
1221 std::upper_bound(container->rowstart.get(),
1222 container->rowstart.get() + container->rows + 1,
1224 return insert_point - container->rowstart.get() - 1;
1230 Accessor::column()
const
1234 return (container->colnums[linear_index]);
1240 Accessor::index()
const
1244 return linear_index - container->rowstart[row()];
1250 Accessor::global_index()
const
1254 return linear_index;
1260 Accessor::operator==(
const Accessor &other)
const
1262 return (container == other.container && linear_index == other.linear_index);
1268 Accessor::operator<(
const Accessor &other)
const
1270 Assert(container !=
nullptr, DummyAccessor());
1271 Assert(other.container !=
nullptr, DummyAccessor());
1274 return linear_index < other.linear_index;
1282 Assert(container !=
nullptr, DummyAccessor());
1283 Assert(linear_index < container->rowstart[container->rows],
1290 const std::size_t linear_index)
1295 inline Iterator::Iterator(
const Accessor &accessor)
1345 const unsigned int index)
const
1372 return {
nullptr, 0};
1412 for (size_type i = 0; i <
rows + 1; ++i)
1428 namespace SparsityPatternTools
1443 template <
typename value>
1452 template <
typename value>
1463template <
typename ForwardIterator>
1466 const size_type n_cols,
1467 const ForwardIterator begin,
1468 const ForwardIterator end)
1478 std::vector<unsigned int> row_lengths;
1479 row_lengths.reserve(
n_rows);
1480 for (ForwardIterator i =
begin; i !=
end; ++i)
1481 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1482 (is_square ? 1 : 0));
1491 using inner_iterator =
1492 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1493 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1496 const inner_iterator end_of_row = i->end();
1497 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
1499 const size_type col =
1500 internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1503 if ((col != row) || !is_square)
1514template <
class Archive>
1519 ar &boost::serialization::base_object<const Subscriptor>(*
this);
1537template <
class Archive>
1542 ar &boost::serialization::base_object<Subscriptor>(*
this);
virtual void add_entries(const ArrayView< const std::pair< size_type, size_type > > &entries)
friend class ChunkSparsityPatternIterators::Accessor
size_type global_index() const
bool operator==(const Accessor &) const
const SparsityPattern * container
Accessor(const SparsityPattern *matrix)
Accessor(const SparsityPattern *matrix, const std::size_t linear_index)
bool operator<(const Accessor &) const
bool is_valid_entry() const
Iterator(const SparsityPattern *sp, const std::size_t linear_index)
Iterator(const Accessor &accessor)
void load(Archive &ar, const unsigned int version)
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
iterator begin(const size_type r) const
void block_write(std::ostream &out) const
void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths)
void print_svg(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)
size_type bandwidth() const
void print_gnuplot(std::ostream &out) const
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
bool is_compressed() const
SparsityPattern & operator=(const SparsityPattern &)
std::size_t n_nonzero_elements() const
bool exists(const size_type i, const size_type j) const
std::unique_ptr< size_type[]> colnums
size_type column_number(const size_type row, const unsigned int index) const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
static constexpr size_type invalid_entry
size_type row_position(const size_type i, const size_type j) const
std::unique_ptr< std::size_t[]> rowstart
void print(std::ostream &out) const
iterator end(const size_type r) const
void add(const size_type i, const size_type j)
bool store_diagonal_first_in_row
size_type max_entries_per_row() const
unsigned int max_row_length
size_type operator()(const size_type i, const size_type j) const
void save(Archive &ar, const unsigned int version) const
unsigned int row_length(const size_type row) const
std::size_t memory_consumption() const
bool operator==(const SparsityPattern &) const
void block_read(std::istream &in)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & DummyAccessor()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
static ::ExceptionBase & ExcIteratorPastEnd()
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcMatrixIsCompressed()
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & ExcIteratorRange(int arg1, int arg2)
types::global_dof_index size_type
const types::global_dof_index invalid_size_type
unsigned int global_dof_index