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