00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #ifndef ANASAZI_THYRA_ADAPTER_HPP
00035 #define ANASAZI_THYRA_ADAPTER_HPP
00036
00037 #include "AnasaziMultiVecTraits.hpp"
00038 #include "AnasaziOperatorTraits.hpp"
00039 #include "AnasaziConfigDefs.hpp"
00040
00041 #include <Thyra_DetachedMultiVectorView.hpp>
00042 #include <Thyra_MultiVectorBaseDecl.hpp>
00043
00044 namespace Anasazi {
00045
00047
00048
00049
00051
00060 template<class ScalarType>
00061 class MultiVecTraits< ScalarType, Thyra::MultiVectorBase<ScalarType> >
00062 {
00063 private:
00064 typedef Thyra::MultiVectorBase<ScalarType> TMVB;
00065 public:
00066
00069
00074 static Teuchos::RCP<TMVB> Clone( const TMVB& mv, const int numvecs )
00075 {
00076 Teuchos::RCP<TMVB> c = Thyra::createMembers( mv.range(), numvecs );
00077 return c;
00078 }
00079
00084 static Teuchos::RCP<TMVB> CloneCopy( const TMVB& mv )
00085 {
00086 int numvecs = mv.domain()->dim();
00087
00088 Teuchos::RCP< TMVB > cc = Thyra::createMembers( mv.range(), numvecs );
00089
00090 Thyra::assign(&*cc, mv);
00091 return cc;
00092 }
00093
00099 static Teuchos::RCP<TMVB> CloneCopy( const TMVB& mv, const std::vector<int>& index )
00100 {
00101 int numvecs = index.size();
00102
00103 Teuchos::RCP< TMVB > cc = Thyra::createMembers( mv.range(), numvecs );
00104
00105 Teuchos::RCP< const TMVB > view = mv.subView( numvecs, &(index[0]) );
00106
00107 Thyra::assign(&*cc, *view);
00108 return cc;
00109 }
00110
00116 static Teuchos::RCP<TMVB> CloneView( TMVB& mv, const std::vector<int>& index )
00117 {
00118 int numvecs = index.size();
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 int lb = index[0];
00133 bool contig = true;
00134 for (int i=0; i<numvecs; i++) {
00135 if (lb+i != index[i]) contig = false;
00136 }
00137
00138 Teuchos::RCP< TMVB > cc;
00139 if (contig) {
00140 const Thyra::Range1D rng(lb,lb+numvecs-1);
00141
00142 cc = mv.subView(rng);
00143 }
00144 else {
00145
00146 cc = mv.subView( numvecs, &(index[0]) );
00147 }
00148 return cc;
00149 }
00150
00156 static Teuchos::RCP<const TMVB> CloneView( const TMVB& mv, const std::vector<int>& index )
00157 {
00158 int numvecs = index.size();
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 int lb = index[0];
00173 bool contig = true;
00174 for (int i=0; i<numvecs; i++) {
00175 if (lb+i != index[i]) contig = false;
00176 }
00177
00178 Teuchos::RCP< const TMVB > cc;
00179 if (contig) {
00180 const Thyra::Range1D rng(lb,lb+numvecs-1);
00181
00182 cc = mv.subView(rng);
00183 }
00184 else {
00185
00186 cc = mv.subView( numvecs, &(index[0]) );
00187 }
00188 return cc;
00189 }
00190
00192
00195
00197 static int GetVecLength( const TMVB& mv )
00198 { return mv.range()->dim(); }
00199
00201 static int GetNumberVecs( const TMVB& mv )
00202 { return mv.domain()->dim(); }
00203
00205
00208
00211 static void MvTimesMatAddMv( const ScalarType alpha, const TMVB& A,
00212 const Teuchos::SerialDenseMatrix<int,ScalarType>& B,
00213 const ScalarType beta, TMVB& mv )
00214 {
00215 int m = B.numRows();
00216 int n = B.numCols();
00217
00218 Teuchos::RCP< const TMVB >
00219 B_thyra = Thyra::createMembersView(
00220 A.domain()
00221 ,RTOpPack::ConstSubMultiVectorView<ScalarType>(0,m,0,n,&B(0,0),B.stride())
00222 );
00223
00224 A.apply(Thyra::NONCONJ_ELE,*B_thyra,&mv,alpha,beta);
00225 }
00226
00229 static void MvAddMv( const ScalarType alpha, const TMVB& A,
00230 const ScalarType beta, const TMVB& B, TMVB& mv )
00231 {
00232 ScalarType coef[2], zero = Teuchos::ScalarTraits<ScalarType>::zero();
00233 const TMVB * in[2];
00234
00235 in[0] = &A;
00236 in[1] = &B;
00237 coef[0] = alpha;
00238 coef[1] = beta;
00239
00240 Thyra::linear_combination(2,coef,in,zero,&mv);
00241 }
00242
00245 static void MvTransMv( const ScalarType alpha, const TMVB& A, const TMVB& mv,
00246 Teuchos::SerialDenseMatrix<int,ScalarType>& B )
00247 {
00248
00249 int m = A.domain()->dim();
00250 int n = mv.domain()->dim();
00251
00252 Teuchos::RCP< TMVB >
00253 B_thyra = Thyra::createMembersView(
00254 A.domain()
00255 ,RTOpPack::SubMultiVectorView<ScalarType>(0,m,0,n,&B(0,0),B.stride())
00256 );
00257 A.applyTranspose(Thyra::CONJ_ELE,mv,&*B_thyra,alpha,Teuchos::ScalarTraits<ScalarType>::zero());
00258 }
00259
00263 static void MvDot( const TMVB& mv, const TMVB& A, std::vector<ScalarType>* b )
00264 { Thyra::dots(mv,A,&((*b)[0])); }
00265
00268 static void MvScale ( TMVB& mv, const ScalarType alpha )
00269 { Thyra::scale(alpha,&mv); }
00270
00273 static void MvScale ( TMVB& mv, const std::vector<ScalarType>& alpha )
00274 {
00275 for (unsigned int i=0; i<alpha.size(); i++) {
00276 Thyra::scale(alpha[i],mv.col(i).get());
00277 }
00278 }
00279
00281
00284
00288 static void MvNorm( const TMVB& mv, std::vector<ScalarType>* normvec )
00289 { Thyra::norms_2(mv,&((*normvec)[0])); }
00290
00292
00295
00298 static void SetBlock( const TMVB& A, const std::vector<int>& index, TMVB& mv )
00299 {
00300
00301 int numvecs = index.size();
00302 std::vector<int> indexA(numvecs);
00303 int numAcols = A.domain()->dim();
00304 for (int i=0; i<numvecs; i++) {
00305 indexA[i] = i;
00306 }
00307
00308
00309 if ( numAcols < numvecs ) {
00310
00311
00312 numvecs = numAcols;
00313 }
00314 else if ( numAcols > numvecs ) {
00315 numAcols = numvecs;
00316 indexA.resize( numAcols );
00317 }
00318
00319 Teuchos::RCP< const TMVB > relsource = A.subView( numAcols, &(indexA[0]) );
00320
00321 Teuchos::RCP< TMVB > reldest = mv.subView( numvecs, &(index[0]) );
00322
00323 Thyra::assign(&*reldest, *relsource);
00324 }
00325
00328 static void MvRandom( TMVB& mv )
00329 {
00330
00331
00332 Thyra::randomize(-Teuchos::ScalarTraits<ScalarType>::one(),
00333 Teuchos::ScalarTraits<ScalarType>::one(),
00334 &mv);
00335 }
00336
00339 static void MvInit( TMVB& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() )
00340 { Thyra::assign(&mv,alpha); }
00341
00343
00346
00349 static void MvPrint( const TMVB& mv, ostream& os )
00350 { }
00351
00353
00354 };
00355
00357
00358
00359
00361
00371 template <class ScalarType>
00372 class OperatorTraits < ScalarType, Thyra::MultiVectorBase<ScalarType>, Thyra::LinearOpBase<ScalarType> >
00373 {
00374 private:
00375 typedef Thyra::MultiVectorBase<ScalarType> TMVB;
00376 typedef Thyra::LinearOpBase<ScalarType> TLOB;
00377 public:
00378
00382 static void Apply ( const TLOB& Op, const TMVB& x, TMVB& y )
00383 {
00384 Op.apply(Thyra::NONCONJ_ELE,x,&y);
00385 }
00386
00387 };
00388
00389 }
00390
00391 #endif
00392