Thyra Version of the Day
Thyra_DelayedLinearOpWithSolve_def.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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 
00043 #ifndef THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
00044 #define THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
00045 
00046 
00047 #include "Thyra_DelayedLinearOpWithSolve_decl.hpp"
00048 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00049 #include "Thyra_LinearOpWithSolveBase.hpp"
00050 #include "Thyra_SolveSupportTypes.hpp"
00051 #include "Teuchos_VerboseObject.hpp"
00052 
00053 
00054 namespace Thyra {
00055 
00056 
00057 // Constructor/Initializers
00058 
00059 
00060 template <class Scalar>
00061 DelayedLinearOpWithSolve<Scalar>::DelayedLinearOpWithSolve()
00062   :lows_is_valid_(false), supportSolveUse_(SUPPORT_SOLVE_UNSPECIFIED)
00063 {}
00064 
00065 
00066 template <class Scalar>
00067 void DelayedLinearOpWithSolve<Scalar>::initialize(
00068   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00069   const RCP<const PreconditionerBase<Scalar> > &prec,
00070   const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
00071   const ESupportSolveUse supportSolveUse,
00072   const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf
00073   )
00074 {
00075 #ifdef TEUCHOS_DEBUG
00076   TEUCHOS_TEST_FOR_EXCEPT(is_null(fwdOpSrc));
00077   TEUCHOS_TEST_FOR_EXCEPT(!is_null(prec) && !is_null(approxFwdOpSrc));
00078   TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
00079 #endif  
00080   fwdOpSrc_ = fwdOpSrc;
00081   prec_ = prec;
00082   approxFwdOpSrc_ = approxFwdOpSrc;
00083   lowsf_ = lowsf;
00084   supportSolveUse_ = supportSolveUse;
00085   fwdOp_ = fwdOpSrc_->getOp().assert_not_null();
00086   lows_is_valid_ = false;
00087 }
00088 
00089 
00090 template <class Scalar>
00091 RCP<const LinearOpSourceBase<Scalar> >
00092 DelayedLinearOpWithSolve<Scalar>::getFwdOpSrc() const
00093 {
00094   return fwdOpSrc_;
00095 }
00096 
00097 
00098 template <class Scalar>
00099 RCP<const PreconditionerBase<Scalar> >
00100 DelayedLinearOpWithSolve<Scalar>::getPrec() const
00101 {
00102   return prec_;
00103 }
00104  
00105 
00106 template <class Scalar>
00107 RCP<const LinearOpSourceBase<Scalar> >
00108 DelayedLinearOpWithSolve<Scalar>::getApproxFwdOpSrc() const
00109 {
00110   return approxFwdOpSrc_;
00111 }
00112 
00113 
00114 template <class Scalar>
00115 ESupportSolveUse
00116 DelayedLinearOpWithSolve<Scalar>::getSupportSolveUse() const
00117 {
00118   return supportSolveUse_;
00119 }
00120 
00121 
00122 // Overridden from Teuchos::Describable
00123 
00124 
00125 template<class Scalar>
00126 std::string DelayedLinearOpWithSolve<Scalar>::description() const
00127 {
00128   std::ostringstream oss;
00129   oss << this->Teuchos::Describable::description()
00130       << "{";
00131   oss << "fwdOp_=";
00132   if (!is_null(fwdOp_))
00133     oss << fwdOp_->description();
00134   else
00135     oss << "NULL,";
00136   oss << "lows=";
00137   if (!is_null(lows_))
00138     oss << lows_->description();
00139   else
00140     oss << "NULL";
00141   oss << "}";
00142   return oss.str();
00143 }
00144 
00145 
00146 // Overridden from LinearOpBase
00147 
00148 
00149 template <class Scalar>
00150 RCP< const VectorSpaceBase<Scalar> >
00151 DelayedLinearOpWithSolve<Scalar>::range() const
00152 {
00153   if (!is_null(fwdOp_))
00154     return fwdOp_->range();
00155   return Teuchos::null;
00156 }
00157 
00158 
00159 template <class Scalar>
00160 RCP< const VectorSpaceBase<Scalar> >
00161 DelayedLinearOpWithSolve<Scalar>::domain() const
00162 {
00163   if (!is_null(fwdOp_))
00164     return fwdOp_->domain();
00165   return Teuchos::null;
00166 }
00167 
00168 
00169 template <class Scalar>
00170 RCP<const LinearOpBase<Scalar> >
00171 DelayedLinearOpWithSolve<Scalar>::clone() const
00172 {
00173   return Teuchos::null; // ToDo: Implement if needed!
00174 }
00175 
00176 
00177 // protected
00178 
00179 
00180 template<class Scalar>
00181 void DelayedLinearOpWithSolve<Scalar>::informUpdatedVerbosityState() const
00182 {
00183   if (!is_null(lowsf_)) {
00184     lowsf_->setVerbLevel(this->getVerbLevel());
00185     lowsf_->setOStream(this->getOStream());
00186   }
00187   if (!is_null(lows_)) {
00188     lows_->setVerbLevel(this->getVerbLevel());
00189     lows_->setOStream(this->getOStream());
00190   }
00191 }
00192 
00193 
00194 // Overridden from LinearOpBase
00195 
00196  
00197 template <class Scalar>
00198 bool DelayedLinearOpWithSolve<Scalar>::opSupportedImpl(EOpTransp M_trans) const
00199 {
00200   return Thyra::opSupported(*fwdOp_,M_trans);
00201 }
00202 
00203 
00204 template <class Scalar>
00205 void DelayedLinearOpWithSolve<Scalar>::applyImpl(
00206   const EOpTransp M_trans,
00207   const MultiVectorBase<Scalar> &X,
00208   const Ptr<MultiVectorBase<Scalar> > &Y,
00209   const Scalar alpha,
00210   const Scalar beta
00211   ) const
00212 {
00213   Thyra::apply(*fwdOp_, M_trans, X, Y, alpha, beta);
00214 }
00215 
00216 
00217 // Overridden from LinearOpWithSolveBase
00218 
00219 
00220 template <class Scalar>
00221 bool DelayedLinearOpWithSolve<Scalar>::solveSupportsImpl(EOpTransp M_trans) const
00222 {
00223   updateSolver();
00224   return Thyra::solveSupports(*lows_, M_trans);
00225 }
00226 
00227 
00228 template <class Scalar>
00229 bool DelayedLinearOpWithSolve<Scalar>::solveSupportsSolveMeasureTypeImpl(
00230   EOpTransp M_trans, const SolveMeasureType& solveMeasureType
00231   ) const
00232 {
00233   updateSolver();
00234   return Thyra::solveSupportsSolveMeasureType(*lows_, M_trans, solveMeasureType);
00235 }
00236 
00237 
00238 template <class Scalar>
00239 SolveStatus<Scalar>
00240 DelayedLinearOpWithSolve<Scalar>::solveImpl(
00241   const EOpTransp transp,
00242   const MultiVectorBase<Scalar> &B,
00243   const Ptr<MultiVectorBase<Scalar> > &X,
00244   const Ptr<const SolveCriteria<Scalar> > solveCriteria
00245   ) const
00246 {
00247   updateSolver();
00248   return Thyra::solve(*lows_, transp, B, X, solveCriteria);
00249 }
00250 
00251 
00252 // private
00253 
00254 
00255 template <class Scalar>
00256 void DelayedLinearOpWithSolve<Scalar>::updateSolver() const
00257 {
00258   if (is_null(lows_))
00259     lows_ = lowsf_->createOp();
00260   if (!lows_is_valid_) {
00261     if (!is_null(prec_))
00262       lowsf_->initializePreconditionedOp(
00263         fwdOpSrc_,prec_,&*lows_,supportSolveUse_);
00264     else if (!is_null(approxFwdOpSrc_))
00265       lowsf_->initializeApproxPreconditionedOp(
00266         fwdOpSrc_,approxFwdOpSrc_,&*lows_,supportSolveUse_);
00267     else
00268       lowsf_->initializeOp(
00269         fwdOpSrc_,&*lows_,supportSolveUse_);
00270     lows_is_valid_ = true;
00271   }
00272 }
00273 
00274 
00275 } // namespace Thyra
00276 
00277 
00278 #endif // THYRA_DELAYED_LINEAR_OP_WITH_SOLVE_HPP
00279 
00280 
00281 
00282 
00283 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines