17 #include <deal.II/base/vector_slice.h> 18 #include <deal.II/base/memory_consumption.h> 19 #include <deal.II/lac/block_sparsity_pattern.h> 21 DEAL_II_NAMESPACE_OPEN
24 template <
class SparsityPatternBase>
33 template <
class SparsityPatternBase>
46 template <
class SparsityPatternBase>
56 ExcMessage(
"This constructor can only be called if the provided argument " 57 "is the sparsity pattern for an empty matrix. This constructor can " 58 "not be used to copy-construct a non-empty sparsity pattern."));
63 template <
class SparsityPatternBase>
77 template <
class SparsityPatternBase>
89 SparsityPatternBase *sp = sub_objects[i][j];
90 sub_objects[i][j] = 0;
93 sub_objects.reinit (0,0);
97 columns = n_block_columns;
98 sub_objects.reinit (rows, columns);
104 SparsityPatternBase *p =
new SparsityPatternBase;
105 sub_objects[i][j] = p;
110 template <
class SparsityPatternBase>
129 template <
class SparsityPatternBase>
133 std::vector<size_type > row_sizes (rows);
134 std::vector<size_type > col_sizes (columns);
139 row_sizes[r] = sub_objects[r][0]->n_rows();
145 Assert (row_sizes[r] == sub_objects[r][c]->n_rows(),
146 ExcIncompatibleRowNumbers (r,0,r,c));
150 row_indices.reinit (row_sizes);
155 col_sizes[c] = sub_objects[0][c]->n_cols();
158 Assert (col_sizes[c] == sub_objects[r][c]->n_cols(),
159 ExcIncompatibleRowNumbers (0,c,r,c));
163 column_indices.reinit (col_sizes);
168 template <
class SparsityPatternBase>
174 sub_objects[i][j]->compress ();
179 template <
class SparsityPatternBase>
185 if (sub_objects[i][j]->empty () ==
false)
192 template <
class SparsityPatternBase>
197 for (
size_type block_row=0; block_row<rows; ++block_row)
201 this_row += sub_objects[block_row][c]->max_entries_per_row ();
203 if (this_row > max_entries)
204 max_entries = this_row;
211 template <
class SparsityPatternBase>
219 count += sub_objects[r][0]->n_rows();
225 template <
class SparsityPatternBase>
233 count += sub_objects[0][c]->n_cols();
239 template <
class SparsityPatternBase>
246 count += sub_objects[i][j]->n_nonzero_elements ();
252 template <
class SparsityPatternBase>
257 for (
size_type ib=0; ib<n_block_rows(); ++ib)
259 for (
size_type i=0; i<block(ib,0).n_rows(); ++i)
263 for (
size_type jb=0; jb<n_block_cols(); ++jb)
265 const SparsityPatternBase &b = block(ib,jb);
271 out <<
']' << std::endl;
273 k += block(ib,0).n_rows();
292 if (b.row_index_set().size()==0 || b.row_index_set().is_element(i))
298 out <<
']' << std::endl;
300 k +=
block(ib,0).n_rows();
305 template <
class SparsityPatternBase>
310 for (
size_type ib=0; ib<n_block_rows(); ++ib)
312 for (
size_type i=0; i<block(ib,0).n_rows(); ++i)
315 for (
size_type jb=0; jb<n_block_cols(); ++jb)
317 const SparsityPatternBase &b = block(ib,jb);
320 out << l+j <<
" " << -static_cast<signed int>(i+k) << std::endl;
324 k += block(ib,0).n_rows();
336 const size_type n_columns)
347 const std::vector<std::vector<unsigned int> > &row_lengths)
358 if (row_lengths[j].size()==1)
364 block_rows(row_lengths[j], start, length);
432 const size_type n_columns)
442 const std::vector<size_type> &col_indices)
448 for (
size_type j=0; j<col_indices.size(); ++j)
460 for (
size_type i=0; i<partitioning.size(); ++i)
461 for (
size_type j=0; j<partitioning.size(); ++j)
463 partitioning[j].size(),
479 const std::vector<size_type> &row_block_sizes,
480 const std::vector<size_type> &col_block_sizes)
483 reinit(row_block_sizes.size(), col_block_sizes.size());
484 for (
size_type i=0; i<row_block_sizes.size(); ++i)
485 for (
size_type j=0; j<col_block_sizes.size(); ++j)
486 this->
block(i,j).
reinit(row_block_sizes[i],col_block_sizes[j]);
492 const std::vector< IndexSet > &partitioning)
495 reinit(partitioning.size(), partitioning.size());
496 for (
size_type i=0; i<partitioning.size(); ++i)
497 for (
size_type j=0; j<partitioning.size(); ++j)
499 partitioning[j].size(),
519 #ifdef DEAL_II_WITH_TRILINOS 530 const size_type n_columns)
540 const std::vector<size_type> &col_indices)
546 for (
size_type j=0; j<col_indices.size(); ++j)
557 (parallel_partitioning.size(),
558 parallel_partitioning.size())
560 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
561 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
563 parallel_partitioning[j]);
571 const MPI_Comm &communicator)
574 (parallel_partitioning.size(),
575 parallel_partitioning.size())
577 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
578 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
580 parallel_partitioning[j],
589 const std::vector<IndexSet> &col_parallel_partitioning,
590 const std::vector<IndexSet> &writable_rows,
591 const MPI_Comm &communicator)
594 (row_parallel_partitioning.size(),
595 col_parallel_partitioning.size())
597 for (
size_type i=0; i<row_parallel_partitioning.size(); ++i)
598 for (
size_type j=0; j<col_parallel_partitioning.size(); ++j)
599 this->
block(i,j).
reinit(row_parallel_partitioning[i],
600 col_parallel_partitioning[j],
610 const std::vector<size_type> &col_block_sizes)
613 reinit(row_block_sizes.size(), col_block_sizes.size());
614 for (
size_type i=0; i<row_block_sizes.size(); ++i)
615 for (
size_type j=0; j<col_block_sizes.size(); ++j)
616 this->
block(i,j).
reinit(row_block_sizes[i],col_block_sizes[j]);
626 reinit(parallel_partitioning.size(),
627 parallel_partitioning.size());
628 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
629 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
631 parallel_partitioning[j]);
639 const MPI_Comm &communicator)
642 reinit(parallel_partitioning.size(),
643 parallel_partitioning.size());
644 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
645 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
647 parallel_partitioning[j],
656 const std::vector<IndexSet> &col_parallel_partitioning,
657 const MPI_Comm &communicator)
660 reinit(row_parallel_partitioning.size(),
661 col_parallel_partitioning.size());
662 for (
size_type i=0; i<row_parallel_partitioning.size(); ++i)
663 for (
size_type j=0; j<col_parallel_partitioning.size(); ++j)
664 this->
block(i,j).
reinit(row_parallel_partitioning[i],
665 col_parallel_partitioning[j],
674 const std::vector<IndexSet> &col_parallel_partitioning,
675 const std::vector<IndexSet> &writable_rows,
676 const MPI_Comm &communicator)
678 AssertDimension(writable_rows.size(), row_parallel_partitioning.size());
680 reinit(row_parallel_partitioning.size(),
681 col_parallel_partitioning.size());
682 for (
size_type i=0; i<row_parallel_partitioning.size(); ++i)
683 for (
size_type j=0; j<col_parallel_partitioning.size(); ++j)
684 this->
block(i,j).
reinit(row_parallel_partitioning[i],
685 col_parallel_partitioning[j],
697 #ifdef DEAL_II_WITH_TRILINOS 701 DEAL_II_NAMESPACE_CLOSE
void reinit(const std::vector< size_type > &row_block_sizes, const std::vector< size_type > &col_block_sizes)
BlockIndices column_indices
#define AssertDimension(dim1, dim2)
void reinit(const std::vector< size_type > &row_block_sizes, const std::vector< size_type > &col_block_sizes)
BlockSparsityPatternBase()
size_type n_block_cols() const
size_type n_block_rows() const
size_type block_size(const unsigned int i) const
SparsityPatternType & block(const size_type row, const size_type column)
~BlockSparsityPatternBase()
void reinit(const size_type n_block_rows, const size_type n_block_columns)
types::global_dof_index size_type
void reinit(const size_type n_block_rows, const size_type n_block_columns)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::size_t memory_consumption() const
void print(std::ostream &out) const
size_type max_entries_per_row() const
#define Assert(cond, exc)
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
BlockSparsityPatternBase & operator=(const BlockSparsityPatternBase &)
size_type n_nonzero_elements() const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
BlockDynamicSparsityPattern()
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Table< 2, SmartPointer< SparsityPatternType, BlockSparsityPatternBase< SparsityPatternType > > > sub_objects
void print_gnuplot(std::ostream &out) const
void copy_from(const BlockDynamicSparsityPattern &dsp)
unsigned int size() const
bool is_compressed() const
static ::ExceptionBase & ExcInternalError()