Reference documentation for deal.II version 8.1.0
iterative_inverse.h
1 // ---------------------------------------------------------------------
2 // @f$Id: iterative_inverse.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 1999 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__iterative_inverse_h
18 #define __deal2__iterative_inverse_h
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/smartpointer.h>
22 #include <deal.II/lac/solver_selector.h>
23 #include <deal.II/lac/vector_memory.h>
24 #include <deal.II/lac/pointer_matrix.h>
25 
27 
28 
78 template <class VECTOR>
80 {
81 public:
88  template <class MATRIX, class PRECONDITION>
89  void initialize (const MATRIX &, const PRECONDITION &);
90 
95  void clear();
96 
100  void vmult (VECTOR &dst, const VECTOR &src) const;
101 
107  template <class VECTOR2>
108  void vmult (VECTOR2 &dst, const VECTOR2 &src) const;
109 
117 
118 private:
122  std_cxx1x::shared_ptr<PointerMatrixBase<VECTOR> > matrix;
123 
127  std_cxx1x::shared_ptr<PointerMatrixBase<VECTOR> > preconditioner;
128 };
129 
130 
131 template <class VECTOR>
132 template <class MATRIX, class PRECONDITION>
133 inline
134 void
135 IterativeInverse<VECTOR>::initialize(const MATRIX &m, const PRECONDITION &p)
136 {
137  // dummy variable
138  VECTOR *v = 0;
139  matrix = std_cxx1x::shared_ptr<PointerMatrixBase<VECTOR> > (new_pointer_matrix_base(m, *v));
140  preconditioner = std_cxx1x::shared_ptr<PointerMatrixBase<VECTOR> > (new_pointer_matrix_base(p, *v));
141 }
142 
143 
144 template <class VECTOR>
145 inline
146 void
148 {
149  matrix = 0;
150  preconditioner = 0;
151 }
152 
153 
154 template <class VECTOR>
155 inline void
156 IterativeInverse<VECTOR>::vmult (VECTOR &dst, const VECTOR &src) const
157 {
158  Assert(matrix.get() != 0, ExcNotInitialized());
159  Assert(preconditioner.get() != 0, ExcNotInitialized());
160  dst = 0.;
161  solver.solve(*matrix, dst, src, *preconditioner);
162 }
163 
164 
165 template <class VECTOR>
166 template <class VECTOR2>
167 inline void
168 IterativeInverse<VECTOR>::vmult (VECTOR2 &dst, const VECTOR2 &src) const
169 {
170  Assert(matrix.get() != 0, ExcNotInitialized());
171  Assert(preconditioner.get() != 0, ExcNotInitialized());
173  typename VectorMemory<VECTOR>::Pointer sol(mem);
174  typename VectorMemory<VECTOR>::Pointer rhs(mem);
175  sol->reinit(dst);
176  *rhs = src;
177  solver.solve(*matrix, *sol, *rhs, *preconditioner);
178  dst = *sol;
179 }
180 
181 
182 
183 DEAL_II_NAMESPACE_CLOSE
184 
185 #endif
186 
187 
SolverSelector< VECTOR > solver
std_cxx1x::shared_ptr< PointerMatrixBase< VECTOR > > matrix
void vmult(VECTOR &dst, const VECTOR &src) const
#define Assert(cond, exc)
Definition: exceptions.h:299
std_cxx1x::shared_ptr< PointerMatrixBase< VECTOR > > preconditioner
::ExceptionBase & ExcNotInitialized()
void initialize(const MATRIX &, const PRECONDITION &)