Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
petsc_parallel_block_sparse_matrix.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
17 
18 #ifdef DEAL_II_WITH_PETSC
19 
21 
22 namespace PETScWrappers
23 {
24  namespace MPI
25  {
28  {
29  BaseClass::operator=(m);
30 
31  return *this;
32  }
33 
34 
35  void
37  const size_type n_block_columns)
38  {
39  // first delete previous content of
40  // the subobjects array
41  clear();
42 
43  // then resize. set sizes of blocks to
44  // zero. user will later have to call
45  // collect_sizes for this
46  this->sub_objects.reinit(n_block_rows, n_block_columns);
47  this->row_block_indices.reinit(n_block_rows, 0);
48  this->column_block_indices.reinit(n_block_columns, 0);
49 
50  // and reinitialize the blocks
51  for (size_type r = 0; r < this->n_block_rows(); ++r)
52  for (size_type c = 0; c < this->n_block_cols(); ++c)
53  {
54  BlockType *p = new BlockType();
55  this->sub_objects[r][c] = p;
56  }
57  }
58 
59  void
60  BlockSparseMatrix::reinit(const std::vector<IndexSet> & rows,
61  const std::vector<IndexSet> & cols,
62  const BlockDynamicSparsityPattern &bdsp,
63  const MPI_Comm & com)
64  {
65  Assert(rows.size() == bdsp.n_block_rows(), ExcMessage("invalid size"));
66  Assert(cols.size() == bdsp.n_block_cols(), ExcMessage("invalid size"));
67 
68 
69  clear();
70  this->sub_objects.reinit(bdsp.n_block_rows(), bdsp.n_block_cols());
71 
72  std::vector<types::global_dof_index> row_sizes;
73  for (unsigned int r = 0; r < bdsp.n_block_rows(); ++r)
74  row_sizes.push_back(bdsp.block(r, 0).n_rows());
75  this->row_block_indices.reinit(row_sizes);
76 
77  std::vector<types::global_dof_index> col_sizes;
78  for (unsigned int c = 0; c < bdsp.n_block_cols(); ++c)
79  col_sizes.push_back(bdsp.block(0, c).n_cols());
80  this->column_block_indices.reinit(col_sizes);
81 
82  for (unsigned int r = 0; r < this->n_block_rows(); ++r)
83  for (unsigned int c = 0; c < this->n_block_cols(); ++c)
84  {
85  Assert(rows[r].size() == bdsp.block(r, c).n_rows(),
86  ExcMessage("invalid size"));
87  Assert(cols[c].size() == bdsp.block(r, c).n_cols(),
88  ExcMessage("invalid size"));
89 
90  BlockType *p = new BlockType();
91  p->reinit(rows[r], cols[c], bdsp.block(r, c), com);
92  this->sub_objects[r][c] = p;
93  }
94 
95  collect_sizes();
96  }
97 
98  void
99  BlockSparseMatrix::reinit(const std::vector<IndexSet> & sizes,
100  const BlockDynamicSparsityPattern &bdsp,
101  const MPI_Comm & com)
102  {
103  reinit(sizes, sizes, bdsp, com);
104  }
105 
106 
107 
108  void
110  {
112  }
113 
114  std::vector<IndexSet>
116  {
117  std::vector<IndexSet> index_sets;
118 
119  for (unsigned int i = 0; i < this->n_block_cols(); ++i)
120  index_sets.push_back(this->block(0, i).locally_owned_domain_indices());
121 
122  return index_sets;
123  }
124 
125  std::vector<IndexSet>
127  {
128  std::vector<IndexSet> index_sets;
129 
130  for (unsigned int i = 0; i < this->n_block_rows(); ++i)
131  index_sets.push_back(this->block(i, 0).locally_owned_range_indices());
132 
133  return index_sets;
134  }
135 
136  const MPI_Comm &
138  {
139  return block(0, 0).get_mpi_communicator();
140  }
141 
142  } // namespace MPI
143 } // namespace PETScWrappers
144 
145 
146 
148 
149 #endif
BlockMatrixBase< SparseMatrix >::row_block_indices
BlockIndices row_block_indices
Definition: block_matrix_base.h:849
DynamicSparsityPattern::n_cols
size_type n_cols() const
Definition: dynamic_sparsity_pattern.h:1024
PETScWrappers
Definition: petsc_block_sparse_matrix.h:36
PETScWrappers::MPI::BlockSparseMatrix::reinit
void reinit(const size_type n_block_rows, const size_type n_block_columns)
BlockMatrixBase< SparseMatrix >::n_block_cols
unsigned int n_block_cols() const
PETScWrappers::MPI::BlockSparseMatrix::collect_sizes
void collect_sizes()
Definition: petsc_parallel_block_sparse_matrix.cc:109
SparseMatrix
Definition: sparse_matrix.h:497
TableBase::reinit
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
MPI_Comm
BlockDynamicSparsityPattern
Definition: block_sparsity_pattern.h:521
BlockMatrixBase< SparseMatrix >::n_block_rows
unsigned int n_block_rows() const
BlockMatrixBase< SparseMatrix >::m
size_type m() const
BlockMatrixBase< SparseMatrix >::sub_objects
Table< 2, SmartPointer< BlockType, BlockMatrixBase< SparseMatrix > > > sub_objects
Definition: block_matrix_base.h:855
BlockSparsityPatternBase::n_block_cols
size_type n_block_cols() const
Definition: block_sparsity_pattern.h:941
BlockMatrixBase< SparseMatrix >::block
BlockType & block(const unsigned int row, const unsigned int column)
BlockMatrixBase< SparseMatrix >::collect_sizes
void collect_sizes()
StandardExceptions::ExcMessage
static ::ExceptionBase & ExcMessage(std::string arg1)
BlockMatrixBase< SparseMatrix >::clear
void clear()
SparseMatrix::reinit
virtual void reinit(const SparsityPattern &sparsity)
BlockSparsityPatternBase::n_block_rows
size_type n_block_rows() const
Definition: block_sparsity_pattern.h:950
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
DynamicSparsityPattern::n_rows
size_type n_rows() const
Definition: dynamic_sparsity_pattern.h:1016
BlockSparsityPatternBase::block
SparsityPatternType & block(const size_type row, const size_type column)
Definition: block_sparsity_pattern.h:755
PETScWrappers::MPI::BlockSparseMatrix::BlockType
BaseClass::BlockType BlockType
Definition: petsc_block_sparse_matrix.h:78
unsigned int
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
BlockIndices::reinit
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
Definition: block_indices.h:260
PETScWrappers::MPI::BlockSparseMatrix::locally_owned_domain_indices
std::vector< IndexSet > locally_owned_domain_indices() const
Definition: petsc_parallel_block_sparse_matrix.cc:115
BlockMatrixBase< SparseMatrix >::column_block_indices
BlockIndices column_block_indices
Definition: block_matrix_base.h:850
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
PETScWrappers::MPI::BlockSparseMatrix::operator=
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
Definition: petsc_parallel_block_sparse_matrix.cc:27
PETScWrappers::MPI::BlockSparseMatrix::get_mpi_communicator
const MPI_Comm & get_mpi_communicator() const
Definition: petsc_parallel_block_sparse_matrix.cc:137
petsc_block_sparse_matrix.h
PETScWrappers::MPI::BlockSparseMatrix
Definition: petsc_block_sparse_matrix.h:67
PETScWrappers::MPI::BlockSparseMatrix::locally_owned_range_indices
std::vector< IndexSet > locally_owned_range_indices() const
Definition: petsc_parallel_block_sparse_matrix.cc:126
BlockSparseMatrix
Definition: block_sparse_matrix.h:50