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.");
409 const std::vector<unsigned int> &row_lengths);
630 std::pair<size_type, size_type>
649 print(std::ostream &out)
const;
682 template <
class Archive>
684 save(Archive &ar,
const unsigned int version)
const;
691 template <
class Archive>
693 load(Archive &ar,
const unsigned int version);
701 template <
class Archive>
703 serialize(Archive &archive,
const unsigned int version);
707 BOOST_SERIALIZATION_SPLIT_MEMBER()
726 "The operation you attempted is only allowed after the SparsityPattern "
727 "has been set up and compress() was called.");
735 <<
"Upon entering a new entry to row " << arg1
736 <<
": there was no free entry any more. " << std::endl
737 <<
"(Maximum number of entries for this row: " << arg2
738 <<
"; maybe the matrix is already compressed?)");
746 "The operation you attempted changes the structure of the SparsityPattern "
747 "and is not possible after compress() has been called.");
835 template <
typename number>
837 template <
typename number>
839 template <
typename number>
841 template <
typename number>
961 const unsigned int max_per_row);
974 const std::vector<unsigned int> &row_lengths);
994 const std::vector<unsigned int> &row_lengths);
1019 const unsigned int max_per_row,
1137 template <
typename ForwardIterator>
1141 const ForwardIterator
begin,
1142 const ForwardIterator
end);
1172 template <
typename number>
1182 template <
typename ForwardIterator>
1185 ForwardIterator
begin,
1186 ForwardIterator
end,
1187 const bool indices_are_sorted =
false);
1308 template <
class Archive>
1310 save(Archive &ar,
const unsigned int version)
const;
1316 template <
class Archive>
1318 load(Archive &ar,
const unsigned int version);
1325 template <
class Archive>
1331 BOOST_SERIALIZATION_SPLIT_MEMBER()
1349 <<
"The iterators denote a range of " << arg1
1350 <<
" elements, but the given number of rows was " << arg2);
1356 <<
"The number of partitions you gave is " << arg1
1357 <<
", but must be greater than zero.");
1368 template <
typename number>
1370 template <
typename number>
1372 template <
typename number>
1374 template <
typename number>
1398 const std::size_t i)
1399 : container(sparsity_pattern)
1406 : container(sparsity_pattern)
1407 , linear_index(container->rowstart[container->rows])
1412 inline Accessor::Accessor()
1413 : container(nullptr)
1420 Accessor::is_valid_entry()
const
1422 Assert(container !=
nullptr, DummyAccessor());
1423 return (linear_index < container->rowstart[container->rows] &&
1430 Accessor::row()
const
1434 const std::size_t *insert_point =
1435 std::upper_bound(container->rowstart.get(),
1436 container->rowstart.get() + container->rows + 1,
1438 return insert_point - container->rowstart.get() - 1;
1444 Accessor::column()
const
1448 return (container->colnums[linear_index]);
1454 Accessor::index()
const
1458 return linear_index - container->rowstart[row()];
1464 Accessor::global_index()
const
1468 return linear_index;
1474 Accessor::operator==(
const Accessor &other)
const
1476 return (container == other.container && linear_index == other.linear_index);
1482 Accessor::operator<(
const Accessor &other)
const
1484 Assert(container !=
nullptr, DummyAccessor());
1485 Assert(other.container !=
nullptr, DummyAccessor());
1488 return linear_index < other.linear_index;
1496 Assert(container !=
nullptr, DummyAccessor());
1497 Assert(linear_index < container->rowstart[container->rows],
1504 const std::size_t linear_index)
1509 inline Iterator::Iterator(
const Accessor &accessor)
1535 return {
nullptr, 0};
1603 const unsigned int index)
const
1627template <
class Archive>
1632 ar &boost::serialization::base_object<const Subscriptor>(*
this);
1649template <
class Archive>
1654 ar &boost::serialization::base_object<Subscriptor>(*
this);
1677template <
class Archive>
1682 ar &boost::serialization::base_object<const SparsityPatternBase>(*
this);
1688template <
class Archive>
1693 ar &boost::serialization::base_object<SparsityPatternBase>(*
this);
1735 namespace SparsityPatternTools
1750 template <
typename value>
1759 template <
typename value>
1770template <
typename ForwardIterator>
1773 const size_type n_cols,
1774 const ForwardIterator begin,
1775 const ForwardIterator end)
1785 std::vector<unsigned int> row_lengths;
1786 row_lengths.reserve(
n_rows);
1787 for (ForwardIterator i =
begin; i !=
end; ++i)
1788 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1789 (is_square ? 1 : 0));
1798 using inner_iterator =
1799 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1800 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1803 const inner_iterator end_of_row = i->end();
1804 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
1807 internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1810 if ((col != row) || !is_square)
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
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
std::unique_ptr< size_type[]> colnums
std::unique_ptr< std::size_t[]> rowstart
void print(std::ostream &out) 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 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
std::size_t memory_consumption() const
SparsityPatternIterators::Iterator const_iterator
size_type row_position(const size_type i, const size_type j) const
iterator end(const size_type r) const
friend class ChunkSparsityPatternIterators::Accessor
size_type global_index() const
bool operator==(const Accessor &) const
const SparsityPatternBase * container
bool operator<(const Accessor &) const
Accessor(const SparsityPatternBase *matrix)
Accessor(const SparsityPatternBase *matrix, const std::size_t linear_index)
bool is_valid_entry() const
Iterator(const SparsityPatternBase *sp, const std::size_t linear_index)
Iterator(const Accessor &accessor)
void load(Archive &ar, const unsigned int version)
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)
SparsityPattern & operator=(const SparsityPattern &)
SparsityPatternBase::size_type size_type
~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
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)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcNotCompressed()
static ::ExceptionBase & DummyAccessor()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcInternalError()
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMatrixIsCompressed()
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