48 #include "Thyra_PreconditionerFactoryHelpers.hpp" 49 #include "Thyra_EpetraOperatorViewExtractorStd.hpp" 50 #include "Thyra_ScaledAdjointLinearOpBase.hpp" 51 #include "Thyra_EpetraLinearOpBase.hpp" 52 #include "Thyra_EpetraOperatorWrapper.hpp" 53 #include "EpetraExt_ProductOperator.h" 54 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 55 #include "Teuchos_ParameterList.hpp" 56 #include "Teuchos_dyn_cast.hpp" 63 const std::string AOOLOWSF_epetraPrecOp_str
64 =
"AOOLOWSF::epetraPrecOp";
65 const std::string AOOLOWSF_aztec_epetra_epetraFwdOp_str
66 =
"AOOLOWSF::aztec_epetra_epetraFwdOp";
67 const std::string AOOLOWSF_aztec_epetra_epetraAdjOp_str
68 =
"AOOLOWSF::aztec_epetra_epetraAdjOp";
69 const std::string AOOLOWSF_rowmatrix_epetraFwdOp_str
70 =
"AOOLOWSF::rowmatrix_epetraFwdOp";
71 const std::string AOOLOWSF_rowmatrix_epetraPrecOp_str
72 =
"AOOLOWSF::rowmatrix_epetraPrecOp";
73 const std::string AOOLOWSF_aztec_fwd_epetra_epetraPrecOp_str
74 =
"AOOLOWSF::aztec_fwd_epetra_epetraPrecOp";
75 const std::string AOOLOWSF_aztec_adj_epetra_epetraPrecOp_str
76 =
"AOOLOWSF::aztec_adj_epetra_epetraPrecOp";
77 const std::string AOOLOWSF_setPrecondtionerOperator_str
78 =
"AOOLOWSF::setPrecondtionerOperator";
79 const std::string AOOLOWSF_constructedAztecPreconditoner_str
80 =
"AOOLOWSF::constructedAztecPreconditoner";
83 const std::string ForwardSolve_name =
"Forward Solve";
84 const std::string AdjointSolve_name =
"Adjoint Solve";
85 const std::string MaxIterations_name =
"Max Iterations";
86 const int MaxIterations_default = 400;
87 const std::string Tolerance_name =
"Tolerance";
88 const double Tolerance_default = 1e-6;
89 const std::string OutputEveryRhs_name =
"Output Every RHS";
90 const bool OutputEveryRhs_default =
false;
91 const std::string AztecOO_Settings_name =
"AztecOO Settings";
104 Teuchos::RCP<Teuchos::ParameterList>
const& paramList
106 :epetraFwdOpViewExtractor_(
Teuchos::rcp(new EpetraOperatorViewExtractorStd()))
107 ,defaultFwdMaxIterations_(MaxIterations_default)
108 ,defaultFwdTolerance_(Tolerance_default)
109 ,defaultAdjMaxIterations_(MaxIterations_default)
110 ,defaultAdjTolerance_(Tolerance_default)
111 ,outputEveryRhs_(OutputEveryRhs_default)
112 ,useAztecPrec_(false)
130 const Teuchos::RCP<PreconditionerFactoryBase<double> > &precFactory,
131 const std::string &precFactoryName
134 TEUCHOS_TEST_FOR_EXCEPT(!precFactory.get());
135 Teuchos::RCP<const Teuchos::ParameterList>
136 precFactoryValidPL = precFactory->getValidParameters();
137 const std::string _precFactoryName =
138 ( precFactoryName !=
"" 140 : ( precFactoryValidPL.get()
141 ? precFactoryValidPL->name()
142 :
"GENERIC PRECONDITIONER FACTORY" 151 Teuchos::RCP<PreconditionerFactoryBase<double> >
159 Teuchos::RCP<PreconditionerFactoryBase<double> > *precFactory,
160 std::string *precFactoryName
172 const LinearOpSourceBase<double> &fwdOpSrc
175 return epetraFwdOpViewExtractor_->isCompatible(*fwdOpSrc.getOp());
179 Teuchos::RCP<LinearOpWithSolveBase<double> >
187 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
188 LinearOpWithSolveBase<double> *Op,
189 const ESupportSolveUse supportSolveUse
197 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
198 LinearOpWithSolveBase<double> *Op
206 const EPreconditionerInputType precOpType
212 paramList_->sublist(ForwardSolve_name).sublist(AztecOO_Settings_name).get(
213 "Aztec Preconditioner",
"none" 217 case PRECONDITIONER_INPUT_TYPE_AS_OPERATOR:
220 case PRECONDITIONER_INPUT_TYPE_AS_MATRIX:
224 TEUCHOS_TEST_FOR_EXCEPT(
true);
226 return PRECONDITIONER_INPUT_TYPE_AS_OPERATOR;
231 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
232 const Teuchos::RCP<
const PreconditionerBase<double> > &prec,
233 LinearOpWithSolveBase<double> *Op,
234 const ESupportSolveUse supportSolveUse
237 TEUCHOS_TEST_FOR_EXCEPT(prec.get()==NULL);
243 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
244 const Teuchos::RCP<
const LinearOpSourceBase<double> > &approxFwdOpSrc,
245 LinearOpWithSolveBase<double> *Op,
246 const ESupportSolveUse supportSolveUse
249 TEUCHOS_TEST_FOR_EXCEPT(approxFwdOpSrc.get()==NULL);
250 TEUCHOS_TEST_FOR_EXCEPT(approxFwdOpSrc->getOp().get()==NULL);
256 LinearOpWithSolveBase<double> *Op,
257 Teuchos::RCP<
const LinearOpSourceBase<double> > *fwdOpSrc,
258 Teuchos::RCP<
const PreconditionerBase<double> > *prec,
259 Teuchos::RCP<
const LinearOpSourceBase<double> > *approxFwdOpSrc,
260 ESupportSolveUse *supportSolveUse
264 TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
269 Teuchos::RCP<const LinearOpSourceBase<double> >
272 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
273 if(approxFwdOpSrc) *approxFwdOpSrc = _approxFwdOpSrc;
278 Teuchos::RCP<const PreconditionerBase<double> >
280 if(prec) *prec = _prec;
292 Teuchos::RCP<Teuchos::ParameterList>
const& paramList
295 TEUCHOS_TEST_FOR_EXCEPT(paramList.get()==NULL);
301 Teuchos::ParameterList
302 &fwdSolvePL =
paramList_->sublist(ForwardSolve_name);
306 if( !
paramList_->getPtr<Teuchos::ParameterList>(AdjointSolve_name) ) {
308 paramList_->sublist(AdjointSolve_name).setParameters(fwdSolvePL);
310 Teuchos::ParameterList
311 &adjSolvePL =
paramList_->sublist(AdjointSolve_name);
320 const bool alreadyHasSublist = !is_null(
precFactory_->getParameterList());
321 if( nestedPFSublistExists || !alreadyHasSublist ) {
325 Teuchos::readVerboseObjectSublist(&*
paramList_,
this);
329 Teuchos::RCP<Teuchos::ParameterList>
336 Teuchos::RCP<Teuchos::ParameterList>
339 Teuchos::RCP<Teuchos::ParameterList> _paramList =
paramList_;
345 Teuchos::RCP<const Teuchos::ParameterList>
352 Teuchos::RCP<const Teuchos::ParameterList>
364 std::ostringstream oss;
365 oss <<
"Thyra::AztecOOLinearOpWithSolveFactory{";
366 oss <<
"precFactory=";
379 Teuchos::RCP<const Teuchos::ParameterList>
382 static Teuchos::RCP<Teuchos::ParameterList> validParamList;
383 if(validParamList.get()==NULL) {
384 validParamList = Teuchos::rcp(
385 new Teuchos::ParameterList(
"AztecOOLinearOpWithSolveFactory"));
387 OutputEveryRhs_name,OutputEveryRhs_default
388 ,
"Determines if output is created for each individual RHS (true or 1) or if output\n" 389 "is just created for an entire set of RHSs (false or 0)." 391 static Teuchos::RCP<const Teuchos::ParameterList>
393 Teuchos::ParameterList
394 &fwdSolvePL = validParamList->sublist(
395 ForwardSolve_name,
false 396 ,
"Gives the options for the forward solve." 399 Tolerance_name,Tolerance_default
400 ,
"The tolerence used in the convergence check (see the convergence test\n" 401 "in the sublist \"" + AztecOO_Settings_name +
"\")" 404 MaxIterations_name,MaxIterations_default
405 ,
"The maximum number of iterations the AztecOO solver is allowed to perform." 408 AztecOO_Settings_name,
false 409 ,
"Sets the parameters on the AztecOO object itself." 410 ).setParameters(*aztecParamList);
411 Teuchos::ParameterList
412 &adjSolvePL = validParamList->sublist(
413 AdjointSolve_name,
false 414 ,
"The options for the adjoint solve.\n" 415 "If this sublist is missing then the parameters from the\n" 416 "\""+ForwardSolve_name+
"\" sublist are used instead." 419 adjSolvePL.setParameters(fwdSolvePL);
421 return validParamList;
431 Teuchos::RCP<const Teuchos::ParameterList>
432 precFactoryValidParamList =
precFactory_->getValidParameters();
433 if(precFactoryValidParamList.get()) {
435 *precFactoryValidParamList);
443 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
444 const Teuchos::RCP<
const PreconditionerBase<double> > &prec,
445 const Teuchos::RCP<
const LinearOpSourceBase<double> > &approxFwdOpSrc,
446 const bool reusePrec,
447 LinearOpWithSolveBase<double> *Op
453 using Teuchos::rcp_dynamic_cast;
454 using Teuchos::rcp_const_cast;
455 using Teuchos::set_extra_data;
456 using Teuchos::get_optional_extra_data;
457 using Teuchos::get_optional_nonconst_extra_data;
458 using Teuchos::outArg;
459 typedef EpetraExt::ProductOperator PO;
461 const Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
462 const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
463 Teuchos::OSTab tab(out);
464 if(out.get() &&
static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW))
465 *out <<
"\nEntering Thyra::AztecOOLinearOpWithSolveFactory::initializeOp_impl(...) ...\n";
467 typedef Teuchos::VerboseObjectTempState<PreconditionerFactoryBase<double> > VOTSPF;
468 VOTSPF precFactoryOutputTempState(
precFactory_,out,verbLevel);
471 TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
472 TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc.get()==NULL);
473 TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc->getOp().get()==NULL);
481 Teuchos::RCP<const LinearOpBase<double> >
482 tmpFwdOp = fwdOpSrc->getOp(),
483 tmpApproxFwdOp = ( approxFwdOpSrc.get() ? approxFwdOpSrc->getOp() : Teuchos::null );
484 Teuchos::RCP<const LinearOpBase<double> > fwdOp;
485 Teuchos::RCP<const LinearOpBase<double> > approxFwdOp;
486 if ( dynamic_cast<const EpetraLinearOpBase*>(tmpFwdOp.get())!=0 )
489 approxFwdOp = tmpApproxFwdOp;
493 fwdOp = makeEpetraWrapper(tmpFwdOp);
497 dynamic_cast<const EpetraLinearOpBase*
>(&*tmpApproxFwdOp.get())
500 approxFwdOp = makeEpetraWrapper(tmpApproxFwdOp);
513 Teuchos::RCP<const Epetra_Operator> epetra_epetraFwdOp;
514 EOpTransp epetra_epetraFwdOpTransp;
515 EApplyEpetraOpAs epetra_epetraFwdOpApplyAs;
516 EAdjointEpetraOp epetra_epetraFwdOpAdjointSupport;
517 double epetra_epetraFwdOpScalar;
518 epetraFwdOpViewExtractor_->getEpetraOpView(
520 outArg(epetra_epetraFwdOp), outArg(epetra_epetraFwdOpTransp),
521 outArg(epetra_epetraFwdOpApplyAs), outArg(epetra_epetraFwdOpAdjointSupport),
522 outArg(epetra_epetraFwdOpScalar)
524 TEUCHOS_TEST_FOR_EXCEPTION(
525 epetra_epetraFwdOp.get()==NULL, std::logic_error
526 ,
"Error, The input fwdOp object must be fully initialized " 527 "before calling this function!" 533 Teuchos::RCP<PreconditionerBase<double> > myPrec;
534 Teuchos::RCP<const PreconditionerBase<double> > precUsed;
544 ? Teuchos::rcp_const_cast<PreconditionerBase<double> >(
562 RCP<const LinearOpBase<double> > rightPrecOp;
563 if (precUsed.get()) {
564 RCP<const LinearOpBase<double> > unspecified = precUsed->getUnspecifiedPrecOp();
565 RCP<const LinearOpBase<double> > left = precUsed->getLeftPrecOp();
566 RCP<const LinearOpBase<double> > right = precUsed->getRightPrecOp();
567 TEUCHOS_TEST_FOR_EXCEPTION(
568 !( left.get() || right.get() || unspecified.get() ), std::logic_error
569 ,
"Error, at least one preconditoner linear operator objects must be set!" 571 if(unspecified.get()) {
572 rightPrecOp = unspecified;
576 TEUCHOS_TEST_FOR_EXCEPTION(
577 left.get(),std::logic_error
578 ,
"Error, we can not currently handle a left" 579 " preconditioner with the AztecOO/Thyra adapters!" 584 double wrappedPrecOpScalar = 0.0;
585 EOpTransp wrappedPrecOpTransp = NOTRANS;
586 RCP<const LinearOpBase<double> > wrappedPrecOp = null;
587 RCP<const EpetraLinearOpBase> epetraPrecOp;
588 Teuchos::RCP<const Epetra_Operator> epetra_epetraPrecOp;
589 EOpTransp epetra_epetraPrecOpTransp;
590 EApplyEpetraOpAs epetra_epetraPrecOpApplyAs;
591 EAdjointEpetraOp epetra_epetraPrecOpAdjointSupport;
592 EOpTransp overall_epetra_epetraPrecOpTransp;
593 if(rightPrecOp.get()) {
594 RCP<const LinearOpBase<double> > tmpWrappedPrecOp;
596 rightPrecOp,&wrappedPrecOpScalar,&wrappedPrecOpTransp,&tmpWrappedPrecOp);
597 if( dynamic_cast<const EpetraLinearOpBase*>(&*tmpWrappedPrecOp) ) {
598 wrappedPrecOp = tmpWrappedPrecOp;
601 wrappedPrecOp = makeEpetraWrapper(tmpWrappedPrecOp);
603 epetraPrecOp = rcp_dynamic_cast<
const EpetraLinearOpBase>(
605 epetraPrecOp->getEpetraOpView(
606 outArg(epetra_epetraPrecOp), outArg(epetra_epetraPrecOpTransp),
607 outArg(epetra_epetraPrecOpApplyAs), outArg(epetra_epetraPrecOpAdjointSupport));
608 TEUCHOS_TEST_FOR_EXCEPTION(
609 epetra_epetraPrecOp.get()==NULL,std::logic_error
610 ,
"Error, The input prec object and its embedded preconditioner" 611 " operator must be fully initialized before calling this function!" 620 overall_epetra_epetraPrecOpTransp
622 real_trans(wrappedPrecOpTransp),
623 real_trans(epetra_epetraPrecOpTransp)
631 if(approxFwdOp.get()) {
634 unwrap(approxFwdOp,&wrappedPrecOpScalar,&wrappedPrecOpTransp,&wrappedPrecOp);
635 epetraPrecOp = rcp_dynamic_cast<
const EpetraLinearOpBase>(
637 epetraPrecOp->getEpetraOpView(
638 outArg(epetra_epetraPrecOp), outArg(epetra_epetraPrecOpTransp),
639 outArg(epetra_epetraPrecOpApplyAs), outArg(epetra_epetraPrecOpAdjointSupport)
641 TEUCHOS_TEST_FOR_EXCEPTION(
642 epetra_epetraPrecOp.get()==NULL,std::logic_error
643 ,
"Error, The input approxFwdOp object must be fully initialized" 644 " before calling this function!" 654 overall_epetra_epetraPrecOpTransp
656 real_trans(wrappedPrecOpTransp),
657 real_trans(epetra_epetraPrecOpTransp)
665 RCP<const Epetra_RowMatrix>
666 rowmatrix_epetraFwdOp = rcp_dynamic_cast<
const Epetra_RowMatrix>(
668 rowmatrix_epetraPrecOp = rcp_dynamic_cast<const Epetra_RowMatrix>(
669 epetra_epetraPrecOp);
675 enum ELocalPrecType {
676 PT_NONE, PT_AZTEC_FROM_OP, PT_AZTEC_FROM_APPROX_FWD_MATRIX,
677 PT_FROM_PREC_OP, PT_UPPER_BOUND
679 ELocalPrecType localPrecType = PT_UPPER_BOUND;
680 if( precUsed.get()==NULL && approxFwdOp.get()==NULL && !
useAztecPrec_ ) {
682 localPrecType = PT_NONE;
684 else if( precUsed.get()==NULL && approxFwdOp.get()==NULL &&
useAztecPrec_ ) {
687 localPrecType = PT_AZTEC_FROM_OP;
692 localPrecType = PT_AZTEC_FROM_APPROX_FWD_MATRIX;
694 else if( precUsed.get() ) {
697 localPrecType = PT_FROM_PREC_OP;
699 TEUCHOS_TEST_FOR_EXCEPTION
700 (localPrecType == PT_UPPER_BOUND, std::logic_error,
701 "AztecOOLinearOpWithSolveFactory::initializeOp_impl(...): " 702 "localPrecType == PT_UPPER_BOUND. This means that previously, " 703 "this value might have been used uninitialized. " 704 "Please report this bug to the Stratimikos developers.");
710 RCP<AztecOO> aztecFwdSolver, aztecAdjSolver;
716 Teuchos::RCP<const LinearOpBase<double> > old_fwdOp;
717 Teuchos::RCP<const LinearOpSourceBase<double> > old_fwdOpSrc;
718 Teuchos::RCP<const PreconditionerBase<double> > old_prec;
719 bool old_isExternalPrec;
720 Teuchos::RCP<const LinearOpSourceBase<double> > old_approxFwdOpSrc;
721 Teuchos::RCP<AztecOO> old_aztecFwdSolver;
722 Teuchos::RCP<AztecOO> old_aztecAdjSolver;
723 double old_aztecSolverScalar;
734 ,&old_aztecSolverScalar
736 if( old_aztecFwdSolver.get()==NULL ) {
744 aztecFwdSolver = old_aztecFwdSolver;
745 aztecAdjSolver = old_aztecAdjSolver;
746 startingOver =
false;
749 Ptr<bool> constructedAztecPreconditioner;
753 !is_null(constructedAztecPreconditioner = get_optional_nonconst_extra_data<bool>(
754 aztecFwdSolver,
"AOOLOWSF::constructedAztecPreconditoner") )
756 *constructedAztecPreconditioner
759 aztecFwdSolver->DestroyPreconditioner();
760 *constructedAztecPreconditioner =
false;
764 Ptr<bool> setPreconditionerOperator;
766 localPrecType != PT_FROM_PREC_OP
767 && !is_null( setPreconditionerOperator = get_optional_nonconst_extra_data<bool>(
768 aztecFwdSolver,
"AOOLOWSF::setPreconditonerOperator") )
769 && *setPreconditionerOperator
785 aztecFwdSolver = rcp(
new AztecOO());
786 aztecFwdSolver->SetAztecOption(AZ_diagnostics,AZ_none);
787 aztecFwdSolver->SetAztecOption(AZ_keep_info,1);
790 epetra_epetraFwdOpAdjointSupport==EPETRA_OP_ADJOINT_SUPPORTED
792 localPrecType!=PT_AZTEC_FROM_OP && localPrecType!=PT_AZTEC_FROM_APPROX_FWD_MATRIX
795 aztecAdjSolver = rcp(
new AztecOO());
796 aztecAdjSolver->SetAztecOption(AZ_diagnostics,AZ_none);
807 &
paramList_->sublist(ForwardSolve_name).sublist(AztecOO_Settings_name),
812 &
paramList_->sublist(AdjointSolve_name).sublist(AztecOO_Settings_name),
820 RCP<const Epetra_Operator>
821 aztec_epetra_epetraFwdOp,
822 aztec_epetra_epetraAdjOp;
824 RCP<const Epetra_Operator>
826 = { epetra_epetraFwdOp };
829 = { epetra_epetraFwdOpTransp==NOTRANS ? Teuchos::NO_TRANS : Teuchos::TRANS };
832 = { epetra_epetraFwdOpApplyAs==EPETRA_OP_APPLY_APPLY
833 ? PO::APPLY_MODE_APPLY
834 : PO::APPLY_MODE_APPLY_INVERSE };
836 epetraOpsTransp[0] == Teuchos::NO_TRANS
838 epetraOpsApplyMode[0] == PO::APPLY_MODE_APPLY
841 aztec_epetra_epetraFwdOp = epetra_epetraFwdOp;
845 aztec_epetra_epetraFwdOp = rcp(
846 new PO(1,epetraOps,epetraOpsTransp,epetraOpsApplyMode));
851 aztec_epetra_epetraFwdOp.get() != aztecFwdSolver->GetUserOperator()
856 aztecFwdSolver->SetUserOperator(
857 const_cast<Epetra_Operator*>(&*aztec_epetra_epetraFwdOp));
859 aztec_epetra_epetraFwdOp, AOOLOWSF_aztec_epetra_epetraFwdOp_str,
860 Teuchos::inOutArg(aztecFwdSolver), Teuchos::POST_DESTROY,
false 864 if( aztecAdjSolver.get() ) {
865 epetraOpsTransp[0] = (
866 epetra_epetraFwdOpTransp==NOTRANS
871 epetraOpsTransp[0] == Teuchos::NO_TRANS
873 epetraOpsApplyMode[0] == PO::APPLY_MODE_APPLY
876 aztec_epetra_epetraAdjOp = epetra_epetraFwdOp;
879 aztec_epetra_epetraAdjOp = rcp(
880 new PO(1,epetraOps,epetraOpsTransp,epetraOpsApplyMode));
882 aztecAdjSolver->SetUserOperator(
883 const_cast<Epetra_Operator*>(&*aztec_epetra_epetraAdjOp));
885 aztec_epetra_epetraAdjOp, AOOLOWSF_aztec_epetra_epetraAdjOp_str,
886 Teuchos::inOutArg(aztecAdjSolver), Teuchos::POST_DESTROY,
false 893 RCP<const Epetra_Operator>
894 aztec_fwd_epetra_epetraPrecOp,
895 aztec_adj_epetra_epetraPrecOp;
896 bool setAztecPreconditioner =
false;
897 switch(localPrecType) {
904 case PT_AZTEC_FROM_OP: {
909 if( startingOver || !reusePrec ) {
910 TEUCHOS_TEST_FOR_EXCEPTION(
911 rowmatrix_epetraFwdOp.get()==NULL, std::logic_error,
912 "AztecOOLinearOpWithSolveFactory::initializeOp_impl(...): " 913 "Error, There is no preconditioner given by client, but the client " 914 "passed in an Epetra_Operator for the forward operator of type \'" 915 <<typeName(*epetra_epetraFwdOp)<<
"\' that does not " 916 "support the Epetra_RowMatrix interface!" 918 TEUCHOS_TEST_FOR_EXCEPTION(
919 epetra_epetraFwdOpTransp!=NOTRANS, std::logic_error,
920 "AztecOOLinearOpWithSolveFactory::initializeOp_impl(...):" 921 " Error, There is no preconditioner given by client and the client " 922 "passed in an Epetra_RowMatrix for the forward operator but the " 923 "overall transpose is not NOTRANS and therefore we can can just " 924 "hand this over to aztec without making a copy which is not supported here!" 926 aztecFwdSolver->SetPrecMatrix(
927 const_cast<Epetra_RowMatrix*>(&*rowmatrix_epetraFwdOp));
929 rowmatrix_epetraFwdOp, AOOLOWSF_rowmatrix_epetraFwdOp_str,
930 Teuchos::inOutArg(aztecFwdSolver), Teuchos::POST_DESTROY,
false 933 setAztecPreconditioner =
true;
936 case PT_AZTEC_FROM_APPROX_FWD_MATRIX: {
941 if( startingOver || !reusePrec ) {
942 TEUCHOS_TEST_FOR_EXCEPTION(
943 rowmatrix_epetraPrecOp.get()==NULL, std::logic_error
944 ,
"AztecOOLinearOpWithSolveFactor::initializeOp_impl(...): The client " 945 "passed in an Epetra_Operator for the preconditioner matrix of type \'" 946 <<typeName(*epetra_epetraPrecOp)<<
"\' that does not " 947 "support the Epetra_RowMatrix interface!" 949 TEUCHOS_TEST_FOR_EXCEPTION(
950 overall_epetra_epetraPrecOpTransp!=NOTRANS, std::logic_error
951 ,
"AztecOOLinearOpWithSolveFactor::initializeOp_impl(...): Error, The client " 952 "passed in an Epetra_RowMatrix for the preconditoner matrix but the overall " 953 "transpose is not NOTRANS and therefore we can can just " 954 "hand this over to aztec without making a copy which is not supported here!" 956 aztecFwdSolver->SetPrecMatrix(
957 const_cast<Epetra_RowMatrix*>(&*rowmatrix_epetraPrecOp));
959 rowmatrix_epetraPrecOp, AOOLOWSF_rowmatrix_epetraPrecOp_str,
960 Teuchos::inOutArg(aztecFwdSolver), Teuchos::POST_DESTROY,
false 963 setAztecPreconditioner =
true;
966 case PT_FROM_PREC_OP: {
971 RCP<const Epetra_Operator>
973 = { epetra_epetraPrecOp };
976 = { overall_epetra_epetraPrecOpTransp==NOTRANS
982 theEpetraOpsApplyMode[]
983 = { epetra_epetraPrecOpApplyAs==EPETRA_OP_APPLY_APPLY
984 ? PO::APPLY_MODE_APPLY_INVERSE
985 : PO::APPLY_MODE_APPLY };
987 theEpetraOpsTransp[0] == Teuchos::NO_TRANS
989 epetra_epetraPrecOpApplyAs==EPETRA_OP_APPLY_APPLY_INVERSE
992 aztec_fwd_epetra_epetraPrecOp = epetra_epetraPrecOp;
995 aztec_fwd_epetra_epetraPrecOp = rcp(
new PO(1,theEpetraOps,theEpetraOpsTransp,theEpetraOpsApplyMode));
997 aztecFwdSolver->SetPrecOperator(
998 const_cast<Epetra_Operator*>(&*aztec_fwd_epetra_epetraPrecOp));
1000 aztec_fwd_epetra_epetraPrecOp, AOOLOWSF_aztec_fwd_epetra_epetraPrecOp_str,
1001 Teuchos::inOutArg(aztecFwdSolver), Teuchos::POST_DESTROY,
false 1005 aztecAdjSolver.get()
1007 epetra_epetraPrecOpAdjointSupport == EPETRA_OP_ADJOINT_SUPPORTED
1010 theEpetraOpsTransp[0] = (
1011 overall_epetra_epetraPrecOpTransp==NOTRANS
1016 theEpetraOpsTransp[0] == Teuchos::NO_TRANS
1018 epetra_epetraPrecOpApplyAs==EPETRA_OP_APPLY_APPLY_INVERSE
1021 aztec_adj_epetra_epetraPrecOp = epetra_epetraPrecOp;
1024 aztec_adj_epetra_epetraPrecOp = rcp(
1025 new PO(1,theEpetraOps,theEpetraOpsTransp,theEpetraOpsApplyMode));
1027 aztecAdjSolver->SetPrecOperator(
1028 const_cast<Epetra_Operator*>(&*aztec_adj_epetra_epetraPrecOp));
1030 aztec_adj_epetra_epetraPrecOp, AOOLOWSF_aztec_adj_epetra_epetraPrecOp_str,
1031 Teuchos::inOutArg(aztecAdjSolver), Teuchos::POST_DESTROY,
false 1033 set_extra_data<bool>(
1034 true, AOOLOWSF_setPrecondtionerOperator_str,
1035 Teuchos::inOutArg(aztecFwdSolver), Teuchos::POST_DESTROY, false
1041 TEUCHOS_TEST_FOR_EXCEPT(
true);
1047 if(setAztecPreconditioner) {
1048 if( startingOver || !reusePrec ) {
1049 double condNumEst = -1.0;
1050 TEUCHOS_TEST_FOR_EXCEPT(0!=aztecFwdSolver->ConstructPreconditioner(condNumEst));
1052 set_extra_data<bool>(
1053 true, AOOLOWSF_constructedAztecPreconditoner_str,
1054 Teuchos::inOutArg(aztecFwdSolver), Teuchos::POST_DESTROY, false
1065 if(aztecAdjSolver.get() && aztecAdjSolver->GetPrecOperator()) {
1067 fwdOp, fwdOpSrc,precUsed, prec.get()!=NULL, approxFwdOpSrc,
1068 aztecFwdSolver,
true, aztecAdjSolver,
true, epetra_epetraFwdOpScalar
1073 fwdOp, fwdOpSrc, precUsed, prec.get()!=NULL, approxFwdOpSrc,
1074 aztecFwdSolver,
true, null,
false, epetra_epetraFwdOpScalar
1082 aztecOp->setOStream(this->getOStream());
1083 if(!is_null(this->getOverridingOStream()))
1084 aztecOp->setOverridingOStream(this->getOverridingOStream());
1085 aztecOp->setVerbLevel(this->getVerbLevel());
1087 #ifdef TEUCHOS_DEBUG 1089 paramList_->validateParameters(*this->getValidParameters());
1092 if(out.get() &&
static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW))
1093 *out <<
"\nLeaving Thyra::AztecOOLinearOpWithSolveFactory::initializeOp_impl(...) ...\n";
void setAztecOOParameters(Teuchos::ParameterList *pl, AztecOO *solver)
Setup an AztecOO solver object with a set of parameters.
Teuchos::RCP< PreconditionerFactoryBase< double > > getPreconditionerFactory() const
Teuchos::RCP< Teuchos::ParameterList > paramList_
bool acceptsPreconditionerFactory() const
Returns true .
Teuchos::RCP< Teuchos::ParameterList > thisValidParamList_
double defaultFwdTolerance_
bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
Teuchos::RCP< PreconditionerFactoryBase< double > > precFactory_
RCP< const LinearOpSourceBase< double > > extract_fwdOpSrc()
Extract the forward LinearOpBase<double> object so that it can be modified.
AztecOOLinearOpWithSolveFactory(Teuchos::RCP< Teuchos::ParameterList > const ¶mList=Teuchos::null)
Construct uninitialized.
void initializeAndReuseOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, LinearOpWithSolveBase< double > *Op) const
std::string description() const
bool isExternalPrec() const
Determine if the preconditioner was external or not.
void updateThisValidParamList()
void initializeApproxPreconditionedOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, const Teuchos::RCP< const LinearOpSourceBase< double > > &approxFwdOpSrc, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
int defaultFwdMaxIterations_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
double defaultAdjTolerance_
void uninitializeOp(LinearOpWithSolveBase< double > *Op, Teuchos::RCP< const LinearOpSourceBase< double > > *fwdOpSrc, Teuchos::RCP< const PreconditionerBase< double > > *prec, Teuchos::RCP< const LinearOpSourceBase< double > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
void unsetPreconditionerFactory(Teuchos::RCP< PreconditionerFactoryBase< double > > *precFactory, std::string *precFactoryName)
Teuchos::RCP< LinearOpWithSolveBase< double > > createOp() const
void initializeOp_impl(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, const Teuchos::RCP< const PreconditionerBase< double > > &prec, const Teuchos::RCP< const LinearOpSourceBase< double > > &approxFwdOpSrc, const bool reusePrec, LinearOpWithSolveBase< double > *Op) const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
std::string precFactoryName_
void uninitialize(RCP< const LinearOpBase< double > > *fwdOp=NULL, RCP< const LinearOpSourceBase< double > > *fwdOpSrc=NULL, RCP< const PreconditionerBase< double > > *prec=NULL, bool *isExternalPrec=NULL, RCP< const LinearOpSourceBase< double > > *approxFwdOpSrc=NULL, RCP< AztecOO > *aztecFwdSolver=NULL, bool *allowInexactFwdSolve=NULL, RCP< AztecOO > *aztecAdjSolver=NULL, bool *allowInexactAdjSolve=NULL, double *aztecSolverScalar=NULL)
Uninitialize.
RCP< const PreconditionerBase< double > > extract_prec()
Extract the preconditioner.
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
int defaultAdjMaxIterations_
bool isCompatible(const LinearOpSourceBase< double > &fwdOpSrc) const
void initializePreconditionedOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, const Teuchos::RCP< const PreconditionerBase< double > > &prec, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
void initializeOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
void initialize(const RCP< const LinearOpBase< double > > &fwdOp, const RCP< const LinearOpSourceBase< double > > &fwdOpSrc, const RCP< const PreconditionerBase< double > > &prec, const bool isExternalPrec, const RCP< const LinearOpSourceBase< double > > &approxFwdOpSrc, const RCP< AztecOO > &aztecFwdSolver, const bool allowInexactFwdSolve=false, const RCP< AztecOO > &aztecAdjSolver=Teuchos::null, const bool allowInexactAdjSolve=false, const double aztecSolverScalar=1.0)
Sets up this object.
Teuchos::RCP< const Teuchos::ParameterList > getValidAztecOOParameters()
Return the list of all valid AztecOO parameters (to validate against).
void setPreconditionerFactory(const Teuchos::RCP< PreconditionerFactoryBase< double > > &precFactory, const std::string &precFactoryName)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Concrete LinearOpWithSolveBase subclass implemented using AztecOO.
static Teuchos::RCP< const Teuchos::ParameterList > generateAndGetValidParameters()
RCP< const LinearOpSourceBase< double > > extract_approxFwdOpSrc()
Extract the approximate forward LinearOpBase<double> object used to build the preconditioner.