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_MATORTHOMANAGER_HPP
00035 #define ANASAZI_MATORTHOMANAGER_HPP
00036
00052 #include "AnasaziConfigDefs.hpp"
00053 #include "AnasaziTypes.hpp"
00054 #include "AnasaziOrthoManager.hpp"
00055 #include "AnasaziMultiVecTraits.hpp"
00056 #include "AnasaziOperatorTraits.hpp"
00057
00058 namespace Anasazi {
00059
00060 template <class ScalarType, class MV, class OP>
00061 class MatOrthoManager : public OrthoManager<ScalarType,MV> {
00062 public:
00064
00065
00066 MatOrthoManager(Teuchos::RCP<const OP> Op = Teuchos::null);
00067
00069 virtual ~MatOrthoManager() {};
00071
00073
00074
00076 void setOp( Teuchos::RCP<const OP> Op );
00077
00079 Teuchos::RCP<const OP> getOp() const;
00080
00082
00087 int getOpCounter() const;
00088
00090
00092 void resetOpCounter();
00093
00095
00097
00098
00108 void innerProdMat( const MV& X, const MV& Y, Teuchos::RCP<const MV> MY,
00109 Teuchos::SerialDenseMatrix<int,ScalarType>& Z ) const;
00110
00119 void normMat(const MV& X, Teuchos::RCP<const MV> MX,
00120 std::vector< typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > *normvec ) const;
00121
00126 virtual void projectMat (
00127 MV &X,
00128 Teuchos::RCP<MV> MX = Teuchos::null,
00129 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C = Teuchos::tuple(Teuchos::null),
00130 Teuchos::Array<Teuchos::RCP<const MV> > Q = Teuchos::tuple(Teuchos::null) ) const = 0;
00131
00136 virtual int normalizeMat (
00137 MV &X,
00138 Teuchos::RCP<MV> MX = Teuchos::null,
00139 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null ) const = 0;
00140
00141
00146 virtual int projectAndNormalizeMat (
00147 MV &X, Teuchos::RCP<MV> MX = Teuchos::null,
00148 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C = Teuchos::tuple(Teuchos::null),
00149 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
00150 Teuchos::Array<Teuchos::RCP<const MV> > Q = Teuchos::tuple(Teuchos::null) ) const = 0;
00151
00156 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
00157 orthonormErrorMat(const MV &X, Teuchos::RCP<const MV> MX = Teuchos::null) const = 0;
00158
00163 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
00164 orthogErrorMat(const MV &X1, Teuchos::RCP<const MV> MX1, const MV &X2) const = 0;
00165
00167
00169
00170
00178 void innerProd( const MV& X, const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z ) const;
00179
00187 void norm( const MV& X, std::vector< typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > *normvec ) const;
00188
00196 void project ( MV &X,
00197 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C = Teuchos::tuple(Teuchos::null),
00198 Teuchos::Array<Teuchos::RCP<const MV> > Q = Teuchos::tuple(Teuchos::null)) const;
00199
00207 int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null) const;
00208
00216 int projectAndNormalize ( MV &X,
00217 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C = Teuchos::tuple(Teuchos::null),
00218 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
00219 Teuchos::Array<Teuchos::RCP<const MV> > Q = Teuchos::tuple(Teuchos::null) ) const;
00220
00228 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
00229 orthonormError(const MV &X) const;
00230
00238 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
00239 orthogError(const MV &X1, const MV &X2) const;
00240
00242
00243 protected:
00244 Teuchos::RCP<const OP> _Op;
00245 bool _hasOp;
00246 mutable int _OpCounter;
00247
00248 };
00249
00250 template <class ScalarType, class MV, class OP>
00251 MatOrthoManager<ScalarType,MV,OP>::MatOrthoManager(Teuchos::RCP<const OP> Op)
00252 : _Op(Op), _hasOp(Op!=Teuchos::null) {}
00253
00254 template <class ScalarType, class MV, class OP>
00255 void MatOrthoManager<ScalarType,MV,OP>::setOp( Teuchos::RCP<const OP> Op )
00256 {
00257 _Op = Op;
00258 _hasOp = (_Op != Teuchos::null);
00259 }
00260
00261 template <class ScalarType, class MV, class OP>
00262 Teuchos::RCP<const OP> MatOrthoManager<ScalarType,MV,OP>::getOp() const
00263 {
00264 return _Op;
00265 }
00266
00267 template <class ScalarType, class MV, class OP>
00268 int MatOrthoManager<ScalarType,MV,OP>::getOpCounter() const
00269 {
00270 return _OpCounter;
00271 }
00272
00273 template <class ScalarType, class MV, class OP>
00274 void MatOrthoManager<ScalarType,MV,OP>::resetOpCounter()
00275 {
00276 _OpCounter = 0;
00277 }
00278
00279 template <class ScalarType, class MV, class OP>
00280 void MatOrthoManager<ScalarType,MV,OP>::innerProd(
00281 const MV& X, const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z ) const
00282 {
00283 typedef Teuchos::ScalarTraits<ScalarType> SCT;
00284 typedef MultiVecTraits<ScalarType,MV> MVT;
00285 typedef OperatorTraits<ScalarType,MV,OP> OPT;
00286
00287 Teuchos::RCP<const MV> P,Q;
00288 Teuchos::RCP<MV> R;
00289
00290 if (_hasOp) {
00291
00292 if ( MVT::GetNumberVecs(X) < MVT::GetNumberVecs(Y) ) {
00293 R = MVT::Clone(X,MVT::GetNumberVecs(X));
00294 OPT::Apply(*_Op,X,*R);
00295 _OpCounter += MVT::GetNumberVecs(X);
00296 P = R;
00297 Q = Teuchos::rcp( &Y, false );
00298 }
00299 else {
00300 P = Teuchos::rcp( &X, false );
00301 R = MVT::Clone(Y,MVT::GetNumberVecs(Y));
00302 OPT::Apply(*_Op,Y,*R);
00303 _OpCounter += MVT::GetNumberVecs(Y);
00304 Q = R;
00305 }
00306 }
00307 else {
00308 P = Teuchos::rcp( &X, false );
00309 Q = Teuchos::rcp( &Y, false );
00310 }
00311
00312 MVT::MvTransMv(SCT::one(),*P,*Q,Z);
00313 }
00314
00315 template <class ScalarType, class MV, class OP>
00316 void MatOrthoManager<ScalarType,MV,OP>::innerProdMat(
00317 const MV& X, const MV& Y, Teuchos::RCP<const MV> MY, Teuchos::SerialDenseMatrix<int,ScalarType>& Z ) const
00318 {
00319 typedef Teuchos::ScalarTraits<ScalarType> SCT;
00320 typedef MultiVecTraits<ScalarType,MV> MVT;
00321 typedef OperatorTraits<ScalarType,MV,OP> OPT;
00322
00323 Teuchos::RCP<MV> P,Q;
00324
00325 if ( MY == Teuchos::null ) {
00326 innerProd(X,Y,Z);
00327 }
00328 else if ( _hasOp ) {
00329
00330 MVT::MvTransMv(SCT::one(),X,*MY,Z);
00331 }
00332 else {
00333
00334 MVT::MvTransMv(SCT::one(),X,Y,Z);
00335 }
00336 }
00337
00338 template <class ScalarType, class MV, class OP>
00339 void MatOrthoManager<ScalarType,MV,OP>::norm(
00340 const MV& X, std::vector< typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > *normvec ) const
00341 {
00342 this->normMat(X,Teuchos::null,normvec);
00343 }
00344
00345 template <class ScalarType, class MV, class OP>
00346 void MatOrthoManager<ScalarType,MV,OP>::normMat(
00347 const MV& X, Teuchos::RCP<const MV> MX,
00348 std::vector< typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > *normvec ) const
00349 {
00350 typedef Teuchos::ScalarTraits<ScalarType> SCT;
00351 typedef MultiVecTraits<ScalarType,MV> MVT;
00352 typedef OperatorTraits<ScalarType,MV,OP> OPT;
00353
00354 if (!_hasOp) {
00355 MX = Teuchos::rcp(&X,false);
00356 }
00357 else if (MX == Teuchos::null) {
00358 Teuchos::RCP<MV> R = MVT::Clone(X,MVT::GetNumberVecs(X));
00359 OPT::Apply(*_Op,X,*R);
00360 _OpCounter += MVT::GetNumberVecs(X);
00361 MX = R;
00362 }
00363
00364 Teuchos::SerialDenseMatrix<int,ScalarType> z(1,1);
00365 Teuchos::RCP<const MV> Xi, MXi;
00366 std::vector<int> ind(1);
00367 for (int i=0; i<MVT::GetNumberVecs(X); i++) {
00368 ind[0] = i;
00369 Xi = MVT::CloneView(X,ind);
00370 MXi = MVT::CloneView(*MX,ind);
00371 MVT::MvTransMv(SCT::one(),*Xi,*MXi,z);
00372 (*normvec)[i] = SCT::magnitude( SCT::squareroot( z(0,0) ) );
00373 }
00374 }
00375
00376 template <class ScalarType, class MV, class OP>
00377 void MatOrthoManager<ScalarType,MV,OP>::project (
00378 MV &X,
00379 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
00380 Teuchos::Array<Teuchos::RCP<const MV> > Q) const
00381 {
00382 this->projectMat(X,Teuchos::null,C,Q);
00383 }
00384
00385 template <class ScalarType, class MV, class OP>
00386 int MatOrthoManager<ScalarType,MV,OP>::normalize (
00387 MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B ) const
00388 {
00389 return this->normalizeMat(X,Teuchos::null,B);
00390 }
00391
00392 template <class ScalarType, class MV, class OP>
00393 int MatOrthoManager<ScalarType,MV,OP>::projectAndNormalize (
00394 MV &X,
00395 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
00396 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
00397 Teuchos::Array<Teuchos::RCP<const MV> > Q ) const
00398 {
00399 return this->projectAndNormalizeMat(X,Teuchos::null,C,B,Q);
00400 }
00401
00402 template <class ScalarType, class MV, class OP>
00403 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
00404 MatOrthoManager<ScalarType,MV,OP>::orthonormError(const MV &X) const
00405 {
00406 return this->orthonormErrorMat(X,Teuchos::null);
00407 }
00408
00409 template <class ScalarType, class MV, class OP>
00410 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
00411 MatOrthoManager<ScalarType,MV,OP>::orthogError(const MV &X1, const MV &X2) const
00412 {
00413 return this->orthogErrorMat(X1,Teuchos::null,X2);
00414 }
00415
00416 }
00417
00418
00419 #endif
00420
00421