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] =
nullptr;
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();
331 const size_type n_columns)
342 const std::vector<std::vector<unsigned int> > &row_lengths)
353 if (row_lengths[j].size()==1)
359 block_rows(row_lengths[j], start, length);
421 const size_type n_columns)
431 const std::vector<size_type> &col_indices)
437 for (
size_type j=0; j<col_indices.size(); ++j)
449 for (
size_type i=0; i<partitioning.size(); ++i)
450 for (
size_type j=0; j<partitioning.size(); ++j)
452 partitioning[j].size(),
468 const std::vector<size_type> &row_block_sizes,
469 const std::vector<size_type> &col_block_sizes)
472 reinit(row_block_sizes.size(), col_block_sizes.size());
473 for (
size_type i=0; i<row_block_sizes.size(); ++i)
474 for (
size_type j=0; j<col_block_sizes.size(); ++j)
475 this->
block(i,j).
reinit(row_block_sizes[i],col_block_sizes[j]);
481 const std::vector< IndexSet > &partitioning)
484 reinit(partitioning.size(), partitioning.size());
485 for (
size_type i=0; i<partitioning.size(); ++i)
486 for (
size_type j=0; j<partitioning.size(); ++j)
488 partitioning[j].size(),
508 #ifdef DEAL_II_WITH_TRILINOS 514 const size_type n_columns)
524 const std::vector<size_type> &col_indices)
530 for (
size_type j=0; j<col_indices.size(); ++j)
541 (parallel_partitioning.size(),
542 parallel_partitioning.size())
544 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
545 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
547 parallel_partitioning[j]);
555 const MPI_Comm &communicator)
558 (parallel_partitioning.size(),
559 parallel_partitioning.size())
561 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
562 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
564 parallel_partitioning[j],
573 const std::vector<IndexSet> &col_parallel_partitioning,
574 const std::vector<IndexSet> &writable_rows,
575 const MPI_Comm &communicator)
578 (row_parallel_partitioning.size(),
579 col_parallel_partitioning.size())
581 for (
size_type i=0; i<row_parallel_partitioning.size(); ++i)
582 for (
size_type j=0; j<col_parallel_partitioning.size(); ++j)
583 this->
block(i,j).
reinit(row_parallel_partitioning[i],
584 col_parallel_partitioning[j],
594 const std::vector<size_type> &col_block_sizes)
597 reinit(row_block_sizes.size(), col_block_sizes.size());
598 for (
size_type i=0; i<row_block_sizes.size(); ++i)
599 for (
size_type j=0; j<col_block_sizes.size(); ++j)
600 this->
block(i,j).
reinit(row_block_sizes[i],col_block_sizes[j]);
610 reinit(parallel_partitioning.size(),
611 parallel_partitioning.size());
612 for (
size_type i=0; i<parallel_partitioning.size(); ++i)
613 for (
size_type j=0; j<parallel_partitioning.size(); ++j)
615 parallel_partitioning[j]);
623 const MPI_Comm &communicator)
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],
640 const std::vector<IndexSet> &col_parallel_partitioning,
641 const MPI_Comm &communicator)
644 reinit(row_parallel_partitioning.size(),
645 col_parallel_partitioning.size());
646 for (
size_type i=0; i<row_parallel_partitioning.size(); ++i)
647 for (
size_type j=0; j<col_parallel_partitioning.size(); ++j)
648 this->
block(i,j).
reinit(row_parallel_partitioning[i],
649 col_parallel_partitioning[j],
658 const std::vector<IndexSet> &col_parallel_partitioning,
659 const std::vector<IndexSet> &writable_rows,
660 const MPI_Comm &communicator)
662 AssertDimension(writable_rows.size(), row_parallel_partitioning.size());
664 reinit(row_parallel_partitioning.size(),
665 col_parallel_partitioning.size());
666 for (
size_type i=0; i<row_parallel_partitioning.size(); ++i)
667 for (
size_type j=0; j<col_parallel_partitioning.size(); ++j)
668 this->
block(i,j).
reinit(row_parallel_partitioning[i],
669 col_parallel_partitioning[j],
681 #ifdef DEAL_II_WITH_TRILINOS 685 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 &)
BlockDynamicSparsityPattern()=default
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)
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
BlockSparsityPattern()=default
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
BlockSparsityPattern()=default
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
static ::ExceptionBase & ExcInternalError()