Thyra Version of the Day
Thyra_DefaultPreconditioner_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 #ifndef THYRA_DEFUALT_PRECONDITIONER_DEF_HPP
00043 #define THYRA_DEFUALT_PRECONDITIONER_DEF_HPP
00044 
00045 #include "Thyra_DefaultPreconditioner_decl.hpp"
00046 #include "Thyra_LinearOpBase.hpp"
00047 
00048 
00049 namespace Thyra {
00050 
00051 
00052 // Constructors/initializers/accessors
00053 
00054 
00055 template <class Scalar>
00056 DefaultPreconditioner<Scalar>::DefaultPreconditioner()
00057 {}
00058 
00059 
00060 template <class Scalar>
00061 DefaultPreconditioner<Scalar>::DefaultPreconditioner(
00062   const Teuchos::RCP<LinearOpBase<Scalar> > &leftPrecOp,
00063   const Teuchos::RCP<LinearOpBase<Scalar> > &rightPrecOp
00064  )
00065 {
00066 #ifdef TEUCHOS_DEBUG
00067   TEUCHOS_TEST_FOR_EXCEPT( is_null(leftPrecOp) && is_null(rightPrecOp) );
00068 #endif
00069   if (!is_null(leftPrecOp))
00070     leftPrecOp_.initialize(leftPrecOp);
00071   if (!is_null(rightPrecOp))
00072     rightPrecOp_.initialize(rightPrecOp);
00073 }
00074 
00075 
00076 template <class Scalar>
00077 DefaultPreconditioner<Scalar>::DefaultPreconditioner(
00078   const Teuchos::RCP<const LinearOpBase<Scalar> > &leftPrecOp,
00079   const Teuchos::RCP<const LinearOpBase<Scalar> > &rightPrecOp
00080   )
00081 {
00082 #ifdef TEUCHOS_DEBUG
00083   TEUCHOS_TEST_FOR_EXCEPT( is_null(leftPrecOp) && is_null(rightPrecOp) );
00084 #endif
00085   if (!is_null(leftPrecOp))
00086     leftPrecOp_.initialize(leftPrecOp);
00087   if (!is_null(rightPrecOp))
00088     rightPrecOp_.initialize(rightPrecOp);
00089 }
00090 
00091 
00092 template <class Scalar>
00093 DefaultPreconditioner<Scalar>::DefaultPreconditioner(
00094   const Teuchos::RCP<LinearOpBase<Scalar> > &unspecifiedPrecOp
00095   )
00096 {
00097   unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
00098 }
00099 
00100 
00101 template <class Scalar>
00102 DefaultPreconditioner<Scalar>::DefaultPreconditioner(
00103   const Teuchos::RCP<const LinearOpBase<Scalar> > &unspecifiedPrecOp
00104   )
00105 {
00106   unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
00107 }
00108 
00109 
00110 template <class Scalar>
00111 void DefaultPreconditioner<Scalar>::initializeLeft(
00112   const Teuchos::RCP<LinearOpBase<Scalar> > &leftPrecOp
00113   )
00114 {
00115   uninitialize();
00116   leftPrecOp_.initialize(leftPrecOp);
00117 }
00118 
00119 
00120 template <class Scalar>
00121 void DefaultPreconditioner<Scalar>::initializeLeft(
00122   const Teuchos::RCP<const LinearOpBase<Scalar> > &leftPrecOp
00123   )
00124 {
00125   uninitialize();
00126   leftPrecOp_.initialize(leftPrecOp);
00127 }
00128 
00129 
00130 template <class Scalar>
00131 void DefaultPreconditioner<Scalar>::initializeRight(
00132   const Teuchos::RCP<LinearOpBase<Scalar> > &rightPrecOp
00133   )
00134 {
00135   uninitialize();
00136   rightPrecOp_.initialize(rightPrecOp);
00137 }
00138 
00139 
00140 template <class Scalar>
00141 void DefaultPreconditioner<Scalar>::initializeRight(
00142   const Teuchos::RCP<const LinearOpBase<Scalar> > &rightPrecOp
00143   )
00144 {
00145   uninitialize();
00146   rightPrecOp_.initialize(rightPrecOp);
00147 }
00148 
00149 
00150 template <class Scalar>
00151 void DefaultPreconditioner<Scalar>::initializeLeftRight(
00152   const Teuchos::RCP<LinearOpBase<Scalar> > &leftPrecOp,
00153   const Teuchos::RCP<LinearOpBase<Scalar> > &rightPrecOp
00154   )
00155 {
00156   uninitialize();
00157   rightPrecOp_.initialize(rightPrecOp);
00158   leftPrecOp_.initialize(leftPrecOp);
00159 }
00160 
00161 
00162 template <class Scalar>
00163 void DefaultPreconditioner<Scalar>::initializeLeftRight(
00164   const Teuchos::RCP<const LinearOpBase<Scalar> > &leftPrecOp,
00165   const Teuchos::RCP<const LinearOpBase<Scalar> > &rightPrecOp
00166   )
00167 {
00168   uninitialize();
00169   rightPrecOp_.initialize(rightPrecOp);
00170   leftPrecOp_.initialize(leftPrecOp);
00171 }
00172 
00173 
00174 template <class Scalar>
00175 void DefaultPreconditioner<Scalar>::initializeUnspecified(
00176   const Teuchos::RCP<LinearOpBase<Scalar> > &unspecifiedPrecOp
00177   )
00178 {
00179   uninitialize();
00180   unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
00181 }
00182 
00183 
00184 template <class Scalar>
00185 void DefaultPreconditioner<Scalar>::initializeUnspecified(
00186   const Teuchos::RCP<const LinearOpBase<Scalar> > &unspecifiedPrecOp
00187   )
00188 {
00189   uninitialize();
00190   unspecifiedPrecOp_.initialize(unspecifiedPrecOp);
00191 }
00192 
00193 
00194 template <class Scalar>
00195 void DefaultPreconditioner<Scalar>::uninitialize()
00196 {
00197   leftPrecOp_.uninitialize();
00198   rightPrecOp_.uninitialize();
00199   unspecifiedPrecOp_.uninitialize();
00200 }
00201 
00202 
00203 // Overridden from PreconditionerBase
00204 
00205 
00206 template <class Scalar>
00207 bool DefaultPreconditioner<Scalar>::isLeftPrecOpConst() const
00208 {
00209   return leftPrecOp_.isConst();
00210 }
00211 
00212 
00213 template <class Scalar>
00214 Teuchos::RCP<LinearOpBase<Scalar> >
00215 DefaultPreconditioner<Scalar>::getNonconstLeftPrecOp()
00216 {
00217   return leftPrecOp_.getNonconstObj();
00218 }
00219 
00220 
00221 template <class Scalar>
00222 Teuchos::RCP<const LinearOpBase<Scalar> >
00223 DefaultPreconditioner<Scalar>::getLeftPrecOp() const
00224 {
00225   return leftPrecOp_.getConstObj();
00226 }
00227 
00228 
00229 template <class Scalar>
00230 bool DefaultPreconditioner<Scalar>::isRightPrecOpConst() const
00231 {
00232   return rightPrecOp_.isConst();
00233 }
00234 
00235 
00236 template <class Scalar>
00237 Teuchos::RCP<LinearOpBase<Scalar> >
00238 DefaultPreconditioner<Scalar>::getNonconstRightPrecOp()
00239 {
00240   return rightPrecOp_.getNonconstObj();
00241 }
00242 
00243 
00244 template <class Scalar>
00245 Teuchos::RCP<const LinearOpBase<Scalar> >
00246 DefaultPreconditioner<Scalar>::getRightPrecOp() const
00247 {
00248   return rightPrecOp_.getConstObj();
00249 }
00250 
00251 
00252 template <class Scalar>
00253 bool DefaultPreconditioner<Scalar>::isUnspecifiedPrecOpConst() const
00254 {
00255   return unspecifiedPrecOp_.isConst();
00256 }
00257 
00258 
00259 template <class Scalar>
00260 Teuchos::RCP<LinearOpBase<Scalar> >
00261 DefaultPreconditioner<Scalar>::getNonconstUnspecifiedPrecOp()
00262 {
00263   return unspecifiedPrecOp_.getNonconstObj();
00264 }
00265 
00266 
00267 template <class Scalar>
00268 Teuchos::RCP<const LinearOpBase<Scalar> >
00269 DefaultPreconditioner<Scalar>::getUnspecifiedPrecOp() const
00270 {
00271   return unspecifiedPrecOp_.getConstObj();
00272 }
00273 
00274 
00275 // Overridden from Teuchos::Describable
00276 
00277                                                 
00278 template <class Scalar>
00279 std::string DefaultPreconditioner<Scalar>::description() const
00280 {
00281   std::ostringstream oss;
00282   oss << Teuchos::Describable::description() << "{";
00283   bool wroteOne = false;
00284   if(!is_null(leftPrecOp_.getConstObj())) {
00285     if(wroteOne) oss << ",";
00286     oss << "leftPrecOp=" << leftPrecOp_.getConstObj()->description();
00287     wroteOne = true;
00288   }
00289   if(!is_null(rightPrecOp_.getConstObj())) {
00290     if(wroteOne) oss << ",";
00291     oss << "rightPrecOp=" << rightPrecOp_.getConstObj()->description();
00292     wroteOne = true;
00293   }
00294   if(!is_null(unspecifiedPrecOp_.getConstObj())) {
00295     if(wroteOne) oss << ",";
00296     oss << "unspecifiedPrecOp=" << unspecifiedPrecOp_.getConstObj()->description();
00297     wroteOne = true;
00298   }
00299   oss << "}";
00300   return oss.str();
00301 }
00302 
00303 
00304 template <class Scalar>
00305 void DefaultPreconditioner<Scalar>::describe(
00306   Teuchos::FancyOStream &out,
00307   const Teuchos::EVerbosityLevel verbLevel
00308   ) const
00309 {
00310   using Teuchos::FancyOStream;
00311   using Teuchos::OSTab;
00312   using Teuchos::describe;
00313   OSTab tab(out);
00314   switch(verbLevel) {
00315     case Teuchos::VERB_DEFAULT:
00316     case Teuchos::VERB_LOW:
00317       out << Teuchos::Describable::description() << std::endl;
00318       break;
00319     case Teuchos::VERB_MEDIUM:
00320     case Teuchos::VERB_HIGH:
00321     case Teuchos::VERB_EXTREME:
00322     {
00323       out
00324         << Teuchos::typeName(*this) << "\n";
00325       OSTab tab2(out);
00326       if(!is_null(leftPrecOp_.getConstObj()))
00327         out << "leftPrecOp=" << describe(*leftPrecOp_.getConstObj(),verbLevel);
00328       if(!is_null(rightPrecOp_.getConstObj()))
00329         out << "rig htPrecOp=" << describe(*rightPrecOp_.getConstObj(),verbLevel);
00330       if(!is_null(unspecifiedPrecOp_.getConstObj()))
00331         out << "unspecifiedPrecOp=" << describe(*unspecifiedPrecOp_.getConstObj(),verbLevel);
00332       break;
00333     }
00334     default:
00335       TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
00336   }
00337 }
00338 
00339 
00340 } // namespace Thyra
00341 
00342 
00343 #endif // THYRA_DEFUALT_PRECONDITIONER_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines