OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
BelosBottomSolver.hpp
Go to the documentation of this file.
1 #include "Ippl.h"
3 
4 extern Inform* gmsg;
5 
6 template <class Level>
8  const std::shared_ptr<prec_t>& prec_p)
9  : BottomSolver<Teuchos::RCP<amr::matrix_t>,
10  Teuchos::RCP<amr::multivector_t>,
11  Level>()
12  , problem_mp( Teuchos::rcp( new problem_t() ) )
13  , prec_mp(prec_p)
14  , A_mp(Teuchos::null)
15  , reltol_m(1.0e-9)
16  , maxiter_m(100)
17 {
18  this->initSolver_m(solvertype);
19 }
20 
21 
22 template <class Level>
23 void BelosBottomSolver<Level>::solve(const Teuchos::RCP<mv_t>& x,
24  const Teuchos::RCP<mv_t>& b)
25 {
26  /*
27  * solve linear system Ax = b
28  */
29 
30  // change sign of rhs due to change of A in BelosBottomSolver::setOperator
31  b->scale(-1.0);
32 
33  problem_mp->setProblem(x, b);
34 
35  solver_mp->setProblem(problem_mp);
36 
37  Belos::ReturnType ret = solver_mp->solve();
38 
39  if ( ret != Belos::Converged ) {
40  *gmsg << "Warning: Bottom solver not converged. Achieved tolerance"
41  << " after " << solver_mp->getNumIters() << " iterations is "
42  << solver_mp->achievedTol() << "." << endl;
43  }
44 
45  // undo sign change
46  b->scale(-1.0);
47 }
48 
49 
50 template <class Level>
51 void BelosBottomSolver<Level>::setOperator(const Teuchos::RCP<matrix_t>& A,
52  Level* level_p)
53 {
54  // make positive definite --> rhs has to change sign as well
55  A_mp = A->clone(A->getNode());
56  A_mp->resumeFill();
57  A_mp->scale(-1.0);
58  A_mp->fillComplete();
59 
60  if ( problem_mp == Teuchos::null )
61  throw OpalException("BelosBottomSolver::setOperator()",
62  "No problem defined.");
63 
64  problem_mp->setOperator(A_mp);
65 
66  static IpplTimings::TimerRef precTimer = IpplTimings::getTimer("AMR MG prec setup");
67 
68  if ( prec_mp != nullptr ) {
69  IpplTimings::startTimer(precTimer);
70  prec_mp->create(A_mp, level_p);
71  IpplTimings::stopTimer(precTimer);
72  problem_mp->setLeftPrec(prec_mp->get());
73  }
74 
75  this->isInitialized_m = true;
76 }
77 
78 
79 template <class Level>
81  if ( solver_mp == Teuchos::null )
82  throw OpalException("BelosBottomSolver::getNumIters()",
83  "No solver initialized.");
84 
85  return solver_mp->getNumIters();
86 }
87 
88 
89 template <class Level>
90 void BelosBottomSolver<Level>::initSolver_m(std::string solvertype) {
91 
92  Belos::SolverFactory<scalar_t, mv_t, op_t> factory;
93 
94  params_mp = Teuchos::parameterList();
95 
96  params_mp->set("Block Size", 1);
97  params_mp->set("Convergence Tolerance", reltol_m);
98  params_mp->set("Adaptive Block Size", false);
99  params_mp->set("Use Single Reduction", true);
100  params_mp->set("Explicit Residual Scaling", "Norm of RHS");
101  params_mp->set("Maximum Iterations", maxiter_m);
102  params_mp->set("Verbosity", Belos::Errors + Belos::Warnings);
103  params_mp->set("Output Frequency", 1);
104 
105  solver_mp = factory.create(solvertype, params_mp);
106 }
Belos::LinearProblem< scalar_t, mv_t, op_t > problem_t
constexpr double e
The value of .
Definition: Physics.h:40
void setOperator(const Teuchos::RCP< matrix_t > &A, Level *level_p=nullptr)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Inform * gmsg
Definition: Main.cpp:21
std::size_t getNumIters()
Abstract base class for all base level solvers.
Definition: BottomSolver.h:8
void solve(const Teuchos::RCP< mv_t > &x, const Teuchos::RCP< mv_t > &b)
amr::matrix_t matrix_t
void initSolver_m(std::string solvertype)
static void startTimer(TimerRef t)
Definition: IpplTimings.h:187
BelosBottomSolver(std::string solvertype="Pseudoblock CG", const std::shared_ptr< prec_t > &prec_p=nullptr)
bool amr
Definition: Options.cpp:100
Tpetra::MultiVector< scalar_t, local_ordinal_t, global_ordinal_t, node_t > multivector_t
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176
static TimerRef getTimer(const char *nm)
Definition: IpplTimings.h:182
static void stopTimer(TimerRef t)
Definition: IpplTimings.h:192
Definition: Inform.h:41
Inform & endl(Inform &inf)
Definition: Inform.cpp:42