16#ifndef dealii_sparsity_pattern_h
17#define dealii_sparsity_pattern_h
31#include <boost/version.hpp>
32#if BOOST_VERSION >= 106400
33# include <boost/serialization/array_wrapper.hpp>
35# include <boost/serialization/array.hpp>
37#include <boost/serialization/split_member.hpp>
51template <
typename number>
53template <
typename number>
55template <
typename number>
57template <
typename number>
73 namespace SparsityPatternTools
93 template <
typename value>
102 template <
typename value>
222 "The instance of this class was initialized"
223 " without SparsityPattern object, which"
224 " means that it is a dummy accessor that can"
225 " not do any operations.");
477 const unsigned int max_per_row);
490 const std::vector<unsigned int> &row_lengths);
510 const std::vector<unsigned int> &row_lengths);
535 const unsigned int max_per_row,
567 const std::vector<unsigned int> &row_lengths);
672 template <
typename ForwardIterator>
676 const ForwardIterator
begin,
677 const ForwardIterator
end);
707 template <
typename number>
726 template <
typename ForwardIterator>
729 ForwardIterator
begin,
731 const bool indices_are_sorted =
false);
736 const bool indices_are_sorted =
false)
override;
797 std::pair<size_type, size_type>
935 print(std::ostream &out)
const;
996 template <
class Archive>
998 save(Archive &ar,
const unsigned int version)
const;
1004 template <
class Archive>
1006 load(Archive &ar,
const unsigned int version);
1013 template <
class Archive>
1019 BOOST_SERIALIZATION_SPLIT_MEMBER()
1037 <<
"The iterators denote a range of " << arg1
1038 <<
" elements, but the given number of rows was " << arg2);
1044 <<
"The number of partitions you gave is " << arg1
1045 <<
", but must be greater than zero.");
1053 <<
"Upon entering a new entry to row " << arg1
1054 <<
": there was no free entry any more. " << std::endl
1055 <<
"(Maximum number of entries for this row: " << arg2
1056 <<
"; maybe the matrix is already compressed?)");
1064 "The operation you attempted changes the structure of the SparsityPattern "
1065 "and is not possible after compress() has been called.");
1073 "The operation you attempted is only allowed after the SparsityPattern "
1074 "has been set up and compress() was called.");
1155 template <
typename number>
1157 template <
typename number>
1159 template <
typename number>
1161 template <
typename number>
1185 const std::size_t i)
1186 : container(sparsity_pattern)
1193 : container(sparsity_pattern)
1194 , linear_index(container->rowstart[container->rows])
1199 inline Accessor::Accessor()
1200 : container(nullptr)
1207 Accessor::is_valid_entry()
const
1209 Assert(container !=
nullptr, DummyAccessor());
1210 return (linear_index < container->rowstart[container->rows] &&
1217 Accessor::row()
const
1221 const std::size_t *insert_point =
1222 std::upper_bound(container->rowstart.get(),
1223 container->rowstart.get() + container->rows + 1,
1225 return insert_point - container->rowstart.get() - 1;
1231 Accessor::column()
const
1235 return (container->colnums[linear_index]);
1241 Accessor::index()
const
1245 return linear_index - container->rowstart[row()];
1251 Accessor::global_index()
const
1255 return linear_index;
1261 Accessor::operator==(
const Accessor &other)
const
1263 return (container == other.container && linear_index == other.linear_index);
1269 Accessor::operator<(
const Accessor &other)
const
1271 Assert(container !=
nullptr, DummyAccessor());
1272 Assert(other.container !=
nullptr, DummyAccessor());
1275 return linear_index < other.linear_index;
1283 Assert(container !=
nullptr, DummyAccessor());
1284 Assert(linear_index < container->rowstart[container->rows],
1291 const std::size_t linear_index)
1296 inline Iterator::Iterator(
const Accessor &accessor)
1346 const unsigned int index)
const
1373 return {
nullptr, 0};
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)
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
types::global_dof_index size_type
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
types::global_dof_index size_type
const types::global_dof_index invalid_size_type
unsigned int global_dof_index