16 #ifndef dealii_sparsity_pattern_h 17 #define dealii_sparsity_pattern_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/array_view.h> 23 #include <deal.II/base/exceptions.h> 24 #include <deal.II/base/linear_index_iterator.h> 25 #include <deal.II/base/std_cxx14/memory.h> 26 #include <deal.II/base/subscriptor.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> 42 DEAL_II_NAMESPACE_OPEN
48 template <
typename number>
50 template <
typename number>
52 template <
typename number>
54 template <
typename number>
69 namespace SparsityPatternTools
82 get_column_index_from_iterator(
const size_type i);
89 template <
typename value>
91 get_column_index_from_iterator(
const std::pair<size_type, value> &i);
98 template <
typename value>
100 get_column_index_from_iterator(
const std::pair<const size_type, value> &i);
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.");
413 const std::vector<unsigned int> &row_lengths);
625 std::pair<size_type, size_type>
641 print(std::ostream &out)
const;
673 template <
class Archive>
675 save(Archive &ar,
const unsigned int version)
const;
681 template <
class Archive>
683 load(Archive &ar,
const unsigned int version);
685 BOOST_SERIALIZATION_SPLIT_MEMBER()
700 "The operation you attempted is only allowed after the
SparsityPattern "
701 "has been
set up and compress() was called.");
709 << "Upon entering a new entry to row " << arg1
710 << ": there was no free entry any more. " <<
std::endl
711 << "(Maximum number of entries for this row: " << arg2
712 << "; maybe the matrix is already
compressed?)");
720 "The operation you attempted changes the structure of the
SparsityPattern "
721 "and is not possible after compress() has been called.");
809 template <typename number>
811 template <typename number>
813 template <typename number>
815 template <typename number>
929 const unsigned int max_per_row);
942 const std::vector<unsigned int> &row_lengths);
962 const std::vector<unsigned int> &row_lengths);
987 const unsigned int max_per_row,
1105 template <
typename ForwardIterator>
1109 const ForwardIterator
begin,
1110 const ForwardIterator
end);
1133 template <
typename number>
1143 template <
typename ForwardIterator>
1146 ForwardIterator
begin,
1147 ForwardIterator
end,
1148 const bool indices_are_sorted =
false);
1176 stores_only_added_elements()
const;
1232 block_write(std::ostream &out)
const;
1248 block_read(std::istream &in);
1254 template <
class Archive>
1256 save(Archive &ar,
const unsigned int version)
const;
1262 template <
class Archive>
1264 load(Archive &ar,
const unsigned int version);
1266 BOOST_SERIALIZATION_SPLIT_MEMBER()
1280 << "The iterators denote a range of " << arg1
1281 << " elements, but the given number of
rows was " << arg2);
1287 << "The number of partitions you gave is " << arg1
1288 << ", but must be greater than zero.");
1294 bool store_diagonal_first_in_row;
1299 template <typename number>
1301 template <typename number>
1303 template <typename number>
1305 template <typename number>
1329 const std::size_t i)
1330 : container(sparsity_pattern)
1337 : container(sparsity_pattern)
1338 , linear_index(container->rowstart[container->rows])
1343 inline Accessor::Accessor()
1344 : container(
nullptr)
1351 Accessor::is_valid_entry()
const 1353 Assert(container !=
nullptr, DummyAccessor());
1354 return (linear_index < container->
rowstart[container->rows] &&
1361 Accessor::row()
const 1365 const std::size_t *insert_point =
1366 std::upper_bound(container->rowstart.get(),
1367 container->rowstart.get() + container->rows + 1,
1369 return insert_point - container->rowstart.get() - 1;
1375 Accessor::column()
const 1379 return (container->colnums[linear_index]);
1385 Accessor::index()
const 1389 return linear_index - container->rowstart[row()];
1395 Accessor::global_index()
const 1399 return linear_index;
1405 Accessor::operator==(
const Accessor &other)
const 1407 Assert(container !=
nullptr, DummyAccessor());
1408 Assert(other.container !=
nullptr, DummyAccessor());
1409 return (container == other.container && linear_index == other.linear_index);
1415 Accessor::operator<(
const Accessor &other)
const 1417 Assert(container !=
nullptr, DummyAccessor());
1418 Assert(other.container !=
nullptr, DummyAccessor());
1421 return linear_index < other.linear_index;
1429 Assert(container !=
nullptr, DummyAccessor());
1437 const std::size_t linear_index)
1442 inline Iterator::Iterator(
const Accessor &accessor)
1468 return {
nullptr, 0};
1520 return (store_diagonal_first_in_row ==
false);
1536 const unsigned int index)
const 1560 template <
class Archive>
1565 ar &boost::serialization::base_object<const Subscriptor>(*this);
1575 template <
class Archive>
1580 ar &boost::serialization::base_object<Subscriptor>(*this);
1593 template <
class Archive>
1598 ar &boost::serialization::base_object<const SparsityPatternBase>(*this);
1599 ar &store_diagonal_first_in_row;
1604 template <
class Archive>
1609 ar &boost::serialization::base_object<SparsityPatternBase>(*this);
1610 ar &store_diagonal_first_in_row;
1641 return (static_cast<const SparsityPatternBase &>(*
this) == sp2) &&
1649 namespace SparsityPatternTools
1657 get_column_index_from_iterator(
const size_type i)
1664 template <
typename value>
1666 get_column_index_from_iterator(
const std::pair<size_type, value> &i)
1673 template <
typename value>
1675 get_column_index_from_iterator(
const std::pair<const size_type, value> &i)
1684 template <
typename ForwardIterator>
1688 const ForwardIterator
begin,
1689 const ForwardIterator
end)
1699 std::vector<unsigned int> row_lengths;
1700 row_lengths.reserve(
n_rows);
1701 for (ForwardIterator i =
begin; i !=
end; ++i)
1702 row_lengths.push_back(std::distance(i->begin(), i->end()) +
1703 (is_square ? 1 : 0));
1712 using inner_iterator =
1713 typename std::iterator_traits<ForwardIterator>::value_type::const_iterator;
1714 for (ForwardIterator i =
begin; i !=
end; ++i, ++row)
1717 const inner_iterator end_of_row = i->end();
1718 for (inner_iterator j = i->begin(); j != end_of_row; ++j)
1721 internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1724 if ((col != row) || !is_square)
1736 DEAL_II_NAMESPACE_CLOSE
SparsityPatternIterators::size_type size_type
const types::global_dof_index invalid_size_type
#define DeclException2(Exception2, type1, type2, outsequence)
unsigned int max_row_length
static ::ExceptionBase & ExcMatrixIsCompressed()
bool operator==(const Accessor &) const
size_type global_index() const
Subscriptor & operator=(const Subscriptor &)
~SparsityPatternBase() override=default
void load(Archive &ar, const unsigned int version)
types::global_dof_index size_type
size_type row_position(const size_type i, const size_type j) const
Iterator(const SparsityPatternBase *sp, const std::size_t linear_index)
std::pair< size_type, size_type > matrix_position(const std::size_t global_index) const
size_type bandwidth() const
bool operator==(const SparsityPatternBase &) const
bool operator<(const Accessor &) const
types::global_dof_index size_type
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
bool is_valid_entry() const
std::unique_ptr< std::size_t[]> rowstart
void print_gnuplot(std::ostream &out) const
static ::ExceptionBase & ExcNotCompressed()
size_type max_entries_per_row() const
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
#define DeclException1(Exception1, type1, outsequence)
SparsityPatternBase::size_type size_type
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
std::size_t memory_consumption() const
void add(const size_type i, const size_type j)
SparsityPatternIterators::Iterator const_iterator
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)
std::size_t n_nonzero_elements() const
bool exists(const size_type i, const size_type j) const
static ::ExceptionBase & ExcIteratorPastEnd()
std::unique_ptr< size_type[]> colnums
static ::ExceptionBase & ExcNotEnoughSpace(int arg1, int arg2)
unsigned int global_dof_index
static ::ExceptionBase & DummyAccessor()
__global__ void set(Number *val, const Number s, const size_type N)
bool is_compressed() const
bool operator==(const SparsityPattern &) const
bool stores_only_added_elements() const
bool store_diagonal_first_in_row
void save(Archive &ar, const unsigned int version) const
static const size_type invalid_entry
types::global_dof_index size_type
size_type column_number(const size_type row, const unsigned int index) const
void save(Archive &ar, const unsigned int version) const
unsigned int row_length(const size_type row) const
void print(std::ostream &out) const
const SparsityPatternBase * container
void print_svg(std::ostream &out) const
static ::ExceptionBase & ExcInternalError()
SparsityPatternIterators::Iterator iterator