LifeV
SolverAmesos.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 Solver Amesos
30 
31  @author Gilles Fourestey <gilles.fourestey@epfl.ch>
32  @contributor Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33  @maintainer Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
34 
35  @date 29-08-2004
36  */
37 
38 #ifndef _SolverAmesos_H
39 #define _SolverAmesos_H
40 
41 
42 #include <Amesos.h>
43 #include <Amesos_BaseSolver.h>
44 #include <Amesos_ConfigDefs.h>
45 #include <Teuchos_ParameterList.hpp>
46 
47 
48 #include <lifev/core/array/VectorEpetra.hpp>
49 #include <lifev/core/array/MatrixEpetra.hpp>
50 #include <lifev/core/util/Displayer.hpp>
51 
52 class GetPot;
53 
54 namespace LifeV
55 {
56 
57 //! SolverAmesos - Class to wrap linear solver
58 /*!
59  @author Simone Deparis <simone.deparis@epfl.ch>
60  @author Gilles Fourestey <gilles.fourestey@epfl.ch>
61 */
63 {
64 public:
65 
66  //! @name Public Types
67  //@{
68 
69  typedef Real value_type;
70 
71  typedef Displayer::commPtr_Type commPtr_Type;
72 
74 
77 
78  typedef void prec_raw_type;
82 
83  //@}
84 
85 
86  //! @name Constructors & Destructor
87  //@{
88 
89  //! Default constructor
90  /*!
91  * @param comm The communicator.
92  */
93  SolverAmesos ( const commPtr_Type& comm );
94 
95  //! Destructor
97  {
98  delete M_solver;
99  }
100 
101  //@}
102 
103 
104  //! @name Methods
105  //@{
106 
107  //! Compute the residual
108  /*!
109  @param solution Solution vector
110  @param rhs Right hand side of the system
111  */
112  Real computeResidual ( const vector_type& solution, const vector_type& rhs );
113 
114  //! Solves the system and returns the number of iterations.
115  /*!
116  returns number of iterations. If negative, the solver did not converge,
117  the preconditionar has been recomputed, and a second solution is tried
118  @param rhsFull Right hand side vector
119  @param solution Vector to store the solution
120  */
121  Int solveSystem ( vector_type& rhsFull,
122  vector_type& solution,
123  const matrix_ptrtype& /* unused */ );
124 
125  //! Display status of the solver
126  void printStatus();
127 
128  //! Return true if the preconditioner is set
129  /*!
130  Note: This method always return true!
131  */
132  bool isPreconditionerSet() const;
133 
134  //! Delete the stored preconditioner
135  /*!
136  Note: This method is empty
137  */
138  void resetPreconditioner();
139 
140  //! Setup the preconditioner
141  /*!
142  Note: This method is empty
143  @param dataFile GetPot object which contains the data about the preconditioner
144  @param section Section the GetPot structure where to find the informations about the preconditioner
145  */
146  void setupPreconditioner ( const GetPot& dataFile, const std::string& section );
147 
148  //! Specify if the preconditioner should be reuse or not
149  /*!
150  Note: This method is empty
151  @param reusePreconditioner If set to true, do not recompute the preconditioner
152  */
153  void setReusePreconditioner ( const bool& /*reusePreconditioner*/ );
154 
155  //! Print informations about the solver
156  void showMe ( std::ostream& output = std::cout ) const;
157 
158  //@}
159 
160 
161  //! @name Set Methods
162  //@{
163 
164  //! Set matrix from MatrixEpetra
165  /*!
166  @param matrix Matrix of the system
167  */
168  Int setMatrix ( const matrix_type& matrix );
169 
170  //! Method to set a general linear operator (of class derived from Epetra_Operator) defining the linear system
171  /*!
172  @param oper Operator for the system
173  */
174  void setOperator ( const Epetra_Operator& oper );
175 
176  //! Method to setup the solver using GetPot
177  /*!
178  @param dataFile GetPot object which contains the data about the solver
179  */
180  void setDataFromGetPot ( const GetPot& dataFile, const std::string& section );
181 
182  //! Set a parameter in the list
183  /*!
184  * @param name name of the parameter
185  * @param value value of the parameter
186  */
187  template <typename ParameterType>
188  void setParameter ( const std::string& name, const ParameterType value )
189  {
190  M_trilinosParameterList.set ( name, value );
191  }
192 
193  //! Set the current parameters with the internal parameters list
194  /*!
195  Note: The parameter list is set using "setDataFromGetPot".
196  @param cerrWarningIfUnused If true the solver return warning if some parameters are unused
197  */
198  void setParameters();
199 
200  //! Set the current parameters list
201  /*!
202  * @param list Teuchos parameters list
203  */
204  void setParametersList ( const Teuchos::ParameterList& list )
205  {
206  M_trilinosParameterList = list;
207  }
208 
209  //! Set the tolerance of the solver
210  /*!
211  @param tolerance Tolerance for the solver
212  */
213  void setTolerance ( const Real tolerance );
214 
215  //! Set the tolerance and the maximum number of iterations
216  /*!
217  * @param maxIter Maximum number of iteration
218  */
219  void setMaxNumIterations ( const Int maxIter = -1 );
220 
221  //@}
222 
223 
224  //! @name Get Methods
225  //@{
226 
227  //! Return the total number of iterations
228  Int numIterations();
229 
230  //! Return the true residual
231  Real trueResidual();
232 
233  //! Get the current parameters list
234  /*!
235  * @return Teuchos parameters list
236  */
238  {
239  return M_trilinosParameterList;
240  }
241 
242  //@}
243 
244 private:
245 
246  //! @name Private Methods
247  //@{
248 
249  //! Create a solver using a factory
250  /*!
251  @param solverType String containing the name of the solver
252  */
253  void createSolver ( const std::string& solverType );
254 
255  //@}
256 
258 
260 
262 
264 
266 };
267 
268 } // namespace LifeV
269 
270 #endif /* _SolverAmesos_H */
VectorEpetra - The Epetra Vector format Wrapper.
Amesos_BaseSolver * M_solver
SolverAmesos solver_type
VectorEpetra vector_type
void printStatus()
Display status of the solver.
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
std::shared_ptr< matrix_type > matrix_ptrtype
MatrixEpetra< Real > matrix_type
~SolverAmesos()
Destructor.
Epetra_LinearProblem M_problem
const Teuchos::ParameterList & parametersList() const
Get the current parameters list.
std::shared_ptr< comm_Type > commPtr_Type
Definition: Displayer.hpp:70
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
Real trueResidual()
Return the true residual.
void updateInverseJacobian(const UInt &iQuadPt)
Real computeResidual(const vector_type &solution, const vector_type &rhs)
Compute the residual.
void setOperator(const Epetra_Operator &oper)
Method to set a general linear operator (of class derived from Epetra_Operator) defining the linear s...
std::shared_ptr< VectorEpetra > vector_ptrtype
std::shared_ptr< prec_raw_type > prec_type
Int setMatrix(const matrix_type &matrix)
Set matrix from MatrixEpetra.
matrix_type::matrix_ptrtype M_matrix
Int solveSystem(vector_type &rhsFull, vector_type &solution, const matrix_ptrtype &)
Solves the system and returns the number of iterations.
void setReusePreconditioner(const bool &)
Specify if the preconditioner should be reuse or not.
void setTolerance(const Real tolerance)
Set the tolerance of the solver.
SolverAmesos - Class to wrap linear solver.
void showMe(std::ostream &output=std::cout) const
Print informations about the solver.
double Real
Generic real data.
Definition: LifeV.hpp:175
Teuchos::ParameterList M_trilinosParameterList
SolverAmesos(const commPtr_Type &comm)
Default constructor.
Int numIterations()
Return the total number of iterations.
void resetPreconditioner()
Delete the stored preconditioner.
bool isPreconditionerSet() const
Return true if the preconditioner is set.
void setParametersList(const Teuchos::ParameterList &list)
Set the current parameters list.
void setMaxNumIterations(const Int maxIter=-1)
Set the tolerance and the maximum number of iterations.
Displayer - This class is used to display messages in parallel simulations.
Definition: Displayer.hpp:62
void setParameters()
Set the current parameters with the internal parameters list.