Reference documentation for deal.II version 8.4.1
iterative_inverse.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2015 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  // dummy variable
133  VectorType *v = 0;
134  matrix = std_cxx11::shared_ptr<PointerMatrixBase<VectorType> > (new_pointer_matrix_base(m, *v));
135  preconditioner = std_cxx11::shared_ptr<PointerMatrixBase<VectorType> > (new_pointer_matrix_base(p, *v));
136 }
137 
138 
139 template <typename VectorType>
140 inline
141 void
143 {
144  matrix = 0;
145  preconditioner = 0;
146 }
147 
148 
149 template <typename VectorType>
150 inline void
151 IterativeInverse<VectorType>::vmult (VectorType &dst, const VectorType &src) const
152 {
153  Assert(matrix.get() != 0, ExcNotInitialized());
154  Assert(preconditioner.get() != 0, ExcNotInitialized());
155  dst = 0.;
156  solver.solve(*matrix, dst, src, *preconditioner);
157 }
158 
159 
160 template <typename VectorType>
161 template <class OtherVectorType>
162 inline void
163 IterativeInverse<VectorType>::vmult (OtherVectorType &dst, const OtherVectorType &src) const
164 {
165  Assert(matrix.get() != 0, ExcNotInitialized());
166  Assert(preconditioner.get() != 0, ExcNotInitialized());
168  typename VectorMemory<VectorType>::Pointer sol(mem);
169  typename VectorMemory<VectorType>::Pointer rhs(mem);
170  sol->reinit(dst);
171  *rhs = src;
172  solver.solve(*matrix, *sol, *rhs, *preconditioner);
173  dst = *sol;
174 }
175 
176 
177 
178 DEAL_II_NAMESPACE_CLOSE
179 
180 #endif
SolverSelector< VectorType > solver
void vmult(VectorType &dst, const VectorType &src) const
PointerMatrixBase< VectorType > * new_pointer_matrix_base(MatrixType &matrix, const VectorType &, const char *name="PointerMatrixAux")
#define Assert(cond, exc)
Definition: exceptions.h:294
void initialize(const MatrixType &, const PreconditionerType &)
std_cxx11::shared_ptr< PointerMatrixBase< VectorType > > matrix
std_cxx11::shared_ptr< PointerMatrixBase< VectorType > > preconditioner