8#ifndef BELOSSOLVER_DECL_HH_
9#define BELOSSOLVER_DECL_HH_
12#include <BelosLinearProblem.hpp>
13#include <BelosBlockGmresSolMgr.hpp>
14#include <BelosPseudoBlockCGSolMgr.hpp>
15#include <BelosBlockCGSolMgr.hpp>
16#include <BelosMinresSolMgr.hpp>
17#include <BelosPseudoBlockGmresSolMgr.hpp>
18#include <Teuchos_ArrayView.hpp>
19#include <Ifpack2_Factory.hpp>
37 std::string solverType,
38 const Teuchos::RCP<Teuchos::ParameterList>&
solverParam,
40 Belos::LinearProblem<T, Tpetra::MultiVector<T, int>,
44 typedef Tpetra::MultiVector<T, int> MV;
45 typedef Tpetra::Operator<T> OP;
47 std::transform(solverType.begin(), solverType.end(), solverType.begin(),
50 if (solverType ==
"blockgmres") {
51 return Teuchos::RCP<Belos::BlockGmresSolMgr<T, MV, OP> >(
53 }
else if (solverType ==
"gmres") {
54 return Teuchos::RCP<Belos::PseudoBlockGmresSolMgr<T, MV, OP> >(
62 }
else if (solverType ==
"blockcg") {
67 else if (solverType ==
"pseudocg") {
71 std::cerr <<
"ERROR: solver type '" << solverType <<
"' unknown."
89 const Teuchos::RCP<
const Tpetra::CrsMatrix<T, int> > A) {
91 Ifpack2::Factory factory;
94 typename Teuchos::RCP<Ifpack2::Preconditioner<T, int> >
prec =
98 }
catch (std::exception &e) {
99 std::cerr <<
"ERROR: preconditioner type '" <<
precType <<
"' unknown."
102 return Teuchos::null;
107 bool BelosSolver<T>::createPrec_() {
109 return !Teuchos::is_null(prec_);
113 bool BelosSolver<T>::createSolver_() {
115 Teuchos::RCP<Belos::LinearProblem<T, MV, OP> >(lp_));
116 solverManager_->setProblem(lp_);
117 return !Teuchos::is_null(solverManager_);
121 bool BelosSolver<T>::phasePrecInit_(
bool verbose) {
122 Teuchos::Time
timer(
"precond");
128 lp_->setLeftPrec(prec_);
131 std::cout <<
"... Finished Computing Ifpack2 preconditioner (time: "
132 <<
timer.totalElapsedTime() <<
"s)" << std::endl;
135 typename Teuchos::ScalarTraits<T>::magnitudeType
condest =
136 prec_->computeCondEst(Ifpack2::Cheap);
138 std::cout <<
"Condition estimate(cheap) for preconditioner: " <<
condest;
139 std::cout << std::endl;
146 bool BelosSolver<T>::phaseSolve_(
bool verbose) {
147 verbose = (Comm_->getRank() == 0);
150 bool ierr = lp_->setProblem();
157 Belos::ReturnType
solverRet = solverManager_->solve();
163 case Belos::Unconverged:
164 std::cout <<
"##### Iterative solver did not converge!" << std::endl;
165 throw std::logic_error(
"Belos did not converge!");
168 case Belos::Converged:
170 std::cout <<
"Iterative solver converged!" << std::endl;
180 lp_->setConceptsRHS(
fncY, Comm_);
184 }
catch (std::logic_error& e) {
185 std::cerr <<
"***** ERROR during solving process: " << e.what()
188 lp_->writeSolution(
fncX, Comm_);
193 void BelosSolver<T>::apply_() {
194 lp_->setConceptsRHS(Comm_);
197 }
catch (std::logic_error& e) {
198 std::cerr <<
"***** ERROR during solving process: " << e.what()
201 lp_->writeSolution(Comm_);
#define conceptsAssert(cond, exc)
Teuchos::RCP< Ifpack2::Preconditioner< T > > createIfpackPrec(std::string precType, Teuchos::RCP< Teuchos::ParameterList > precParam, const Teuchos::RCP< const Tpetra::CrsMatrix< T, int > > A)
Teuchos::RCP< Belos::SolverManager< T, Tpetra::MultiVector< T, int >, Tpetra::Operator< T > > > createBelosSolverMgr(std::string solverType, const Teuchos::RCP< Teuchos::ParameterList > &solverParam, Teuchos::RCP< Belos::LinearProblem< T, Tpetra::MultiVector< T, int >, Tpetra::Operator< T > > > linearProblem)
Set< F > makeSet(uint n, const F &first,...)