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>,
41 Tpetra::Operator<T> > > linearProblem)
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> >(
52 new Belos::BlockGmresSolMgr<T, MV, OP>(linearProblem, solverParam));
53 }
else if (solverType ==
"gmres") {
54 return Teuchos::RCP<Belos::PseudoBlockGmresSolMgr<T, MV, OP> >(
55 new Belos::PseudoBlockGmresSolMgr<T, MV, OP>(linearProblem,
62 }
else if (solverType ==
"blockcg") {
64 new Belos::BlockCGSolMgr<T, MV, OP>(linearProblem, solverParam));
67 else if (solverType ==
"pseudocg") {
69 new Belos::PseudoBlockCGSolMgr<T, MV, OP>(linearProblem, solverParam));
71 std::cerr <<
"ERROR: solver type '" << solverType <<
"' unknown."
88 std::string precType, Teuchos::RCP<Teuchos::ParameterList> precParam,
89 const Teuchos::RCP<
const Tpetra::CrsMatrix<T, int> > A) {
91 Ifpack2::Factory factory;
94 typename Teuchos::RCP<Ifpack2::Preconditioner<T, int> > prec =
95 factory.create(precType, A);
96 prec->setParameters(*precParam);
98 }
catch (std::exception &e) {
99 std::cerr <<
"ERROR: preconditioner type '" << precType <<
"' unknown."
102 return Teuchos::null;
108 prec_ = createIfpackPrec<T>(precType_, precParam_, lp_->getCrsMat());
109 return !Teuchos::is_null(prec_);
115 Teuchos::RCP<Belos::LinearProblem<T, MV, OP> >(lp_));
116 solverManager_->setProblem(lp_);
117 return !Teuchos::is_null(solverManager_);
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;
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_);
194 lp_->setConceptsRHS(Comm_);
197 }
catch (std::logic_error& e) {
198 std::cerr <<
"***** ERROR during solving process: " << e.what()
201 lp_->writeSolution(Comm_);