Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_BelosLinearOpWithSolveFactory_def.hpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Stratimikos: Thyra-based strategies for linear solvers
6 // Copyright (2006) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 
45 #ifndef THYRA_BELOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
46 #define THYRA_BELOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
47 
48 
50 #include "Thyra_BelosLinearOpWithSolve.hpp"
51 #include "Thyra_ScaledAdjointLinearOpBase.hpp"
52 #include "BelosBlockGmresSolMgr.hpp"
53 #include "BelosPseudoBlockGmresSolMgr.hpp"
54 #include "BelosBlockCGSolMgr.hpp"
55 #include "BelosPseudoBlockCGSolMgr.hpp"
56 #include "BelosGCRODRSolMgr.hpp"
57 #include "BelosRCGSolMgr.hpp"
58 #include "BelosMinresSolMgr.hpp"
59 #include "BelosThyraAdapter.hpp"
63 #include "Teuchos_dyn_cast.hpp"
66 
67 
68 namespace Thyra {
69 
70 
71 // Parameter names for Paramter List
72 
73 template<class Scalar>
74 const std::string BelosLinearOpWithSolveFactory<Scalar>::SolverType_name = "Solver Type";
75 template<class Scalar>
76 const std::string BelosLinearOpWithSolveFactory<Scalar>::SolverType_default = "Pseudo Block GMRES";
77 template<class Scalar>
78 const std::string BelosLinearOpWithSolveFactory<Scalar>::SolverTypes_name = "Solver Types";
79 template<class Scalar>
80 const std::string BelosLinearOpWithSolveFactory<Scalar>::BlockGMRES_name = "Block GMRES";
81 template<class Scalar>
82 const std::string BelosLinearOpWithSolveFactory<Scalar>::PseudoBlockGMRES_name = "Pseudo Block GMRES";
83 template<class Scalar>
84 const std::string BelosLinearOpWithSolveFactory<Scalar>::BlockCG_name = "Block CG";
85 template<class Scalar>
86 const std::string BelosLinearOpWithSolveFactory<Scalar>::PseudoBlockCG_name = "Pseudo Block CG";
87 template<class Scalar>
88 const std::string BelosLinearOpWithSolveFactory<Scalar>::GCRODR_name = "GCRODR";
89 template<class Scalar>
90 const std::string BelosLinearOpWithSolveFactory<Scalar>::RCG_name = "RCG";
91 template<class Scalar>
92 const std::string BelosLinearOpWithSolveFactory<Scalar>::MINRES_name = "MINRES";
93 template<class Scalar>
94 const std::string BelosLinearOpWithSolveFactory<Scalar>::ConvergenceTestFrequency_name = "Convergence Test Frequency";
95 
96 // Constructors/initializers/accessors
97 
98 
99 template<class Scalar>
101  :solverType_(SOLVER_TYPE_PSEUDO_BLOCK_GMRES),
102  convergenceTestFrequency_(1)
103 {
105 }
106 
107 
108 template<class Scalar>
110  const RCP<PreconditionerFactoryBase<Scalar> > &precFactory
111  )
112  :solverType_(SOLVER_TYPE_PSEUDO_BLOCK_GMRES)
113 {
114  this->setPreconditionerFactory(precFactory, "");
115 }
116 
117 
118 // Overridden from LinearOpWithSolveFactoryBase
119 
120 
121 template<class Scalar>
123 {
124  return true;
125 }
126 
127 
128 template<class Scalar>
130  const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
131  const std::string &precFactoryName
132  )
133 {
134  TEUCHOS_TEST_FOR_EXCEPT(!precFactory.get());
136  precFactoryValidPL = precFactory->getValidParameters();
137  const std::string _precFactoryName =
138  ( precFactoryName != ""
139  ? precFactoryName
140  : ( precFactoryValidPL.get() ? precFactoryValidPL->name() : "GENERIC PRECONDITIONER FACTORY" )
141  );
142  precFactory_ = precFactory;
143  precFactoryName_ = _precFactoryName;
144  updateThisValidParamList();
145 }
146 
147 
148 template<class Scalar>
151 {
152  return precFactory_;
153 }
154 
155 
156 template<class Scalar>
158  RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
159  std::string *precFactoryName
160  )
161 {
162  if(precFactory) *precFactory = precFactory_;
163  if(precFactoryName) *precFactoryName = precFactoryName_;
164  precFactory_ = Teuchos::null;
165  precFactoryName_ = "";
166  updateThisValidParamList();
167 }
168 
169 
170 template<class Scalar>
172  const LinearOpSourceBase<Scalar> &fwdOpSrc
173  ) const
174 {
175  if(precFactory_.get())
176  return precFactory_->isCompatible(fwdOpSrc);
177  return true; // Without a preconditioner, we are compatible with all linear operators!
178 }
179 
180 
181 template<class Scalar>
184 {
186 }
187 
188 
189 template<class Scalar>
191  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
192  LinearOpWithSolveBase<Scalar> *Op,
193  const ESupportSolveUse supportSolveUse
194  ) const
195 {
196  using Teuchos::null;
197  initializeOpImpl(fwdOpSrc,null,null,false,Op,supportSolveUse);
198 }
199 
200 
201 template<class Scalar>
203  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
204  LinearOpWithSolveBase<Scalar> *Op
205  ) const
206 {
207  using Teuchos::null;
208  initializeOpImpl(fwdOpSrc,null,null,true,Op,SUPPORT_SOLVE_UNSPECIFIED);
209 }
210 
211 
212 template<class Scalar>
214  const EPreconditionerInputType precOpType
215  ) const
216 {
217  if(precFactory_.get())
218  return true;
219  return (precOpType==PRECONDITIONER_INPUT_TYPE_AS_OPERATOR);
220 }
221 
222 
223 template<class Scalar>
225  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
226  const RCP<const PreconditionerBase<Scalar> > &prec,
227  LinearOpWithSolveBase<Scalar> *Op,
228  const ESupportSolveUse supportSolveUse
229  ) const
230 {
231  using Teuchos::null;
232  initializeOpImpl(fwdOpSrc,null,prec,false,Op,supportSolveUse);
233 }
234 
235 
236 template<class Scalar>
238  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
239  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
240  LinearOpWithSolveBase<Scalar> *Op,
241  const ESupportSolveUse supportSolveUse
242  ) const
243 {
244  using Teuchos::null;
245  initializeOpImpl(fwdOpSrc,approxFwdOpSrc,null,false,Op,supportSolveUse);
246 }
247 
248 
249 template<class Scalar>
251  LinearOpWithSolveBase<Scalar> *Op,
252  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
253  RCP<const PreconditionerBase<Scalar> > *prec,
254  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
255  ESupportSolveUse *supportSolveUse
256  ) const
257 {
258 #ifdef TEUCHOS_DEBUG
259  TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
260 #endif
264  _fwdOpSrc = belosOp.extract_fwdOpSrc();
266  _prec = ( belosOp.isExternalPrec() ? belosOp.extract_prec() : Teuchos::null );
267  // Note: above we only extract the preconditioner if it was passed in
268  // externally. Otherwise, we need to hold on to it so that we can reuse it
269  // in the next initialization.
271  _approxFwdOpSrc = belosOp.extract_approxFwdOpSrc();
272  ESupportSolveUse
273  _supportSolveUse = belosOp.supportSolveUse();
274  if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
275  if(prec) *prec = _prec;
276  if(approxFwdOpSrc) *approxFwdOpSrc = _approxFwdOpSrc;
277  if(supportSolveUse) *supportSolveUse = _supportSolveUse;
278 }
279 
280 
281 // Overridden from ParameterListAcceptor
282 
283 
284 template<class Scalar>
286  RCP<Teuchos::ParameterList> const& paramList
287  )
288 {
289  TEUCHOS_TEST_FOR_EXCEPT(paramList.get()==NULL);
290  paramList->validateParametersAndSetDefaults(*this->getValidParameters(), 1);
291  paramList_ = paramList;
292  solverType_ =
293  Teuchos::getIntegralValue<EBelosSolverType>(*paramList_, SolverType_name);
294  convergenceTestFrequency_ =
295  Teuchos::getParameter<int>(*paramList_, ConvergenceTestFrequency_name);
296  Teuchos::readVerboseObjectSublist(&*paramList_,this);
297 }
298 
299 
300 template<class Scalar>
303 {
304  return paramList_;
305 }
306 
307 
308 template<class Scalar>
311 {
312  RCP<Teuchos::ParameterList> _paramList = paramList_;
313  paramList_ = Teuchos::null;
314  return _paramList;
315 }
316 
317 
318 template<class Scalar>
321 {
322  return paramList_;
323 }
324 
325 
326 template<class Scalar>
329 {
330  return thisValidParamList_;
331 }
332 
333 
334 // Public functions overridden from Teuchos::Describable
335 
336 
337 template<class Scalar>
339 {
340  std::ostringstream oss;
341  oss << "Thyra::BelosLinearOpWithSolveFactory";
342  //oss << "{";
343  // ToDo: Fill this in some!
344  //oss << "}";
345  return oss.str();
346 }
347 
348 
349 // private
350 
351 
352 template<class Scalar>
355 {
356  using Teuchos::as;
357  using Teuchos::tuple;
358  using Teuchos::setStringToIntegralParameter;
362  >::getDummyObject(),
364  EBelosSolverType> >::getDummyObject());
365 
366  typedef MultiVectorBase<Scalar> MV_t;
367  typedef LinearOpBase<Scalar> LO_t;
368  static RCP<Teuchos::ParameterList> validParamList;
369  if(validParamList.get()==NULL) {
370  validParamList = Teuchos::rcp(new Teuchos::ParameterList("BelosLinearOpWithSolveFactory"));
371  setStringToIntegralParameter<EBelosSolverType>(
372  SolverType_name, SolverType_default,
373  "Type of linear solver algorithm to use.",
374  tuple<std::string>(
375  "Block GMRES",
376  "Pseudo Block GMRES",
377  "Block CG",
378  "Pseudo Block CG",
379  "GCRODR",
380  "RCG",
381  "MINRES"
382  ),
383  tuple<std::string>(
384  "Block GMRES solver for nonsymmetric linear systems. It can also solve "
385  "single right-hand side systems, and can also perform Flexible GMRES "
386  "(where the preconditioner may change at every iteration, for example "
387  "for inner-outer iterations), by setting options in the \"Block GMRES\" "
388  "sublist.",
389 
390  "GMRES solver for nonsymmetric linear systems, that performs single "
391  "right-hand side solves on multiple right-hand sides at once. It "
392  "exploits operator multivector multiplication in order to amortize "
393  "global communication costs. Individual linear systems are deflated "
394  "out as they are solved.",
395 
396  "Block CG solver for symmetric (Hermitian in complex arithmetic) "
397  "positive definite linear systems. It can also solve single "
398  "right-hand-side systems.",
399 
400  "CG solver that performs single right-hand side CG on multiple right-hand "
401  "sides at once. It exploits operator multivector multiplication in order "
402  "to amortize global communication costs. Individual linear systems are "
403  "deflated out as they are solved.",
404 
405  "GMRES solver for nonsymmetric linear systems, that performs subspace "
406  "recycling to accelerate convergence for sequences of related linear "
407  "systems.",
408 
409  "CG solver for symmetric (Hermitian in complex arithmetic) positive "
410  "definite linear systems, that performs subspace recycling to "
411  "accelerate convergence for sequences of related linear systems.",
412 
413  "MINRES solver for symmetric indefinite linear systems. It performs "
414  "single-right-hand-side solves on multiple right-hand sides sequentially."
415  ),
416  tuple<EBelosSolverType>(
417  SOLVER_TYPE_BLOCK_GMRES,
418  SOLVER_TYPE_PSEUDO_BLOCK_GMRES,
419  SOLVER_TYPE_BLOCK_CG,
420  SOLVER_TYPE_PSEUDO_BLOCK_CG,
421  SOLVER_TYPE_GCRODR,
422  SOLVER_TYPE_RCG,
423  SOLVER_TYPE_MINRES
424  ),
425  &*validParamList
426  );
427  validParamList->set(ConvergenceTestFrequency_name, as<int>(1),
428  "Number of linear solver iterations to skip between applying"
429  " user-defined convergence test.");
431  &solverTypesSL = validParamList->sublist(SolverTypes_name);
432  {
433  Belos::BlockGmresSolMgr<Scalar,MV_t,LO_t> mgr;
434  solverTypesSL.sublist(BlockGMRES_name).setParameters(
435  *mgr.getValidParameters()
436  );
437  }
438  {
439  Belos::PseudoBlockGmresSolMgr<Scalar,MV_t,LO_t> mgr;
440  solverTypesSL.sublist(PseudoBlockGMRES_name).setParameters(
441  *mgr.getValidParameters()
442  );
443  }
444  {
445  Belos::BlockCGSolMgr<Scalar,MV_t,LO_t> mgr;
446  solverTypesSL.sublist(BlockCG_name).setParameters(
447  *mgr.getValidParameters()
448  );
449  }
450  {
451  Belos::PseudoBlockCGSolMgr<Scalar,MV_t,LO_t> mgr;
452  solverTypesSL.sublist(PseudoBlockCG_name).setParameters(
453  *mgr.getValidParameters()
454  );
455  }
456  {
457  Belos::GCRODRSolMgr<Scalar,MV_t,LO_t> mgr;
458  solverTypesSL.sublist(GCRODR_name).setParameters(
459  *mgr.getValidParameters()
460  );
461  }
462  {
463  Belos::RCGSolMgr<Scalar,MV_t,LO_t> mgr;
464  solverTypesSL.sublist(RCG_name).setParameters(
465  *mgr.getValidParameters()
466  );
467  }
468  {
469  Belos::MinresSolMgr<Scalar,MV_t,LO_t> mgr;
470  solverTypesSL.sublist(MINRES_name).setParameters(
471  *mgr.getValidParameters()
472  );
473  }
474  }
475  return validParamList;
476 }
477 
478 
479 template<class Scalar>
481 {
482  thisValidParamList_ = Teuchos::rcp(
483  new Teuchos::ParameterList(*generateAndGetValidParameters())
484  );
485  Teuchos::setupVerboseObjectSublist(&*thisValidParamList_);
486 }
487 
488 
489 template<class Scalar>
491  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
492  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
493  const RCP<const PreconditionerBase<Scalar> > &prec_in,
494  const bool reusePrec,
495  LinearOpWithSolveBase<Scalar> *Op,
496  const ESupportSolveUse supportSolveUse
497  ) const
498 {
499 
500  using Teuchos::rcp;
501  using Teuchos::set_extra_data;
503  typedef MultiVectorBase<Scalar> MV_t;
504  typedef LinearOpBase<Scalar> LO_t;
505 
506  const RCP<Teuchos::FancyOStream> out = this->getOStream();
507  const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
508  Teuchos::OSTab tab(out);
509  if(out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW))
510  *out << "\nEntering Thyra::BelosLinearOpWithSolveFactory<"<<ST::name()<<">::initializeOpImpl(...) ...\n";
511 
512  // These lines are changing the verbosity of the preconditioner, which has its own verbose object list,
513  // so I am commenting these out, as it is not the job of the linear solver to dictate preconditioner verbosity.
514  //typedef Teuchos::VerboseObjectTempState<PreconditionerFactoryBase<Scalar> > VOTSPF;
515  //VOTSPF precFactoryOutputTempState(precFactory_,out,verbLevel);
516 
517  TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
518  TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc.get()==NULL);
519  TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc->getOp().get()==NULL);
521  fwdOp = fwdOpSrc->getOp(),
522  approxFwdOp = ( approxFwdOpSrc.get() ? approxFwdOpSrc->getOp() : Teuchos::null );
523 
524  //
525  // Get the BelosLinearOpWithSolve interface
526  //
527 
530 
531  //
532  // Get/Create the preconditioner
533  //
534 
537  if(prec_in.get()) {
538  // Use an externally defined preconditioner
539  prec = prec_in;
540  }
541  else {
542  // Try and generate a preconditioner on our own
543  if(precFactory_.get()) {
544  myPrec =
545  ( !belosOp->isExternalPrec()
546  ? Teuchos::rcp_const_cast<PreconditionerBase<Scalar> >(belosOp->extract_prec())
547  : Teuchos::null
548  );
549  bool hasExistingPrec = false;
550  if(myPrec.get()) {
551  hasExistingPrec = true;
552  // ToDo: Get the forward operator and validate that it is the same
553  // operator that is used here!
554  }
555  else {
556  hasExistingPrec = false;
557  myPrec = precFactory_->createPrec();
558  }
559  if( hasExistingPrec && reusePrec ) {
560  // Just reuse the existing preconditioner again!
561  }
562  else {
563  // Update the preconditioner
564  if(approxFwdOp.get())
565  precFactory_->initializePrec(approxFwdOpSrc,&*myPrec);
566  else
567  precFactory_->initializePrec(fwdOpSrc,&*myPrec);
568  }
569  prec = myPrec;
570  }
571  }
572 
573  //
574  // Uninitialize the current solver object
575  //
576 
577  bool oldIsExternalPrec = false;
582  ESupportSolveUse oldSupportSolveUse = SUPPORT_SOLVE_UNSPECIFIED;
583 
584  belosOp->uninitialize( &oldLP, NULL, &oldIterSolver, &oldFwdOpSrc,
585  NULL, &oldIsExternalPrec, &oldApproxFwdOpSrc, &oldSupportSolveUse );
586 
587  //
588  // Create the Belos linear problem
589  // NOTE: If one exists already, reuse it.
590  //
591 
592  typedef Belos::LinearProblem<Scalar,MV_t,LO_t> LP_t;
593  RCP<LP_t> lp;
594  if (oldLP != Teuchos::null) {
595  lp = oldLP;
596  }
597  else {
598  lp = rcp(new LP_t());
599  }
600 
601  //
602  // Set the operator
603  //
604 
605  lp->setOperator(fwdOp);
606 
607  //
608  // Set the preconditioner
609  //
610 
611  if(prec.get()) {
612  RCP<const LinearOpBase<Scalar> > unspecified = prec->getUnspecifiedPrecOp();
613  RCP<const LinearOpBase<Scalar> > left = prec->getLeftPrecOp();
614  RCP<const LinearOpBase<Scalar> > right = prec->getRightPrecOp();
616  !( left.get() || right.get() || unspecified.get() ), std::logic_error
617  ,"Error, at least one preconditoner linear operator objects must be set!"
618  );
619  if(unspecified.get()) {
620  lp->setRightPrec(unspecified);
621  // ToDo: Allow user to determine whether this should be placed on the
622  // left or on the right through a parameter in the parameter list!
623  }
624  else {
625  // Set a left, right or split preconditioner
627  left.get(),std::logic_error
628  ,"Error, we can not currently handle a left preconditioner!"
629  );
630  lp->setRightPrec(right);
631  }
632  }
633  if(myPrec.get()) {
634  set_extra_data<RCP<PreconditionerBase<Scalar> > >(myPrec,"Belos::InternalPrec",
635  Teuchos::inOutArg(lp), Teuchos::POST_DESTROY, false);
636  }
637  else if(prec.get()) {
638  set_extra_data<RCP<const PreconditionerBase<Scalar> > >(prec,"Belos::ExternalPrec",
639  Teuchos::inOutArg(lp), Teuchos::POST_DESTROY, false);
640  }
641 
642  //
643  // Generate the parameter list.
644  //
645 
646  typedef Belos::SolverManager<Scalar,MV_t,LO_t> IterativeSolver_t;
647  RCP<IterativeSolver_t> iterativeSolver = Teuchos::null;
649 
650  switch(solverType_) {
651  case SOLVER_TYPE_BLOCK_GMRES:
652  {
653  // Set the PL
654  if(paramList_.get()) {
655  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
656  Teuchos::ParameterList &gmresPL = solverTypesPL.sublist(BlockGMRES_name);
657  solverPL = Teuchos::rcp( &gmresPL, false );
658  }
659  // Create the solver
660  if (oldIterSolver != Teuchos::null) {
661  iterativeSolver = oldIterSolver;
662  iterativeSolver->setProblem( lp );
663  iterativeSolver->setParameters( solverPL );
664  }
665  else {
666  iterativeSolver = rcp(new Belos::BlockGmresSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
667  }
668  break;
669  }
670  case SOLVER_TYPE_PSEUDO_BLOCK_GMRES:
671  {
672  // Set the PL
673  if(paramList_.get()) {
674  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
675  Teuchos::ParameterList &pbgmresPL = solverTypesPL.sublist(PseudoBlockGMRES_name);
676  solverPL = Teuchos::rcp( &pbgmresPL, false );
677  }
678  //
679  // Create the solver
680  //
681  if (oldIterSolver != Teuchos::null) {
682  iterativeSolver = oldIterSolver;
683  iterativeSolver->setProblem( lp );
684  iterativeSolver->setParameters( solverPL );
685  }
686  else {
687  iterativeSolver = rcp(new Belos::PseudoBlockGmresSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
688  }
689  break;
690  }
691  case SOLVER_TYPE_BLOCK_CG:
692  {
693  // Set the PL
694  if(paramList_.get()) {
695  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
696  Teuchos::ParameterList &cgPL = solverTypesPL.sublist(BlockCG_name);
697  solverPL = Teuchos::rcp( &cgPL, false );
698  }
699  // Create the solver
700  if (oldIterSolver != Teuchos::null) {
701  iterativeSolver = oldIterSolver;
702  iterativeSolver->setProblem( lp );
703  iterativeSolver->setParameters( solverPL );
704  }
705  else {
706  iterativeSolver = rcp(new Belos::BlockCGSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
707  }
708  break;
709  }
710  case SOLVER_TYPE_PSEUDO_BLOCK_CG:
711  {
712  // Set the PL
713  if(paramList_.get()) {
714  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
715  Teuchos::ParameterList &pbcgPL = solverTypesPL.sublist(PseudoBlockCG_name);
716  solverPL = Teuchos::rcp( &pbcgPL, false );
717  }
718  //
719  // Create the solver
720  //
721  if (oldIterSolver != Teuchos::null) {
722  iterativeSolver = oldIterSolver;
723  iterativeSolver->setProblem( lp );
724  iterativeSolver->setParameters( solverPL );
725  }
726  else {
727  iterativeSolver = rcp(new Belos::PseudoBlockCGSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
728  }
729  break;
730  }
731  case SOLVER_TYPE_GCRODR:
732  {
733  // Set the PL
734  if(paramList_.get()) {
735  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
736  Teuchos::ParameterList &gcrodrPL = solverTypesPL.sublist(GCRODR_name);
737  solverPL = Teuchos::rcp( &gcrodrPL, false );
738  }
739  // Create the solver
740  if (oldIterSolver != Teuchos::null) {
741  iterativeSolver = oldIterSolver;
742  iterativeSolver->setProblem( lp );
743  iterativeSolver->setParameters( solverPL );
744  }
745  else {
746  iterativeSolver = rcp(new Belos::GCRODRSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
747  }
748  break;
749  }
750  case SOLVER_TYPE_RCG:
751  {
752  // Set the PL
753  if(paramList_.get()) {
754  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
755  Teuchos::ParameterList &rcgPL = solverTypesPL.sublist(RCG_name);
756  solverPL = Teuchos::rcp( &rcgPL, false );
757  }
758  // Create the solver
759  if (oldIterSolver != Teuchos::null) {
760  iterativeSolver = oldIterSolver;
761  iterativeSolver->setProblem( lp );
762  iterativeSolver->setParameters( solverPL );
763  }
764  else {
765  iterativeSolver = rcp(new Belos::RCGSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
766  }
767  break;
768  }
769  case SOLVER_TYPE_MINRES:
770  {
771  // Set the PL
772  if(paramList_.get()) {
773  Teuchos::ParameterList &solverTypesPL = paramList_->sublist(SolverTypes_name);
774  Teuchos::ParameterList &minresPL = solverTypesPL.sublist(MINRES_name);
775  solverPL = Teuchos::rcp( &minresPL, false );
776  }
777  // Create the solver
778  if (oldIterSolver != Teuchos::null) {
779  iterativeSolver = oldIterSolver;
780  iterativeSolver->setProblem( lp );
781  iterativeSolver->setParameters( solverPL );
782  }
783  else {
784  iterativeSolver = rcp(new Belos::MinresSolMgr<Scalar,MV_t,LO_t>(lp,solverPL));
785  }
786  break;
787  }
788 
789  default:
790  {
792  }
793  }
794 
795  //
796  // Initialize the LOWS object
797  //
798 
799  belosOp->initialize(
800  lp, solverPL, iterativeSolver,
801  fwdOpSrc, prec, myPrec.get()==NULL, approxFwdOpSrc,
802  supportSolveUse, convergenceTestFrequency_
803  );
804  belosOp->setOStream(out);
805  belosOp->setVerbLevel(verbLevel);
806 #ifdef TEUCHOS_DEBUG
807  if(paramList_.get()) {
808  // Make sure we read the list correctly
809  paramList_->validateParameters(*this->getValidParameters(),1); // Validate 0th and 1st level deep
810  }
811 #endif
812  if(out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW))
813  *out << "\nLeaving Thyra::BelosLinearOpWithSolveFactory<"<<ST::name()<<">::initializeOpImpl(...) ...\n";
814 
815 }
816 
817 
818 } // namespace Thyra
819 
820 
821 #endif // THYRA_BELOS_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, Teuchos::RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, Teuchos::RCP< const PreconditionerBase< Scalar > > *prec, Teuchos::RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
RCP< const LinearOpSourceBase< Scalar > > extract_approxFwdOpSrc()
static void addConverter(RCP< const ParameterEntryValidator > validator, RCP< ValidatorXMLConverter > converterToAdd)
void initialize(const RCP< Belos::LinearProblem< Scalar, MV_t, LO_t > > &lp, const RCP< Teuchos::ParameterList > &solverPL, const RCP< Belos::SolverManager< Scalar, MV_t, LO_t > > &iterativeSolver, const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, const bool isExternalPrec, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, const ESupportSolveUse &supportSolveUse, const int convergenceTestFrequency)
Initializes given precreated solver objects.
Concrete LinearOpWithSolveBase subclass in terms of Belos.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const PreconditionerBase< Scalar > > extract_prec()
void initializeAndReuseOp(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
T * get() const
static Teuchos::RCP< const Teuchos::ParameterList > generateAndGetValidParameters()
void unsetPreconditionerFactory(Teuchos::RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Thyra specializations of MultiVecTraits and OperatorTraits.
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
T_To & dyn_cast(T_From &from)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
void initializeOp(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
void setPreconditionerFactory(const Teuchos::RCP< PreconditionerFactoryBase< Scalar > > &precFactory, const std::string &precFactoryName)
TypeTo as(const TypeFrom &t)
bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
RCP< const LinearOpSourceBase< Scalar > > extract_fwdOpSrc()
Teuchos::RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
void initializeApproxPreconditionedOp(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
void initializePreconditionedOp(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const Teuchos::RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Teuchos::RCP< LinearOpWithSolveBase< Scalar > > createOp() const
void uninitialize(RCP< Belos::LinearProblem< Scalar, MV_t, LO_t > > *lp=NULL, RCP< Teuchos::ParameterList > *solverPL=NULL, RCP< Belos::SolverManager< Scalar, MV_t, LO_t > > *iterativeSolver=NULL, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc=NULL, RCP< const PreconditionerBase< Scalar > > *prec=NULL, bool *isExternalPrec=NULL, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc=NULL, ESupportSolveUse *supportSolveUse=NULL)
Uninitializes and returns stored quantities.
BelosLinearOpWithSolveFactory()
Construct without preconditioner factory.
void initializeOpImpl(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, const Teuchos::RCP< const PreconditionerBase< Scalar > > &prec, const bool reusePrec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)