LifeV
PreconditionerLinearSolver.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 Preconditioner Solver Belos
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @maintainer Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33 
34  @date 17-09-2011
35  */
36 
37 #ifndef PRECONDITIONERSOLVERBELOS_HPP
38 #define PRECONDITIONERSOLVERBELOS_HPP 1
39 
40 
41 #include <Teuchos_ParameterList.hpp>
42 #include "Teuchos_XMLParameterListHelpers.hpp"
43 #include <Epetra_Operator.h>
44 
45 
46 #include <lifev/core/array/MapEpetra.hpp>
47 #include <lifev/core/array/VectorEpetra.hpp>
48 #include <lifev/core/array/MatrixEpetra.hpp>
49 #include <lifev/core/util/Displayer.hpp>
50 #include <lifev/core/algorithm/Preconditioner.hpp>
51 #include <lifev/core/algorithm/LinearSolver.hpp>
52 #include <lifev/core/filter/GetPot.hpp>
53 
54 class GetPot;
55 
56 namespace LifeV
57 {
58 
59 //! PreconditionerLinearSolver - Class to wrap linear solver
60 /*!
61  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
62 */
63 class PreconditionerLinearSolver
64  : public Preconditioner
65 {
66 public:
67 
68  //! @name Public Types
69  //@{
70 
71  typedef Epetra_Operator prec_raw_type;
72  typedef std::shared_ptr<prec_raw_type> prec_type;
73 
74  typedef LinearSolver solver_Type;
75  typedef std::shared_ptr<solver_Type> solverPtr_Type;
76 
77  typedef MatrixEpetra<Real> operator_raw_type;
78  typedef std::shared_ptr<operator_raw_type> operator_type;
79 
80  typedef Preconditioner preconditioner_Type;
81  typedef std::shared_ptr<preconditioner_Type> preconditionerPtr_Type;
82 
83  typedef Displayer::comm_Type comm_Type;
84  typedef Displayer::commPtr_Type commPtr_Type;
85 
86  typedef Teuchos::ParameterList list_Type;
87 
88  //@}
89 
90 
91  //! @name Constructors & Destructor
92  //@{
93 
94  //! Default constructor
95  /*!
96  * @param comm The communicator.
97  */
98 #ifdef HAVE_MPI
99  PreconditionerLinearSolver ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_MpiComm ( MPI_COMM_WORLD ) ) );
100 #else
101  PreconditionerLinearSolver ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_SerialComm ) );
102 #endif
103 
104  //! Destructor
105  virtual ~PreconditionerLinearSolver();
106 
107  //@}
108 
109  //! @name Methods
110  //@{
111 
112  //! Create the list of parameters of the preconditioner
113  /*!
114  @param list A Parameter list to be filled
115  @param dataFile A GetPot object containing the data about the preconditioner
116  @param section The section in "dataFile" where to find data about the preconditioner
117  @param subSection The subsection in "dataFile" where to find data about the preconditioner
118  */
119  virtual void createParametersList ( list_Type& list,
120  const GetPot& dataFile,
121  const std::string& section,
122  const std::string& subSection );
123 
124  //! Create the list of parameters of the preconditioner
125  /*!
126  @param list A Parameter list to be filled
127  @param dataFile A GetPot object containing the data about the preconditioner
128  @param section The section in "dataFile" where to find data about the preconditioner
129  @param subSection The subsection in "dataFile" where to find data about the preconditioner
130  */
131  static void createLinearSolverList ( list_Type& list,
132  const GetPot& dataFile,
133  const std::string& section,
134  const std::string& subSection = "SolverLinear",
135  const bool& verbose = true );
136 
137  //! Build a preconditioner based on the given matrix
138  /*!
139  @param matrix Matrix upon which construct the preconditioner
140  */
141  virtual Int buildPreconditioner ( operator_type& matrix );
142 
143  //! Reset the preconditioner
144  virtual void resetPreconditioner();
145 
146  //! Return An estimation of the condition number of the preconditioner
147  virtual Real condest();
148 
149  //! Show informations about the preconditioner
150  virtual void showMe ( std::ostream& output = std::cout ) const;
151 
152  //@}
153 
154 
155  //! @name Epetra Operator Interface Methods
156  //@{
157 
158  //! Set the matrix to be used transposed (or not)
159  /*!
160  @param useTranspose If true the preconditioner is transposed
161  */
162  Int SetUseTranspose ( const bool useTranspose = false );
163 
164  //! Return true if the preconditioner is transposed
165  bool UseTranspose();
166 
167  //! Apply the inverse of the preconditioner on vector1 and store the result in vector2
168  /*!
169  @param vector1 Vector to which we apply the preconditioner
170  @param vector2 Vector to the store the result
171  */
172  Int Apply ( const Epetra_MultiVector& vector1, Epetra_MultiVector& vector2 ) const;
173 
174  //! Apply the inverse of the preconditioner on vector1 and store the result in vector2
175  /*!
176  @param vector1 Vector to which we apply the preconditioner
177  @param vector2 Vector to the store the result
178  */
179  Int ApplyInverse ( const Epetra_MultiVector& vector1, Epetra_MultiVector& vector2 ) const;
180 
181 
182  //! Return the Range map of the operator
183  const Epetra_Map& OperatorRangeMap() const;
184 
185  //! Return the Domain map of the operator
186  const Epetra_Map& OperatorDomainMap() const;
187  //@}
188 
189 
190  //! @name Set Methods
191  //@{
192 
193  //! Set the data of the preconditioner using a GetPot object
194  /*!
195  @param dataFile A GetPot object containing the data about the preconditioner
196  @param section The section in "dataFile" where to find data about the preconditioner
197  */
198  void setDataFromGetPot ( const GetPot& dataFile, const std::string& section );
199 
200  //! Set the internal solver
201  /*!
202  Note: the argument is unused
203  @param solver SolverAztecOO
204  */
205  void setSolver ( SolverAztecOO& /*solver*/ );
206 
207  //@}
208 
209 
210  //! @name Get Methods
211  //@{
212 
213  //! Return true if the preconditioner is set
214  bool isPreconditionerSet() const;
215 
216  //! Return a raw pointer on the preconditioner
217  prec_raw_type* preconditioner();
218 
219  //! Return a shared pointer on the preconditioner
220  prec_type preconditionerPtr();
221 
222  //! Return a shared pointer on the solver
223  solverPtr_Type solverPtr();
224 
225  //! Return the type of preconditioner
226  std::string preconditionerType();
227 
228  //@}
229 
230 private:
231 
232  solverPtr_Type M_solver;
233  preconditionerPtr_Type M_preconditioner;
234  GetPot M_dataFile;
235 
236  bool M_printSubiterationCount;
237  std::string M_precName;
238  std::string M_precDataSection;
239 
240 };
241 
242 inline Preconditioner* createLinearSolverPreconditioner()
243 {
244  return new PreconditionerLinearSolver();
245 }
246 namespace
247 {
249 }
250 
251 } // namespace LifeV
252 
253 #endif /* PRECONDITIONERAMESOS_HPP */
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
double Real
Generic real data.
Definition: LifeV.hpp:175