34 #ifndef ANASAZI_MATORTHOMANAGER_HPP 35 #define ANASAZI_MATORTHOMANAGER_HPP 62 template <
class ScalarType,
class MV,
class OP>
78 virtual void setOp( Teuchos::RCP<const OP> Op );
81 virtual Teuchos::RCP<const OP>
getOp()
const;
111 const MV& X,
const MV& Y,
112 Teuchos::SerialDenseMatrix<int,ScalarType>& Z,
113 Teuchos::RCP<const MV> MX = Teuchos::null,
114 Teuchos::RCP<const MV> MY = Teuchos::null
127 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec,
128 Teuchos::RCP<const MV> MX = Teuchos::null
143 Teuchos::Array<Teuchos::RCP<const MV> > Q,
144 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
145 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
146 Teuchos::RCP<MV> MX = Teuchos::null,
147 Teuchos::Array<Teuchos::RCP<const MV> > MQ
148 = Teuchos::tuple(Teuchos::RCP<const MV>(Teuchos::null))
165 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
166 Teuchos::RCP<MV> MX = Teuchos::null
186 Teuchos::Array<Teuchos::RCP<const MV> > Q,
187 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
188 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
189 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
190 Teuchos::RCP<MV> MX = Teuchos::null,
191 Teuchos::Array<Teuchos::RCP<const MV> > MQ
192 = Teuchos::tuple(Teuchos::RCP<const MV>(Teuchos::null))
199 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
200 orthonormErrorMat(
const MV &X, Teuchos::RCP<const MV> MX = Teuchos::null)
const = 0;
206 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
210 Teuchos::RCP<const MV> MX = Teuchos::null,
211 Teuchos::RCP<const MV> MY = Teuchos::null
226 void innerProd(
const MV& X,
const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z )
const;
235 void norm(
const MV& X, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec )
const;
246 Teuchos::Array<Teuchos::RCP<const MV> > Q,
247 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
248 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null))
258 int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null)
const;
269 Teuchos::Array<Teuchos::RCP<const MV> > Q,
270 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
271 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
272 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null
282 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
292 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
298 Teuchos::RCP<const OP> _Op;
300 mutable int _OpCounter;
304 template <
class ScalarType,
class MV,
class OP>
306 : _Op(Op), _hasOp(Op!=Teuchos::null), _OpCounter(0) {}
308 template <
class ScalarType,
class MV,
class OP>
312 _hasOp = (_Op != Teuchos::null);
315 template <
class ScalarType,
class MV,
class OP>
321 template <
class ScalarType,
class MV,
class OP>
327 template <
class ScalarType,
class MV,
class OP>
333 template <
class ScalarType,
class MV,
class OP>
335 const MV& X,
const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z )
const 337 typedef Teuchos::ScalarTraits<ScalarType> SCT;
341 Teuchos::RCP<const MV> P,Q;
346 if ( MVT::GetNumberVecs(X) < MVT::GetNumberVecs(Y) ) {
347 R = MVT::Clone(X,MVT::GetNumberVecs(X));
348 OPT::Apply(*_Op,X,*R);
349 _OpCounter += MVT::GetNumberVecs(X);
351 Q = Teuchos::rcpFromRef(Y);
354 P = Teuchos::rcpFromRef(X);
355 R = MVT::Clone(Y,MVT::GetNumberVecs(Y));
356 OPT::Apply(*_Op,Y,*R);
357 _OpCounter += MVT::GetNumberVecs(Y);
362 P = Teuchos::rcpFromRef(X);
363 Q = Teuchos::rcpFromRef(Y);
366 MVT::MvTransMv(SCT::one(),*P,*Q,Z);
369 template <
class ScalarType,
class MV,
class OP>
371 const MV& X,
const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z, Teuchos::RCP<const MV> MX, Teuchos::RCP<const MV> MY)
const 374 typedef Teuchos::ScalarTraits<ScalarType> SCT;
378 Teuchos::RCP<MV> P,Q;
380 if ( MY == Teuchos::null ) {
385 MVT::MvTransMv(SCT::one(),X,*MY,Z);
389 MVT::MvTransMv(SCT::one(),X,Y,Z);
392 for (
int j=0; j<Z.numCols(); j++) {
393 for (
int i=0; i<Z.numRows(); i++) {
394 TEUCHOS_TEST_FOR_EXCEPTION(SCT::isnaninf(Z(i,j)), std::logic_error,
395 "Anasazi::MatOrthoManager::innerProdMat(): detected NaN/inf.");
401 template <
class ScalarType,
class MV,
class OP>
403 const MV& X, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec )
const 405 this->normMat(X,normvec);
408 template <
class ScalarType,
class MV,
class OP>
411 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec,
412 Teuchos::RCP<const MV> MX)
const 414 typedef Teuchos::ScalarTraits<ScalarType> SCT;
415 typedef Teuchos::ScalarTraits<typename SCT::magnitudeType> MT;
419 int nvecs = MVT::GetNumberVecs(X);
425 if (normvec.size() <
static_cast<size_t>(nvecs))
426 normvec.resize (nvecs);
430 MX = Teuchos::rcp(&X,
false);
431 MVT::MvNorm(X, normvec);
438 if(MX == Teuchos::null) {
439 Teuchos::RCP<MV> tempVec = MVT::Clone(X,nvecs);
440 OPT::Apply(*_Op,X,*tempVec);
447 const int numColsMX = MVT::GetNumberVecs(*MX);
448 TEUCHOS_TEST_FOR_EXCEPTION(numColsMX < nvecs, std::invalid_argument,
449 "MatOrthoManager::norm(X, MX, normvec): " 450 "MX has fewer columns than X: " 451 "MX has " << numColsMX <<
" columns, " 452 "and X has " << nvecs <<
" columns.");
455 std::vector<ScalarType> dotvec(nvecs);
456 MVT::MvDot(X,*MX,dotvec);
457 for (
int i=0; i<nvecs; i++) {
458 normvec[i] = MT::squareroot( SCT::magnitude(dotvec[i]) );
463 template <
class ScalarType,
class MV,
class OP>
466 Teuchos::Array<Teuchos::RCP<const MV> > Q,
467 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
470 this->projectMat(X,Q,C);
473 template <
class ScalarType,
class MV,
class OP>
475 MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const 477 return this->normalizeMat(X,B);
480 template <
class ScalarType,
class MV,
class OP>
483 Teuchos::Array<Teuchos::RCP<const MV> > Q,
484 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
485 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B
488 return this->projectAndNormalizeMat(X,Q,C,B);
491 template <
class ScalarType,
class MV,
class OP>
492 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
495 return this->orthonormErrorMat(X,Teuchos::null);
498 template <
class ScalarType,
class MV,
class OP>
499 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
502 return this->orthogErrorMat(X1,X2);
void project(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null))) const
Implements the interface OrthoManager::project().
virtual void setOp(Teuchos::RCP< const OP > Op)
Set operator used for inner product.
Declaration of basic traits for the multivector type.
void norm(const MV &X, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Implements the interface OrthoManager::norm().
Virtual base class which defines basic traits for the operator type.
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogError(const MV &X1, const MV &X2) const
Implements the interface OrthoManager::orthogError().
virtual void projectMat(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)), Teuchos::RCP< MV > MX=Teuchos::null, Teuchos::Array< Teuchos::RCP< const MV > > MQ=Teuchos::tuple(Teuchos::RCP< const MV >(Teuchos::null))) const =0
Provides matrix-based projection method.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
int normalize(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null) const
Implements the interface OrthoManager::normalize().
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormErrorMat(const MV &X, Teuchos::RCP< const MV > MX=Teuchos::null) const =0
This method computes the error in orthonormality of a multivector.
MatOrthoManager(Teuchos::RCP< const OP > Op=Teuchos::null)
Default constructor.
Templated virtual class for providing orthogonalization/orthonormalization methods.
void normMat(const MV &X, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, Teuchos::RCP< const MV > MX=Teuchos::null) const
Provides the norm induced by the matrix-based inner product.
Traits class which defines basic operations on multivectors.
Virtual base class which defines basic traits for the operator type.
virtual ~MatOrthoManager()
Destructor.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
void innerProdMat(const MV &X, const MV &Y, Teuchos::SerialDenseMatrix< int, ScalarType > &Z, Teuchos::RCP< const MV > MX=Teuchos::null, Teuchos::RCP< const MV > MY=Teuchos::null) const
Provides a matrix-based inner product.
virtual Teuchos::RCP< const OP > getOp() const
Get operator used for inner product.
void resetOpCounter()
Reset the operator counter to zero.
int projectAndNormalize(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)), Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null) const
Implements the interface OrthoManager::projectAndNormalize().
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X) const
Implements the interface OrthoManager::orthonormError().
virtual int normalizeMat(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null, Teuchos::RCP< MV > MX=Teuchos::null) const =0
Provides matrix-based orthonormalization method.
int getOpCounter() const
Retrieve operator counter.
Types and exceptions used within Anasazi solvers and interfaces.
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogErrorMat(const MV &X, const MV &Y, Teuchos::RCP< const MV > MX=Teuchos::null, Teuchos::RCP< const MV > MY=Teuchos::null) const =0
This method computes the error in orthogonality of two multivectors.
void innerProd(const MV &X, const MV &Y, Teuchos::SerialDenseMatrix< int, ScalarType > &Z) const
Implements the interface OrthoManager::innerProd().
virtual int projectAndNormalizeMat(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)), Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null, Teuchos::RCP< MV > MX=Teuchos::null, Teuchos::Array< Teuchos::RCP< const MV > > MQ=Teuchos::tuple(Teuchos::RCP< const MV >(Teuchos::null))) const =0
Provides matrix-based projection/orthonormalization method.