Thyra_DelayedLinearOpWithSolve.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 
00030 #ifndef THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
00031 #define THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
00032 
00033 
00034 #include "Thyra_DelayedLinearOpWithSolveDecl.hpp"
00035 #include "Thyra_LinearOpWithSolveBase.hpp"
00036 #include "Thyra_SolveSupportTypes.hpp"
00037 #include "Teuchos_VerboseObject.hpp"
00038 
00039 
00040 namespace Thyra {
00041 
00042 
00043 // Constructor/Initializers
00044 
00045 
00046 template <class Scalar>
00047 DelayedLinearOpWithSolve<Scalar>::DelayedLinearOpWithSolve()
00048   :lows_is_valid_(false)
00049 {}
00050 
00051 
00052 template <class Scalar>
00053 void DelayedLinearOpWithSolve<Scalar>::initialize(
00054   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00055   const RCP<const PreconditionerBase<Scalar> > &prec,
00056   const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
00057   const ESupportSolveUse supportSolveUse,
00058   const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf
00059   )
00060 {
00061 #ifdef TEUCHOS_DEBUG
00062   TEST_FOR_EXCEPT(is_null(fwdOpSrc));
00063   TEST_FOR_EXCEPT(!is_null(prec) && !is_null(approxFwdOpSrc));
00064   TEST_FOR_EXCEPT(is_null(lowsf));
00065 #endif  
00066   fwdOpSrc_ = fwdOpSrc;
00067   prec_ = prec;
00068   approxFwdOpSrc_ = approxFwdOpSrc;
00069   lowsf_ = lowsf;
00070   supportSolveUse_ = supportSolveUse;
00071   fwdOp_ = fwdOpSrc_->getOp().assert_not_null();
00072   lows_is_valid_ = false;
00073 }
00074 
00075 
00076 template <class Scalar>
00077 RCP<const LinearOpSourceBase<Scalar> >
00078 DelayedLinearOpWithSolve<Scalar>::getFwdOpSrc() const
00079 {
00080   return fwdOpSrc_;
00081 }
00082 
00083 
00084 template <class Scalar>
00085 RCP<const PreconditionerBase<Scalar> >
00086 DelayedLinearOpWithSolve<Scalar>::getPrec() const
00087 {
00088   return prec_;
00089 }
00090  
00091 
00092 template <class Scalar>
00093 RCP<const LinearOpSourceBase<Scalar> >
00094 DelayedLinearOpWithSolve<Scalar>::getApproxFwdOpSrc() const
00095 {
00096   return approxFwdOpSrc_;
00097 }
00098 
00099 
00100 template <class Scalar>
00101 ESupportSolveUse
00102 DelayedLinearOpWithSolve<Scalar>::getSupportSolveUse() const
00103 {
00104   return supportSolveUse_;
00105 }
00106 
00107 
00108 // Overridden from Teuchos::Describable
00109 
00110 
00111 template<class Scalar>
00112 std::string DelayedLinearOpWithSolve<Scalar>::description() const
00113 {
00114   std::ostringstream oss;
00115   oss << this->Teuchos::Describable::description()
00116       << "{";
00117   oss << "fwdOp_=";
00118   if (!is_null(fwdOp_))
00119     oss << fwdOp_->description();
00120   else
00121     oss << "NULL";
00122   oss << "lows=";
00123   if (!is_null(lows_))
00124     oss << lows_->description();
00125   else
00126     oss << "NULL";
00127   oss << "}";
00128   return oss.str();
00129 }
00130 
00131 
00132 // Overridden from LinearOpBase
00133 
00134 
00135 template <class Scalar>
00136 RCP< const VectorSpaceBase<Scalar> >
00137 DelayedLinearOpWithSolve<Scalar>::range() const
00138 {
00139   if (!is_null(fwdOp_))
00140     return fwdOp_->range();
00141   return Teuchos::null;
00142 }
00143 
00144 
00145 template <class Scalar>
00146 RCP< const VectorSpaceBase<Scalar> >
00147 DelayedLinearOpWithSolve<Scalar>::domain() const
00148 {
00149   if (!is_null(fwdOp_))
00150     return fwdOp_->domain();
00151   return Teuchos::null;
00152 }
00153 
00154 
00155 template <class Scalar>
00156 RCP<const LinearOpBase<Scalar> >
00157 DelayedLinearOpWithSolve<Scalar>::clone() const
00158 {
00159   return Teuchos::null; // ToDo: Implement if needed!
00160 }
00161 
00162 
00163 // protected
00164 
00165 
00166 template<class Scalar>
00167 void DelayedLinearOpWithSolve<Scalar>::informUpdatedVerbosityState() const
00168 {
00169   if (!is_null(lowsf_)) {
00170     lowsf_->setVerbLevel(this->getVerbLevel());
00171     lowsf_->setOStream(this->getOStream());
00172   }
00173   if (!is_null(lows_)) {
00174     lows_->setVerbLevel(this->getVerbLevel());
00175     lows_->setOStream(this->getOStream());
00176   }
00177 }
00178 
00179 
00180 // Overridden from SingleScalarLinearOpBase
00181 
00182  
00183 template <class Scalar>
00184 bool DelayedLinearOpWithSolve<Scalar>::opSupported(ETransp M_trans) const
00185 {
00186   return Thyra::opSupported(*fwdOp_,M_trans);
00187 }
00188 
00189 
00190 template <class Scalar>
00191 void DelayedLinearOpWithSolve<Scalar>::apply(
00192   const ETransp M_trans,
00193   const MultiVectorBase<Scalar> &X,
00194     MultiVectorBase<Scalar> *Y,
00195   const Scalar alpha,
00196   const Scalar beta
00197   ) const
00198 {
00199   Thyra::apply(*fwdOp_,M_trans,X,Y,alpha,beta);
00200 }
00201 
00202 
00203 template <class Scalar>
00204 bool DelayedLinearOpWithSolve<Scalar>::solveSupportsTrans(
00205   ETransp M_trans
00206   ) const
00207 {
00208   updateSolver();
00209   return Thyra::solveSupports(*lows_,M_trans);
00210 }
00211 
00212 
00213 template <class Scalar>
00214 bool DelayedLinearOpWithSolve<Scalar>::solveSupportsSolveMeasureType(
00215   ETransp M_trans, const SolveMeasureType& solveMeasureType
00216   ) const
00217 {
00218   updateSolver();
00219   return Thyra::solveSupportsSolveMeasureType(*lows_,M_trans,solveMeasureType);
00220 }
00221 
00222 
00223 template <class Scalar>
00224 void DelayedLinearOpWithSolve<Scalar>::solve(
00225   const ETransp M_trans,
00226   const MultiVectorBase<Scalar> &B,
00227   MultiVectorBase<Scalar> *X,
00228   const int numBlocks,
00229   const BlockSolveCriteria<Scalar> blockSolveCriteria[],
00230   SolveStatus<Scalar> blockSolveStatus[]
00231   ) const
00232 {
00233   updateSolver();
00234   Thyra::solve(
00235     *lows_, M_trans, B, X, numBlocks, blockSolveCriteria, blockSolveStatus );
00236 }
00237 
00238 
00239 // private
00240 
00241 
00242 template <class Scalar>
00243 void DelayedLinearOpWithSolve<Scalar>::updateSolver() const
00244 {
00245   if (is_null(lows_))
00246     lows_ = lowsf_->createOp();
00247   if (!lows_is_valid_) {
00248     if (!is_null(prec_))
00249       lowsf_->initializePreconditionedOp(
00250         fwdOpSrc_,prec_,&*lows_,supportSolveUse_);
00251     else if (!is_null(approxFwdOpSrc_))
00252       lowsf_->initializeApproxPreconditionedOp(
00253         fwdOpSrc_,approxFwdOpSrc_,&*lows_,supportSolveUse_);
00254     else
00255       lowsf_->initializeOp(
00256         fwdOpSrc_,&*lows_,supportSolveUse_);
00257     lows_is_valid_ = true;
00258   }
00259 }
00260 
00261 
00262 } // namespace Thyra
00263 
00264 
00265 #endif // THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
00266 
00267 
00268 
00269 
00270 

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