LifeV
BelosOperatorAlgebra.cpp
Go to the documentation of this file.
1 /*
2  * BelosOperator.cpp
3  *
4  * Created on: Sep 28, 2010
5  * Author: uvilla
6  */
7 
8 #include <BelosBlockCGSolMgr.hpp>
9 #include <BelosBlockGmresSolMgr.hpp>
10 #include <BelosGCRODRSolMgr.hpp>
11 #include <BelosGmresPolySolMgr.hpp>
12 #include <BelosPCPGSolMgr.hpp>
13 #include <BelosPseudoBlockCGSolMgr.hpp>
14 #include <BelosPseudoBlockGmresSolMgr.hpp>
15 #include <BelosRCGSolMgr.hpp>
16 #include <BelosMinresSolMgr.hpp>
17 #include <BelosTFQMRSolMgr.hpp>
18 
19 #include<lifev/core/linear_algebra/BelosOperatorAlgebra.hpp>
20 
21 namespace LifeV
22 {
23 namespace Operators
24 {
25 
28 
32 {
33  M_name = "BelosOperatorAlgebra";
34 }
35 
37 {
38 
39  Teuchos::RCP<vector_Type> Xcopy(new vector_Type(X) );
40  Y.PutScalar(0.0);
41  bool set = M_linProblem->setProblem(Teuchos::rcp(&Y, false), Xcopy);
42  if (set == false)
43  {
44  std::cout << std::endl << "ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
45  return -12;
46  }
47 
48  M_solverManager->setProblem ( M_linProblem );
49 
50  LifeChrono chrono;
51  chrono.start();
52 
53  Belos::ReturnType ret = M_solverManager->solve();
54 
55  chrono.stop();
56  M_solutionTime = chrono.diff();
57 
58  M_numIterations = M_solverManager->getNumIters();
59 
60  if(ret == Belos::Converged)
61  return 0;
62  else
63  return -1;
64 
65 }
66 
68 {
69  M_linProblem->setOperator(M_oper);
70 }
71 
73 {
74  M_belosPrec = Teuchos::rcp( new Belos::EpetraPrecOp( M_prec ) );
75 
76  std::string precSideStr( M_pList->get<std::string>("Preconditioner Side"));
77  PreconditionerSide precSide((*S_precSideMap)[precSideStr]);
78 
79  switch(precSide)
80  {
81  case None:
82  break;
83  case Left:
84  M_linProblem->setLeftPrec(M_belosPrec);
85  break;
86  case Right:
87  M_linProblem->setRightPrec(M_belosPrec);
88  break;
89  default:
90  exit(1);
91  }
92 
93  M_solverManager->setProblem(M_linProblem);
94 
95 }
96 
98 {
99  if(! M_pList->sublist("options").isParameter("Verbosity"))
100  M_pList->sublist("options").set( "Verbosity", Belos::Errors + Belos::Warnings +
101  Belos::TimingDetails + Belos::StatusTestDetails );
102 
103  std::string solverType(M_pList->get<std::string>("Solver Type"));
104  allocateSolver( (*S_solverManagerMap)[solverType]);
105  M_solverManager->setParameters(sublist(M_pList, "options", true));
106 
107  std::string precSideStr( M_pList->get<std::string>("Preconditioner Side"));
108  PreconditionerSide precSide((*S_precSideMap)[precSideStr]);
109 
110  switch(precSide)
111  {
112  case None:
113  break;
114  case Left:
115  M_linProblem->setLeftPrec(M_belosPrec);
116  break;
117  case Right:
118  M_linProblem->setRightPrec(M_belosPrec);
119  break;
120  default:
121  exit(1);
122  }
123 
124  M_solverManager->setProblem(M_linProblem);
125 
126 }
127 
128 //============================================================================//
129 // Protected or Private Methods //
130 //============================================================================//
131 void BelosOperatorAlgebra::allocateSolver(const SolverManagerType & solverManagerType)
132 {
133  // If a SolverManager already exists we simply clean it!
134  if ( !M_solverManager.is_null() )
135  {
136  M_solverManager.reset();
137  }
138 
139  switch ( solverManagerType )
140  {
141  case NotAValidSolverManager:
142  std::cout<<"Not a Valid Solver Manager \n";
143  exit(1);
144  break;
145  case BlockCG:
146  // Create the block CG iteration
147  M_solverManager = Teuchos::rcp( new Belos::BlockCGSolMgr<Real,vector_Type,operator_Type>() );
148  break;
149  case PseudoBlockCG:
150  // Create the pseudo block CG iteration
151  M_solverManager = Teuchos::rcp( new Belos::PseudoBlockCGSolMgr<Real,vector_Type,operator_Type>() );
152  break;
153  case RCG:
154  M_solverManager = Teuchos::rcp( new Belos::RCGSolMgr<Real,vector_Type,operator_Type>() );
155  break;
156  case BlockGmres:
157  M_solverManager = Teuchos::rcp( new Belos::BlockGmresSolMgr<Real,vector_Type,operator_Type>() );
158  break;
159  case PseudoBlockGmres:
160  M_solverManager = Teuchos::rcp( new Belos::PseudoBlockGmresSolMgr<Real,vector_Type,operator_Type>() );
161  break;
162  case GmresPoly:
163  M_solverManager = Teuchos::rcp( new Belos::GmresPolySolMgr<Real,vector_Type,operator_Type>() );
164  break;
165  case GCRODR:
166  M_solverManager = Teuchos::rcp( new Belos::GCRODRSolMgr<Real,vector_Type,operator_Type>() );
167  break;
168  case PCPG:
169  M_solverManager = Teuchos::rcp( new Belos::PCPGSolMgr<Real,vector_Type,operator_Type>() );
170  break;
171  case Minres:
172  M_solverManager = Teuchos::rcp( new Belos::MinresSolMgr<Real,vector_Type,operator_Type>() );
173  break;
174  case TFQMR:
175  // Create TFQMR iteration
176  M_solverManager = Teuchos::rcp( new Belos::TFQMRSolMgr<Real,vector_Type,operator_Type>() );
177  break;
178  }
179 
180 }
181 
183 {
185  (*map)["BlockCG"] = BlockCG;
186  (*map)["PseudoBlockCG"] = PseudoBlockCG;
187  (*map)["RCG"] = RCG;
188  (*map)["BlockGmres"] = BlockGmres;
189  (*map)["PseudoBlockGmres"] = PseudoBlockGmres;
190  (*map)["GmresPoly"] = GmresPoly;
191  (*map)["GCRODR"] = GCRODR;
192  (*map)["PCPG"] = PCPG;
193  (*map)["Minres"] = Minres;
194  (*map)["TFQMR"] = TFQMR;
195 
196  return map;
197 }
198 
200 {
202  (*map)["None"] = None;
203  (*map)["Right"] = Right;
204  (*map)["Left"] = Left;
205 
206  (*map)["none"] = None;
207  (*map)["right"] = Right;
208  (*map)["left"] = Left;
209 
210  return map;
211 }
212 
213 
214 } /* end namespace Operators */
215 } /* end namespace */
void start()
Start the timer.
Definition: LifeChrono.hpp:93
std::map< std::string, PreconditionerSide > precSideMap_Type
virtual int doApplyInverse(const vector_Type &X, vector_Type &Y) const
static precSideMap_Type * singletonPrecSideMap()
static solverManagerMap_Type * singletonSolverManagerMap()
std::map< std::string, SolverManagerType > solverManagerMap_Type
void updateInverseJacobian(const UInt &iQuadPt)
InvertibleOperator interface to Belos in Trilinos. BelosOperator requires the operator to be solved a...
Abstract class which defines the interface of an Invertible Linear Operator Algebra.
static std::unique_ptr< precSideMap_Type > S_precSideMap
double M_solutionTime
Time spent to solve the linear system.
static std::unique_ptr< solverManagerMap_Type > S_solverManagerMap
void allocateSolver(const SolverManagerType &solverManagerType)
Real diff()
Compute the difference in time between start and stop.
Definition: LifeChrono.hpp:111
BelosOperatorAlgebra()
null constructor and destructor
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100