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

Generated on Wed May 12 21:26:53 2010 for Thyra Operator/Vector Support by  doxygen 1.4.7