Reference documentation for deal.II version 8.5.1
iterative_inverse.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2017 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__iterative_inverse_h
17 #define dealii__iterative_inverse_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/smartpointer.h>
21 #include <deal.II/lac/solver_selector.h>
22 #include <deal.II/lac/vector_memory.h>
23 #include <deal.II/lac/pointer_matrix.h>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
27 
78 template <typename VectorType>
80 {
81 public:
86  template <typename MatrixType, typename PreconditionerType>
87  void initialize (const MatrixType &, const PreconditionerType &);
88 
92  void clear();
93 
97  void vmult (VectorType &dst, const VectorType &src) const;
98 
104  template <class OtherVectorType>
105  void vmult (OtherVectorType &dst, const OtherVectorType &src) const;
106 
112 
113 private:
117  std_cxx11::shared_ptr<PointerMatrixBase<VectorType> > matrix;
118 
122  std_cxx11::shared_ptr<PointerMatrixBase<VectorType> > preconditioner;
123 };
124 
125 
126 template <typename VectorType>
127 template <typename MatrixType, typename PreconditionerType>
128 inline
129 void
130 IterativeInverse<VectorType>::initialize(const MatrixType &m, const PreconditionerType &p)
131 {
132  VectorType v;
133  matrix = std_cxx11::shared_ptr<PointerMatrixBase<VectorType> > (new_pointer_matrix_base(m, v));
134  preconditioner = std_cxx11::shared_ptr<PointerMatrixBase<VectorType> > (new_pointer_matrix_base(p, v));
135 }
136 
137 
138 template <typename VectorType>
139 inline
140 void
142 {
143  matrix = 0;
144  preconditioner = 0;
145 }
146 
147 
148 template <typename VectorType>
149 inline void
150 IterativeInverse<VectorType>::vmult (VectorType &dst, const VectorType &src) const
151 {
152  Assert(matrix.get() != 0, ExcNotInitialized());
153  Assert(preconditioner.get() != 0, ExcNotInitialized());
154  dst = 0.;
155  solver.solve(*matrix, dst, src, *preconditioner);
156 }
157 
158 
159 template <typename VectorType>
160 template <class OtherVectorType>
161 inline void
162 IterativeInverse<VectorType>::vmult (OtherVectorType &dst, const OtherVectorType &src) const
163 {
164  Assert(matrix.get() != 0, ExcNotInitialized());
165  Assert(preconditioner.get() != 0, ExcNotInitialized());
167  typename VectorMemory<VectorType>::Pointer sol(mem);
168  typename VectorMemory<VectorType>::Pointer rhs(mem);
169  sol->reinit(dst);
170  *rhs = src;
171  solver.solve(*matrix, *sol, *rhs, *preconditioner);
172  dst = *sol;
173 }
174 
175 
176 
177 DEAL_II_NAMESPACE_CLOSE
178 
179 #endif
SolverSelector< VectorType > solver
static ::ExceptionBase & ExcNotInitialized()
PointerMatrixBase< VectorType > * new_pointer_matrix_base(MatrixType &matrix, const VectorType &, const char *name="PointerMatrixAux")
#define Assert(cond, exc)
Definition: exceptions.h:313
void initialize(const MatrixType &, const PreconditionerType &)
void vmult(VectorType &dst, const VectorType &src) const
std_cxx11::shared_ptr< PointerMatrixBase< VectorType > > matrix
std_cxx11::shared_ptr< PointerMatrixBase< VectorType > > preconditioner