15#ifndef ANASAZI_MATORTHOMANAGER_HPP
16#define ANASAZI_MATORTHOMANAGER_HPP
43 template <
class ScalarType,
class MV,
class OP>
59 virtual void setOp( Teuchos::RCP<const OP> Op );
62 virtual Teuchos::RCP<const OP>
getOp()
const;
92 const MV& X,
const MV& Y,
93 Teuchos::SerialDenseMatrix<int,ScalarType>& Z,
94 Teuchos::RCP<const MV> MX = Teuchos::null,
95 Teuchos::RCP<const MV> MY = Teuchos::null
108 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec,
109 Teuchos::RCP<const MV> MX = Teuchos::null
124 Teuchos::Array<Teuchos::RCP<const MV> > Q,
125 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
126 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
127 Teuchos::RCP<MV> MX = Teuchos::null,
128 Teuchos::Array<Teuchos::RCP<const MV> > MQ
129 = Teuchos::tuple(Teuchos::RCP<const MV>(Teuchos::null))
146 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
147 Teuchos::RCP<MV> MX = Teuchos::null
167 Teuchos::Array<Teuchos::RCP<const MV> > Q,
168 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
169 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
170 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null,
171 Teuchos::RCP<MV> MX = Teuchos::null,
172 Teuchos::Array<Teuchos::RCP<const MV> > MQ
173 = Teuchos::tuple(Teuchos::RCP<const MV>(Teuchos::null))
180 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
187 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
191 Teuchos::RCP<const MV> MX = Teuchos::null,
192 Teuchos::RCP<const MV> MY = Teuchos::null
207 void innerProd(
const MV& X,
const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z )
const;
216 void norm(
const MV& X, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec )
const;
227 Teuchos::Array<Teuchos::RCP<const MV> > Q,
228 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
229 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null))
239 int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null)
const;
250 Teuchos::Array<Teuchos::RCP<const MV> > Q,
251 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
252 = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,ScalarType> >(Teuchos::null)),
253 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B = Teuchos::null
263 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
273 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
279 Teuchos::RCP<const OP> _Op;
281 mutable int _OpCounter;
285 template <
class ScalarType,
class MV,
class OP>
287 : _Op(Op), _hasOp(Op!=Teuchos::null), _OpCounter(0) {}
289 template <
class ScalarType,
class MV,
class OP>
293 _hasOp = (_Op != Teuchos::null);
296 template <
class ScalarType,
class MV,
class OP>
302 template <
class ScalarType,
class MV,
class OP>
308 template <
class ScalarType,
class MV,
class OP>
314 template <
class ScalarType,
class MV,
class OP>
316 const MV& X,
const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z )
const
318 typedef Teuchos::ScalarTraits<ScalarType> SCT;
322 Teuchos::RCP<const MV> P,Q;
327 if ( MVT::GetNumberVecs(X) < MVT::GetNumberVecs(Y) ) {
328 R = MVT::Clone(X,MVT::GetNumberVecs(X));
329 OPT::Apply(*_Op,X,*R);
330 _OpCounter += MVT::GetNumberVecs(X);
332 Q = Teuchos::rcpFromRef(Y);
335 P = Teuchos::rcpFromRef(X);
336 R = MVT::Clone(Y,MVT::GetNumberVecs(Y));
337 OPT::Apply(*_Op,Y,*R);
338 _OpCounter += MVT::GetNumberVecs(Y);
343 P = Teuchos::rcpFromRef(X);
344 Q = Teuchos::rcpFromRef(Y);
347 MVT::MvTransMv(SCT::one(),*P,*Q,Z);
350 template <
class ScalarType,
class MV,
class OP>
352 const MV& X,
const MV& Y, Teuchos::SerialDenseMatrix<int,ScalarType>& Z, Teuchos::RCP<const MV> MX, Teuchos::RCP<const MV> MY)
const
355 typedef Teuchos::ScalarTraits<ScalarType> SCT;
359 Teuchos::RCP<MV> P,Q;
361 if ( MY == Teuchos::null ) {
366 MVT::MvTransMv(SCT::one(),X,*MY,Z);
370 MVT::MvTransMv(SCT::one(),X,Y,Z);
373 for (
int j=0; j<Z.numCols(); j++) {
374 for (
int i=0; i<Z.numRows(); i++) {
375 TEUCHOS_TEST_FOR_EXCEPTION(SCT::isnaninf(Z(i,j)), std::logic_error,
376 "Anasazi::MatOrthoManager::innerProdMat(): detected NaN/inf.");
382 template <
class ScalarType,
class MV,
class OP>
384 const MV& X, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec )
const
386 this->normMat(X,normvec);
389 template <
class ScalarType,
class MV,
class OP>
392 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &normvec,
393 Teuchos::RCP<const MV> MX)
const
395 typedef Teuchos::ScalarTraits<ScalarType> SCT;
396 typedef Teuchos::ScalarTraits<typename SCT::magnitudeType> MT;
400 int nvecs = MVT::GetNumberVecs(X);
406 if (normvec.size() <
static_cast<size_t>(nvecs))
407 normvec.resize (nvecs);
411 MX = Teuchos::rcp(&X,
false);
412 MVT::MvNorm(X, normvec);
419 if(MX == Teuchos::null) {
420 Teuchos::RCP<MV> tempVec = MVT::Clone(X,nvecs);
421 OPT::Apply(*_Op,X,*tempVec);
428 const int numColsMX = MVT::GetNumberVecs(*MX);
429 TEUCHOS_TEST_FOR_EXCEPTION(numColsMX < nvecs, std::invalid_argument,
430 "MatOrthoManager::norm(X, MX, normvec): "
431 "MX has fewer columns than X: "
432 "MX has " << numColsMX <<
" columns, "
433 "and X has " << nvecs <<
" columns.");
436 std::vector<ScalarType> dotvec(nvecs);
437 MVT::MvDot(X,*MX,dotvec);
438 for (
int i=0; i<nvecs; i++) {
439 normvec[i] = MT::squareroot( SCT::magnitude(dotvec[i]) );
444 template <
class ScalarType,
class MV,
class OP>
447 Teuchos::Array<Teuchos::RCP<const MV> > Q,
448 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C
451 this->projectMat(X,Q,C);
454 template <
class ScalarType,
class MV,
class OP>
456 MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const
458 return this->normalizeMat(X,B);
461 template <
class ScalarType,
class MV,
class OP>
464 Teuchos::Array<Teuchos::RCP<const MV> > Q,
465 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
466 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B
469 return this->projectAndNormalizeMat(X,Q,C,B);
472 template <
class ScalarType,
class MV,
class OP>
473 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
476 return this->orthonormErrorMat(X,Teuchos::null);
479 template <
class ScalarType,
class MV,
class OP>
480 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
483 return this->orthogErrorMat(X1,X2);
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Declaration of basic traits for the multivector type.
Virtual base class which defines basic traits for the operator type.
Templated virtual class for providing orthogonalization/orthonormalization methods.
Types and exceptions used within Anasazi solvers and interfaces.
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
MatOrthoManager(Teuchos::RCP< const OP > Op=Teuchos::null)
Default constructor.
virtual Teuchos::RCP< const OP > getOp() const
Get operator used for inner product.
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.
void innerProd(const MV &X, const MV &Y, Teuchos::SerialDenseMatrix< int, ScalarType > &Z) const
Implements the interface OrthoManager::innerProd().
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().
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().
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.
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.
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X) const
Implements the interface OrthoManager::orthonormError().
void norm(const MV &X, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Implements the interface OrthoManager::norm().
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.
virtual void setOp(Teuchos::RCP< const OP > Op)
Set operator used for inner product.
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.
virtual ~MatOrthoManager()
Destructor.
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.
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.
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogError(const MV &X1, const MV &X2) const
Implements the interface OrthoManager::orthogError().
int normalize(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B=Teuchos::null) const
Implements the interface OrthoManager::normalize().
int getOpCounter() const
Retrieve operator counter.
void resetOpCounter()
Reset the operator counter to zero.
Traits class which defines basic operations on multivectors.
Virtual base class which defines basic traits for the operator type.
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.