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 THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
00030 #define THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
00031
00032 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00033 #include "Thyra_DefaultLinearOpSource.hpp"
00034 #include "Thyra_DefaultPreconditioner.hpp"
00035 #include "Thyra_DefaultInverseLinearOp.hpp"
00036
00037
00038 namespace Thyra {
00039
00040
00046 template<class Scalar>
00047 bool isCompatible(
00048 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00049 const LinearOpBase<Scalar> &fwdOp
00050 )
00051 {
00052 return lowsFactory.isCompatible(*defaultLinearOpSource(fwdOp));
00053 }
00054
00055
00060 template<class Scalar>
00061 void setDefaultObjectLabel(
00062 const LinearOpBase<Scalar> &fwdOp,
00063 LinearOpWithSolveBase<Scalar> *Op
00064 )
00065 {
00066 TEST_FOR_EXCEPT(0==Op);
00067 const std::string OpLabel = Op->getObjectLabel();
00068 const std::string fwdOpLabel = fwdOp.getObjectLabel();
00069 if ( !OpLabel.length() && fwdOpLabel.length() )
00070 Op->setObjectLabel(fwdOpLabel);
00071 }
00072
00073
00078 template<class Scalar>
00079 void initializeOp(
00080 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00081 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00082 LinearOpWithSolveBase<Scalar> *Op,
00083 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00084 )
00085 {
00086 lowsFactory.initializeOp(defaultLinearOpSource(fwdOp),Op,supportSolveUse);
00087 setDefaultObjectLabel(*fwdOp,Op);
00088 }
00089
00090
00096 template<class Scalar>
00097 void initializeAndReuseOp(
00098 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00099 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00100 LinearOpWithSolveBase<Scalar> *Op
00101 )
00102 {
00103 lowsFactory.initializeAndReuseOp(defaultLinearOpSource(fwdOp),Op);
00104 setDefaultObjectLabel(*fwdOp,Op);
00105 }
00106
00107
00113 template<class Scalar>
00114 void initializePreconditionedOp(
00115 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00116 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00117 const Teuchos::RCP<const PreconditionerBase<Scalar> > &prec,
00118 LinearOpWithSolveBase<Scalar> *Op,
00119 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00120 )
00121 {
00122 lowsFactory.initializePreconditionedOp(
00123 defaultLinearOpSource(fwdOp),prec,Op,supportSolveUse
00124 );
00125 setDefaultObjectLabel(*fwdOp,Op);
00126 }
00127
00128
00134 template<class Scalar>
00135 void initializeApproxPreconditionedOp(
00136 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00137 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00138 const Teuchos::RCP<const LinearOpBase<Scalar> > &approxFwdOp,
00139 LinearOpWithSolveBase<Scalar> *Op,
00140 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00141 )
00142 {
00143 lowsFactory.initializeApproxPreconditionedOp(
00144 defaultLinearOpSource(fwdOp),defaultLinearOpSource(approxFwdOp),Op,supportSolveUse
00145 );
00146 setDefaultObjectLabel(*fwdOp,Op);
00147 }
00148
00149
00154 template<class Scalar>
00155 Teuchos::RCP<LinearOpWithSolveBase<Scalar> >
00156 linearOpWithSolve(
00157 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00158 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00159 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00160 )
00161 {
00162 Teuchos::RCP<LinearOpWithSolveBase<Scalar> >
00163 Op = lowsFactory.createOp();
00164 Thyra::initializeOp<Scalar>( lowsFactory, fwdOp, &*Op, supportSolveUse
00165 );
00166 return Op;
00167 }
00168
00169
00174 template<class Scalar>
00175 Teuchos::RCP<LinearOpBase<Scalar> >
00176 inverse(
00177 const LinearOpWithSolveFactoryBase<Scalar> &LOWSF,
00178 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00179 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED,
00180 const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00181 const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00182 const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00183 const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00184 )
00185 {
00186 return inverse<Scalar>(
00187 linearOpWithSolve<Scalar>(LOWSF,fwdOp,supportSolveUse),
00188 fwdSolveCriteria, throwOnFwdSolveFailure,
00189 adjSolveCriteria, throwOnAdjSolveFailure
00190 );
00191 }
00192
00193
00199 template<class Scalar>
00200 void uninitializeOp(
00201 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00202 LinearOpWithSolveBase<Scalar> *Op,
00203 Teuchos::RCP<const LinearOpBase<Scalar> > *fwdOp = NULL,
00204 Teuchos::RCP<const PreconditionerBase<Scalar> > *prec = NULL,
00205 Teuchos::RCP<const LinearOpBase<Scalar> > *approxFwdOp = NULL,
00206 ESupportSolveUse *supportSolveUse = NULL
00207 )
00208 {
00209 Teuchos::RCP<const LinearOpSourceBase<Scalar> > fwdOpSrc;
00210 Teuchos::RCP<const LinearOpSourceBase<Scalar> > approxFwdOpSrc;
00211 lowsFactory.uninitializeOp(Op,&fwdOpSrc,prec,&approxFwdOpSrc,supportSolveUse);
00212 if(fwdOp)
00213 *fwdOp = ( fwdOpSrc.get() ? fwdOpSrc->getOp() : Teuchos::null );
00214 if(approxFwdOp)
00215 *approxFwdOp = ( approxFwdOpSrc.get() ? approxFwdOpSrc->getOp() : Teuchos::null );
00216 }
00217
00218
00219 }
00220
00221
00222 #endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP