Anasazi Version of the Day
Loading...
Searching...
No Matches
AnasaziEpetraAdapter.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Anasazi: Block Eigensolvers Package
4//
5// Copyright 2004 NTESS and the Anasazi contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
14#ifndef ANASAZI_EPETRA_ADAPTER_HPP
15#define ANASAZI_EPETRA_ADAPTER_HPP
16
17#include "AnasaziConfigDefs.hpp"
18#include "Anasaziepetra_DLLExportMacro.h"
19#include "AnasaziTypes.hpp"
20#include "AnasaziMultiVec.hpp"
21#include "AnasaziOperator.hpp"
23
24#include "Teuchos_Assert.hpp"
25#include "Teuchos_SerialDenseMatrix.hpp"
26#include "Teuchos_FancyOStream.hpp"
27
28#include "Epetra_MultiVector.h"
29#include "Epetra_Vector.h"
30#include "Epetra_Operator.h"
31#include "Epetra_Map.h"
32#include "Epetra_LocalMap.h"
33#include "Epetra_Comm.h"
34
35#if defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
36# include <Tpetra_ConfigDefs.hpp> // HAVE_TPETRA_EPETRA
37# if defined(HAVE_TPETRA_EPETRA)
38# include <Epetra_TsqrAdaptor.hpp>
39# endif // defined(HAVE_TPETRA_EPETRA)
40#endif // defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
41
42namespace Anasazi {
43
45
46
50 class EpetraMultiVecFailure : public AnasaziError {public:
51 EpetraMultiVecFailure(const std::string& what_arg) : AnasaziError(what_arg)
52 {}};
53
57 class EpetraOpFailure : public AnasaziError {public:
58 EpetraOpFailure(const std::string& what_arg) : AnasaziError(what_arg)
59 {}};
60
62
64
65
70
71 public:
74
76 virtual Epetra_MultiVector* GetEpetraMultiVec() { return 0; }
77
79 virtual const Epetra_MultiVector* GetEpetraMultiVec() const { return 0; }
80 };
81
83
85 //
86 //--------template class AnasaziEpetraMultiVec-----------------
87 //
89
96 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraMultiVec : public MultiVec<double>, public Epetra_MultiVector, public EpetraMultiVecAccessor {
97 public:
99
100
102
107 EpetraMultiVec(const Epetra_BlockMap& Map_in, const int numvecs);
108
110 EpetraMultiVec(const Epetra_MultiVector & P_vec);
111
113
121 EpetraMultiVec(const Epetra_BlockMap& Map_in, double * array, const int numvecs, const int stride=0);
122
124
130 EpetraMultiVec(Epetra_DataAccess CV, const Epetra_MultiVector& P_vec, const std::vector<int>& index);
131
133 virtual ~EpetraMultiVec() {};
134
136
138
139
144 MultiVec<double> * Clone ( const int numvecs ) const;
145
151 MultiVec<double> * CloneCopy () const;
152
160 MultiVec<double> * CloneCopy ( const std::vector<int>& index ) const;
161
169 MultiVec<double> * CloneViewNonConst ( const std::vector<int>& index );
170
178 const MultiVec<double> * CloneView ( const std::vector<int>& index ) const;
179
181
183 ptrdiff_t GetGlobalLength () const
184 {
185 if ( Map().GlobalIndicesLongLong() )
186 return static_cast<ptrdiff_t>( GlobalLength64() );
187 else
188 return static_cast<ptrdiff_t>( GlobalLength() );
189 }
190
193 int GetNumberVecs () const { return NumVectors(); }
194
196
198
199
201 void MvTimesMatAddMv ( double alpha, const MultiVec<double>& A,
202 const Teuchos::SerialDenseMatrix<int,double>& B,
203 double beta );
204
207 void MvAddMv ( double alpha, const MultiVec<double>& A,
208 double beta, const MultiVec<double>& B);
209
212 void MvTransMv ( double alpha, const MultiVec<double>& A, Teuchos::SerialDenseMatrix<int,double>& B
213#ifdef HAVE_ANASAZI_EXPERIMENTAL
214 , ConjType conj = Anasazi::CONJ
215#endif
216 ) const;
217
220 void MvDot ( const MultiVec<double>& A, std::vector<double> &b
221#ifdef HAVE_ANASAZI_EXPERIMENTAL
222 , ConjType conj = Anasazi::CONJ
223#endif
224 ) const;
225
228 void MvScale ( double alpha ) {
229 TEUCHOS_TEST_FOR_EXCEPTION( this->Scale( alpha )!=0, EpetraMultiVecFailure,
230 "Anasazi::EpetraMultiVec::MvScale call to Epetra_MultiVector::Scale() returned a nonzero value.");
231 }
232
235 void MvScale ( const std::vector<double>& alpha );
236
238
240
244 void MvNorm ( std::vector<double> & normvec ) const {
245 if (((int)normvec.size() >= GetNumberVecs()) ) {
246 TEUCHOS_TEST_FOR_EXCEPTION( this->Norm2(&normvec[0])!=0, EpetraMultiVecFailure,
247 "Anasazi::EpetraMultiVec::MvNorm call to Epetra_MultiVector::Norm2() returned a nonzero value.");
248 }
249 };
251
253
254
259 void SetBlock ( const MultiVec<double>& A, const std::vector<int>& index );
260
263 void MvRandom() {
264 TEUCHOS_TEST_FOR_EXCEPTION( this->Random()!=0, EpetraMultiVecFailure,
265 "Anasazi::EpetraMultiVec::MvRandom call to Epetra_MultiVector::Random() returned a nonzero value.");
266 };
267
270 void MvInit ( double alpha ) {
271 TEUCHOS_TEST_FOR_EXCEPTION( this->PutScalar( alpha )!=0, EpetraMultiVecFailure,
272 "Anasazi::EpetraMultiVec::MvInit call to Epetra_MultiVector::PutScalar() returned a nonzero value.");
273 };
274
276
277
279 Epetra_MultiVector* GetEpetraMultiVec() { return this; };
280
282 const Epetra_MultiVector* GetEpetraMultiVec() const { return this; };
283
285
287
289
291 void MvPrint( std::ostream& os ) const { os << *this << std::endl; };
293
294 private:
295 };
296 //-------------------------------------------------------------
297
299 //
300 //--------template class AnasaziEpetraOp---------------------
301 //
303
310 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraOp : public virtual Operator<double> {
311 public:
313
314
316 EpetraOp(const Teuchos::RCP<Epetra_Operator> &Op );
317
319 ~EpetraOp();
321
323
324
328 void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
330
331 private:
332//use pragmas to disable some false-positive warnings for windows
333// sharedlibs export
334#ifdef _MSC_VER
335#pragma warning(push)
336#pragma warning(disable:4251)
337#endif
338 Teuchos::RCP<Epetra_Operator> Epetra_Op;
339#ifdef _MSC_VER
340#pragma warning(pop)
341#endif
342 };
343 //-------------------------------------------------------------
344
346 //
347 //--------template class AnasaziEpetraGenOp--------------------
348 //
350
364 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraGenOp : public virtual Operator<double>, public virtual Epetra_Operator {
365 public:
367
370 EpetraGenOp(const Teuchos::RCP<Epetra_Operator> &AOp,
371 const Teuchos::RCP<Epetra_Operator> &MOp,
372 bool isAInverse = true );
373
375 ~EpetraGenOp();
376
378
380 void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
381
383
385 int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
386
388
390 int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
391
393 const char* Label() const { return "Epetra_Operator applying A^{-1}M"; };
394
396 bool UseTranspose() const { return (false); };
397
399 int SetUseTranspose(bool /*UseTranspose_in*/) { return 0; };
400
402 bool HasNormInf() const { return (false); };
403
405 double NormInf() const { return (-1.0); };
406
408 const Epetra_Comm& Comm() const { return Epetra_AOp->Comm(); };
409
411 const Epetra_Map& OperatorDomainMap() const { return Epetra_AOp->OperatorDomainMap(); };
412
414 const Epetra_Map& OperatorRangeMap() const { return Epetra_AOp->OperatorRangeMap(); };
415
416 private:
417 bool isAInverse;
418
419//use pragmas to disable some false-positive warnings for windows
420// sharedlibs export
421#ifdef _MSC_VER
422#pragma warning(push)
423#pragma warning(disable:4251)
424#endif
425 Teuchos::RCP<Epetra_Operator> Epetra_AOp;
426 Teuchos::RCP<Epetra_Operator> Epetra_MOp;
427#ifdef _MSC_VER
428#pragma warning(pop)
429#endif
430 };
431
433 //
434 //--------template class AnasaziEpetraSymOp--------------------
435 //
437
450 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraSymOp : public virtual Operator<double>, public virtual Epetra_Operator {
451 public:
453
455 EpetraSymOp(const Teuchos::RCP<Epetra_Operator> &Op, bool isTrans = false );
456
458 ~EpetraSymOp();
459
461
463 void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
464
466
468 int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
469
471
474 int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
475
477 const char* Label() const { return "Epetra_Operator applying A^TA or AA^T"; };
478
480 bool UseTranspose() const { return (false); };
481
483 int SetUseTranspose(bool /*UseTranspose_in*/) { return 0; };
484
486 bool HasNormInf() const { return (false); };
487
489 double NormInf() const { return (-1.0); };
490
492 const Epetra_Comm& Comm() const { return Epetra_Op->Comm(); };
493
495 const Epetra_Map& OperatorDomainMap() const { return Epetra_Op->OperatorDomainMap(); };
496
498 const Epetra_Map& OperatorRangeMap() const { return Epetra_Op->OperatorRangeMap(); };
499
500 private:
501
502//use pragmas to disable false-positive warnings in generating windows sharedlib exports
503#ifdef _MSC_VER
504#pragma warning(push)
505#pragma warning(disable:4251)
506#endif
507 Teuchos::RCP<Epetra_Operator> Epetra_Op;
508#ifdef _MSC_VER
509#pragma warning(pop)
510#endif
511
512 bool isTrans_;
513 };
514
515
517 //
518 //--------template class AnasaziEpetraSymMVOp---------------------
519 //
521
534 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraSymMVOp : public virtual Operator<double> {
535 public:
537
539 EpetraSymMVOp(const Teuchos::RCP<const Epetra_MultiVector> &MV,
540 bool isTrans = false );
541
544
546
548 void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
549
550 private:
551
552//use pragmas to disable some false-positive warnings for windows
553// sharedlibs export
554#ifdef _MSC_VER
555#pragma warning(push)
556#pragma warning(disable:4251)
557#endif
558 Teuchos::RCP<const Epetra_MultiVector> Epetra_MV;
559 Teuchos::RCP<const Epetra_Map> MV_localmap;
560 Teuchos::RCP<const Epetra_BlockMap> MV_blockmap;
561#ifdef _MSC_VER
562#pragma warning(pop)
563#endif
564
565 bool isTrans_;
566 };
567
569 //
570 //--------template class AnasaziEpetraWSymMVOp---------------------
571 //
573
586 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraWSymMVOp : public virtual Operator<double> {
587 public:
589 EpetraWSymMVOp(const Teuchos::RCP<const Epetra_MultiVector> &MV,
590 const Teuchos::RCP<Epetra_Operator> &OP );
591
594
596
598 void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
599
600 private:
601//use pragmas to disable some false-positive warnings for windows
602// sharedlibs export
603#ifdef _MSC_VER
604#pragma warning(push)
605#pragma warning(disable:4251)
606#endif
607 Teuchos::RCP<const Epetra_MultiVector> Epetra_MV;
608 Teuchos::RCP<Epetra_Operator> Epetra_OP;
609 Teuchos::RCP<Epetra_MultiVector> Epetra_WMV;
610 Teuchos::RCP<const Epetra_Map> MV_localmap;
611 Teuchos::RCP<const Epetra_BlockMap> MV_blockmap;
612#ifdef _MSC_VER
613#pragma warning(pop)
614#endif
615 };
616
618 //
619 //--------template class AnasaziEpetraW2SymMVOp---------------------
620 //
622
635 class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraW2SymMVOp : public virtual Operator<double> {
636 public:
638 EpetraW2SymMVOp(const Teuchos::RCP<const Epetra_MultiVector> &MV,
639 const Teuchos::RCP<Epetra_Operator> &OP );
640
643
645
647 void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
648
649 private:
650//use pragmas to disable some false-positive warnings for windows
651// sharedlibs export
652#ifdef _MSC_VER
653#pragma warning(push)
654#pragma warning(disable:4251)
655#endif
656 Teuchos::RCP<const Epetra_MultiVector> Epetra_MV;
657 Teuchos::RCP<Epetra_Operator> Epetra_OP;
658 Teuchos::RCP<Epetra_MultiVector> Epetra_WMV;
659 Teuchos::RCP<const Epetra_Map> MV_localmap;
660 Teuchos::RCP<const Epetra_BlockMap> MV_blockmap;
661#ifdef _MSC_VER
662#pragma warning(pop)
663#endif
664 };
665
666
668 //
669 // Implementation of the Anasazi::MultiVecTraits for Epetra::MultiVector.
670 //
672
683 template<>
684 class MultiVecTraits<double, Epetra_MultiVector>
685 {
686 public:
687
689
690
695 static Teuchos::RCP<Epetra_MultiVector>
696 Clone (const Epetra_MultiVector& mv, const int outNumVecs)
697 {
698 TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs <= 0, std::invalid_argument,
699 "Belos::MultiVecTraits<double, Epetra_MultiVector>::"
700 "Clone(mv, outNumVecs = " << outNumVecs << "): "
701 "outNumVecs must be positive.");
702 // FIXME (mfh 13 Jan 2011) Anasazi currently lets Epetra fill in
703 // the entries of the returned multivector with zeros, but Belos
704 // does not. We retain this different behavior for now, but the
705 // two versions will need to be reconciled.
706 return Teuchos::rcp (new Epetra_MultiVector (mv.Map(), outNumVecs));
707 }
708
713 static Teuchos::RCP<Epetra_MultiVector>
714 CloneCopy (const Epetra_MultiVector& mv)
715 {
716 return Teuchos::rcp (new Epetra_MultiVector (mv));
717 }
718
724 static Teuchos::RCP<Epetra_MultiVector>
725 CloneCopy (const Epetra_MultiVector& mv, const std::vector<int>& index)
726 {
727 const int inNumVecs = GetNumberVecs (mv);
728 const int outNumVecs = index.size();
729
730 // Simple, inexpensive tests of the index vector.
731 TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
732 "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
733 "CloneCopy(mv, index = {}): At least one vector must be"
734 " cloned from mv.");
735 if (outNumVecs > inNumVecs)
736 {
737 std::ostringstream os;
738 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
739 "CloneCopy(mv, index = {";
740 for (int k = 0; k < outNumVecs - 1; ++k)
741 os << index[k] << ", ";
742 os << index[outNumVecs-1] << "}): There are " << outNumVecs
743 << " indices to copy, but only " << inNumVecs << " columns of mv.";
744 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
745 }
746#ifdef TEUCHOS_DEBUG
747 // In debug mode, we perform more expensive tests of the index
748 // vector, to ensure all the elements are in range.
749 // Dereferencing the iterator is valid because index has length
750 // > 0.
751 const int minIndex = *std::min_element (index.begin(), index.end());
752 const int maxIndex = *std::max_element (index.begin(), index.end());
753
754 if (minIndex < 0)
755 {
756 std::ostringstream os;
757 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
758 "CloneCopy(mv, index = {";
759 for (int k = 0; k < outNumVecs - 1; ++k)
760 os << index[k] << ", ";
761 os << index[outNumVecs-1] << "}): Indices must be nonnegative, but "
762 "the smallest index " << minIndex << " is negative.";
763 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
764 }
765 if (maxIndex >= inNumVecs)
766 {
767 std::ostringstream os;
768 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
769 "CloneCopy(mv, index = {";
770 for (int k = 0; k < outNumVecs - 1; ++k)
771 os << index[k] << ", ";
772 os << index[outNumVecs-1] << "}): Indices must be strictly less than "
773 "the number of vectors " << inNumVecs << " in mv; the largest index "
774 << maxIndex << " is out of bounds.";
775 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
776 }
777#endif // TEUCHOS_DEBUG
778 // Cast to nonconst, because Epetra_MultiVector's constructor
779 // wants a nonconst int array argument. It doesn't actually
780 // change the entries of the array.
781 std::vector<int>& tmpind = const_cast< std::vector<int>& > (index);
782 return Teuchos::rcp (new Epetra_MultiVector (Epetra_DataAccess::Copy, mv, &tmpind[0], index.size()));
783 }
784
785 static Teuchos::RCP<Epetra_MultiVector>
786 CloneCopy (const Epetra_MultiVector& mv, const Teuchos::Range1D& index)
787 {
788 const int inNumVecs = GetNumberVecs (mv);
789 const int outNumVecs = index.size();
790 const bool validRange = outNumVecs > 0 && index.lbound() >= 0 &&
791 index.ubound() < inNumVecs;
792 if (! validRange)
793 {
794 std::ostringstream os;
795 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::Clone(mv,"
796 "index=[" << index.lbound() << ", " << index.ubound() << "]): ";
797 TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
798 os.str() << "Column index range must be nonempty.");
799 TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
800 os.str() << "Column index range must be nonnegative.");
801 TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= inNumVecs, std::invalid_argument,
802 os.str() << "Column index range must not exceed "
803 "number of vectors " << inNumVecs << " in the "
804 "input multivector.");
805 }
806 return Teuchos::rcp (new Epetra_MultiVector (Epetra_DataAccess::Copy, mv, index.lbound(), index.size()));
807 }
808
814 static Teuchos::RCP<Epetra_MultiVector>
815 CloneViewNonConst (Epetra_MultiVector& mv, const std::vector<int>& index)
816 {
817 const int inNumVecs = GetNumberVecs (mv);
818 const int outNumVecs = index.size();
819
820 // Simple, inexpensive tests of the index vector.
821 TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
822 "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
823 "CloneViewNonConst(mv, index = {}): The output view "
824 "must have at least one column.");
825 if (outNumVecs > inNumVecs)
826 {
827 std::ostringstream os;
828 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
829 "CloneViewNonConst(mv, index = {";
830 for (int k = 0; k < outNumVecs - 1; ++k)
831 os << index[k] << ", ";
832 os << index[outNumVecs-1] << "}): There are " << outNumVecs
833 << " indices to view, but only " << inNumVecs << " columns of mv.";
834 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
835 }
836#ifdef TEUCHOS_DEBUG
837 // In debug mode, we perform more expensive tests of the index
838 // vector, to ensure all the elements are in range.
839 // Dereferencing the iterator is valid because index has length
840 // > 0.
841 const int minIndex = *std::min_element (index.begin(), index.end());
842 const int maxIndex = *std::max_element (index.begin(), index.end());
843
844 if (minIndex < 0)
845 {
846 std::ostringstream os;
847 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
848 "CloneViewNonConst(mv, index = {";
849 for (int k = 0; k < outNumVecs - 1; ++k)
850 os << index[k] << ", ";
851 os << index[outNumVecs-1] << "}): Indices must be nonnegative, but "
852 "the smallest index " << minIndex << " is negative.";
853 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
854 }
855 if (maxIndex >= inNumVecs)
856 {
857 std::ostringstream os;
858 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
859 "CloneViewNonConst(mv, index = {";
860 for (int k = 0; k < outNumVecs - 1; ++k)
861 os << index[k] << ", ";
862 os << index[outNumVecs-1] << "}): Indices must be strictly less than "
863 "the number of vectors " << inNumVecs << " in mv; the largest index "
864 << maxIndex << " is out of bounds.";
865 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
866 }
867#endif // TEUCHOS_DEBUG
868 // Cast to nonconst, because Epetra_MultiVector's constructor
869 // wants a nonconst int array argument. It doesn't actually
870 // change the entries of the array.
871 std::vector<int>& tmpind = const_cast< std::vector<int>& > (index);
872 return Teuchos::rcp (new Epetra_MultiVector (Epetra_DataAccess::View, mv, &tmpind[0], index.size()));
873 }
874
875 static Teuchos::RCP<Epetra_MultiVector>
876 CloneViewNonConst (Epetra_MultiVector& mv, const Teuchos::Range1D& index)
877 {
878 const bool validRange = index.size() > 0 &&
879 index.lbound() >= 0 &&
880 index.ubound() < mv.NumVectors();
881 if (! validRange)
882 {
883 std::ostringstream os;
884 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::CloneView"
885 "NonConst(mv,index=[" << index.lbound() << ", " << index.ubound()
886 << "]): ";
887 TEUCHOS_TEST_FOR_EXCEPTION(index.size() == 0, std::invalid_argument,
888 os.str() << "Column index range must be nonempty.");
889 TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
890 os.str() << "Column index range must be nonnegative.");
891 TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= mv.NumVectors(),
892 std::invalid_argument,
893 os.str() << "Column index range must not exceed "
894 "number of vectors " << mv.NumVectors() << " in "
895 "the input multivector.");
896 }
897 return Teuchos::rcp (new Epetra_MultiVector (Epetra_DataAccess::View, mv, index.lbound(), index.size()));
898 }
899
905 static Teuchos::RCP<const Epetra_MultiVector>
906 CloneView (const Epetra_MultiVector& mv, const std::vector<int>& index)
907 {
908 const int inNumVecs = GetNumberVecs (mv);
909 const int outNumVecs = index.size();
910
911 // Simple, inexpensive tests of the index vector.
912 TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
913 "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
914 "CloneView(mv, index = {}): The output view "
915 "must have at least one column.");
916 if (outNumVecs > inNumVecs)
917 {
918 std::ostringstream os;
919 os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
920 "CloneView(mv, index = {";
921 for (int k = 0; k < outNumVecs - 1; ++k)
922 os << index[k] << ", ";
923 os << index[outNumVecs-1] << "}): There are " << outNumVecs
924 << " indices to view, but only " << inNumVecs << " columns of mv.";
925 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
926 }
927#ifdef TEUCHOS_DEBUG
928 // In debug mode, we perform more expensive tests of the index
929 // vector, to ensure all the elements are in range.
930 // Dereferencing the iterator is valid because index has length
931 // > 0.
932 const int minIndex = *std::min_element (index.begin(), index.end());
933 const int maxIndex = *std::max_element (index.begin(), index.end());
934
935 if (minIndex < 0)
936 {
937 std::ostringstream os;
938 os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
939 "CloneView(mv, index = {";
940 for (int k = 0; k < outNumVecs - 1; ++k)
941 os << index[k] << ", ";
942 os << index[outNumVecs-1] << "}): Indices must be nonnegative, but "
943 "the smallest index " << minIndex << " is negative.";
944 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
945 }
946 if (maxIndex >= inNumVecs)
947 {
948 std::ostringstream os;
949 os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
950 "CloneView(mv, index = {";
951 for (int k = 0; k < outNumVecs - 1; ++k)
952 os << index[k] << ", ";
953 os << index[outNumVecs-1] << "}): Indices must be strictly less than "
954 "the number of vectors " << inNumVecs << " in mv; the largest index "
955 << maxIndex << " is out of bounds.";
956 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
957 }
958#endif // TEUCHOS_DEBUG
959 // Cast to nonconst, because Epetra_MultiVector's constructor
960 // wants a nonconst int array argument. It doesn't actually
961 // change the entries of the array.
962 std::vector<int>& tmpind = const_cast< std::vector<int>& > (index);
963 return Teuchos::rcp (new Epetra_MultiVector (Epetra_DataAccess::View, mv, &tmpind[0], index.size()));
964 }
965
966 static Teuchos::RCP<Epetra_MultiVector>
967 CloneView (const Epetra_MultiVector& mv, const Teuchos::Range1D& index)
968 {
969 const bool validRange = index.size() > 0 &&
970 index.lbound() >= 0 &&
971 index.ubound() < mv.NumVectors();
972 if (! validRange)
973 {
974 std::ostringstream os;
975 os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::CloneView"
976 "(mv,index=[" << index.lbound() << ", " << index.ubound()
977 << "]): ";
978 TEUCHOS_TEST_FOR_EXCEPTION(index.size() == 0, std::invalid_argument,
979 os.str() << "Column index range must be nonempty.");
980 TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
981 os.str() << "Column index range must be nonnegative.");
982 TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= mv.NumVectors(),
983 std::invalid_argument,
984 os.str() << "Column index range must not exceed "
985 "number of vectors " << mv.NumVectors() << " in "
986 "the input multivector.");
987 }
988 return Teuchos::rcp (new Epetra_MultiVector(Epetra_DataAccess::View, mv, index.lbound(), index.size()));
989 }
990
992
994
995
997 static ptrdiff_t GetGlobalLength( const Epetra_MultiVector& mv )
998 {
999 if (mv.Map().GlobalIndicesLongLong())
1000 return static_cast<ptrdiff_t>( mv.GlobalLength64() );
1001 else
1002 return static_cast<ptrdiff_t>( mv.GlobalLength() );
1003 }
1004
1006 static int GetNumberVecs( const Epetra_MultiVector& mv )
1007 { return mv.NumVectors(); }
1008
1009 static bool HasConstantStride( const Epetra_MultiVector& mv )
1010 { return mv.ConstantStride(); }
1012
1014
1015
1018 static void MvTimesMatAddMv( double alpha, const Epetra_MultiVector& A,
1019 const Teuchos::SerialDenseMatrix<int,double>& B,
1020 double beta, Epetra_MultiVector& mv )
1021 {
1022 Epetra_LocalMap LocalMap(B.numRows(), 0, mv.Map().Comm());
1023 Epetra_MultiVector B_Pvec(Epetra_DataAccess::View, LocalMap, B.values(), B.stride(), B.numCols());
1024
1025 TEUCHOS_TEST_FOR_EXCEPTION( mv.Multiply( 'N', 'N', alpha, A, B_Pvec, beta )!=0, EpetraMultiVecFailure,
1026 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvTimesMatAddMv call to Epetra_MultiVector::Multiply() returned a nonzero value.");
1027 }
1028
1031 static void MvAddMv( double alpha, const Epetra_MultiVector& A, double beta, const Epetra_MultiVector& B, Epetra_MultiVector& mv )
1032 {
1033 // epetra mv.Update(alpha,A,beta,B,gamma) will check
1034 // alpha == 0.0
1035 // and
1036 // beta == 0.0
1037 // and based on this will call
1038 // mv.Update(beta,B,gamma)
1039 // or
1040 // mv.Update(alpha,A,gamma)
1041 //
1042 // mv.Update(alpha,A,gamma)
1043 // will then check for one of
1044 // gamma == 0
1045 // or
1046 // gamma == 1
1047 // or
1048 // alpha == 1
1049 // in that order. however, it will not look for the combination
1050 // alpha == 1 and gamma = 0
1051 // which is a common use case when we wish to assign
1052 // mv = A (in which case alpha == 1, beta == gamma == 0)
1053 // or
1054 // mv = B (in which case beta == 1, alpha == gamma == 0)
1055 //
1056 // therefore, we will check for these use cases ourselves
1057 if (beta == 0.0) {
1058 if (alpha == 1.0) {
1059 // assign
1060 mv = A;
1061 }
1062 else {
1063 // single update
1064 TEUCHOS_TEST_FOR_EXCEPTION( mv.Update( alpha, A, 0.0 )!=0, EpetraMultiVecFailure,
1065 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvAddMv call to Epetra_MultiVector::Update(alpha,A,0.0) returned a nonzero value.");
1066 }
1067 }
1068 else if (alpha == 0.0) {
1069 if (beta == 1.0) {
1070 // assign
1071 mv = B;
1072 }
1073 else {
1074 // single update
1075 TEUCHOS_TEST_FOR_EXCEPTION( mv.Update( beta, B, 0.0 )!=0, EpetraMultiVecFailure,
1076 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvAddMv call to Epetra_MultiVector::Update(beta,B,0.0) returned a nonzero value.");
1077 }
1078 }
1079 else {
1080 // double update
1081 TEUCHOS_TEST_FOR_EXCEPTION( mv.Update( alpha, A, beta, B, 0.0 )!=0, EpetraMultiVecFailure,
1082 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvAddMv call to Epetra_MultiVector::Update(alpha,A,beta,B,0.0) returned a nonzero value.");
1083 }
1084 }
1085
1088 static void MvTransMv( double alpha, const Epetra_MultiVector& A, const Epetra_MultiVector& mv, Teuchos::SerialDenseMatrix<int,double>& B
1089#ifdef HAVE_ANASAZI_EXPERIMENTAL
1090 , ConjType conj = Anasazi::CONJ
1091#endif
1092 )
1093 {
1094 Epetra_LocalMap LocalMap(B.numRows(), 0, mv.Map().Comm());
1095 Epetra_MultiVector B_Pvec(Epetra_DataAccess::View, LocalMap, B.values(), B.stride(), B.numCols());
1096
1097 TEUCHOS_TEST_FOR_EXCEPTION( B_Pvec.Multiply( 'T', 'N', alpha, A, mv, 0.0 )!=0, EpetraMultiVecFailure,
1098 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvTransMv call to Epetra_MultiVector::Multiply() returned a nonzero value.");
1099 }
1100
1103 static void MvDot( const Epetra_MultiVector& A, const Epetra_MultiVector& B, std::vector<double> &b
1104#ifdef HAVE_ANASAZI_EXPERIMENTAL
1105 , ConjType conj = Anasazi::CONJ
1106#endif
1107 )
1108 {
1109#ifdef TEUCHOS_DEBUG
1110 TEUCHOS_TEST_FOR_EXCEPTION(A.NumVectors() != B.NumVectors(),std::invalid_argument,
1111 "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::MvDot(A,B,b): A and B must have the same number of vectors.");
1112 TEUCHOS_TEST_FOR_EXCEPTION(b.size() != (unsigned int)A.NumVectors(),std::invalid_argument,
1113 "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::MvDot(A,B,b): b must have room for all dot products.");
1114#endif
1115 TEUCHOS_TEST_FOR_EXCEPTION( A.Dot( B, &b[0] )!=0, EpetraMultiVecFailure,
1116 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvDot(A,B,b) call to Epetra_MultiVector::Dot() returned a nonzero value.");
1117 }
1118
1120
1122
1126 static void MvNorm( const Epetra_MultiVector& mv, std::vector<double> &normvec )
1127 {
1128#ifdef TEUCHOS_DEBUG
1129 TEUCHOS_TEST_FOR_EXCEPTION((unsigned int)mv.NumVectors() != normvec.size(),std::invalid_argument,
1130 "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::MvNorm(mv,normvec): normvec must be the same size of mv.");
1131#endif
1132 TEUCHOS_TEST_FOR_EXCEPTION( mv.Norm2(&normvec[0])!=0, EpetraMultiVecFailure,
1133 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvNorm call to Epetra_MultiVector::Norm2() returned a nonzero value.");
1134 }
1135
1137
1139
1140
1142 static void
1143 SetBlock (const Epetra_MultiVector& A,
1144 const std::vector<int>& index,
1145 Epetra_MultiVector& mv)
1146 {
1147 const int inNumVecs = GetNumberVecs (A);
1148 const int outNumVecs = index.size();
1149
1150 // FIXME (mfh 13 Jan 2011) Belos allows A to have more columns
1151 // than index.size(), in which case we just take the first
1152 // index.size() columns of A. Anasazi requires that A have the
1153 // same number of columns as index.size(). Changing Anasazi's
1154 // behavior should not break existing Anasazi solvers, but the
1155 // tests need to be done.
1156 if (inNumVecs != outNumVecs)
1157 {
1158 std::ostringstream os;
1159 os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
1160 "SetBlock(A, mv, index = {";
1161 if (outNumVecs > 0)
1162 {
1163 for (int k = 0; k < outNumVecs - 1; ++k)
1164 os << index[k] << ", ";
1165 os << index[outNumVecs-1];
1166 }
1167 os << "}): A has only " << inNumVecs << " columns, but there are "
1168 << outNumVecs << " indices in the index vector.";
1169 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
1170 }
1171 // Make a view of the columns of mv indicated by the index std::vector.
1172 Teuchos::RCP<Epetra_MultiVector> mv_view = CloneViewNonConst (mv, index);
1173
1174 // View of columns [0, outNumVecs-1] of the source multivector A.
1175 // If A has fewer columns than mv_view, then create a view of
1176 // the first outNumVecs columns of A.
1177 Teuchos::RCP<const Epetra_MultiVector> A_view;
1178 if (outNumVecs == inNumVecs)
1179 A_view = Teuchos::rcpFromRef (A); // Const, non-owning RCP
1180 else
1181 A_view = CloneView (A, Teuchos::Range1D(0, outNumVecs - 1));
1182
1183 // Assignment calls Epetra_MultiVector::Assign(), which deeply
1184 // copies the data directly, ignoring the underlying
1185 // Epetra_Map(s). If A and mv don't have the same data
1186 // distribution (Epetra_Map), this may result in incorrect or
1187 // undefined behavior. Epetra_MultiVector::Update() also
1188 // ignores the Epetra_Maps, so we might as well just use the
1189 // (perhaps slightly cheaper) Assign() method via operator=().
1190 *mv_view = *A_view;
1191 }
1192
1193 static void
1194 SetBlock (const Epetra_MultiVector& A,
1195 const Teuchos::Range1D& index,
1196 Epetra_MultiVector& mv)
1197 {
1198 const int numColsA = A.NumVectors();
1199 const int numColsMv = mv.NumVectors();
1200 // 'index' indexes into mv; it's the index set of the target.
1201 const bool validIndex = index.lbound() >= 0 && index.ubound() < numColsMv;
1202 // We can't take more columns out of A than A has.
1203 const bool validSource = index.size() <= numColsA;
1204
1205 if (! validIndex || ! validSource)
1206 {
1207 std::ostringstream os;
1208 os << "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::SetBlock"
1209 "(A, index=[" << index.lbound() << ", " << index.ubound() << "], "
1210 "mv): ";
1211 TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
1212 os.str() << "Range lower bound must be nonnegative.");
1213 TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= numColsMv, std::invalid_argument,
1214 os.str() << "Range upper bound must be less than "
1215 "the number of columns " << numColsA << " in the "
1216 "'mv' output argument.");
1217 TEUCHOS_TEST_FOR_EXCEPTION(index.size() > numColsA, std::invalid_argument,
1218 os.str() << "Range must have no more elements than"
1219 " the number of columns " << numColsA << " in the "
1220 "'A' input argument.");
1221 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Should never get here!");
1222 }
1223
1224 // View of columns [index.lbound(), index.ubound()] of the
1225 // target multivector mv. We avoid view creation overhead by
1226 // only creating a view if the index range is different than [0,
1227 // (# columns in mv) - 1].
1228 Teuchos::RCP<Epetra_MultiVector> mv_view;
1229 if (index.lbound() == 0 && index.ubound()+1 == numColsMv)
1230 mv_view = Teuchos::rcpFromRef (mv); // Non-const, non-owning RCP
1231 else
1232 mv_view = CloneViewNonConst (mv, index);
1233
1234 // View of columns [0, index.size()-1] of the source multivector
1235 // A. If A has fewer columns than mv_view, then create a view
1236 // of the first index.size() columns of A.
1237 Teuchos::RCP<const Epetra_MultiVector> A_view;
1238 if (index.size() == numColsA)
1239 A_view = Teuchos::rcpFromRef (A); // Const, non-owning RCP
1240 else
1241 A_view = CloneView (A, Teuchos::Range1D(0, index.size()-1));
1242
1243 // Assignment calls Epetra_MultiVector::Assign(), which deeply
1244 // copies the data directly, ignoring the underlying
1245 // Epetra_Map(s). If A and mv don't have the same data
1246 // distribution (Epetra_Map), this may result in incorrect or
1247 // undefined behavior. Epetra_MultiVector::Update() also
1248 // ignores the Epetra_Maps, so we might as well just use the
1249 // (perhaps slightly cheaper) Assign() method via operator=().
1250 *mv_view = *A_view;
1251 }
1252
1253 static void
1254 Assign (const Epetra_MultiVector& A,
1255 Epetra_MultiVector& mv)
1256 {
1257 const int numColsA = GetNumberVecs (A);
1258 const int numColsMv = GetNumberVecs (mv);
1259 if (numColsA > numColsMv)
1260 {
1261 std::ostringstream os;
1262 os << "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::Assign"
1263 "(A, mv): ";
1264 TEUCHOS_TEST_FOR_EXCEPTION(numColsA > numColsMv, std::invalid_argument,
1265 os.str() << "Input multivector 'A' has "
1266 << numColsA << " columns, but output multivector "
1267 "'mv' has only " << numColsMv << " columns.");
1268 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Should never get here!");
1269 }
1270 // View of the first [0, numColsA-1] columns of mv.
1271 Teuchos::RCP<Epetra_MultiVector> mv_view;
1272 if (numColsMv == numColsA)
1273 mv_view = Teuchos::rcpFromRef (mv); // Non-const, non-owning RCP
1274 else // numColsMv > numColsA
1275 mv_view = CloneView (mv, Teuchos::Range1D(0, numColsA - 1));
1276
1277 // Assignment calls Epetra_MultiVector::Assign(), which deeply
1278 // copies the data directly, ignoring the underlying
1279 // Epetra_Map(s). If A and mv don't have the same data
1280 // distribution (Epetra_Map), this may result in incorrect or
1281 // undefined behavior. Epetra_MultiVector::Update() also
1282 // ignores the Epetra_Maps, so we might as well just use the
1283 // (perhaps slightly cheaper) Assign() method via operator=().
1284 *mv_view = A;
1285 }
1286
1289 static void MvScale ( Epetra_MultiVector& mv, double alpha )
1290 {
1291 TEUCHOS_TEST_FOR_EXCEPTION( mv.Scale( alpha )!=0, EpetraMultiVecFailure,
1292 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvScale call to Epetra_MultiVector::Scale(mv,double alpha) returned a nonzero value.");
1293 }
1294
1297 static void MvScale ( Epetra_MultiVector& mv, const std::vector<double>& alpha )
1298 {
1299 // Check to make sure the vector is as long as the multivector has columns.
1300 int numvecs = mv.NumVectors();
1301#ifdef TEUCHOS_DEBUG
1302 TEUCHOS_TEST_FOR_EXCEPTION( alpha.size() != (unsigned int)numvecs, std::invalid_argument,
1303 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvScale(mv,vector alpha): size of alpha inconsistent with number of vectors in mv.")
1304#endif
1305 for (int i=0; i<numvecs; i++) {
1306 TEUCHOS_TEST_FOR_EXCEPTION( mv(i)->Scale(alpha[i])!=0, EpetraMultiVecFailure,
1307 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvScale call to Epetra_MultiVector::Scale() returned a nonzero value.");
1308 }
1309 }
1310
1313 static void MvRandom( Epetra_MultiVector& mv )
1314 {
1315 TEUCHOS_TEST_FOR_EXCEPTION( mv.Random()!=0, EpetraMultiVecFailure,
1316 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvRandom call to Epetra_MultiVector::Random() returned a nonzero value.");
1317 }
1318
1321 static void MvInit( Epetra_MultiVector& mv, double alpha = Teuchos::ScalarTraits<double>::zero() )
1322 {
1323 TEUCHOS_TEST_FOR_EXCEPTION( mv.PutScalar(alpha)!=0, EpetraMultiVecFailure,
1324 "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvInit call to Epetra_MultiVector::PutScalar() returned a nonzero value.");
1325 }
1326
1328
1330
1331
1334 static void MvPrint( const Epetra_MultiVector& mv, std::ostream& os )
1335 { os << mv << std::endl; }
1336
1338
1339#if defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
1340# if defined(HAVE_TPETRA_EPETRA)
1346 typedef Epetra::TsqrAdaptor tsqr_adaptor_type;
1347# endif // defined(HAVE_TPETRA_EPETRA)
1348#endif // defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
1349 };
1350
1352 //
1353 // Implementation of the Anasazi::OperatorTraits for Epetra::Operator.
1354 //
1356
1368 template <>
1369 class OperatorTraits < double, Epetra_MultiVector, Epetra_Operator >
1370 {
1371 public:
1372
1376 static void Apply ( const Epetra_Operator& Op,
1377 const Epetra_MultiVector& x,
1378 Epetra_MultiVector& y )
1379 {
1380#ifdef TEUCHOS_DEBUG
1381 TEUCHOS_TEST_FOR_EXCEPTION(x.NumVectors() != y.NumVectors(),std::invalid_argument,
1382 "Anasazi::OperatorTraits<double,Epetra_MultiVector,Epetra_Operator>::Apply(Op,x,y): x and y must have the same number of columns.");
1383#endif
1384 int ret = Op.Apply(x,y);
1385 TEUCHOS_TEST_FOR_EXCEPTION(ret != 0, OperatorError,
1386 "Anasazi::OperatorTraits<double,Epetra_Multivector,Epetra_Operator>::Apply(): Error in Epetra_Operator::Apply(). Code " << ret);
1387 }
1388
1389 };
1390
1391 template<>
1392 struct OutputStreamTraits<Epetra_Operator>
1393 {
1394 static Teuchos::RCP<Teuchos::FancyOStream>
1395 getOutputStream (const Epetra_Operator& op, int rootRank = 0)
1396 {
1397 Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
1398 const Epetra_Comm & comm = op.Comm();
1399
1400 // Select minimum MPI rank as the root rank for printing if provided rank is less than 0.
1401 int myRank = comm.MyPID();
1402 int numProcs = comm.NumProc();
1403 if (rootRank < 0)
1404 {
1405 comm.MinAll( &myRank, &rootRank, 1 );
1406 }
1407
1408 // This is irreversible, but that's only a problem if the input std::ostream
1409 // is actually a Teuchos::FancyOStream on which this method has been
1410 // called before, with a different root rank.
1411 fos->setProcRankAndSize (myRank, numProcs);
1412 fos->setOutputToRootOnly (rootRank);
1413 return fos;
1414 }
1415 };
1416
1417} // end of Anasazi namespace
1418
1419#endif
1420// end of file ANASAZI_EPETRA_ADAPTER_HPP
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Interface for multivectors used by Anasazi' linear solvers.
Templated virtual class for creating operators that can interface with the Anasazi::OperatorTraits cl...
Abstract class definition for Anasazi output stream.
Types and exceptions used within Anasazi solvers and interfaces.
An exception class parent to all Anasazi exceptions.
Adapter class for creating an operators often used in solving generalized eigenproblems.
bool UseTranspose() const
Returns the current UseTranspose setting [always false for this operator].
bool HasNormInf() const
Returns true if this object can provide an approximate inf-norm [always false for this operator].
int SetUseTranspose(bool)
If set true, the transpose of this operator will be applied [not functional for this operator].
const Epetra_Comm & Comm() const
Returns the Epetra_Comm communicator associated with this operator.
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
const char * Label() const
Returns a character string describing the operator.
double NormInf() const
Returns the infinity norm of the global matrix [not functional for this operator].
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
EpetraMultiVecAccessor is an interfaceto allow any Anasazi::MultiVec implementation that is based on ...
virtual const Epetra_MultiVector * GetEpetraMultiVec() const
Return the pointer to the Epetra_MultiVector object.
virtual Epetra_MultiVector * GetEpetraMultiVec()
Return the pointer to the Epetra_MultiVector object.
EpetraMultiVecFailure is thrown when a return value from an Epetra call on an Epetra_MultiVector is n...
Basic adapter class for Anasazi::MultiVec that uses Epetra_MultiVector.
virtual ~EpetraMultiVec()
Destructor.
ptrdiff_t GetGlobalLength() const
The number of rows in the multivector.
void MvRandom()
Fill the vectors in *this with random numbers.
void MvScale(double alpha)
Scale each element of the vectors in *this with alpha.
void MvNorm(std::vector< double > &normvec) const
Compute the 2-norm of each individual vector of *this. Upon return, normvec[i] holds the 2-norm of ...
void MvPrint(std::ostream &os) const
Print *this EpetraMultiVec.
const Epetra_MultiVector * GetEpetraMultiVec() const
Return the pointer to the Epetra_MultiVector object.
Epetra_MultiVector * GetEpetraMultiVec()
Return the pointer to the Epetra_MultiVector object.
int GetNumberVecs() const
The number of vectors (i.e., columns) in the multivector.
void MvInit(double alpha)
Replace each element of the vectors in *this with alpha.
EpetraOpFailure is thrown when a return value from an Epetra call on an Epetra_Operator is non-zero.
Basic adapter class for Anasazi::Operator that uses Epetra_Operator.
Adapter class for creating a symmetric operator from an Epetra_MultiVector.
Adapter class for creating a symmetric operator from an Epetra_Operator.
const Epetra_Comm & Comm() const
Returns the Epetra_Comm communicator associated with this operator.
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
double NormInf() const
Returns the infinity norm of the global matrix [not functional for this operator].
bool UseTranspose() const
Returns the current UseTranspose setting [always false for this operator].
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
const char * Label() const
Returns a character string describing the operator.
bool HasNormInf() const
Returns true if this object can provide an approximate inf-norm [always false for this operator].
int SetUseTranspose(bool)
If set true, the transpose of this operator will be applied [not functional for this operator].
Adapter class for creating a weighted symmetric operator from an Epetra_MultiVector and Epetra_Operat...
Adapter class for creating a weighted operator from an Epetra_MultiVector and Epetra_Operator.
static void MvInit(Epetra_MultiVector &mv, double alpha=Teuchos::ScalarTraits< double >::zero())
Replace each element of the vectors in mv with alpha.
static void MvNorm(const Epetra_MultiVector &mv, std::vector< double > &normvec)
Compute the 2-norm of each individual vector of mv. Upon return, normvec[i] holds the value of ,...
static void MvAddMv(double alpha, const Epetra_MultiVector &A, double beta, const Epetra_MultiVector &B, Epetra_MultiVector &mv)
Replace mv with .
static void MvTransMv(double alpha, const Epetra_MultiVector &A, const Epetra_MultiVector &mv, Teuchos::SerialDenseMatrix< int, double > &B)
Compute a dense matrix B through the matrix-matrix multiply .
static ptrdiff_t GetGlobalLength(const Epetra_MultiVector &mv)
Obtain the vector length of mv.
static void MvTimesMatAddMv(double alpha, const Epetra_MultiVector &A, const Teuchos::SerialDenseMatrix< int, double > &B, double beta, Epetra_MultiVector &mv)
Update mv with .
static Teuchos::RCP< const Epetra_MultiVector > CloneView(const Epetra_MultiVector &mv, const std::vector< int > &index)
Creates a new const Epetra_MultiVector that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< Epetra_MultiVector > Clone(const Epetra_MultiVector &mv, const int outNumVecs)
Creates a new empty Epetra_MultiVector containing numVecs columns.
static Teuchos::RCP< Epetra_MultiVector > CloneCopy(const Epetra_MultiVector &mv)
Creates a new Epetra_MultiVector and copies contents of mv into the new vector (deep copy).
static void MvPrint(const Epetra_MultiVector &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
static Teuchos::RCP< Epetra_MultiVector > CloneViewNonConst(Epetra_MultiVector &mv, const std::vector< int > &index)
Creates a new Epetra_MultiVector that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< Epetra_MultiVector > CloneCopy(const Epetra_MultiVector &mv, const std::vector< int > &index)
Creates a new Epetra_MultiVector and copies the selected contents of mv into the new vector (deep cop...
static void MvDot(const Epetra_MultiVector &A, const Epetra_MultiVector &B, std::vector< double > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
static void MvScale(Epetra_MultiVector &mv, const std::vector< double > &alpha)
Scale each element of the i-th vector in mv with alpha[i].
static void SetBlock(const Epetra_MultiVector &A, const std::vector< int > &index, Epetra_MultiVector &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index.
static void MvRandom(Epetra_MultiVector &mv)
Replace the vectors in mv with random vectors.
static void MvScale(Epetra_MultiVector &mv, double alpha)
Scale each element of the vectors in mv with alpha.
static int GetNumberVecs(const Epetra_MultiVector &mv)
Obtain the number of vectors in mv.
Traits class which defines basic operations on multivectors.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
static void Assign(const MV &A, MV &mv)
mv := A
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index.
Interface for multivectors used by Anasazi's linear solvers.
Exceptions thrown to signal error in operator application.
static void Apply(const Epetra_Operator &Op, const Epetra_MultiVector &x, Epetra_MultiVector &y)
This method takes the Epetra_MultiVector x and applies the Epetra_Operator Op to it resulting in the ...
Virtual base class which defines basic traits for the operator type.
Anasazi's templated virtual class for constructing an operator that can interface with the OperatorTr...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
ConjType
Enumerated types used to specify conjugation arguments.