LifeV
SolverOperator.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 Operator
30 
31  @author Umberto Villa <umberto.villa@gmail.com>
32  @contributor Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33 
34  @date 03-09-2010
35  */
36 
37 #ifndef _SOLVEROPERATOR_HPP_
38 #define _SOLVEROPERATOR_HPP_
39 
40 
41 #include <lifev/core/operator/LinearOperator.hpp>
42 #include <lifev/core/util/FactorySingleton.hpp>
43 #include <lifev/core/util/Factory.hpp>
44 #include <lifev/core/array/VectorEpetra.hpp>
45 
46 #include <Teuchos_ParameterList.hpp>
47 #include <Teuchos_RCPDecl.hpp>
48 #include <Epetra_MpiComm.h>
49 
50 namespace LifeV
51 {
52 namespace Operators
53 {
54 
55 //! @class SolverOperator
56 /*! @brief Abstract class which defines the interface of an Invertible Linear Operator.
57  *
58  */
60 {
61 public:
63 
64 #ifdef HAVE_MPI
66 #else
67  SolverOperator ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_SerialComm ) );
68 #endif
69  virtual ~SolverOperator();
70 
71  //! @name Attribute set methods
72  //@{
73 
74  //! If set true, transpose of this operator will be applied.
75  virtual int SetUseTranspose ( bool useTranspose );
76 
77  void setOperator ( operatorPtr_Type _oper );
78 
79  void setPreconditioner ( operatorPtr_Type _prec );
80 
81  void setParameters ( const Teuchos::ParameterList& _pList );
82 
83  void setTolerance ( const Real& tolerance );
84 
85  void setUsedForPreconditioning ( const bool& enable );
86 
88  {
90  }
91 
92  void resetSolver();
93 
94  //@}
95 
96  //! @name Mathematical methods
97  //@{
98 
99  //! Returns the result of a Epetra_Operator applied to a vector_Type X in Y.
100  virtual int Apply ( const vector_Type& X, vector_Type& Y ) const;
101 
102  //! Returns the result of a Epetra_Operator inverse applied to an vector_Type X in Y.
103  virtual int ApplyInverse ( const vector_Type& X, vector_Type& Y ) const;
104 
105  //! Returns the infinity norm of the global matrix.
106  double NormInf() const
107  {
108  return M_oper->NormInf();
109  }
110 
111  //! Reset the status for the state of convergence and loss of accuracy
112  void resetStatus()
113  {
116  M_numIterations = 0;
117  }
118 
119  //@}
120 
121  //! @name Attribute access methods
122  //@{
123 
124  //! Returns a character string describing the operator
125  virtual const char* Label() const
126  {
127  return M_name.c_str();
128  }
129 
130  //! Returns the current UseTranspose setting.
131  virtual bool UseTranspose() const
132  {
133  return M_useTranspose;
134  }
135 
136  //! Returns true if the \e this object can provide an approximate Inf-norm, false otherwise.
137  virtual bool HasNormInf() const
138  {
139  return M_oper->HasNormInf();
140  }
141 
142  //! Returns a pointer to the Epetra_Comm communicator associated with this operator.
143  virtual const comm_Type& Comm() const
144  {
145  return M_oper->Comm();
146  }
147 
148  //! Returns the Epetra_Map object associated with the domain of this operator.
149  virtual const map_Type& OperatorDomainMap() const
150  {
151  return M_oper->OperatorDomainMap();
152  }
153 
154  //! Returns the Epetra_Map object associated with the range of this operator.
155  virtual const map_Type& OperatorRangeMap() const
156  {
157  return M_oper->OperatorRangeMap();
158  }
159 
160  //! Returns if a loss of precision has been detected
162  {
163  return M_lossOfAccuracy;
164  }
165 
166  //! Returns if the convergence has been achieved
168  {
169  return M_converged;
170  }
171 
172  //! Returns the number of iterations
173  /*
174  * @note Negative value usually indicates problem of convergence
175  */
176  int numIterations() const
177  {
178  return M_numIterations;
179  }
180 
181  //! Returns the cumul of iterations
182  int numCumulIterations() const
183  {
184  return M_numCumulIterations;
185  }
186 
187  //@}
188 
189 protected:
190 
191  virtual int doApplyInverse ( const vector_Type& X, vector_Type& Y ) const = 0;
192  virtual void doSetOperator() = 0;
193  virtual void doSetPreconditioner() = 0;
194  virtual void doSetParameterList() = 0;
195  virtual void doResetSolver() = 0;
196 
197  //! The name of the Operator
198  std::string M_name;
199 
200  //! The list of Parameter to feed the linear solver
202 
203  //! The preconditioner operator
205 
206  //! The operator to be solved
208 
209  //! Whenever to use the transpose
211 
212  //! Status to see if there is a loss of accuracy
214 
215  //! Status to see if the solver has converged
217 
218  //! Number of iterations performed by the solver
219  mutable int M_numIterations;
220 
221  //! Number of cumulated iterations performed by the solver
222  mutable int M_numCumulIterations;
223 
224  //! Solver tolerance
226 
227  //! Print the number of iteration (used only for preconditioner LinearSolver)
229 
230  //! Communicator
232 
233 };
234 
236 
237 } // Namespace Operators
238 
239 } // Namespace LifeV
240 
241 #endif // _SOLVEROPERATOR_HPP_
int numCumulIterations() const
Returns the cumul of iterations.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
Abstract class which defines the interface of a Linear Operator.
virtual int ApplyInverse(const vector_Type &X, vector_Type &Y) const
Returns the result of a Epetra_Operator inverse applied to an vector_Type X in Y. ...
int numIterations() const
Returns the number of iterations.
void setTolerance(const Real &tolerance)
SolverOperatorStatusType M_lossOfAccuracy
Status to see if there is a loss of accuracy.
SolverOperatorStatusType hasConverged() const
Returns if the convergence has been achieved.
virtual void doSetParameterList()=0
SolverOperator(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
virtual int Apply(const vector_Type &X, vector_Type &Y) const
Returns the result of a Epetra_Operator applied to a vector_Type X in Y.
void updateInverseJacobian(const UInt &iQuadPt)
SolverOperatorStatusType M_converged
Status to see if the solver has converged.
virtual const char * Label() const
Returns a character string describing the operator.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
void setPreconditioner(operatorPtr_Type _prec)
operatorPtr_Type M_oper
The operator to be solved.
void setUsedForPreconditioning(const bool &enable)
double NormInf() const
Returns the infinity norm of the global matrix.
bool M_printSubiterationCount
Print the number of iteration (used only for preconditioner LinearSolver)
void setOperator(operatorPtr_Type _oper)
double Real
Generic real data.
Definition: LifeV.hpp:175
virtual const map_Type & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual void doSetPreconditioner()=0
FactorySingleton< Factory< SolverOperator, std::string > > SolverOperatorFactory
operatorPtr_Type M_prec
The preconditioner operator.
std::shared_ptr< Epetra_Comm > M_comm
Communicator.
std::shared_ptr< operator_Type > operatorPtr_Type
virtual int SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
SolverOperatorStatusType isLossOfAccuracyDetected() const
Returns if a loss of precision has been detected.
bool M_useTranspose
Whenever to use the transpose.
void resetStatus()
Reset the status for the state of convergence and loss of accuracy.
Real M_tolerance
Solver tolerance.
int M_numCumulIterations
Number of cumulated iterations performed by the solver.
virtual const map_Type & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
virtual int doApplyInverse(const vector_Type &X, vector_Type &Y) const =0
std::string M_name
The name of the Operator.
virtual const comm_Type & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
void setParameters(const Teuchos::ParameterList &_pList)
int M_numIterations
Number of iterations performed by the solver.
Teuchos::RCP< Teuchos::ParameterList > M_pList
The list of Parameter to feed the linear solver.