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 Teuchos::RCP<LinearOpWithSolveBase<Scalar> >
00062 linearOpWithSolve(
00063 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00064 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00065 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00066 )
00067 {
00068 Teuchos::RCP<LinearOpWithSolveBase<Scalar> >
00069 Op = lowsFactory.createOp();
00070 lowsFactory.initializeOp(defaultLinearOpSource(fwdOp),&*Op,supportSolveUse);
00071 return Op;
00072 }
00073
00074
00079 template<class Scalar>
00080 Teuchos::RCP<LinearOpBase<Scalar> >
00081 inverse(
00082 const LinearOpWithSolveFactoryBase<Scalar> &LOWSF,
00083 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00084 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED,
00085 const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00086 const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00087 const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00088 const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00089 )
00090 {
00091 return inverse<Scalar>(
00092 linearOpWithSolve<Scalar>(LOWSF,fwdOp,supportSolveUse),
00093 fwdSolveCriteria, throwOnFwdSolveFailure,
00094 adjSolveCriteria, throwOnAdjSolveFailure
00095 );
00096 }
00097
00098
00103 template<class Scalar>
00104 void initializeOp(
00105 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00106 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00107 LinearOpWithSolveBase<Scalar> *Op,
00108 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00109 )
00110 {
00111 lowsFactory.initializeOp(defaultLinearOpSource(fwdOp),Op,supportSolveUse);
00112 }
00113
00114
00120 template<class Scalar>
00121 void initializeAndReuseOp(
00122 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00123 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00124 LinearOpWithSolveBase<Scalar> *Op
00125 )
00126 {
00127 lowsFactory.initializeAndReuseOp(defaultLinearOpSource(fwdOp),Op);
00128 }
00129
00130
00136 template<class Scalar>
00137 void initializePreconditionedOp(
00138 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00139 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00140 const Teuchos::RCP<const PreconditionerBase<Scalar> > &prec,
00141 LinearOpWithSolveBase<Scalar> *Op,
00142 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00143 )
00144 {
00145 lowsFactory.initializePreconditionedOp(
00146 defaultLinearOpSource(fwdOp),prec,Op,supportSolveUse
00147 );
00148 }
00149
00150
00156 template<class Scalar>
00157 void initializeApproxPreconditionedOp(
00158 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00159 const Teuchos::RCP<const LinearOpBase<Scalar> > &fwdOp,
00160 const Teuchos::RCP<const LinearOpBase<Scalar> > &approxFwdOp,
00161 LinearOpWithSolveBase<Scalar> *Op,
00162 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00163 )
00164 {
00165 lowsFactory.initializeApproxPreconditionedOp(
00166 defaultLinearOpSource(fwdOp),defaultLinearOpSource(approxFwdOp),Op,supportSolveUse
00167 );
00168 }
00169
00170
00176 template<class Scalar>
00177 void uninitializeOp(
00178 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00179 LinearOpWithSolveBase<Scalar> *Op,
00180 Teuchos::RCP<const LinearOpBase<Scalar> > *fwdOp = NULL,
00181 Teuchos::RCP<const PreconditionerBase<Scalar> > *prec = NULL,
00182 Teuchos::RCP<const LinearOpBase<Scalar> > *approxFwdOp = NULL,
00183 ESupportSolveUse *supportSolveUse = NULL
00184 )
00185 {
00186 Teuchos::RCP<const LinearOpSourceBase<Scalar> > fwdOpSrc;
00187 Teuchos::RCP<const LinearOpSourceBase<Scalar> > approxFwdOpSrc;
00188 lowsFactory.uninitializeOp(Op,&fwdOpSrc,prec,&approxFwdOpSrc,supportSolveUse);
00189 if(fwdOp)
00190 *fwdOp = ( fwdOpSrc.get() ? fwdOpSrc->getOp() : Teuchos::null );
00191 if(approxFwdOp)
00192 *approxFwdOp = ( approxFwdOpSrc.get() ? approxFwdOpSrc->getOp() : Teuchos::null );
00193 }
00194
00195
00196 }
00197
00198
00199 #endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP