Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DefaultDiagonalLinearOp_def.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_DEF_HPP
00030 #define THYRA_DIAGONAL_LINEAR_OP_DEF_HPP
00031 
00032 
00033 #include "Thyra_DefaultDiagonalLinearOp_decl.hpp"
00034 #include "Thyra_MultiVectorStdOps.hpp"
00035 #include "Thyra_VectorStdOps.hpp"
00036 #include "Thyra_VectorBase.hpp"
00037 #include "Thyra_AssertOp.hpp"
00038 
00039 
00040 namespace Thyra {
00041 
00042 
00043 // Constructors/initializers/accessors
00044 
00045 
00046 template<class Scalar>
00047 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp()
00048 {}
00049 
00050 
00051 template<class Scalar>
00052 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp(
00053   const RCP<const VectorSpaceBase<Scalar> > &space
00054   )
00055 {
00056   initialize(space);
00057 }
00058 
00059 
00060 template<class Scalar>
00061 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp(
00062   const RCP<VectorBase<Scalar> > &diag
00063   )
00064 {
00065   initialize(diag);
00066 }
00067 
00068 
00069 template<class Scalar>
00070 DefaultDiagonalLinearOp<Scalar>::DefaultDiagonalLinearOp(
00071   const RCP<const VectorBase<Scalar> > &diag
00072   )
00073 {
00074   initialize(diag);
00075 }
00076 
00077 
00078 template<class Scalar>
00079 void DefaultDiagonalLinearOp<Scalar>::initialize(
00080   const RCP<const VectorSpaceBase<Scalar> > &space
00081   )
00082 {
00083 #ifdef TEUCHOS_DEBUG
00084   TEST_FOR_EXCEPT(space.get()==NULL);
00085 #endif
00086   initialize(createMember(space)); // Note that the space is guaranteed to be remembered here!
00087 }
00088 
00089 
00090 template<class Scalar>
00091 void DefaultDiagonalLinearOp<Scalar>::initialize(
00092   const RCP<VectorBase<Scalar> > &diag
00093   )
00094 {
00095   diag_.initialize(diag);
00096 }
00097 
00098 
00099 template<class Scalar>
00100 void DefaultDiagonalLinearOp<Scalar>::initialize(
00101   const RCP<const VectorBase<Scalar> > &diag
00102   )
00103 {
00104   diag_.initialize(diag);
00105 }
00106 
00107 
00108 template<class Scalar>
00109 void DefaultDiagonalLinearOp<Scalar>::uninitialize()
00110 {
00111   diag_.uninitialize();
00112 }
00113 
00114 
00115 // Overridden from DiagonalLinearOpBase
00116 
00117 
00118 template<class Scalar>
00119 bool DefaultDiagonalLinearOp<Scalar>::isDiagConst() const
00120 {
00121   return diag_.isConst();
00122 }
00123 
00124 
00125 template<class Scalar>
00126 RCP<VectorBase<Scalar> > 
00127 DefaultDiagonalLinearOp<Scalar>::getNonconstDiag()
00128 {
00129   return diag_.getNonconstObj();
00130 }
00131 
00132 
00133 template<class Scalar>
00134 RCP<const VectorBase<Scalar> > 
00135 DefaultDiagonalLinearOp<Scalar>::getDiag() const
00136 {
00137   return diag_.getConstObj();
00138 }
00139 
00140 
00141 // Overridden from LinearOpBase
00142 
00143 
00144 template<class Scalar>
00145 RCP< const VectorSpaceBase<Scalar> >
00146 DefaultDiagonalLinearOp<Scalar>::range() const
00147 {
00148   return diag_.getConstObj()->space();
00149 }
00150 
00151 
00152 template<class Scalar>
00153 RCP< const VectorSpaceBase<Scalar> >
00154 DefaultDiagonalLinearOp<Scalar>::domain() const
00155 {
00156   return diag_.getConstObj()->space();
00157 }
00158 
00159 
00160 template<class Scalar>
00161 RCP<const LinearOpBase<Scalar> >
00162 DefaultDiagonalLinearOp<Scalar>::clone() const
00163 {
00164   return Teuchos::rcp(new DefaultDiagonalLinearOp<Scalar>(diag_.getConstObj()->clone_v()));
00165 }
00166 
00167 
00168 // protected
00169 
00170 
00171 // Protected functions overridden from LinearOpBase
00172 
00173 
00174 template<class Scalar>
00175 bool DefaultDiagonalLinearOp<Scalar>::opSupportedImpl(EOpTransp M_trans) const
00176 {
00177   return true;
00178 }
00179 
00180 
00181 template<class Scalar>
00182 void DefaultDiagonalLinearOp<Scalar>::applyImpl(
00183   const EOpTransp M_trans,
00184   const MultiVectorBase<Scalar> &X,
00185   const Ptr<MultiVectorBase<Scalar> > &Y,
00186   const Scalar alpha,
00187   const Scalar beta
00188   ) const
00189 {
00190   typedef Teuchos::ScalarTraits<Scalar> ST;
00191 
00192 #ifdef TEUCHOS_DEBUG
00193   THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(
00194     "DefaultDiagonalLinearOp<Scalar>::apply(...)",*this, M_trans, X, &*Y
00195     );
00196 #endif // TEUCHOS_DEBUG
00197 
00198   // Y = beta * Y
00199 
00200   if( beta != ST::one() ) scale<Scalar>(beta, Y);
00201 
00202   // Y += alpha *op(M) * X
00203 
00204   const Ordinal m = X.domain()->dim();
00205 
00206   for (Ordinal col_j = 0; col_j < m; ++col_j) {
00207     const RCP<const VectorBase<Scalar> > x = X.col(col_j);
00208     const RCP<VectorBase<Scalar> > y = Y->col(col_j);
00209     if (ST::isComplex) {
00210       if ( M_trans==NOTRANS || M_trans==TRANS ) {
00211         ele_wise_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
00212       }
00213       else {
00214         ele_wise_conj_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
00215       }
00216     }
00217     else {
00218       ele_wise_prod( alpha, *diag_.getConstObj(), *x, y.ptr() );
00219     }
00220   }
00221 
00222 }
00223 
00224 
00225 } // end namespace Thyra
00226 
00227 
00228 #endif  // THYRA_DIAGONAL_LINEAR_OP_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines