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 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 } // namespace Thyra
00197 
00198 
00199 #endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP

Generated on Tue Oct 20 12:47:11 2009 for Thyra Operator Solve Support by doxygen 1.4.7