|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
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_DelayedLinearOpWithSolve_decl.hpp" 00035 #include "Thyra_LinearOpWithSolveFactoryBase.hpp" 00036 #include "Thyra_LinearOpWithSolveBase.hpp" 00037 #include "Thyra_SolveSupportTypes.hpp" 00038 #include "Teuchos_VerboseObject.hpp" 00039 00040 00041 namespace Thyra { 00042 00043 00044 // Constructor/Initializers 00045 00046 00047 template <class Scalar> 00048 DelayedLinearOpWithSolve<Scalar>::DelayedLinearOpWithSolve() 00049 :lows_is_valid_(false) 00050 {} 00051 00052 00053 template <class Scalar> 00054 void DelayedLinearOpWithSolve<Scalar>::initialize( 00055 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc, 00056 const RCP<const PreconditionerBase<Scalar> > &prec, 00057 const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc, 00058 const ESupportSolveUse supportSolveUse, 00059 const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf 00060 ) 00061 { 00062 #ifdef TEUCHOS_DEBUG 00063 TEST_FOR_EXCEPT(is_null(fwdOpSrc)); 00064 TEST_FOR_EXCEPT(!is_null(prec) && !is_null(approxFwdOpSrc)); 00065 TEST_FOR_EXCEPT(is_null(lowsf)); 00066 #endif 00067 fwdOpSrc_ = fwdOpSrc; 00068 prec_ = prec; 00069 approxFwdOpSrc_ = approxFwdOpSrc; 00070 lowsf_ = lowsf; 00071 supportSolveUse_ = supportSolveUse; 00072 fwdOp_ = fwdOpSrc_->getOp().assert_not_null(); 00073 lows_is_valid_ = false; 00074 } 00075 00076 00077 template <class Scalar> 00078 RCP<const LinearOpSourceBase<Scalar> > 00079 DelayedLinearOpWithSolve<Scalar>::getFwdOpSrc() const 00080 { 00081 return fwdOpSrc_; 00082 } 00083 00084 00085 template <class Scalar> 00086 RCP<const PreconditionerBase<Scalar> > 00087 DelayedLinearOpWithSolve<Scalar>::getPrec() const 00088 { 00089 return prec_; 00090 } 00091 00092 00093 template <class Scalar> 00094 RCP<const LinearOpSourceBase<Scalar> > 00095 DelayedLinearOpWithSolve<Scalar>::getApproxFwdOpSrc() const 00096 { 00097 return approxFwdOpSrc_; 00098 } 00099 00100 00101 template <class Scalar> 00102 ESupportSolveUse 00103 DelayedLinearOpWithSolve<Scalar>::getSupportSolveUse() const 00104 { 00105 return supportSolveUse_; 00106 } 00107 00108 00109 // Overridden from Teuchos::Describable 00110 00111 00112 template<class Scalar> 00113 std::string DelayedLinearOpWithSolve<Scalar>::description() const 00114 { 00115 std::ostringstream oss; 00116 oss << this->Teuchos::Describable::description() 00117 << "{"; 00118 oss << "fwdOp_="; 00119 if (!is_null(fwdOp_)) 00120 oss << fwdOp_->description(); 00121 else 00122 oss << "NULL,"; 00123 oss << "lows="; 00124 if (!is_null(lows_)) 00125 oss << lows_->description(); 00126 else 00127 oss << "NULL"; 00128 oss << "}"; 00129 return oss.str(); 00130 } 00131 00132 00133 // Overridden from LinearOpBase 00134 00135 00136 template <class Scalar> 00137 RCP< const VectorSpaceBase<Scalar> > 00138 DelayedLinearOpWithSolve<Scalar>::range() const 00139 { 00140 if (!is_null(fwdOp_)) 00141 return fwdOp_->range(); 00142 return Teuchos::null; 00143 } 00144 00145 00146 template <class Scalar> 00147 RCP< const VectorSpaceBase<Scalar> > 00148 DelayedLinearOpWithSolve<Scalar>::domain() const 00149 { 00150 if (!is_null(fwdOp_)) 00151 return fwdOp_->domain(); 00152 return Teuchos::null; 00153 } 00154 00155 00156 template <class Scalar> 00157 RCP<const LinearOpBase<Scalar> > 00158 DelayedLinearOpWithSolve<Scalar>::clone() const 00159 { 00160 return Teuchos::null; // ToDo: Implement if needed! 00161 } 00162 00163 00164 // protected 00165 00166 00167 template<class Scalar> 00168 void DelayedLinearOpWithSolve<Scalar>::informUpdatedVerbosityState() const 00169 { 00170 if (!is_null(lowsf_)) { 00171 lowsf_->setVerbLevel(this->getVerbLevel()); 00172 lowsf_->setOStream(this->getOStream()); 00173 } 00174 if (!is_null(lows_)) { 00175 lows_->setVerbLevel(this->getVerbLevel()); 00176 lows_->setOStream(this->getOStream()); 00177 } 00178 } 00179 00180 00181 // Overridden from LinearOpBase 00182 00183 00184 template <class Scalar> 00185 bool DelayedLinearOpWithSolve<Scalar>::opSupportedImpl(EOpTransp M_trans) const 00186 { 00187 return Thyra::opSupported(*fwdOp_,M_trans); 00188 } 00189 00190 00191 template <class Scalar> 00192 void DelayedLinearOpWithSolve<Scalar>::applyImpl( 00193 const EOpTransp M_trans, 00194 const MultiVectorBase<Scalar> &X, 00195 const Ptr<MultiVectorBase<Scalar> > &Y, 00196 const Scalar alpha, 00197 const Scalar beta 00198 ) const 00199 { 00200 Thyra::apply(*fwdOp_, M_trans, X, Y, alpha, beta); 00201 } 00202 00203 00204 // Overridden from LinearOpWithSolveBase 00205 00206 00207 template <class Scalar> 00208 bool DelayedLinearOpWithSolve<Scalar>::solveSupportsImpl(EOpTransp M_trans) const 00209 { 00210 updateSolver(); 00211 return Thyra::solveSupports(*lows_, M_trans); 00212 } 00213 00214 00215 template <class Scalar> 00216 bool DelayedLinearOpWithSolve<Scalar>::solveSupportsSolveMeasureTypeImpl( 00217 EOpTransp M_trans, const SolveMeasureType& solveMeasureType 00218 ) const 00219 { 00220 updateSolver(); 00221 return Thyra::solveSupportsSolveMeasureType(*lows_, M_trans, solveMeasureType); 00222 } 00223 00224 00225 template <class Scalar> 00226 SolveStatus<Scalar> 00227 DelayedLinearOpWithSolve<Scalar>::solveImpl( 00228 const EOpTransp transp, 00229 const MultiVectorBase<Scalar> &B, 00230 const Ptr<MultiVectorBase<Scalar> > &X, 00231 const Ptr<const SolveCriteria<Scalar> > solveCriteria 00232 ) const 00233 { 00234 updateSolver(); 00235 return Thyra::solve(*lows_, transp, B, X, solveCriteria); 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
1.7.4