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   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 } // namespace Thyra
00220 
00221 
00222 #endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP

Generated on Wed May 12 21:42:47 2010 for Thyra Operator Solve Support by  doxygen 1.4.7