Reference documentation for deal.II version 9.5.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\}}\)
Loading...
Searching...
No Matches
petsc_matrix_free.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2012 - 2023 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
16
18
19#ifdef DEAL_II_WITH_PETSC
20
23
25
26namespace PETScWrappers
27{
29 {
30 const int m = 0;
32 }
33
34
35
36 MatrixFree::MatrixFree(const MPI_Comm communicator,
37 const unsigned int m,
38 const unsigned int n,
39 const unsigned int local_rows,
40 const unsigned int local_columns)
41 {
42 do_reinit(communicator, m, n, local_rows, local_columns);
43 }
44
45
46
48 const MPI_Comm communicator,
49 const unsigned int m,
50 const unsigned int n,
51 const std::vector<unsigned int> &local_rows_per_process,
52 const std::vector<unsigned int> &local_columns_per_process,
53 const unsigned int this_process)
54 {
59
60 do_reinit(communicator,
61 m,
62 n,
65 }
66
67
68
69 MatrixFree::MatrixFree(const unsigned int m,
70 const unsigned int n,
71 const unsigned int local_rows,
72 const unsigned int local_columns)
73 {
75 }
76
77
78
97
98
99
100 void
101 MatrixFree::reinit(const MPI_Comm communicator,
102 const unsigned int m,
103 const unsigned int n,
104 const unsigned int local_rows,
105 const unsigned int local_columns)
106 {
107 // destroy the matrix and generate a new one
110
111 do_reinit(communicator, m, n, local_rows, local_columns);
112 }
113
114
115
116 void
117 MatrixFree::reinit(const MPI_Comm communicator,
118 const unsigned int m,
119 const unsigned int n,
120 const std::vector<unsigned int> &local_rows_per_process,
121 const std::vector<unsigned int> &local_columns_per_process,
122 const unsigned int this_process)
123 {
128
131
132 do_reinit(communicator,
133 m,
134 n,
137 }
138
139
140
141 void
142 MatrixFree::reinit(const unsigned int m,
143 const unsigned int n,
144 const unsigned int local_rows,
145 const unsigned int local_columns)
146 {
148 }
149
150
151
152 void
153 MatrixFree::reinit(const unsigned int m,
154 const unsigned int n,
155 const std::vector<unsigned int> &local_rows_per_process,
156 const std::vector<unsigned int> &local_columns_per_process,
157 const unsigned int this_process)
158 {
160 m,
161 n,
165 }
166
167
168
169 void
171 {
174
175 const int m = 0;
177 }
178
179
180
181 void
182 MatrixFree::vmult(Vec &dst, const Vec &src) const
183 {
184 // VectorBase permits us to manipulate, but not own, a Vec
187
188 // This is implemented by derived classes
189 vmult(y, x);
190 }
191
192
193
194 int
195 MatrixFree::matrix_free_mult(Mat A, Vec src, Vec dst)
196 {
197 // create a pointer to this MatrixFree
198 // object and link the given matrix A
199 // to the matrix-vector multiplication
200 // of this MatrixFree object,
201 void * this_object;
204
205 // call vmult of this object:
206 reinterpret_cast<MatrixFree *>(this_object)->vmult(dst, src);
207
208 return (0);
209 }
210
211
212
213 void
214 MatrixFree::do_reinit(const MPI_Comm communicator,
215 const unsigned int m,
216 const unsigned int n,
217 const unsigned int local_rows,
218 const unsigned int local_columns)
219 {
222
223 // create a PETSc MatShell matrix-type
224 // object of dimension m x n and local size
225 // local_rows x local_columns
226 PetscErrorCode ierr = MatCreateShell(communicator,
229 m,
230 n,
231 static_cast<void *>(this),
232 &matrix);
234 // register the MatrixFree::matrix_free_mult function
235 // as the matrix multiplication used by this matrix
237 matrix,
239 reinterpret_cast<void (*)()>(
242
245 }
246} // namespace PETScWrappers
247
248
250
251#endif // DEAL_II_WITH_PETSC
std::size_t size() const
Definition array_view.h:576
MPI_Comm get_mpi_communicator() const
void reinit(const MPI_Comm communicator, const unsigned int m, const unsigned int n, const unsigned int local_rows, const unsigned int local_columns)
static int matrix_free_mult(Mat A, Vec src, Vec dst)
void do_reinit(const MPI_Comm comm, const unsigned int m, const unsigned int n, const unsigned int local_rows, const unsigned int local_columns)
virtual void vmult(VectorBase &dst, const VectorBase &src) const =0
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define AssertThrow(cond, exc)