PlayaSimpleScaledOpImpl.hpp

00001 /* @HEADER@ */
00002 //   
00003  /* @HEADER@ */
00004 
00005 #ifndef PLAYA_SIMPLE_SCALED_OP_IMPL_HPP
00006 #define PLAYA_SIMPLE_SCALED_OP_IMPL_HPP
00007 
00008 
00009 
00010 #include "PlayaSimpleScaledOpDecl.hpp"
00011 #include "PlayaOut.hpp"
00012 #include "PlayaTabs.hpp"
00013 
00014 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00015 #include "PlayaLinearOperatorImpl.hpp"
00016 #endif
00017 
00018 
00019 namespace Playa
00020 {
00021 using namespace Teuchos;
00022 
00023 
00024 
00025 
00026 
00027 /*
00028  * --- scaled op
00029  */
00030 
00031 template <class Scalar> inline
00032 SimpleScaledOp<Scalar>::SimpleScaledOp(const Scalar& alpha,
00033   const LinearOperator<Scalar>& A)
00034   : LinearOpWithSpaces<Scalar>(
00035     A.domain(), A.range()
00036     ) 
00037   , alpha_(alpha), A_(A)
00038 {}
00039   
00040 /* */
00041 template <class Scalar> inline
00042 void SimpleScaledOp<Scalar>::apply(Teuchos::ETransp transApplyType,
00043   const Vector<Scalar>& in,
00044   Vector<Scalar> out) const
00045 {
00046   Tabs tab(0);
00047   PLAYA_MSG2(this->verb(), tab << "SimpleScaledOp::apply()");
00048 
00049   if (transApplyType == Teuchos::NO_TRANS)
00050     A_.apply(in, out);
00051   else if (transApplyType == Teuchos::TRANS)
00052     A_.applyTranspose(in, out);
00053   else 
00054     TEUCHOS_TEST_FOR_EXCEPT(transApplyType !=Teuchos::TRANS && transApplyType != Teuchos::NO_TRANS);
00055 
00056   out.scale(alpha_);
00057 
00058   PLAYA_MSG2(this->verb(), tab << "done SimpleScaledOp::apply()");
00059 }
00060   
00061 /* */
00062 template <class Scalar> inline
00063 std::string SimpleScaledOp<Scalar>::description() const 
00064 {
00065   return "ScaledOp[alpha="  + Teuchos::toString(alpha_)
00066     + ", " + A_.description() + "]";
00067 }
00068 
00069 
00070 /* */
00071 template <class Scalar> inline
00072 void SimpleScaledOp<Scalar>::print(std::ostream& os) const 
00073 {
00074   Tabs tab(0);
00075   os << tab << "ScaledOp[" << std::endl;
00076   Tabs tab1;
00077   os << tab1 << "scale = " << alpha_ << std::endl;
00078   os << tab1 << "operator = " << A_.description() << std::endl;
00079   os << tab << "]" << std::endl;
00080 }
00081 
00082 
00083 
00084 template <class Scalar> inline
00085 LinearOperator<Scalar> scaledOperator(
00086   const Scalar& scale,
00087   const LinearOperator<Scalar>& op)
00088 {
00089   RCP<LinearOperatorBase<Scalar> > A 
00090     = rcp(new SimpleScaledOp<Scalar>(scale, op));
00091 
00092   return A;
00093 }
00094 
00095 
00096 template <class Scalar> inline
00097 LinearOperator<Scalar> operator*(const Scalar& a, const LinearOperator<Scalar>& A)
00098 {
00099   return scaledOperator(a, A);
00100 }
00101   
00102 
00103 }
00104 
00105 #endif

doxygen