Go to the documentation of this file.00001 #include "TSFBelosSolver.hpp"
00002 #include "BelosBlockGmresSolMgr.hpp"
00003 #include "BelosBlockCGSolMgr.hpp"
00004 #include "BelosConfigDefs.hpp"
00005 #include "BelosLinearProblem.hpp"
00006 #include "BelosThyraAdapter.hpp"
00007 #include "TSFPreconditioner.hpp"
00008 #include "TSFPreconditionerFactory.hpp"
00009 #include "TSFParameterListPreconditionerFactory.hpp"
00010
00011
00012 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00013 #include "TSFVectorImpl.hpp"
00014 #include "TSFLinearOperatorImpl.hpp"
00015 #include "TSFLinearSolverImpl.hpp"
00016 #endif
00017
00018 using namespace TSFExtended;
00019 using namespace Teuchos;
00020
00021
00022 BelosSolver::BelosSolver(const ParameterList& params)
00023 : LinearSolverBase<double>(params), pf_()
00024 {
00025 setName("BelosSolver");
00026 if (params.isSublist("Preconditioner"))
00027 {
00028 ParameterList precParams = params.sublist("Preconditioner");
00029 pf_ = new ParameterListPreconditionerFactory(precParams);
00030 }
00031 }
00032
00033
00034
00035 SolverState<double> BelosSolver::solve(const LinearOperator<double>& A,
00036 const Vector<double>& rhs,
00037 Vector<double>& soln) const
00038 {
00039 typedef Thyra::MultiVectorBase<double> MV;
00040 typedef Thyra::LinearOpBase<double> OP;
00041 typedef Belos::LinearProblem<double, MV, OP> LP;
00042
00043 TEST_FOR_EXCEPT(!A.ptr().get());
00044 TEST_FOR_EXCEPT(!rhs.ptr().get());
00045
00046
00047 RCP<OP> APtr = A.ptr();
00048 RCP<MV> bPtr = rhs.ptr();
00049
00050 if (!soln.ptr().get()) soln = rhs.copy();
00051
00052 RCP<MV> ansPtr = soln.ptr();
00053
00054
00055
00056 RCP<LP> prob = rcp(new LP(APtr, ansPtr, bPtr));
00057
00058 TEST_FOR_EXCEPT(!prob->setProblem());
00059
00060
00061 if (pf_.ptr().get())
00062 {
00063 Preconditioner<double> P = pf_.createPreconditioner(A);
00064 if (P.hasLeft())
00065 {
00066 prob->setLeftPrec(P.left().ptr());
00067 }
00068
00069 if (P.hasRight())
00070 {
00071 prob->setRightPrec(P.right().ptr());
00072 }
00073 }
00074
00075 ParameterList plist = parameters();
00076
00077 RCP<ParameterList> belosList = rcp(&plist, false);
00078 RCP<Belos::SolverManager<double, MV, OP> > solver ;
00079 std::string solverType = parameters().get<string>("Method");
00080
00081 if (solverType=="GMRES")
00082 {
00083 solver=rcp(new Belos::BlockGmresSolMgr<double, MV, OP>(prob, belosList));
00084 }
00085 else if (solverType=="CG")
00086 {
00087 solver=rcp(new Belos::BlockCGSolMgr<double, MV, OP>(prob, belosList));
00088 }
00089 else
00090 {
00091 TEST_FOR_EXCEPT(!(solverType=="GMRES" || solverType=="CG"));
00092 }
00093
00094 Belos::ReturnType rtn = solver->solve();
00095
00096 int numIters = solver->getNumIters();
00097 double resid = -1.0;
00098
00099 SolverStatusCode code = SolveFailedToConverge;
00100 if (rtn==Belos::Converged) code = SolveConverged;
00101 SolverState<double> state(code, "Belos solver completed", numIters, resid);
00102
00103 return state;
00104 }
00105
00106
00107