00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef MEROS_LINEAR_SOLVE_STRATEGY_H
00030 #define MEROS_LINEAR_SOLVE_STRATEGY_H
00031
00032 #include "Thyra_LinearOpBase.hpp"
00033 #include "Thyra_VectorImpl.hpp"
00034 #include "Thyra_VectorSpaceImpl.hpp"
00035 #include "Thyra_LinearOperatorImpl.hpp"
00036 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00037 #include "Thyra_LinearOpWithSolveBase.hpp"
00038 #include "Thyra_DefaultLinearOpSource.hpp"
00039 #include "Meros_Preconditioner.hpp"
00040
00041 namespace Meros
00042 {
00043 using namespace Teuchos;
00044 using namespace Thyra;
00045
00049 template <class Scalar>
00050 class LinearSolveStrategy
00051 {
00052 public:
00054 LinearSolveStrategy() : lowsf_(), pf_() {;}
00055
00057 LinearSolveStrategy(const RCP<LinearOpWithSolveFactoryBase<Scalar> >& lowsf)
00058 : lowsf_(lowsf), pf_(lowsf->getPreconditionerFactory()) {;}
00059
00061 LinearSolveStrategy(Handleable<LinearOpWithSolveFactoryBase<Scalar> >* lowsf)
00062 : lowsf_(lowsf->getRcp()), pf_(lowsf_->getPreconditionerFactory()) {;}
00063
00065 RCP<LinearOpWithSolveFactoryBase<Scalar> > getLOWSF() const
00066 {
00067 return lowsf_;
00068 }
00069
00071 RCP<LinearOpWithSolveBase<Scalar> > getLOWS(const LinearOperator<Scalar>& op) const
00072 {
00073 RCP<LinearOpWithSolveBase<Scalar> > rtn = lowsf_->createOp();
00074 RCP<const LinearOpSourceBase<Scalar> > src
00075 = rcp(new DefaultLinearOpSource<Scalar>(op.ptr()));
00076
00077 if (pf_.get() == 0)
00078 {
00079 LinearOpWithSolveBase<Scalar>* rtnPtr = rtn.get();
00080 lowsf_->initializeOp(src, rtnPtr);
00081 }
00082 else
00083 {
00084 Preconditioner<Scalar> p = pf_->createPrec();
00085 pf_->initializePrec(src, p.ptr().get());
00086 lowsf_->initializePreconditionedOp(src, p.ptr(), &*rtn);
00087 }
00088
00089 return rtn;
00090 }
00091
00093 RCP<LinearOpWithSolveBase<Scalar> > getLOWS(const ConstLinearOperator<Scalar>& op) const
00094 {
00095 RCP<LinearOpWithSolveBase<Scalar> > rtn = lowsf_->createOp();
00096 RCP<const LinearOpSourceBase<Scalar> > src
00097 = rcp(new DefaultLinearOpSource<Scalar>(op.constPtr()));
00098
00099 if (pf_.get() == 0)
00100 {
00101 LinearOpWithSolveBase<Scalar>* rtnPtr = rtn.get();
00102 lowsf_->initializeOp(src, rtnPtr);
00103 }
00104 else
00105 {
00106 Preconditioner<Scalar> p = pf_->createPrec();
00107 pf_->initializePrec(src, p.ptr().get());
00108 lowsf_->initializePreconditionedOp(src, p.ptr(), &*rtn);
00109 }
00110
00111 return rtn;
00112 }
00113
00114 protected:
00115 RCP<LinearOpWithSolveFactoryBase<Scalar> > lowsf() {return lowsf_;}
00116 RCP<PreconditionerFactoryBase<Scalar> > pf() {return pf_;}
00117
00118 private:
00119
00120 RCP<LinearOpWithSolveFactoryBase<Scalar> > lowsf_;
00121 RCP<PreconditionerFactoryBase<Scalar> > pf_;
00122 };
00123
00124
00125 }
00126
00127 #endif // MEROS_PCD_OPERATOR_SOURCE_H