PlayaBelosAdapter.hpp

00001 /* @HEADER@ */
00002 //
00003  /* @HEADER@ */
00004 
00005 #ifndef BELOS_PLAYA_ADAPTER_HPP
00006 #define BELOS_PLAYA_ADAPTER_HPP
00007 
00008 
00009 #include "PlayaDefs.hpp"
00010 #include "PlayaAnasaziAdapter.hpp"
00011 #include "BelosMultiVecTraits.hpp"
00012 #include "BelosOperatorTraits.hpp"
00013 
00014 namespace Belos
00015 {
00016 
00017 
00018 using Playa::Vector;
00019 using Teuchos::RCP;
00020 using Teuchos::Array;
00021 using Anasazi::SimpleMV;
00022 
00024 template<> 
00025 class MultiVecTraits<double, SimpleMV>
00026 {
00027 public:
00028   typedef SimpleMV _MV;
00029   typedef Teuchos::ScalarTraits<double> SCT;
00030   typedef Anasazi::MultiVecTraits<double, _MV> AMVT;
00031 
00032   static double one() {static double rtn = SCT::one(); return rtn;}
00033   static double zero() {static double rtn = SCT::zero(); return rtn;}
00034   
00036   static RCP<_MV> Clone( const  _MV & mv, const int numvecs )
00037     {return AMVT::Clone(mv, numvecs);}
00038 
00040   static RCP< _MV > CloneCopy( const  _MV & mv )
00041     {return AMVT::CloneCopy(mv);}
00042 
00044   static RCP< _MV > CloneCopy( const  _MV & mv, const std::vector<int>& index )
00045     {return AMVT::CloneCopy(mv, index);}
00046 
00048   static RCP< _MV > CloneViewNonConst(  _MV & mv, 
00049     const std::vector<int>& index )
00050     {return AMVT::CloneViewNonConst(mv, index);}   
00051 
00053   static RCP<const _MV > CloneView( const _MV & mv, const std::vector<int>& index )
00054     {return AMVT::CloneView(mv, index);}
00055   
00057   static int GetVecLength( const  _MV & mv )
00058     {return AMVT::GetVecLength(mv);}
00059 
00061   static int GetNumberVecs( const  _MV & mv )
00062     {return AMVT::GetNumberVecs(mv);}
00063 
00064 
00066   static void MvTimesMatAddMv( const double alpha, const  _MV & A, 
00067     const Teuchos::SerialDenseMatrix<int,double>& B, 
00068     const double beta,  _MV & mv )
00069     {AMVT::MvTimesMatAddMv(alpha, A, B, beta, mv);}
00070 
00071   
00073   static void MvAddMv( const double alpha, const  _MV & A, 
00074     const double beta,  const  _MV & B,  _MV & mv )
00075     {AMVT::MvAddMv(alpha, A, beta, B, mv);}
00076 
00080   static void MvTransMv( const double alpha, const  _MV & A, const  _MV & mv, 
00081     Teuchos::SerialDenseMatrix<int,double>& B )
00082     {AMVT::MvTransMv(alpha, A, mv, B);}
00083 
00084   
00088   static void MvDot( const  _MV & mv, const  _MV & A, std::vector<double> &b )
00089     {AMVT::MvDot(mv, A, b);}
00090 
00091   
00094   static void MvScale (  _MV & mv, const double alpha )
00095     {AMVT::MvScale(mv, alpha);}
00096       
00097 
00098     
00101   static void MvScale (  _MV & mv, const std::vector<double>& alpha ) 
00102     {AMVT::MvScale(mv, alpha);}
00103     
00105   static void MvNorm( const  _MV & mv, 
00106     std::vector<Teuchos::ScalarTraits<double>::magnitudeType> &normvec,
00107     NormType type = TwoNorm)
00108     {
00109       normvec.resize(mv.size());
00110       for (int i=0; i<mv.size(); i++)
00111       {
00112         if (type==OneNorm) 
00113           normvec[i] = mv[i].norm1();
00114         else if (type==TwoNorm) 
00115           normvec[i] = mv[i].norm2();
00116         else 
00117           normvec[i] = mv[i].normInf();
00118       }
00119     }
00120 
00123   static void SetBlock( const  _MV & A, const std::vector<int>& index,  
00124     _MV & mv )
00125     {AMVT::SetBlock(A, index, mv);}
00126 
00129   static void MvRandom(  _MV & mv )
00130     {AMVT::MvRandom(mv);}
00131 
00134   static void MvInit(  _MV & mv, 
00135     double alpha = Teuchos::ScalarTraits<double>::zero() )
00136     { AMVT::MvInit(mv, alpha);}
00137     
00139   static void MvPrint( const  _MV & mv, std::ostream& os )
00140     { AMVT::MvPrint(mv, os);}
00141 
00142 
00143       
00144 };
00145 
00146 
00150 template <> 
00151 class OperatorTraits < double, SimpleMV, LinearOperator<double> >
00152 {
00153 public:
00154   typedef Anasazi::SimpleMV _MV;  
00155   typedef Anasazi::OperatorTraits<double, SimpleMV, LinearOperator<double> > AOPT;
00158   static void Apply ( 
00159     const LinearOperator< double >& Op, 
00160     const  _MV & x,  
00161     _MV & y,
00162     ETrans trans=NOTRANS
00163     )
00164     {
00165       if (trans==NOTRANS) AOPT::Apply(Op, x, y);
00166       else AOPT::Apply(Op.transpose(), x, y);
00167     }
00168     
00169 };
00170 
00171 
00172 
00173 }
00174 
00175 #endif

doxygen