Stratimikos Package Browser (Single Doxygen Collection) Version of the Day
Thyra_BelosLinearOpWithSolveFactory_def.hpp
Go to the documentation of this file.
00001 
00002 #ifndef THYRA_BELOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
00003 #define THYRA_BELOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
00004 
00005 
00006 #include "Thyra_BelosLinearOpWithSolveFactory_decl.hpp"
00007 #include "Thyra_BelosLinearOpWithSolve.hpp"
00008 #include "Thyra_ScaledAdjointLinearOpBase.hpp"
00009 #include "BelosBlockGmresSolMgr.hpp"
00010 #include "BelosPseudoBlockGmresSolMgr.hpp"
00011 #include "BelosBlockCGSolMgr.hpp"
00012 #include "BelosPseudoBlockCGSolMgr.hpp"
00013 #include "BelosGCRODRSolMgr.hpp"
00014 #include "BelosThyraAdapter.hpp"
00015 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
00016 #include "Teuchos_StandardParameterEntryValidators.hpp"
00017 #include "Teuchos_ParameterList.hpp"
00018 #include "Teuchos_dyn_cast.hpp"
00019 
00020 
00021 namespace Thyra {
00022 
00023 
00024 // Parameter names for Paramter List
00025 
00026 template<class Scalar>
00027 const std::string BelosLinearOpWithSolveFactory<Scalar>::SolverType_name = "Solver Type";
00028 template<class Scalar>
00029 const std::string BelosLinearOpWithSolveFactory<Scalar>::SolverType_default = "Pseudo Block GMRES";
00030 template<class Scalar>
00031 const std::string BelosLinearOpWithSolveFactory<Scalar>::SolverTypes_name = "Solver Types";
00032 template<class Scalar>
00033 const std::string BelosLinearOpWithSolveFactory<Scalar>::BlockGMRES_name = "Block GMRES";
00034 template<class Scalar>
00035 const std::string BelosLinearOpWithSolveFactory<Scalar>::PseudoBlockGMRES_name = "Pseudo Block GMRES";
00036 template<class Scalar>
00037 const std::string BelosLinearOpWithSolveFactory<Scalar>::BlockCG_name = "Block CG";
00038 template<class Scalar>
00039 const std::string BelosLinearOpWithSolveFactory<Scalar>::PseudoBlockCG_name = "Pseudo Block CG";
00040 template<class Scalar>
00041 const std::string BelosLinearOpWithSolveFactory<Scalar>::GCRODR_name = "GCRODR";
00042 template<class Scalar>
00043 const std::string BelosLinearOpWithSolveFactory<Scalar>::ConvergenceTestFrequency_name = "Convergence Test Frequency";
00044 
00045 
00046 // Constructors/initializers/accessors
00047 
00048 
00049 template<class Scalar>
00050 BelosLinearOpWithSolveFactory<Scalar>::BelosLinearOpWithSolveFactory()
00051   :solverType_(SOLVER_TYPE_PSEUDO_BLOCK_GMRES),
00052    convergenceTestFrequency_(1)
00053 {
00054   updateThisValidParamList();
00055 }
00056 
00057 
00058 template<class Scalar>
00059 BelosLinearOpWithSolveFactory<Scalar>::BelosLinearOpWithSolveFactory(
00060   const RCP<PreconditionerFactoryBase<Scalar> > &precFactory
00061   )
00062   :solverType_(SOLVER_TYPE_PSEUDO_BLOCK_GMRES)
00063 {
00064   this->setPreconditionerFactory(precFactory, "");
00065 }
00066 
00067 
00068 // Overridden from LinearOpWithSolveFactoryBase
00069 
00070 
00071 template<class Scalar>
00072 bool BelosLinearOpWithSolveFactory<Scalar>::acceptsPreconditionerFactory() const
00073 {
00074   return true;
00075 }
00076 
00077 
00078 template<class Scalar>
00079 void BelosLinearOpWithSolveFactory<Scalar>::setPreconditionerFactory(
00080   const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
00081   const std::string &precFactoryName
00082   )
00083 {
00084   TEST_FOR_EXCEPT(!precFactory.get());
00085   RCP<const Teuchos::ParameterList>
00086     precFactoryValidPL = precFactory->getValidParameters();
00087   const std::string _precFactoryName =
00088     ( precFactoryName != ""
00089       ? precFactoryName
00090       : ( precFactoryValidPL.get() ? precFactoryValidPL->name() : "GENERIC PRECONDITIONER FACTORY" )
00091       );
00092   precFactory_ = precFactory;
00093   precFactoryName_ = _precFactoryName;
00094   updateThisValidParamList();
00095 }
00096 
00097 
00098 template<class Scalar>
00099 RCP<PreconditionerFactoryBase<Scalar> >
00100 BelosLinearOpWithSolveFactory<Scalar>::getPreconditionerFactory() const
00101 {
00102   return precFactory_;
00103 }
00104 
00105 
00106 template<class Scalar>
00107 void BelosLinearOpWithSolveFactory<Scalar>::unsetPreconditionerFactory(
00108   RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
00109   std::string *precFactoryName
00110   )
00111 {
00112   if(precFactory) *precFactory = precFactory_;
00113   if(precFactoryName) *precFactoryName = precFactoryName_;
00114   precFactory_ = Teuchos::null;
00115   precFactoryName_ = "";
00116   updateThisValidParamList();
00117 }
00118 
00119 
00120 template<class Scalar>
00121 bool BelosLinearOpWithSolveFactory<Scalar>::isCompatible(
00122   const LinearOpSourceBase<Scalar> &fwdOpSrc
00123   ) const
00124 {
00125   if(precFactory_.get())
00126     return precFactory_->isCompatible(fwdOpSrc);
00127   return true; // Without a preconditioner, we are compatible with all linear operators!
00128 }
00129 
00130 
00131 template<class Scalar>
00132 RCP<LinearOpWithSolveBase<Scalar> >
00133 BelosLinearOpWithSolveFactory<Scalar>::createOp() const
00134 {
00135   return Teuchos::rcp(new BelosLinearOpWithSolve<Scalar>());
00136 }
00137 
00138 
00139 template<class Scalar>
00140 void BelosLinearOpWithSolveFactory<Scalar>::initializeOp(
00141   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00142   LinearOpWithSolveBase<Scalar> *Op,
00143   const ESupportSolveUse supportSolveUse
00144   ) const
00145 {
00146   using Teuchos::null;
00147   initializeOpImpl(fwdOpSrc,null,null,false,Op,supportSolveUse);
00148 }
00149 
00150 
00151 template<class Scalar>
00152 void BelosLinearOpWithSolveFactory<Scalar>::initializeAndReuseOp(
00153   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00154   LinearOpWithSolveBase<Scalar> *Op
00155   ) const
00156 {
00157   using Teuchos::null;
00158   initializeOpImpl(fwdOpSrc,null,null,true,Op,SUPPORT_SOLVE_UNSPECIFIED);
00159 }
00160 
00161 
00162 template<class Scalar>
00163 bool BelosLinearOpWithSolveFactory<Scalar>::supportsPreconditionerInputType(
00164   const EPreconditionerInputType precOpType
00165   ) const
00166 {
00167   if(precFactory_.get())
00168     return true;
00169   return (precOpType==PRECONDITIONER_INPUT_TYPE_AS_OPERATOR);
00170 }
00171 
00172 
00173 template<class Scalar>
00174 void BelosLinearOpWithSolveFactory<Scalar>::initializePreconditionedOp(
00175   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00176   const RCP<const PreconditionerBase<Scalar> > &prec,
00177   LinearOpWithSolveBase<Scalar> *Op,
00178   const ESupportSolveUse supportSolveUse
00179   ) const
00180 {
00181   using Teuchos::null;
00182   initializeOpImpl(fwdOpSrc,null,prec,false,Op,supportSolveUse);
00183 }
00184 
00185 
00186 template<class Scalar>
00187 void BelosLinearOpWithSolveFactory<Scalar>::initializeApproxPreconditionedOp(
00188   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00189   const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
00190   LinearOpWithSolveBase<Scalar> *Op,
00191   const ESupportSolveUse supportSolveUse
00192   ) const
00193 {
00194   using Teuchos::null;
00195   initializeOpImpl(fwdOpSrc,approxFwdOpSrc,null,false,Op,supportSolveUse);
00196 }
00197 
00198 
00199 template<class Scalar>
00200 void BelosLinearOpWithSolveFactory<Scalar>::uninitializeOp(
00201   LinearOpWithSolveBase<Scalar> *Op,
00202   RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
00203   RCP<const PreconditionerBase<Scalar> > *prec,
00204   RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
00205   ESupportSolveUse *supportSolveUse
00206   ) const
00207 {
00208 #ifdef TEUCHOS_DEBUG
00209   TEST_FOR_EXCEPT(Op==NULL);
00210 #endif
00211   BelosLinearOpWithSolve<Scalar>
00212     &belosOp = Teuchos::dyn_cast<BelosLinearOpWithSolve<Scalar> >(*Op);
00213   RCP<const LinearOpSourceBase<Scalar> > 
00214     _fwdOpSrc = belosOp.extract_fwdOpSrc();
00215   RCP<const PreconditionerBase<Scalar> >
00216     _prec = ( belosOp.isExternalPrec() ? belosOp.extract_prec() : Teuchos::null );
00217   // Note: above we only extract the preconditioner if it was passed in
00218   // externally.  Otherwise, we need to hold on to it so that we can reuse it
00219   // in the next initialization.
00220   RCP<const LinearOpSourceBase<Scalar> >
00221     _approxFwdOpSrc = belosOp.extract_approxFwdOpSrc();
00222   ESupportSolveUse
00223     _supportSolveUse = belosOp.supportSolveUse();
00224   if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
00225   if(prec) *prec = _prec;
00226   if(approxFwdOpSrc) *approxFwdOpSrc = _approxFwdOpSrc;
00227   if(supportSolveUse) *supportSolveUse = _supportSolveUse;
00228 }
00229 
00230 
00231 // Overridden from ParameterListAcceptor
00232 
00233 
00234 template<class Scalar>
00235 void BelosLinearOpWithSolveFactory<Scalar>::setParameterList(
00236   RCP<Teuchos::ParameterList> const& paramList
00237   )
00238 {
00239   TEST_FOR_EXCEPT(paramList.get()==NULL);
00240   paramList->validateParametersAndSetDefaults(*this->getValidParameters(), 1);
00241   paramList_ = paramList;
00242   solverType_ =
00243     Teuchos::getIntegralValue<ESolverType>(*paramList_, SolverType_name);
00244   convergenceTestFrequency_ =
00245     Teuchos::getParameter<int>(*paramList_, ConvergenceTestFrequency_name);
00246   Teuchos::readVerboseObjectSublist(&*paramList_,this);
00247 }
00248 
00249 
00250 template<class Scalar>
00251 RCP<Teuchos::ParameterList>
00252 BelosLinearOpWithSolveFactory<Scalar>::getNonconstParameterList()
00253 {
00254   return paramList_;
00255 }
00256 
00257 
00258 template<class Scalar>
00259 RCP<Teuchos::ParameterList>
00260 BelosLinearOpWithSolveFactory<Scalar>::unsetParameterList()
00261 {
00262   RCP<Teuchos::ParameterList> _paramList = paramList_;
00263   paramList_ = Teuchos::null;
00264   return _paramList;
00265 }
00266 
00267 
00268 template<class Scalar>
00269 RCP<const Teuchos::ParameterList>
00270 BelosLinearOpWithSolveFactory<Scalar>::getParameterList() const
00271 {
00272   return paramList_;
00273 }
00274 
00275 
00276 template<class Scalar>
00277 RCP<const Teuchos::ParameterList>
00278 BelosLinearOpWithSolveFactory<Scalar>::getValidParameters() const
00279 {
00280   return thisValidParamList_;
00281 }
00282 
00283 
00284 // Public functions overridden from Teuchos::Describable
00285 
00286 
00287 template<class Scalar>
00288 std::string BelosLinearOpWithSolveFactory<Scalar>::description() const
00289 {
00290   std::ostringstream oss;
00291   oss << "Thyra::BelosLinearOpWithSolveFactory";
00292   //oss << "{";
00293   // ToDo: Fill this in some!
00294   //oss << "}";
00295   return oss.str();
00296 }
00297 
00298 
00299 // private
00300 
00301 
00302 template<class Scalar>
00303 RCP<const Teuchos::ParameterList>
00304 BelosLinearOpWithSolveFactory<Scalar>::generateAndGetValidParameters()
00305 {
00306   using Teuchos::as;
00307   using Teuchos::tuple;
00308   using Teuchos::setStringToIntegralParameter;
00309   typedef MultiVectorBase<Scalar> MV_t;
00310   typedef LinearOpBase<Scalar> LO_t;
00311   static RCP<Teuchos::ParameterList> validParamList;
00312   if(validParamList.get()==NULL) {
00313     validParamList = Teuchos::rcp(new Teuchos::ParameterList("BelosLinearOpWithSolveFactory"));
00314     setStringToIntegralParameter<ESolverType>(
00315       SolverType_name, SolverType_default,
00316       "Type of linear solver algorithm to use.",
00317       tuple<std::string>(
00318         "Block GMRES",
00319         "Pseudo Block GMRES",
00320         "Block CG",
00321         "Pseudo Block CG",
00322         "GCRODR"
00323         ),
00324       tuple<std::string>(
00325         "Performs block and single single-RHS GMRES as well as\n"
00326         "flexible GMRES by setting options in the \"Block GMRES\" sublist.",
00327 
00328         "GMRES solver that performs single-RHS GMRES on multiple RHSs taking\n"
00329         "advantage of operator multi-vector multiplication and the amortization\n"
00330         "of global communication.  Individual linear systems are deflated out as\n"
00331         "they are solved.",
00332 
00333         "CG solver that performs block and single-RHS CG.",
00334 
00335         "CG solver that performs single-RHS CG on multiple RHSs taking\n"
00336         "advantage of operator multi-vector multiplication and the amortization\n"
00337         "of global communication.  Individual linear systems are deflated out as\n"
00338         "they are solved.",
00339 
00340         "GMRES solver that performs subspace recycling between RHS and linear systems."
00341         ),
00342       tuple<ESolverType>(
00343         SOLVER_TYPE_BLOCK_GMRES,
00344         SOLVER_TYPE_PSEUDO_BLOCK_GMRES,
00345         SOLVER_TYPE_BLOCK_CG,
00346         SOLVER_TYPE_PSEUDO_BLOCK_CG,
00347         SOLVER_TYPE_GCRODR
00348         ),
00349       &*validParamList
00350       );
00351     validParamList->set(ConvergenceTestFrequency_name, as<int>(1),
00352       "Number of linear solver iterations to skip betwee applying"
00353       " user-defined convergence test.");
00354     Teuchos::ParameterList
00355       &solverTypesSL = validParamList->sublist(SolverTypes_name);
00356     {
00357       Belos::BlockGmresSolMgr<Scalar,MV_t,LO_t> mgr;
00358       solverTypesSL.sublist(BlockGMRES_name).setParameters(
00359         *mgr.getValidParameters()
00360         );
00361     }
00362     {
00363       Belos::PseudoBlockGmresSolMgr<Scalar,MV_t,LO_t> mgr;
00364       solverTypesSL.sublist(PseudoBlockGMRES_name).setParameters(
00365         *mgr.getValidParameters()
00366         );
00367     }
00368     {
00369       Belos::BlockCGSolMgr<Scalar,MV_t,LO_t> mgr;
00370       solverTypesSL.sublist(BlockCG_name).setParameters(
00371         *mgr.getValidParameters()
00372         );
00373     }
00374     {
00375       Belos::PseudoBlockCGSolMgr<Scalar,MV_t,LO_t> mgr;
00376       solverTypesSL.sublist(PseudoBlockCG_name).setParameters(
00377         *mgr.getValidParameters()
00378         );
00379     }
00380     {
00381       Belos::GCRODRSolMgr<Scalar,MV_t,LO_t> mgr;
00382       solverTypesSL.sublist(GCRODR_name).setParameters(
00383         *mgr.getValidParameters()
00384         );
00385     }
00386   }
00387   return validParamList;
00388 }
00389 
00390 
00391 template<class Scalar>
00392 void BelosLinearOpWithSolveFactory<Scalar>::updateThisValidParamList()
00393 {
00394   thisValidParamList_ = Teuchos::rcp(
00395     new Teuchos::ParameterList(*generateAndGetValidParameters())
00396     );
00397   Teuchos::setupVerboseObjectSublist(&*thisValidParamList_);
00398 }
00399 
00400 
00401 template<class Scalar>
00402 void BelosLinearOpWithSolveFactory<Scalar>::initializeOpImpl(
00403   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00404   const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
00405   const RCP<const PreconditionerBase<Scalar> > &prec_in,
00406   const bool reusePrec,
00407   LinearOpWithSolveBase<Scalar> *Op,
00408   const ESupportSolveUse supportSolveUse
00409   ) const
00410 {
00411 
00412   using Teuchos::rcp;
00413   using Teuchos::set_extra_data;
00414   typedef Teuchos::ScalarTraits<Scalar> ST;
00415   typedef typename ST::magnitudeType ScalarMag;
00416   typedef MultiVectorBase<Scalar> MV_t;
00417   typedef LinearOpBase<Scalar> LO_t;
00418 
00419   const RCP<Teuchos::FancyOStream> out = this->getOStream();
00420   const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00421   Teuchos::OSTab tab(out);
00422   if(out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW))
00423     *out << "\nEntering Thyra::BelosLinearOpWithSolveFactory<"<<ST::name()<<">::initializeOpImpl(...) ...\n";
00424 
00425   typedef Teuchos::VerboseObjectTempState<PreconditionerFactoryBase<Scalar> > VOTSPF;
00426   VOTSPF precFactoryOutputTempState(precFactory_,out,verbLevel);
00427   
00428   TEST_FOR_EXCEPT(Op==NULL);
00429   TEST_FOR_EXCEPT(fwdOpSrc.get()==NULL);
00430   TEST_FOR_EXCEPT(fwdOpSrc->getOp().get()==NULL);
00431   RCP<const LinearOpBase<Scalar> >
00432     fwdOp = fwdOpSrc->getOp(),
00433     approxFwdOp = ( approxFwdOpSrc.get() ? approxFwdOpSrc->getOp() : Teuchos::null );
00434 
00435   //
00436   // Get the BelosLinearOpWithSolve interface
00437   //
00438 
00439   BelosLinearOpWithSolve<Scalar>
00440     *belosOp = &Teuchos::dyn_cast<BelosLinearOpWithSolve<Scalar> >(*Op);
00441 
00442   //
00443   // Get/Create the preconditioner
00444   //
00445 
00446   RCP<PreconditionerBase<Scalar> > myPrec = Teuchos::null;
00447   RCP<const PreconditionerBase<Scalar> > prec = Teuchos::null;
00448   if(prec_in.get()) {
00449     // Use an externally defined preconditioner
00450     prec = prec_in;
00451   }
00452   else {
00453     // Try and generate a preconditioner on our own
00454     if(precFactory_.get()) {
00455       myPrec =
00456         ( !belosOp->isExternalPrec()
00457           ? Teuchos::rcp_const_cast<PreconditionerBase<Scalar> >(belosOp->extract_prec())
00458           : Teuchos::null
00459           );
00460       bool hasExistingPrec = false;
00461       if(myPrec.get()) {
00462         hasExistingPrec = true;
00463         // ToDo: Get the forward operator and validate that it is the same
00464         // operator that is used here!
00465       }
00466       else {
00467         hasExistingPrec = false;
00468         myPrec = precFactory_->createPrec();
00469       }
00470       if( hasExistingPrec && reusePrec ) {
00471         // Just reuse the existing preconditioner again!
00472       }
00473       else {
00474         // Update the preconditioner
00475         if(approxFwdOp.get())
00476           precFactory_->initializePrec(approxFwdOpSrc,&*myPrec);
00477         else
00478           precFactory_->initializePrec(fwdOpSrc,&*myPrec);
00479       }
00480       prec = myPrec;
00481     }
00482   }
00483 
00484   //
00485   // Uninitialize the current solver object
00486   //
00487 
00488   bool oldIsExternalPrec = false;
00489   RCP<Belos::LinearProblem<Scalar,MV_t,LO_t> > oldLP = Teuchos::null;
00490   RCP<Belos::SolverManager<Scalar,MV_t,LO_t> > oldIterSolver = Teuchos::null;
00491   RCP<const LinearOpSourceBase<Scalar> > oldFwdOpSrc = Teuchos::null;
00492   RCP<const LinearOpSourceBase<Scalar> > oldApproxFwdOpSrc = Teuchos::null;   
00493   ESupportSolveUse oldSupportSolveUse = SUPPORT_SOLVE_UNSPECIFIED;
00494 
00495   belosOp->uninitialize( &oldLP, NULL, &oldIterSolver, &oldFwdOpSrc,
00496     NULL, &oldIsExternalPrec, &oldApproxFwdOpSrc, &oldSupportSolveUse );
00497 
00498   //
00499   // Create the Belos linear problem
00500   // NOTE:  If one exists already, reuse it.
00501   //
00502 
00503   typedef Belos::LinearProblem<Scalar,MV_t,LO_t> LP_t;
00504   RCP<LP_t> lp;
00505   if (oldLP != Teuchos::null) {
00506     lp = oldLP;
00507   }
00508   else {
00509     lp = rcp(new LP_t());
00510   }
00511 
00512   //
00513   // Set the operator
00514   //
00515 
00516   lp->setOperator(fwdOp);
00517 
00518   //
00519   // Set the preconditioner
00520   //
00521 
00522   if(prec.get()) {
00523     RCP<const LinearOpBase<Scalar> > unspecified = prec->getUnspecifiedPrecOp();
00524     RCP<const LinearOpBase<Scalar> > left = prec->getLeftPrecOp();
00525     RCP<const LinearOpBase<Scalar> > right = prec->getRightPrecOp();
00526     TEST_FOR_EXCEPTION(
00527       !( left.get() || right.get() || unspecified.get() ), std::logic_error
00528       ,"Error, at least one preconditoner linear operator objects must be set!"
00529       );
00530     if(unspecified.get()) {
00531       lp->setRightPrec(unspecified);
00532       // ToDo: Allow user to determine whether this should be placed on the
00533       // left or on the right through a parameter in the parameter list!
00534     }
00535     else {
00536       // Set a left, right or split preconditioner
00537       TEST_FOR_EXCEPTION(
00538         left.get(),std::logic_error
00539         ,"Error, we can not currently handle a left preconditioner!"
00540         );
00541       lp->setRightPrec(right);
00542     }
00543   }
00544   if(myPrec.get()) {
00545     set_extra_data<RCP<PreconditionerBase<Scalar> > >(myPrec,"Belos::InternalPrec",
00546       Teuchos::inOutArg(lp), Teuchos::POST_DESTROY, false);
00547   }
00548   else if(prec.get()) {
00549     set_extra_data<RCP<const PreconditionerBase<Scalar> > >(prec,"Belos::ExternalPrec",
00550       Teuchos::inOutArg(lp), Teuchos::POST_DESTROY, false);
00551   }
00552 
00553   //
00554   // Generate the parameter list.
00555   //
00556 
00557   typedef Belos::SolverManager<Scalar,MV_t,LO_t> IterativeSolver_t;
00558   RCP<IterativeSolver_t> iterativeSolver = Teuchos::null;
00559   RCP<Teuchos::ParameterList> solverPL = Teuchos::rcp( new Teuchos::ParameterList() );
00560   
00561   switch(solverType_) {
00562     case SOLVER_TYPE_BLOCK_GMRES: 
00563     {
00564       // Set the PL
00565       if(paramList_.get()) {
00566         Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
00567         Teuchos::ParameterList &gmresPL = solverTypesPL.sublist(BlockGMRES_name);
00568         solverPL = Teuchos::rcp( &gmresPL, false );
00569       }
00570       // Create the solver
00571       if (oldIterSolver != Teuchos::null) {
00572         iterativeSolver = oldIterSolver;
00573         iterativeSolver->setProblem( lp );
00574         iterativeSolver->setParameters( solverPL );
00575       } 
00576       else {
00577         iterativeSolver = rcp(new Belos::BlockGmresSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
00578       }
00579       break;
00580     }
00581     case SOLVER_TYPE_PSEUDO_BLOCK_GMRES:
00582     {
00583       // Set the PL
00584       if(paramList_.get()) {
00585         Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
00586         Teuchos::ParameterList &pbgmresPL = solverTypesPL.sublist(PseudoBlockGMRES_name);
00587         solverPL = Teuchos::rcp( &pbgmresPL, false );
00588       }
00589       // 
00590       // Create the solver
00591       // 
00592       if (oldIterSolver != Teuchos::null) {
00593         iterativeSolver = oldIterSolver;
00594         iterativeSolver->setProblem( lp );
00595         iterativeSolver->setParameters( solverPL );
00596       }
00597       else {
00598         iterativeSolver = rcp(new Belos::PseudoBlockGmresSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
00599       }
00600       break;
00601     }
00602     case SOLVER_TYPE_BLOCK_CG:
00603     {
00604       // Set the PL
00605       if(paramList_.get()) {
00606         Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
00607         Teuchos::ParameterList &cgPL = solverTypesPL.sublist(BlockCG_name);
00608         solverPL = Teuchos::rcp( &cgPL, false );
00609       }
00610       // Create the solver
00611       if (oldIterSolver != Teuchos::null) {
00612         iterativeSolver = oldIterSolver;
00613         iterativeSolver->setProblem( lp );
00614         iterativeSolver->setParameters( solverPL );
00615       }
00616       else {
00617         iterativeSolver = rcp(new Belos::BlockCGSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
00618       }
00619       break;
00620     }
00621     case SOLVER_TYPE_PSEUDO_BLOCK_CG:
00622     {
00623       // Set the PL
00624       if(paramList_.get()) {
00625         Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
00626         Teuchos::ParameterList &pbcgPL = solverTypesPL.sublist(PseudoBlockCG_name);
00627         solverPL = Teuchos::rcp( &pbcgPL, false );
00628       }
00629       // 
00630       // Create the solver
00631       // 
00632       if (oldIterSolver != Teuchos::null) {
00633         iterativeSolver = oldIterSolver;
00634         iterativeSolver->setProblem( lp );
00635         iterativeSolver->setParameters( solverPL );
00636       }
00637       else {
00638         iterativeSolver = rcp(new Belos::PseudoBlockCGSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
00639       }
00640       break;
00641     }
00642     case SOLVER_TYPE_GCRODR:
00643     {
00644       // Set the PL
00645       if(paramList_.get()) {
00646         Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
00647         Teuchos::ParameterList &gcrodrPL = solverTypesPL.sublist(GCRODR_name);
00648         solverPL = Teuchos::rcp( &gcrodrPL, false );
00649       }
00650       // Create the solver
00651       if (oldIterSolver != Teuchos::null) {
00652         iterativeSolver = oldIterSolver;
00653         iterativeSolver->setProblem( lp );
00654         iterativeSolver->setParameters( solverPL );
00655       } 
00656       else {
00657         iterativeSolver = rcp(new Belos::GCRODRSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
00658       }
00659       break;
00660     }
00661     default:
00662     {
00663       TEST_FOR_EXCEPT(true);
00664     }
00665   }
00666 
00667   //
00668   // Initialize the LOWS object
00669   //
00670 
00671   belosOp->initialize(
00672     lp, solverPL, iterativeSolver,
00673     fwdOpSrc, prec, myPrec.get()==NULL, approxFwdOpSrc,
00674     supportSolveUse, convergenceTestFrequency_
00675     );
00676   belosOp->setOStream(out);
00677   belosOp->setVerbLevel(verbLevel);
00678 #ifdef TEUCHOS_DEBUG
00679   if(paramList_.get()) {
00680     // Make sure we read the list correctly
00681     paramList_->validateParameters(*this->getValidParameters(),1); // Validate 0th and 1st level deep
00682   }
00683 #endif
00684   if(out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW))
00685     *out << "\nLeaving Thyra::BelosLinearOpWithSolveFactory<"<<ST::name()<<">::initializeOpImpl(...) ...\n";
00686   
00687 }
00688 
00689 
00690 } // namespace Thyra
00691 
00692 
00693 #endif // THYRA_BELOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines