Reference documentation for deal.II version 8.4.2
mg_coarse.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__mg_coarse_h
17 #define dealii__mg_coarse_h
18 
19 
20 #include <deal.II/lac/full_matrix.h>
21 #include <deal.II/lac/matrix_lib.h>
22 #include <deal.II/lac/householder.h>
23 #include <deal.II/multigrid/mg_base.h>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
29 
41 template<typename SolverType, class VectorType = Vector<double> >
42 class MGCoarseGridLACIteration : public MGCoarseGridBase<VectorType>
43 {
44 public:
49 
54  template<typename MatrixType, typename PreconditionerType>
55  MGCoarseGridLACIteration (SolverType &,
56  const MatrixType &,
57  const PreconditionerType &);
58 
63 
67  template<typename MatrixType, typename PreconditionerType>
68  void initialize (SolverType &,
69  const MatrixType &,
70  const PreconditionerType &);
71 
75  void clear ();
76 
81  void operator() (const unsigned int level,
82  VectorType &dst,
83  const VectorType &src) const;
84 
89  template <typename MatrixType>
90  void set_matrix (const MatrixType &);
91 
92 private:
97 
102 
107 };
108 
109 
110 
121 template<typename number = double, class VectorType = Vector<number> >
122 class MGCoarseGridHouseholder : public MGCoarseGridBase<VectorType>
123 {
124 public:
129 
133  void initialize (const FullMatrix<number> &A);
134 
135  void operator() (const unsigned int level,
136  VectorType &dst,
137  const VectorType &src) const;
138 
139 private:
144 };
145 
154 template<typename number = double, class VectorType = Vector<number> >
155 class MGCoarseGridSVD : public MGCoarseGridBase<VectorType>
156 {
157 public:
161  MGCoarseGridSVD ();
162 
166  void initialize (const FullMatrix<number> &A, const double threshold = 0);
167 
168  void operator() (const unsigned int level,
169  VectorType &dst,
170  const VectorType &src) const;
171 
175  void log () const;
176 
177 private:
178 
183 };
184 
187 #ifndef DOXYGEN
188 /* ------------------ Functions for MGCoarseGridLACIteration ------------ */
189 
190 
191 template<typename SolverType, class VectorType>
194  :
195  solver(0, typeid(*this).name()),
196  matrix(0),
197  precondition(0)
198 {}
199 
200 
201 template<typename SolverType, class VectorType>
202 template<typename MatrixType, typename PreconditionerType>
204 ::MGCoarseGridLACIteration (SolverType &s,
205  const MatrixType &m,
206  const PreconditionerType &p)
207  :
208  solver(&s, typeid(*this).name())
209 {
212 }
213 
214 
215 template<typename SolverType, class VectorType>
218 {
219  clear();
220 }
221 
222 
223 template<typename SolverType, class VectorType>
224 template<typename MatrixType, typename PreconditionerType>
225 void
227 ::initialize (SolverType &s,
228  const MatrixType &m,
229  const PreconditionerType &p)
230 {
231  solver = &s;
232  if (matrix)
233  delete matrix;
235  if (precondition)
236  delete precondition;
238 }
239 
240 
241 template<typename SolverType, class VectorType>
242 void
244 ::clear()
245 {
246  solver = 0;
247  if (matrix)
248  delete matrix;
249  matrix = 0;
250  if (precondition)
251  delete precondition;
252  precondition = 0;
253 }
254 
255 
256 template<typename SolverType, class VectorType>
257 void
259 ::operator() (const unsigned int /* level */,
260  VectorType &dst,
261  const VectorType &src) const
262 {
263  Assert(solver!=0, ExcNotInitialized());
264  Assert(matrix!=0, ExcNotInitialized());
265  Assert(precondition!=0, ExcNotInitialized());
266  solver->solve(*matrix, dst, src, *precondition);
267 }
268 
269 
270 template<typename SolverType, class VectorType>
271 template<typename MatrixType>
272 void
274 ::set_matrix(const MatrixType &m)
275 {
276  if (matrix)
277  delete matrix;
279 }
280 
281 //---------------------------------------------------------------------------
282 
283 template<typename number, class VectorType>
285 (const FullMatrix<number> *A)
286 {
287  if (A != 0) householder.initialize(*A);
288 }
289 
290 
291 
292 template<typename number, class VectorType>
293 void
295 {
296  householder.initialize(A);
297 }
298 
299 
300 
301 template<typename number, class VectorType>
302 void
304  VectorType &dst,
305  const VectorType &src) const
306 {
307  householder.least_squares(dst, src);
308 }
309 
310 //---------------------------------------------------------------------------
311 
312 template<typename number, class VectorType>
313 inline
315 {}
316 
317 
318 
319 template<typename number, class VectorType>
320 void
322  double threshold)
323 {
324  matrix.reinit(A.n_rows(), A.n_cols());
325  matrix = A;
326  matrix.compute_inverse_svd(threshold);
327 }
328 
329 
330 template<typename number, class VectorType>
331 void
333  const unsigned int /*level*/,
334  VectorType &dst,
335  const VectorType &src) const
336 {
337  matrix.vmult(dst, src);
338 }
339 
340 
341 template<typename number, class VectorType>
342 void
344 {
345  const unsigned int n = std::min(matrix.n_rows(), matrix.n_cols());
346 
347  for (unsigned int i=0; i<n; ++i)
348  deallog << ' ' << matrix.singular_value(i);
349  deallog << std::endl;
350 }
351 
352 
353 #endif // DOXYGEN
354 
355 DEAL_II_NAMESPACE_CLOSE
356 
357 #endif
void initialize(const FullMatrix< number > &A, const double threshold=0)
MGCoarseGridHouseholder(const FullMatrix< number > *A=0)
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const
void initialize(SolverType &, const MatrixType &, const PreconditionerType &)
LAPACKFullMatrix< number > matrix
Definition: mg_coarse.h:182
PointerMatrixBase< VectorType > * matrix
Definition: mg_coarse.h:101
SmartPointer< SolverType, MGCoarseGridLACIteration< SolverType, VectorType > > solver
Definition: mg_coarse.h:96
#define Assert(cond, exc)
Definition: exceptions.h:294
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const
PointerMatrixBase< VectorType > * precondition
Definition: mg_coarse.h:106
Householder< number > householder
Definition: mg_coarse.h:143
void operator()(const unsigned int level, VectorType &dst, const VectorType &src) const
void initialize(const FullMatrix< number > &A)
void set_matrix(const MatrixType &)
void log() const