Thyra Version of the Day
Thyra_LinearOpWithSolveFactoryHelpers.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
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   const Ptr<LinearOpWithSolveBase<Scalar> > &Op
00064   )
00065 {
00066   const std::string OpLabel = Op->getObjectLabel();
00067   const std::string fwdOpLabel = fwdOp.getObjectLabel();
00068   if ( !OpLabel.length() && fwdOpLabel.length() )
00069     Op->setObjectLabel(fwdOpLabel);
00070 }
00071 
00072 
00077 template<class Scalar>
00078 void initializeOp(
00079   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00080   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00081   const Ptr<LinearOpWithSolveBase<Scalar> > &Op,
00082   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00083   )
00084 {
00085   lowsFactory.initializeOp(defaultLinearOpSource(fwdOp), &*Op, supportSolveUse);
00086   setDefaultObjectLabel(*fwdOp, Op);
00087 }
00088 
00089 
00095 template<class Scalar>
00096 void initializeAndReuseOp(
00097   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00098   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00099   const Ptr<LinearOpWithSolveBase<Scalar> > &Op
00100   )
00101 {
00102   lowsFactory.initializeAndReuseOp(defaultLinearOpSource(fwdOp), &*Op);
00103   setDefaultObjectLabel(*fwdOp, Op);
00104 }
00105 
00106 
00112 template<class Scalar>
00113 void initializePreconditionedOp(
00114   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00115   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00116   const RCP<const PreconditionerBase<Scalar> > &prec,
00117   const Ptr<LinearOpWithSolveBase<Scalar> > &Op,
00118   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00119   )
00120 {
00121   lowsFactory.initializePreconditionedOp(defaultLinearOpSource(fwdOp),
00122     prec, &*Op, supportSolveUse);
00123   setDefaultObjectLabel(*fwdOp ,Op);
00124 }
00125 
00126 
00132 template<class Scalar>
00133 void initializeApproxPreconditionedOp(
00134   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00135   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00136   const RCP<const LinearOpBase<Scalar> > &approxFwdOp,
00137   const Ptr<LinearOpWithSolveBase<Scalar> > &Op,
00138   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00139   )
00140 {
00141   lowsFactory.initializeApproxPreconditionedOp(defaultLinearOpSource(fwdOp),
00142     defaultLinearOpSource(approxFwdOp), &*Op, supportSolveUse);
00143   setDefaultObjectLabel(*fwdOp,Op);
00144 }
00145 
00146 
00151 template<class Scalar>
00152 RCP<LinearOpWithSolveBase<Scalar> >
00153 linearOpWithSolve(
00154   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00155   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00156   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00157   )
00158 {
00159   RCP<LinearOpWithSolveBase<Scalar> > Op = lowsFactory.createOp();
00160   Thyra::initializeOp<Scalar>( lowsFactory, fwdOp, Op.ptr(), supportSolveUse);
00161   return Op;
00162 }
00163 
00164 
00170 template<class Scalar>
00171 RCP<LinearOpBase<Scalar> >
00172 inverse(
00173   const LinearOpWithSolveFactoryBase<Scalar> &LOWSF,
00174   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00175   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED,
00176   const Ptr<const SolveCriteria<Scalar> > &fwdSolveCriteria = Teuchos::null,
00177   const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00178   const Ptr<const SolveCriteria<Scalar> > &adjSolveCriteria = Teuchos::null,
00179   const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00180   )
00181 {
00182   return inverse<Scalar>(linearOpWithSolve<Scalar>(LOWSF, fwdOp, supportSolveUse),
00183     fwdSolveCriteria, throwOnFwdSolveFailure, adjSolveCriteria, throwOnAdjSolveFailure);
00184 }
00185 
00186   
00192 template<class Scalar>
00193 void uninitializeOp(
00194   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00195   const Ptr<LinearOpWithSolveBase<Scalar> > &Op,
00196   const Ptr<RCP<const LinearOpBase<Scalar> > > &fwdOp = Teuchos::null,
00197   const Ptr<RCP<const PreconditionerBase<Scalar> > > &prec = Teuchos::null,
00198   const Ptr<RCP<const LinearOpBase<Scalar> > > &approxFwdOp = Teuchos::null,
00199   const Ptr<ESupportSolveUse> &supportSolveUse = Teuchos::null
00200   )
00201 {
00202   RCP<const LinearOpSourceBase<Scalar> > fwdOpSrc;
00203   RCP<const LinearOpSourceBase<Scalar> > approxFwdOpSrc;
00204   lowsFactory.uninitializeOp(Op.get(), &fwdOpSrc, prec.get(), &approxFwdOpSrc,
00205     supportSolveUse.get());
00206   if (nonnull(fwdOp)) {
00207     *fwdOp = ( nonnull(fwdOpSrc) ? fwdOpSrc->getOp() : Teuchos::null );
00208   }
00209   if (nonnull(approxFwdOp)) {
00210     *approxFwdOp = ( nonnull(approxFwdOpSrc) ? approxFwdOpSrc->getOp() : Teuchos::null );
00211   }
00212 }
00213 
00214 
00215 //
00216 // Deprecated
00217 //
00218 
00219 
00224 template<class Scalar>
00225 THYRA_DEPRECATED
00226 void setDefaultObjectLabel(
00227   const LinearOpBase<Scalar> &fwdOp,
00228   LinearOpWithSolveBase<Scalar> *Op
00229   )
00230 {
00231   setDefaultObjectLabel<Scalar>(fwdOp, Teuchos::ptr(Op));
00232 }
00233 
00234 
00239 template<class Scalar>
00240 THYRA_DEPRECATED
00241 void initializeOp(
00242   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00243   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00244   LinearOpWithSolveBase<Scalar> *Op,
00245   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00246   )
00247 {
00248   initializeOp<Scalar>(lowsFactory, fwdOp, Teuchos::ptr(Op), supportSolveUse);
00249 }
00250 
00251 
00256 template<class Scalar>
00257 THYRA_DEPRECATED
00258 void initializeAndReuseOp(
00259   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00260   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00261   LinearOpWithSolveBase<Scalar> *Op
00262   )
00263 {
00264   initializeAndReuseOp<Scalar>(lowsFactory, fwdOp, Teuchos::ptr(Op));
00265 }
00266 
00267 
00272 template<class Scalar>
00273 THYRA_DEPRECATED
00274 void initializePreconditionedOp(
00275   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00276   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00277   const RCP<const PreconditionerBase<Scalar> > &prec,
00278   LinearOpWithSolveBase<Scalar> *Op,
00279   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00280   )
00281 {
00282   initializePreconditionedOp<Scalar>(lowsFactory, fwdOp, prec, Teuchos::ptr(Op),
00283     supportSolveUse);
00284 }
00285 
00286 
00291 template<class Scalar>
00292 THYRA_DEPRECATED
00293 void initializeApproxPreconditionedOp(
00294   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00295   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00296   const RCP<const LinearOpBase<Scalar> > &approxFwdOp,
00297   LinearOpWithSolveBase<Scalar> *Op,
00298   const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
00299   )
00300 {
00301   initializeApproxPreconditionedOp<Scalar>(lowsFactory, fwdOp, approxFwdOp,
00302     Teuchos::ptr(Op), supportSolveUse);
00303 }
00304 
00305 
00310 template<class Scalar>
00311 THYRA_DEPRECATED
00312 RCP<LinearOpBase<Scalar> >
00313 inverse(
00314   const LinearOpWithSolveFactoryBase<Scalar> &LOWSF,
00315   const RCP<const LinearOpBase<Scalar> > &fwdOp,
00316   const ESupportSolveUse supportSolveUse,
00317   const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00318   const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00319   const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00320   const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00321   )
00322 {
00323   return inverse<Scalar>(LOWSF, fwdOp, supportSolveUse,
00324     Teuchos::ptr(fwdSolveCriteria), throwOnFwdSolveFailure,
00325     Teuchos::ptr(adjSolveCriteria), throwOnAdjSolveFailure);
00326 }
00327 
00328   
00333 template<class Scalar>
00334 THYRA_DEPRECATED
00335 void uninitializeOp(
00336   const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
00337   LinearOpWithSolveBase<Scalar> *Op,
00338   RCP<const LinearOpBase<Scalar> > *fwdOp = NULL,
00339   RCP<const PreconditionerBase<Scalar> > *prec = NULL,
00340   RCP<const LinearOpBase<Scalar> > *approxFwdOp = NULL,
00341   ESupportSolveUse *supportSolveUse = NULL
00342   )
00343 {
00344   using Teuchos::ptr;
00345   uninitializeOp<Scalar>(lowsFactory, ptr(Op), ptr(fwdOp), ptr(prec),
00346     ptr(approxFwdOp), ptr(supportSolveUse));
00347 }
00348 
00349 
00350 } // namespace Thyra
00351 
00352 
00353 #endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines