Teko Version of the Day
Teko_PreconditionerLinearOp.hpp
00001 /*
00002 // @HEADER
00003 // 
00004 // ***********************************************************************
00005 // 
00006 //      Teko: A package for block and physics based preconditioning
00007 //                  Copyright 2010 Sandia Corporation 
00008 //  
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 //  
00012 // Redistribution and use in source and binary forms, with or without
00013 // modification, are permitted provided that the following conditions are
00014 // met:
00015 //  
00016 // 1. Redistributions of source code must retain the above copyright
00017 // notice, this list of conditions and the following disclaimer.
00018 //  
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 // notice, this list of conditions and the following disclaimer in the
00021 // documentation and/or other materials provided with the distribution.
00022 //  
00023 // 3. Neither the name of the Corporation nor the names of the
00024 // contributors may be used to endorse or promote products derived from
00025 // this software without specific prior written permission. 
00026 //  
00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 //  
00039 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
00040 // 
00041 // ***********************************************************************
00042 // 
00043 // @HEADER
00044 
00045 */
00046 
00047 #ifndef __Teko_PreconditionerLinearOp_hpp__
00048 #define __Teko_PreconditionerLinearOp_hpp__
00049 
00050 #include "Teko_PreconditionerLinearOpDecl.hpp"
00051 
00052 #include "Thyra_LinearOpBase.hpp"
00053 #include "Thyra_PreconditionerBase.hpp"
00054 
00055 namespace Teko {
00056 
00057 template <typename ScalarT>
00058 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp()
00059 { }
00060 
00061 template <typename ScalarT>
00062 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> > & prec)
00063 {
00064    preconditioner_.initialize(prec);
00065 }
00066 
00067 template <typename ScalarT>
00068 PreconditionerLinearOp<ScalarT>::PreconditionerLinearOp(const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> > & prec)
00069 {
00070    preconditioner_.initialize(prec);
00071 }
00072 
00074 template <typename ScalarT>
00075 void PreconditionerLinearOp<ScalarT>::initialize(const Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> > & prec)
00076 {
00077    uninitialize();
00078    preconditioner_.initialize(prec);
00079 }
00080 
00082 template <typename ScalarT>
00083 void PreconditionerLinearOp<ScalarT>::initialize(const Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> > & prec)
00084 {
00085    uninitialize();
00086    preconditioner_.initialize(prec);
00087 }
00088 
00090 template <typename ScalarT>
00091 void PreconditionerLinearOp<ScalarT>::uninitialize()
00092 {
00093    preconditioner_.uninitialize();
00094 }
00095 
00097 template <typename ScalarT>
00098 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::range() const
00099 {
00100    return getOperator_cnoc()->range();
00101 }
00102 
00104 template <typename ScalarT>
00105 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > PreconditionerLinearOp<ScalarT>::domain() const
00106 {
00107    return getOperator_cnoc()->domain();
00108 }
00109 
00110 template <typename ScalarT>
00111 bool PreconditionerLinearOp<ScalarT>::opSupportedImpl(
00112   const Thyra::EOpTransp M_trans) const
00113 {
00114   return getOperator_cnoc()->opSupported(M_trans);
00115 }
00116 
00117 template <typename ScalarT>
00118 void PreconditionerLinearOp<ScalarT>::applyImpl(
00119   const Thyra::EOpTransp M_trans,
00120   const Thyra::MultiVectorBase<ScalarT> & x,
00121   const Teuchos::Ptr<Thyra::MultiVectorBase<ScalarT> > & y,
00122   const ScalarT alpha,
00123   const ScalarT beta
00124   ) const
00125 {
00126    getOperator_cnoc()->apply(M_trans, x, y, alpha, beta);
00127 }
00128 
00129 
00131 template <typename ScalarT>
00132 Teuchos::RCP<Thyra::PreconditionerBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getNonconstPreconditioner()
00133 {
00134    return preconditioner_.getNonconstObj();
00135 }
00136 
00138 template <typename ScalarT>
00139 Teuchos::RCP<const Thyra::PreconditionerBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getPreconditioner() const
00140 {
00141    return preconditioner_.getConstObj();
00142 }
00143 
00145 template <typename ScalarT>
00146 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getOperator_cnoc() const
00147 {
00148    Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
00149    oper.initialize(preconditioner_.getConstObj()->getUnspecifiedPrecOp());
00150 
00151    return oper;
00152 }
00153 
00155 template <typename ScalarT>
00156 Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > PreconditionerLinearOp<ScalarT>::getOperator_cnoc()
00157 {
00158    Teuchos::ConstNonconstObjectContainer<Thyra::LinearOpBase<ScalarT> > oper;
00159    oper.initialize(preconditioner_.getNonconstObj()->getNonconstUnspecifiedPrecOp());
00160 
00161    return oper;
00162 }
00163 
00164 template <typename ScalarT>
00165 void PreconditionerLinearOp<ScalarT>::describe(Teuchos::FancyOStream & out_arg,
00166                                       const Teuchos::EVerbosityLevel verbLevel) const
00167 {
00168    using Teuchos::OSTab;
00169  
00170    Teuchos::RCP<Teuchos::FancyOStream> out = rcp(&out_arg,false);
00171    OSTab tab(out);
00172    switch(verbLevel) {
00173       case Teuchos::VERB_DEFAULT:
00174       case Teuchos::VERB_LOW:
00175          *out << this->description() << " ( [Operator] = " << getOperator_cnoc()->description() << " )" << std::endl;
00176          break;
00177       case Teuchos::VERB_MEDIUM:
00178       case Teuchos::VERB_HIGH:
00179       case Teuchos::VERB_EXTREME:
00180          {
00181             *out << Teuchos::Describable::description() << "{"
00182                  << "rangeDim=" << this->range()->dim()
00183                  << ",domainDim=" << this->domain()->dim()
00184                  << "}\n";
00185             {
00186                OSTab tab(out);
00187                *out << "[Operator] = ";
00188                *out << Teuchos::describe(*getOperator_cnoc(),verbLevel);
00189             }
00190             break;
00191          }
00192       default:
00193          TEST_FOR_EXCEPT(true); // Should never get here!
00194    }
00195 }
00196 
00197 inline Teko::LinearOp extractOperatorFromPrecOp(const Teko::LinearOp & lo)
00198 {
00199    Teuchos::RCP<const Teko::PreconditionerLinearOp<double> > plo = 
00200       Teuchos::rcp_dynamic_cast<const Teko::PreconditionerLinearOp<double> >(lo); 
00201    if(plo!=Teuchos::null)
00202       return plo->getOperator();
00203    else
00204       return lo;
00205 }
00206 
00207 } // end namespace Teko
00208 
00209 #endif
 All Classes Files Functions Variables