LifeV
SolverOperatorAlgo.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 _SOLVEROPERATORALGO_HPP_
38 #define _SOLVEROPERATORALGO_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  SolverOperatorAlgo ( boost::shared_ptr<Epetra_Comm> comm = boost::shared_ptr<Epetra_Comm> ( new Epetra_SerialComm ) );
68 #endif
69  virtual ~SolverOperatorAlgo();
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 // _SOLVEROPERATORALGO_HPP_
virtual const map_Type & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
FactorySingleton< Factory< SolverOperatorAlgo, std::string > > SolverOperatorAlgoFactory
Abstract class which defines the interface of a Linear Operator.
virtual int SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
int numCumulIterations() const
Returns the cumul of iterations.
operatorPtr_Type M_prec
The preconditioner operator.
void setOperator(operatorPtr_Type _oper)
bool M_printSubiterationCount
Print the number of iteration (used only for preconditioner LinearSolver)
void updateInverseJacobian(const UInt &iQuadPt)
int numIterations() const
Returns the number of iterations.
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. ...
bool M_useTranspose
Whenever to use the transpose.
virtual const char * Label() const
Returns a character string describing the operator.
void setTolerance(const Real &tolerance)
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.
virtual const comm_Type & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
int M_numIterations
Number of iterations performed by the solver.
void setUsedForPreconditioning(const bool &enable)
boost::shared_ptr< Epetra_Comm > M_comm
Communicator.
double Real
Generic real data.
Definition: LifeV.hpp:175
virtual const map_Type & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
SolverOperatorAlgo(boost::shared_ptr< Epetra_Comm > comm=boost::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
SolverOperatorStatusType isLossOfAccuracyDetected() const
Returns if a loss of precision has been detected.
double NormInf() const
Returns the infinity norm of the global matrix.
std::string M_name
The name of the Operator.
Teuchos::RCP< Teuchos::ParameterList > M_pList
The list of Parameter to feed the linear solver.
std::shared_ptr< operator_Type > operatorPtr_Type
void setPreconditioner(operatorPtr_Type _prec)
SolverOperatorStatusType hasConverged() const
Returns if the convergence has been achieved.
operatorPtr_Type M_oper
The operator to be solved.
SolverOperatorStatusType M_converged
Status to see if the solver has converged.
void resetStatus()
Reset the status for the state of convergence and loss of accuracy.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
SolverOperatorStatusType M_lossOfAccuracy
Status to see if there is a loss of accuracy.
void setParameters(const Teuchos::ParameterList &_pList)
virtual int doApplyInverse(const vector_Type &X, vector_Type &Y) const =0
int M_numCumulIterations
Number of cumulated iterations performed by the solver.