Thyra_DefaultDiagonalLinearOp.hpp

Go to the documentation of this file.
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 #ifndef THYRA_DIAGONAL_LINEAR_OP_HPP
00030 #define THYRA_DIAGONAL_LINEAR_OP_HPP
00031 
00032 #include "Thyra_DefaultDiagonalLinearOpDecl.hpp"
00033 #include "Thyra_SingleRhsLinearOpWithSolveBase.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 
00036 namespace Thyra {
00037 
00038 // Constructors/initializers/accessors
00039 
00040 template<class Scalar>
00041 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp()
00042 {}
00043 
00044 template<class Scalar>
00045 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp(
00046   const Teuchos::RCP<const VectorSpaceBase<Scalar> >   &space
00047   )
00048 {
00049   initialize(space);
00050 }
00051 
00052 template<class Scalar>
00053 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp(
00054   const Teuchos::RCP<VectorBase<Scalar> >   &diag
00055   )
00056 {
00057   initialize(diag);
00058 }
00059 
00060 template<class Scalar>
00061 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp(
00062   const Teuchos::RCP<const VectorBase<Scalar> >   &diag
00063   )
00064 {
00065   initialize(diag);
00066 }
00067 
00068 template<class Scalar>
00069 void DefaultDiagonalLinearOp<Scalar>::initialize(
00070   const Teuchos::RCP<const VectorSpaceBase<Scalar> >  &space
00071   )
00072 {
00073 #ifdef TEUCHOS_DEBUG
00074   TEST_FOR_EXCEPT(space.get()==NULL);
00075 #endif
00076   initialize(createMember(space)); // Note that the space is guaranteed to be remembered here!
00077 }
00078 
00079 template<class Scalar>
00080 void DefaultDiagonalLinearOp<Scalar>::initialize(
00081   const Teuchos::RCP<VectorBase<Scalar> >   &diag
00082   )
00083 {
00084   diag_.initialize(diag);
00085 }
00086 
00087 template<class Scalar>
00088 void DefaultDiagonalLinearOp<Scalar>::initialize(
00089   const Teuchos::RCP<const VectorBase<Scalar> >   &diag
00090   )
00091 {
00092   diag_.initialize(diag);
00093 }
00094 
00095 template<class Scalar>
00096 void DefaultDiagonalLinearOp<Scalar>::uninitialize()
00097 {
00098   diag_.uninitialize();
00099 }
00100 
00101 // Overridden from DiagonalLinearOpBase
00102 
00103 template<class Scalar>
00104 bool DefaultDiagonalLinearOp<Scalar>::isDiagConst() const
00105 {
00106   return diag_.isConst();
00107 }
00108 
00109 template<class Scalar>
00110 Teuchos::RCP<VectorBase<Scalar> >  
00111 DefaultDiagonalLinearOp<Scalar>::getNonconstDiag()
00112 {
00113   return diag_.getNonconstObj();
00114 }
00115 
00116 template<class Scalar>
00117 Teuchos::RCP<const VectorBase<Scalar> >  
00118 DefaultDiagonalLinearOp<Scalar>::getDiag() const
00119 {
00120   return diag_.getConstObj();
00121 }
00122 
00123 // Overridden from LinearOpBase
00124 
00125 template<class Scalar>
00126 Teuchos::RCP< const VectorSpaceBase<Scalar> >
00127 DefaultDiagonalLinearOp<Scalar>::range() const
00128 {
00129   return diag_.getConstObj()->space();
00130 }
00131 
00132 template<class Scalar>
00133 Teuchos::RCP< const VectorSpaceBase<Scalar> >
00134 DefaultDiagonalLinearOp<Scalar>::domain() const
00135 {
00136   return diag_.getConstObj()->space();
00137 }
00138 
00139 template<class Scalar>
00140 Teuchos::RCP<const LinearOpBase<Scalar> >
00141 DefaultDiagonalLinearOp<Scalar>::clone() const
00142 {
00143   return Teuchos::rcp(new DefaultDiagonalLinearOp<Scalar>(diag_.getConstObj()->clone_v()));
00144 }
00145 
00146 // protected
00147 
00148 // Overridden from SingleScalarLinearOpBase
00149 
00150 template<class Scalar>
00151 bool DefaultDiagonalLinearOp<Scalar>::opSupported(ETransp M_trans) const
00152 {
00153   return
00154     ( Teuchos::ScalarTraits<Scalar>::isComplex
00155       ? ( M_trans==NOTRANS || M_trans==TRANS )
00156       : true
00157       );
00158 }
00159 
00160 // Overridden from SingleRhsLinearOpBase
00161 
00162 template<class Scalar>
00163 void DefaultDiagonalLinearOp<Scalar>::apply(
00164   const ETransp                M_trans
00165   ,const VectorBase<Scalar>    &x
00166   ,VectorBase<Scalar>          *y
00167   ,const Scalar                alpha
00168   ,const Scalar                beta
00169   ) const
00170 {
00171   typedef Teuchos::ScalarTraits<Scalar> ST;
00172 #ifdef TEUCHOS_DEBUG
00173   TEST_FOR_EXCEPT( ST::isComplex && !(M_trans==NOTRANS||M_trans==TRANS) );
00174   THYRA_ASSERT_LINEAR_OP_VEC_APPLY_SPACES(
00175     "DefaultDiagonalLinearOp<Scalar>::apply(...)",*this,M_trans,x,y
00176     );
00177 #endif // TEUCHOS_DEBUG  
00178   typedef Teuchos::ScalarTraits<Scalar> ST;
00179   if( beta != ST::one() ) Vt_S( y, beta );
00180   ele_wise_prod( alpha, x, *diag_.getConstObj(), y );
00181 }
00182 
00183 } // end namespace Thyra
00184 
00185 #endif  // THYRA_DIAGONAL_LINEAR_OP_HPP

Generated on Tue Oct 20 12:47:25 2009 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.4.7