LifeV
PreconditionerComposed.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief File containing the Composed Preconditioner Class
30  *
31  * @date 07-05-2009
32  * @author Simone Deparis <simone.deparis@epfl.ch>, Paolo Crosetto <paolo.crosetto@epfl.ch>
33  *
34  * @contributor Paolo Crosetto <paolo.crosetto@epfl.ch>
35  * @maintainer Paolo Crosetto <paolo.crosetto@epfl.ch>
36  * Class handling a preconditioner defined as a multiplication of several preconditioners. The class inherits
37  * from the base Preconditioner class and implements some methds which are used in the EpetraOperator, so that it can be
38  * passed as a template argument to the ComposedOperator object.
39  */
40 
41 #ifndef PreconditionerComposed_HPP
42 #define PreconditionerComposed_HPP
43 
44 #include <lifev/core/filter/GetPot.hpp>
45 #include <lifev/core/array/MatrixEpetra.hpp>
46 #include <lifev/core/algorithm/Preconditioner.hpp>
47 #include <lifev/core/algorithm/ComposedOperator.hpp>
48 
49 namespace LifeV
50 {
51 
52 //! PreconditionerComposed -
53 /*!
54  @author Simone Deparis, Paolo Crosetto
55  @mantainer Paolo Crosetto
56  * Class handling a preconditioner defined as a multiplication of several preconditioners. The class inherits
57  * from the base Preconditioner class and implements some methds which are used in the EpetraOperator, so that it can be
58  * passed as a template argument to the ComposedOperator object. It contains an instance of ComposedOperator, which will be filled with
59  * shared pointers to trilinos preconditioners (more generally Epetra_Operators)
60  * and a vector of shared pointers to LifeV matrices (of MatrixEpetra type, in M_operVector). Notice that the matrices are not copied when the
61  * push_back method is called, and not even if the
62  * copy constructor is called. Only the shared pointers are copied. The same happens to the preconditioners through the constructor of
63  * the ComposedOperator class, which behave in the same way.
64  */
65 class PreconditionerComposed:
66  public Preconditioner
67 {
68 public:
69 
70  /** @name Typedefs
71  */
72  //@{
73 
74  typedef Preconditioner super_Type;
75  typedef ComposedOperator<Preconditioner> prec_Type;
76  typedef std::shared_ptr<prec_Type> precPtr_Type;
77  typedef std::shared_ptr<Preconditioner> epetraPrecPtr_Type;
78  typedef super_Type::operator_raw_type operator_Type;
79  typedef std::shared_ptr<operator_Type> operatorPtr_Type;
80  typedef super_Type::list_Type list_Type;
81  //typedef std::shared_ptr<Preconditioner> epetraPrec_Type;
82 
83 
84  /** @name Constructors, destructor
85  */
86  //@{
87  //! default constructor.
88  PreconditionerComposed ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm>() );
89 
90 private: //set it private to be sure that it's never called
91  //!Copy Constructor
92  /**
93  This copy constructor does not copy the matrices, but just the shared_ptrs. It calls the copy constructor of ComposedOperator.
94  */
95  PreconditionerComposed ( PreconditionerComposed& P );
96 
97 public:
98  //! constructor from matrix A.
99  //! @param A MatrixEpetra<double> matrix upon which construct the preconditioner
100  // PreconditionerComposed(operatorPtr_Type& A);
101 
102  //! default destructor
103 
104  virtual ~PreconditionerComposed();
105 
106  //@}
107 
108 
109  //!@name Public Methods
110  //@{
111  //! Sets the data from GetPot
112  void setDataFromGetPot ( const GetPot& dataFile,
113  const std::string& section);
114  //! Creates the Trilinos Teuchos parameter list reading from data file
115  void createParametersList ( list_Type& /*list*/, const GetPot& dataFile, const std::string& section, const std::string& subSection );
116 
117  //! Returns an estimate of the condition number
118  double condest ();
119 
120  //! same as push_back
121  int buildPreconditioner (operatorPtr_Type& A);
122 
123  //! same as push_back
124  int buildPreconditioner (operatorPtr_Type& A,
125  const bool useInverse,
126  const bool useTranspose = false);
127  //! Builds a preconditioner based on A and pushes it back in the composedPreconditioner.
128  int push_back (operatorPtr_Type& A,
129  const bool useInverse = false,
130  const bool useTranspose = false
131  );
132 
133  //! Builds a preconditioner based on A and replaces it in the composedPreconditioner.
134  int replace (operatorPtr_Type& A,
135  const UInt index,
136  const bool useInverse = false,
137  const bool useTranspose = false);
138 
139  //! resets the pointer to the preconditioner M_prec
140  void resetPreconditioner();
141 
142  //! returns the operator vectir
143  const std::vector<operatorPtr_Type>& operVector() const
144  {
145  return M_operVector;
146  }
147  //@}
148 
149  //!@name Implementation of Methods from Epetra_Operator
150  //@{
151  //! returns the communicator
152  const Epetra_Comm& Comm()
153  {
154  return preconditioner()->Comm();
155  }
156 
157  //! sets the M_useTranspose flag
158  int SetUseTranspose ( bool useTranspose = false )
159  {
160  return M_prec->SetUseTranspose (useTranspose);
161  }
162  //! returns the M_useTranspose flag
163  bool UseTranspose( )
164  {
165  return M_prec->UseTranspose();
166  }
167 
168  //! Applies the inverse operator to an input vector
169  /**
170  \param X: input vector
171  \param Y: output vector
172  */
173  virtual int ApplyInverse (const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
174  {
175  return M_prec->ApplyInverse (X, Y);
176  }
177 
178  //! Applies the operator to an input vector
179  /**
180  \param X: input vector
181  \param Y: output vector
182  */
183  virtual int Apply (const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
184  {
185  return M_prec->Apply (X, Y);
186  }
187 
188  //! returns the range map
189  const Epetra_Map& OperatorRangeMap() const
190  {
191  return M_prec->OperatorRangeMap();
192  }
193 
194  //! returns the domain map
195  const Epetra_Map& OperatorDomainMap() const
196  {
197  return M_prec->OperatorDomainMap();
198  }
199  //@}
200 
201  //!@name Get Methods
202  //@{
203  //! returns a raw pointer to the preconditioner base class
204  super_Type::prec_raw_type* preconditioner ();
205 
206  //! returms the number of factors in the preconditioner
207  UInt number() const
208  {
209  return M_prec->number();
210  }
211 
212  //! returns a shared pointer to the preconditioner
213  super_Type::prec_type preconditionerPtr()
214  {
215  return M_prec;
216  }
217 
218  //! returns a shared pointer to the preconditioner
219  const precPtr_Type composedPreconditionerPtr()
220  {
221  return M_prec;
222  }
223 
224  //! returns a string identifying the preconditioner type
225  std::string preconditionerType()
226  {
227  return "PreconditionerComposed";
228  }
229  //@}
230 
231  //!@name Static Methods
232  //@{
233 
234  //! Factory method
235  static Preconditioner* createComposedPreconditioner()
236  {
237  return new PreconditionerComposed();
238  }
239  //@}
240 
241 private:
242 
243  //!@name Private Methods
244  //@{
245  void myCreateParametersList (const GetPot& dataFile, const std::string& section, const std::string& subSection);
246 
247  Int createPrec (operatorPtr_Type& oper,
248  std::shared_ptr<Preconditioner>& prec);
249  //@}
250 
251 
252  //!@name Private Members
253  //@{
254  std::vector<operatorPtr_Type> M_operVector; // we need to keep track of all the operators.
255  precPtr_Type M_prec;
256  static bool registerComposed;
257  //@}
258 };
259 
260 } // namespace LifeV
261 
262 #endif // PreconditionerComposed_HPP
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191