Loading [MathJax]/extensions/TeX/newcommand.js
 Reference documentation for deal.II version 9.4.1
\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\}}
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
petsc_parallel_block_sparse_matrix.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2004 - 2022 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
22namespace PETScWrappers
23{
24 namespace MPI
25 {
28 {
30
31 return *this;
32 }
33
34
35# ifndef DOXYGEN
36 void
37 BlockSparseMatrix::reinit(const size_type n_block_rows,
38 const size_type n_block_columns)
39 {
40 // first delete previous content of
41 // the subobjects array
42 clear();
43
44 // then resize. set sizes of blocks to
45 // zero. user will later have to call
46 // collect_sizes for this
47 this->sub_objects.reinit(n_block_rows, n_block_columns);
48 this->row_block_indices.reinit(n_block_rows, 0);
49 this->column_block_indices.reinit(n_block_columns, 0);
50
51 // and reinitialize the blocks
52 for (size_type r = 0; r < this->n_block_rows(); ++r)
53 for (size_type c = 0; c < this->n_block_cols(); ++c)
54 {
55 BlockType *p = new BlockType();
56 this->sub_objects[r][c] = p;
57 }
58 }
59# endif
60
61 void
62 BlockSparseMatrix::reinit(const std::vector<IndexSet> & rows,
63 const std::vector<IndexSet> & cols,
65 const MPI_Comm & com)
66 {
67 Assert(rows.size() == bdsp.n_block_rows(), ExcMessage("invalid size"));
68 Assert(cols.size() == bdsp.n_block_cols(), ExcMessage("invalid size"));
69
70
71 clear();
72 this->sub_objects.reinit(bdsp.n_block_rows(), bdsp.n_block_cols());
73
74 std::vector<types::global_dof_index> row_sizes;
75 for (unsigned int r = 0; r < bdsp.n_block_rows(); ++r)
76 row_sizes.push_back(bdsp.block(r, 0).n_rows());
77 this->row_block_indices.reinit(row_sizes);
78
79 std::vector<types::global_dof_index> col_sizes;
80 for (unsigned int c = 0; c < bdsp.n_block_cols(); ++c)
81 col_sizes.push_back(bdsp.block(0, c).n_cols());
82 this->column_block_indices.reinit(col_sizes);
83
84 for (unsigned int r = 0; r < this->n_block_rows(); ++r)
85 for (unsigned int c = 0; c < this->n_block_cols(); ++c)
86 {
87 Assert(rows[r].size() == bdsp.block(r, c).n_rows(),
88 ExcMessage("invalid size"));
89 Assert(cols[c].size() == bdsp.block(r, c).n_cols(),
90 ExcMessage("invalid size"));
91
92 BlockType *p = new BlockType();
93 p->reinit(rows[r], cols[c], bdsp.block(r, c), com);
94 this->sub_objects[r][c] = p;
95 }
96
98 }
99
100 void
101 BlockSparseMatrix::reinit(const std::vector<IndexSet> & sizes,
102 const BlockDynamicSparsityPattern &bdsp,
103 const MPI_Comm & com)
104 {
105 reinit(sizes, sizes, bdsp, com);
106 }
107
108
109
110 void
112 {
114 }
115
116 std::vector<IndexSet>
118 {
119 std::vector<IndexSet> index_sets;
120
121 for (unsigned int i = 0; i < this->n_block_cols(); ++i)
122 index_sets.push_back(this->block(0, i).locally_owned_domain_indices());
123
124 return index_sets;
125 }
126
127 std::vector<IndexSet>
129 {
130 std::vector<IndexSet> index_sets;
131
132 for (unsigned int i = 0; i < this->n_block_rows(); ++i)
133 index_sets.push_back(this->block(i, 0).locally_owned_range_indices());
134
135 return index_sets;
136 }
137
138 std::uint64_t
140 {
141 std::uint64_t n_nonzero = 0;
142 for (size_type rows = 0; rows < this->n_block_rows(); ++rows)
143 for (size_type cols = 0; cols < this->n_block_cols(); ++cols)
144 n_nonzero += this->block(rows, cols).n_nonzero_elements();
145
146 return n_nonzero;
147 }
148
149 const MPI_Comm &
151 {
152 return block(0, 0).get_mpi_communicator();
153 }
154
155 } // namespace MPI
156} // namespace PETScWrappers
157
158
159
161
162#endif
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
std::size_t n_nonzero_elements() const
virtual void reinit(const SparsityPattern &sparsity)
Subscriptor & operator=(const Subscriptor &)
Definition: subscriptor.h:291
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Table< 2, SmartPointer< BlockType, BlockMatrixBase< SparseMatrix > > > sub_objects
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcMessage(std::string arg1)
unsigned int n_block_rows() const
unsigned int n_block_cols() const
BlockType & block(const unsigned int row, const unsigned int column)
void reinit(const size_type n_block_rows, const size_type n_block_columns)
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
std::vector< IndexSet > locally_owned_domain_indices() const
SparsityPatternType & block(const size_type row, const size_type column)