TSFSimpleScaledOpImpl.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
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 TSF_SIMPLE_SCALED_OP_IMPL_HPP
00030 #define TSF_SIMPLE_SCALED_OP_IMPL_HPP
00031 
00032 
00033 
00034 #include "TSFSimpleScaledOpDecl.hpp"
00035 #include "SundanceOut.hpp"
00036 #include "SundanceTabs.hpp"
00037 
00038 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00039 #include "TSFLinearOperatorImpl.hpp"
00040 #include "TSFSimplifiedLinearOpBaseImpl.hpp"
00041 #endif
00042 
00043 
00044 namespace TSFExtended
00045 {
00046 using namespace Teuchos;
00047 using namespace Sundance;
00048 
00049 
00050 
00051 
00052 /*
00053  * --- scaled op
00054  */
00055 
00056 template <class Scalar> inline
00057 SimpleScaledOp<Scalar>::SimpleScaledOp(const Scalar& alpha,
00058   const LinearOperator<Scalar>& A)
00059   : SimplifiedLinearOpWithSpaces<Scalar>(
00060     A.domain(), A.range()
00061     ) 
00062   , alpha_(alpha), A_(A)
00063 {}
00064   
00065 /* */
00066 template <class Scalar> inline
00067 void SimpleScaledOp<Scalar>::applyOp(const Thyra::EOpTransp M_trans,
00068   const Vector<Scalar>& in,
00069   Vector<Scalar> out) const
00070 {
00071   Tabs tab(0);
00072   SUNDANCE_MSG2(this->verb(), tab << "SimpleScaledOp::applyOp()");
00073 
00074   if (M_trans == Thyra::NOTRANS)
00075     A_.apply(in, out);
00076   else if (M_trans == Thyra::TRANS)
00077     A_.applyTranspose(in, out);
00078   else 
00079     TEST_FOR_EXCEPT(M_trans !=Thyra::TRANS && M_trans != Thyra::NOTRANS);
00080 
00081   out.scale(alpha_);
00082 
00083   SUNDANCE_MSG2(this->verb(), tab << "done SimpleScaledOp::applyOp()");
00084 }
00085   
00086 /* */
00087 template <class Scalar> inline
00088 std::string SimpleScaledOp<Scalar>::description() const 
00089 {
00090   return "ScaledOp[alpha="  + Teuchos::toString(alpha_)
00091     + ", " + A_.description() + "]";
00092 }
00093 
00094 
00095 /* */
00096 template <class Scalar> inline
00097 void SimpleScaledOp<Scalar>::print(std::ostream& os) const 
00098 {
00099   Tabs tab(0);
00100   os << tab << "ScaledOp[" << std::endl;
00101   Tabs tab1;
00102   os << tab1 << "scale = " << alpha_ << std::endl;
00103   os << tab1 << "operator = " << A_.description() << std::endl;
00104   os << tab << "]" << std::endl;
00105 }
00106 
00107 
00108 
00109 template <class Scalar> inline
00110 LinearOperator<Scalar> scaledOperator(
00111   const Scalar& scale,
00112   const LinearOperator<Scalar>& op)
00113 {
00114   RCP<LinearOpBase<Scalar> > A 
00115     = rcp(new SimpleScaledOp<Scalar>(scale, op));
00116 
00117   return A;
00118 }
00119 
00120 
00121 template <class Scalar> inline
00122 LinearOperator<Scalar> operator*(const Scalar& a, const LinearOperator<Scalar>& A)
00123 {
00124   return scaledOperator(a, A);
00125 }
00126   
00127 
00128 }
00129 
00130 #endif

Site Contact