16 #ifndef dealii__sparsity_pattern_h 17 #define dealii__sparsity_pattern_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/subscriptor.h> 23 #include <boost/serialization/array.hpp> 24 #include <boost/serialization/split_member.hpp> 29 DEAL_II_NAMESPACE_OPEN
36 template <
typename number>
class SparseILU;
51 namespace SparsityPatternTools
64 get_column_index_from_iterator (
const size_type i);
71 template <
typename value>
73 get_column_index_from_iterator (
const std::pair<size_type, value> &i);
80 template <
typename value>
82 get_column_index_from_iterator (
const std::pair<const size_type, value> &i);
121 const std::size_t index_within_sparsity);
132 size_type row ()
const;
139 size_type index ()
const;
145 size_type column ()
const;
156 bool is_valid_entry ()
const;
161 bool operator == (
const Accessor &)
const;
170 bool operator < (
const Accessor &)
const;
238 const std::size_t index_within_sparsity);
258 const Accessor *operator-> ()
const;
263 bool operator == (
const Iterator &)
const;
268 bool operator != (
const Iterator &)
const;
277 bool operator < (
const Iterator &)
const;
285 int operator - (
const Iterator &p)
const;
413 const unsigned int max_per_row);
426 const std::vector<unsigned int> &row_lengths);
437 const unsigned int max_per_row);
447 const std::vector<unsigned int> &row_lengths);
472 const unsigned int max_per_row,
473 const size_type extra_off_diagonals);
495 void reinit (
const size_type m,
497 const unsigned int max_per_row);
514 void reinit (
const size_type m,
516 const std::vector<unsigned int> &row_lengths);
522 void reinit (
const size_type m,
524 const VectorSlice<
const std::vector<unsigned int> > &row_lengths);
617 template <
typename ForwardIterator>
618 void copy_from (
const size_type n_rows,
619 const size_type n_cols,
620 const ForwardIterator begin,
621 const ForwardIterator end);
630 template <
typename SparsityPatternType>
631 void copy_from (
const SparsityPatternType &dsp);
641 template <
typename number>
659 void add (
const size_type i,
668 template <
typename ForwardIterator>
669 void add_entries (
const size_type row,
670 ForwardIterator begin,
672 const bool indices_are_sorted =
false);
710 iterator begin (
const size_type r)
const;
720 iterator end (
const size_type r)
const;
744 size_type max_entries_per_row ()
const;
755 size_type bandwidth ()
const;
765 size_type n_nonzero_elements ()
const;
770 bool is_compressed ()
const;
776 size_type n_rows ()
const;
782 size_type n_cols ()
const;
787 unsigned int row_length (
const size_type row)
const;
801 bool stores_only_added_elements ()
const;
807 std::size_t memory_consumption ()
const;
836 size_type operator() (
const size_type i,
837 const size_type j)
const;
850 std::pair<size_type, size_type>
851 matrix_position (
const size_type global_index)
const;
856 bool exists (
const size_type i,
857 const size_type j)
const;
866 size_type row_position(
const size_type i,
867 const size_type j)
const;
879 size_type column_number (
const size_type row,
880 const unsigned int index)
const;
898 void block_write (std::ostream &out)
const;
913 void block_read (std::istream &in);
920 void print (std::ostream &out)
const;
935 void print_gnuplot (std::ostream &out)
const;
944 void print_svg (std::ostream &out)
const;
951 template <
class Archive>
952 void save (Archive &ar,
const unsigned int version)
const;
958 template <
class Archive>
959 void load (Archive &ar,
const unsigned int version);
961 BOOST_SERIALIZATION_SPLIT_MEMBER()
974 << "Upon entering a new entry to row " << arg1
975 << ": there was no free entry any more. " <<
std::endl
976 << "(Maximum number of entries for this row: "
977 << arg2 << "; maybe the matrix is already compressed?)");
1003 << "The iterators denote a range of " << arg1
1004 << " elements, but the given number of rows was " << arg2);
1010 << "The number of partitions you gave is " << arg1
1011 << ", but must be greater than zero.");
1038 size_type max_vec_len;
1047 unsigned int max_row_length;
1096 bool store_diagonal_first_in_row;
1103 template <typename number> friend class
SparseILU;
1128 const std::size_t i)
1130 sparsity_pattern(sparsity_pattern),
1131 index_within_sparsity(i)
1139 sparsity_pattern(sparsity_pattern),
1140 index_within_sparsity(sparsity_pattern->
rowstart[sparsity_pattern->
rows])
1148 return (index_within_sparsity < sparsity_pattern->rowstart[sparsity_pattern->
rows]
1150 sparsity_pattern->
colnums[index_within_sparsity]
1159 Assert (is_valid_entry() ==
true, ExcInvalidIterator());
1161 const std::size_t *insert_point =
1162 std::upper_bound(sparsity_pattern->
rowstart,
1163 sparsity_pattern->
rowstart + sparsity_pattern->
rows + 1,
1164 index_within_sparsity);
1165 return insert_point - sparsity_pattern->
rowstart - 1;
1173 Assert (is_valid_entry() ==
true, ExcInvalidIterator());
1175 return (sparsity_pattern->
colnums[index_within_sparsity]);
1181 Accessor::index()
const 1183 Assert (is_valid_entry() ==
true, ExcInvalidIterator());
1185 return index_within_sparsity - sparsity_pattern->
rowstart[row()];
1195 return (sparsity_pattern == other.sparsity_pattern &&
1196 index_within_sparsity == other.index_within_sparsity);
1205 Assert (sparsity_pattern == other.sparsity_pattern,
1206 ExcInternalError());
1208 return index_within_sparsity < other.index_within_sparsity;
1216 Assert (index_within_sparsity < sparsity_pattern->rowstart[sparsity_pattern->
rows],
1217 ExcIteratorPastEnd());
1218 ++index_within_sparsity;
1225 const std::size_t i)
1227 accessor(sparsity_pattern, i)
1236 accessor.advance ();
1246 const Iterator iter = *
this;
1247 accessor.advance ();
1274 return (accessor == other.accessor);
1283 return ! (*
this == other);
1291 return accessor < other.accessor;
1297 Iterator::operator - (
const Iterator &other)
const 1299 Assert (accessor.sparsity_pattern == other.accessor.sparsity_pattern,
1300 ExcInternalError());
1302 return (*this)->index_within_sparsity - other->index_within_sparsity;
1312 return iterator(
this, rowstart[0]);
1320 return iterator(
this, rowstart[rows]);
1329 Assert (r<n_rows(), ExcIndexRangeType<size_type>(r,0,n_rows()));
1331 return iterator(
this, rowstart[r]);
1340 Assert (r<n_rows(), ExcIndexRangeType<size_type>(r,0,n_rows()));
1342 return iterator(
this, rowstart[r+1]);
1375 return (store_diagonal_first_in_row ==
false);
1384 Assert(row<rows, ExcIndexRangeType<size_type>(row,0,rows));
1385 return rowstart[row+1]-rowstart[row];
1393 const unsigned int index)
const 1395 Assert(row<rows, ExcIndexRangeType<size_type>(row,0,rows));
1396 Assert(index<row_length(row), ExcIndexRange(index,0,row_length(row)));
1398 return colnums[rowstart[row]+index];
1406 Assert ((rowstart!=0) && (colnums!=0), ExcEmptyObject());
1407 Assert (compressed, ExcNotCompressed());
1408 return rowstart[rows]-rowstart[0];
1413 template <
class Archive>
1421 ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed &store_diagonal_first_in_row;
1423 ar &boost::serialization::make_array(rowstart, max_dim + 1);
1424 ar &boost::serialization::make_array(colnums, max_vec_len);
1429 template <
class Archive>
1437 ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed &store_diagonal_first_in_row;
1439 rowstart =
new std::size_t [max_dim + 1];
1440 colnums =
new size_type [max_vec_len];
1442 ar &boost::serialization::make_array(rowstart, max_dim + 1);
1443 ar &boost::serialization::make_array(colnums, max_vec_len);
1456 if (rows != sp2.
rows ||
1462 for (size_type i = 0; i < rows+1; ++i)
1463 if (rowstart[i] != sp2.
rowstart[i])
1466 for (size_type i = 0; i < rowstart[rows]; ++i)
1467 if (colnums[i] != sp2.
colnums[i])
1477 namespace SparsityPatternTools
1486 get_column_index_from_iterator (
const size_type i)
1493 template <
typename value>
1496 get_column_index_from_iterator (
const std::pair<size_type, value> &i)
1503 template <
typename value>
1506 get_column_index_from_iterator (
const std::pair<const size_type, value> &i)
1515 template <
typename ForwardIterator>
1518 const size_type n_cols,
1519 const ForwardIterator begin,
1520 const ForwardIterator end)
1522 Assert (static_cast<size_type>(std::distance (begin, end)) == n_rows,
1523 ExcIteratorRange (std::distance (begin, end), n_rows));
1529 const bool is_square = (n_rows == n_cols);
1530 std::vector<unsigned int> row_lengths;
1531 row_lengths.reserve(n_rows);
1532 for (ForwardIterator i=begin; i!=end; ++i)
1533 row_lengths.push_back (std::distance (i->begin(), i->end())
1535 (is_square ? 1 : 0));
1536 reinit (n_rows, n_cols, row_lengths);
1544 typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
1545 for (ForwardIterator i=begin; i!=end; ++i, ++row)
1547 size_type *cols = &colnums[rowstart[row]] + (is_square ? 1 : 0);
1548 const inner_iterator end_of_row = i->end();
1549 for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
1552 = internal::SparsityPatternTools::get_column_index_from_iterator(*j);
1553 Assert (col < n_cols, ExcIndexRange(col,0,n_cols));
1555 if ((col!=row) || !is_square)
1567 DEAL_II_NAMESPACE_CLOSE
bool operator==(const Iterator &) const
types::global_dof_index size_type
const types::global_dof_index invalid_size_type
SparsityPatternIterators::Iterator iterator
std::size_t index_within_sparsity
#define DeclException2(Exception2, type1, type2, outsequence)
bool is_valid_entry() const
Iterator(const ChunkSparsityPattern *sp, const unsigned int row)
types::global_dof_index size_type
static const size_type invalid_entry
bool operator!=(const Iterator &) const
unsigned int column() const
bool is_compressed() const
bool operator<(const Iterator &) const
#define DeclException1(Exception1, type1, outsequence)
unsigned int global_dof_index
#define Assert(cond, exc)
size_type column_number(const size_type row, const unsigned int index) const
#define DeclException0(Exception0)
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)
const Accessor & operator*() const
SparsityPatternIterators::Iterator const_iterator
size_type n_nonzero_elements() const
Accessor(const ChunkSparsityPattern *matrix, const unsigned int row)
types::global_dof_index size_type
bool operator==(const SparsityPattern &) const
bool stores_only_added_elements() const
bool store_diagonal_first_in_row
const SparsityPattern * sparsity_pattern
bool operator<(const Accessor &) const
void save(Archive &ar, const unsigned int version) const
bool operator==(const Accessor &) const
unsigned int row_length(const size_type row) const
const Accessor * operator->() const