Anasazi  Version of the Day
AnasaziEpetraAdapter.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
33 #ifndef ANASAZI_EPETRA_ADAPTER_HPP
34 #define ANASAZI_EPETRA_ADAPTER_HPP
35 
36 #include "AnasaziConfigDefs.hpp"
37 #include "Anasaziepetra_DLLExportMacro.h"
38 #include "AnasaziTypes.hpp"
39 #include "AnasaziMultiVec.hpp"
40 #include "AnasaziOperator.hpp"
41 
42 #include "Teuchos_Assert.hpp"
44 #include "Epetra_MultiVector.h"
45 #include "Epetra_Vector.h"
46 #include "Epetra_Operator.h"
47 #include "Epetra_Map.h"
48 #include "Epetra_LocalMap.h"
49 
50 #if defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
51 # include <Tpetra_ConfigDefs.hpp> // HAVE_TPETRA_EPETRA
52 # if defined(HAVE_TPETRA_EPETRA)
53 # include <Epetra_TsqrAdaptor.hpp>
54 # endif // defined(HAVE_TPETRA_EPETRA)
55 #endif // defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
56 
57 namespace Anasazi {
58 
60 
61 
65  class EpetraMultiVecFailure : public AnasaziError {public:
66  EpetraMultiVecFailure(const std::string& what_arg) : AnasaziError(what_arg)
67  {}};
68 
72  class EpetraOpFailure : public AnasaziError {public:
73  EpetraOpFailure(const std::string& what_arg) : AnasaziError(what_arg)
74  {}};
75 
77 
79 
80 
85 
86  public:
89 
91  virtual Epetra_MultiVector* GetEpetraMultiVec() { return 0; }
92 
94  virtual const Epetra_MultiVector* GetEpetraMultiVec() const { return 0; }
95  };
96 
98 
100  //
101  //--------template class AnasaziEpetraMultiVec-----------------
102  //
104 
111  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraMultiVec : public MultiVec<double>, public Epetra_MultiVector, public EpetraMultiVecAccessor {
112  public:
114 
115 
117 
122  EpetraMultiVec(const Epetra_BlockMap& Map_in, const int numvecs);
123 
125  EpetraMultiVec(const Epetra_MultiVector & P_vec);
126 
128 
136  EpetraMultiVec(const Epetra_BlockMap& Map_in, double * array, const int numvecs, const int stride=0);
137 
139 
145  EpetraMultiVec(Epetra_DataAccess CV, const Epetra_MultiVector& P_vec, const std::vector<int>& index);
146 
148  virtual ~EpetraMultiVec() {};
149 
151 
153 
154 
159  MultiVec<double> * Clone ( const int numvecs ) const;
160 
166  MultiVec<double> * CloneCopy () const;
167 
175  MultiVec<double> * CloneCopy ( const std::vector<int>& index ) const;
176 
184  MultiVec<double> * CloneViewNonConst ( const std::vector<int>& index );
185 
193  const MultiVec<double> * CloneView ( const std::vector<int>& index ) const;
194 
196 
198  int GetVecLength () const { return GlobalLength(); }
199 
202  ptrdiff_t GetGlobalLength () const
203  {
204  if ( Map().GlobalIndicesLongLong() )
205  return static_cast<ptrdiff_t>( GlobalLength64() );
206  else
207  return static_cast<ptrdiff_t>( GlobalLength() );
208  }
209 
212  int GetNumberVecs () const { return NumVectors(); }
213 
215 
217 
218 
220  void MvTimesMatAddMv ( double alpha, const MultiVec<double>& A,
222  double beta );
223 
226  void MvAddMv ( double alpha, const MultiVec<double>& A,
227  double beta, const MultiVec<double>& B);
228 
231  void MvTransMv ( double alpha, const MultiVec<double>& A, Teuchos::SerialDenseMatrix<int,double>& B
232 #ifdef HAVE_ANASAZI_EXPERIMENTAL
233  , ConjType conj = Anasazi::CONJ
234 #endif
235  ) const;
236 
239  void MvDot ( const MultiVec<double>& A, std::vector<double> &b
240 #ifdef HAVE_ANASAZI_EXPERIMENTAL
241  , ConjType conj = Anasazi::CONJ
242 #endif
243  ) const;
244 
247  void MvScale ( double alpha ) {
248  TEUCHOS_TEST_FOR_EXCEPTION( this->Scale( alpha )!=0, EpetraMultiVecFailure,
249  "Anasazi::EpetraMultiVec::MvScale call to Epetra_MultiVector::Scale() returned a nonzero value.");
250  }
251 
254  void MvScale ( const std::vector<double>& alpha );
255 
257 
259 
263  void MvNorm ( std::vector<double> & normvec ) const {
264  if (((int)normvec.size() >= GetNumberVecs()) ) {
265  TEUCHOS_TEST_FOR_EXCEPTION( this->Norm2(&normvec[0])!=0, EpetraMultiVecFailure,
266  "Anasazi::EpetraMultiVec::MvNorm call to Epetra_MultiVector::Norm2() returned a nonzero value.");
267  }
268  };
270 
272 
273 
278  void SetBlock ( const MultiVec<double>& A, const std::vector<int>& index );
279 
282  void MvRandom() {
284  "Anasazi::EpetraMultiVec::MvRandom call to Epetra_MultiVector::Random() returned a nonzero value.");
285  };
286 
289  void MvInit ( double alpha ) {
290  TEUCHOS_TEST_FOR_EXCEPTION( this->PutScalar( alpha )!=0, EpetraMultiVecFailure,
291  "Anasazi::EpetraMultiVec::MvInit call to Epetra_MultiVector::PutScalar() returned a nonzero value.");
292  };
293 
295 
296 
298  Epetra_MultiVector* GetEpetraMultiVec() { return this; };
299 
301  const Epetra_MultiVector* GetEpetraMultiVec() const { return this; };
302 
304 
306 
308 
310  void MvPrint( std::ostream& os ) const { os << *this << std::endl; };
312 
313  private:
314  };
315  //-------------------------------------------------------------
316 
318  //
319  //--------template class AnasaziEpetraOp---------------------
320  //
322 
329  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraOp : public virtual Operator<double> {
330  public:
332 
333 
336 
338  ~EpetraOp();
340 
342 
343 
347  void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
349 
350  private:
351 //use pragmas to disable some false-positive warnings for windows
352 // sharedlibs export
353 #ifdef _MSC_VER
354 #pragma warning(push)
355 #pragma warning(disable:4251)
356 #endif
358 #ifdef _MSC_VER
359 #pragma warning(pop)
360 #endif
361  };
362  //-------------------------------------------------------------
363 
365  //
366  //--------template class AnasaziEpetraGenOp--------------------
367  //
369 
383  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraGenOp : public virtual Operator<double>, public virtual Epetra_Operator {
384  public:
386 
391  bool isAInverse = true );
392 
394  ~EpetraGenOp();
395 
397 
399  void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
400 
402 
404  int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
405 
407 
409  int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
410 
412  const char* Label() const { return "Epetra_Operator applying A^{-1}M"; };
413 
415  bool UseTranspose() const { return (false); };
416 
418  int SetUseTranspose(bool /*UseTranspose_in*/) { return 0; };
419 
421  bool HasNormInf() const { return (false); };
422 
424  double NormInf() const { return (-1.0); };
425 
427  const Epetra_Comm& Comm() const { return Epetra_AOp->Comm(); };
428 
430  const Epetra_Map& OperatorDomainMap() const { return Epetra_AOp->OperatorDomainMap(); };
431 
433  const Epetra_Map& OperatorRangeMap() const { return Epetra_AOp->OperatorRangeMap(); };
434 
435  private:
436  bool isAInverse;
437 
438 //use pragmas to disable some false-positive warnings for windows
439 // sharedlibs export
440 #ifdef _MSC_VER
441 #pragma warning(push)
442 #pragma warning(disable:4251)
443 #endif
446 #ifdef _MSC_VER
447 #pragma warning(pop)
448 #endif
449  };
450 
452  //
453  //--------template class AnasaziEpetraSymOp--------------------
454  //
456 
469  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraSymOp : public virtual Operator<double>, public virtual Epetra_Operator {
470  public:
472 
474  EpetraSymOp(const Teuchos::RCP<Epetra_Operator> &Op, bool isTrans = false );
475 
477  ~EpetraSymOp();
478 
480 
482  void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
483 
485 
487  int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
488 
490 
493  int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const;
494 
496  const char* Label() const { return "Epetra_Operator applying A^TA or AA^T"; };
497 
499  bool UseTranspose() const { return (false); };
500 
502  int SetUseTranspose(bool /*UseTranspose_in*/) { return 0; };
503 
505  bool HasNormInf() const { return (false); };
506 
508  double NormInf() const { return (-1.0); };
509 
511  const Epetra_Comm& Comm() const { return Epetra_Op->Comm(); };
512 
514  const Epetra_Map& OperatorDomainMap() const { return Epetra_Op->OperatorDomainMap(); };
515 
517  const Epetra_Map& OperatorRangeMap() const { return Epetra_Op->OperatorRangeMap(); };
518 
519  private:
520 
521 //use pragmas to disable false-positive warnings in generating windows sharedlib exports
522 #ifdef _MSC_VER
523 #pragma warning(push)
524 #pragma warning(disable:4251)
525 #endif
527 #ifdef _MSC_VER
528 #pragma warning(pop)
529 #endif
530 
531  bool isTrans_;
532  };
533 
534 
536  //
537  //--------template class AnasaziEpetraSymMVOp---------------------
538  //
540 
553  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraSymMVOp : public virtual Operator<double> {
554  public:
556 
559  bool isTrans = false );
560 
563 
565 
567  void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
568 
569  private:
570 
571 //use pragmas to disable some false-positive warnings for windows
572 // sharedlibs export
573 #ifdef _MSC_VER
574 #pragma warning(push)
575 #pragma warning(disable:4251)
576 #endif
578  Teuchos::RCP<const Epetra_Map> MV_localmap;
580 #ifdef _MSC_VER
581 #pragma warning(pop)
582 #endif
583 
584  bool isTrans_;
585  };
586 
588  //
589  //--------template class AnasaziEpetraWSymMVOp---------------------
590  //
592 
605  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraWSymMVOp : public virtual Operator<double> {
606  public:
609  const Teuchos::RCP<Epetra_Operator> &OP );
610 
613 
615 
617  void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
618 
619  private:
620 //use pragmas to disable some false-positive warnings for windows
621 // sharedlibs export
622 #ifdef _MSC_VER
623 #pragma warning(push)
624 #pragma warning(disable:4251)
625 #endif
629  Teuchos::RCP<const Epetra_Map> MV_localmap;
631 #ifdef _MSC_VER
632 #pragma warning(pop)
633 #endif
634  };
635 
637  //
638  //--------template class AnasaziEpetraW2SymMVOp---------------------
639  //
641 
654  class ANASAZIEPETRA_LIB_DLL_EXPORT EpetraW2SymMVOp : public virtual Operator<double> {
655  public:
658  const Teuchos::RCP<Epetra_Operator> &OP );
659 
662 
664 
666  void Apply ( const MultiVec<double>& X, MultiVec<double>& Y ) const;
667 
668  private:
669 //use pragmas to disable some false-positive warnings for windows
670 // sharedlibs export
671 #ifdef _MSC_VER
672 #pragma warning(push)
673 #pragma warning(disable:4251)
674 #endif
678  Teuchos::RCP<const Epetra_Map> MV_localmap;
680 #ifdef _MSC_VER
681 #pragma warning(pop)
682 #endif
683  };
684 
685 
687  //
688  // Implementation of the Anasazi::MultiVecTraits for Epetra::MultiVector.
689  //
691 
702  template<>
703  class MultiVecTraits<double, Epetra_MultiVector>
704  {
705  public:
706 
708 
709 
715  Clone (const Epetra_MultiVector& mv, const int outNumVecs)
716  {
717  TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs <= 0, std::invalid_argument,
718  "Belos::MultiVecTraits<double, Epetra_MultiVector>::"
719  "Clone(mv, outNumVecs = " << outNumVecs << "): "
720  "outNumVecs must be positive.");
721  // FIXME (mfh 13 Jan 2011) Anasazi currently lets Epetra fill in
722  // the entries of the returned multivector with zeros, but Belos
723  // does not. We retain this different behavior for now, but the
724  // two versions will need to be reconciled.
725  return Teuchos::rcp (new Epetra_MultiVector (mv.Map(), outNumVecs));
726  }
727 
733  CloneCopy (const Epetra_MultiVector& mv)
734  {
735  return Teuchos::rcp (new Epetra_MultiVector (mv));
736  }
737 
744  CloneCopy (const Epetra_MultiVector& mv, const std::vector<int>& index)
745  {
746  const int inNumVecs = GetNumberVecs (mv);
747  const int outNumVecs = index.size();
748 
749  // Simple, inexpensive tests of the index vector.
750  TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
751  "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
752  "CloneCopy(mv, index = {}): At least one vector must be"
753  " cloned from mv.");
754  if (outNumVecs > inNumVecs)
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] << "}): There are " << outNumVecs
762  << " indices to copy, but only " << inNumVecs << " columns of mv.";
763  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
764  }
765 #ifdef TEUCHOS_DEBUG
766  // In debug mode, we perform more expensive tests of the index
767  // vector, to ensure all the elements are in range.
768  // Dereferencing the iterator is valid because index has length
769  // > 0.
770  const int minIndex = *std::min_element (index.begin(), index.end());
771  const int maxIndex = *std::max_element (index.begin(), index.end());
772 
773  if (minIndex < 0)
774  {
775  std::ostringstream os;
776  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
777  "CloneCopy(mv, index = {";
778  for (int k = 0; k < outNumVecs - 1; ++k)
779  os << index[k] << ", ";
780  os << index[outNumVecs-1] << "}): Indices must be nonnegative, but "
781  "the smallest index " << minIndex << " is negative.";
782  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
783  }
784  if (maxIndex >= inNumVecs)
785  {
786  std::ostringstream os;
787  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
788  "CloneCopy(mv, index = {";
789  for (int k = 0; k < outNumVecs - 1; ++k)
790  os << index[k] << ", ";
791  os << index[outNumVecs-1] << "}): Indices must be strictly less than "
792  "the number of vectors " << inNumVecs << " in mv; the largest index "
793  << maxIndex << " is out of bounds.";
794  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
795  }
796 #endif // TEUCHOS_DEBUG
797  // Cast to nonconst, because Epetra_MultiVector's constructor
798  // wants a nonconst int array argument. It doesn't actually
799  // change the entries of the array.
800  std::vector<int>& tmpind = const_cast< std::vector<int>& > (index);
801  return Teuchos::rcp (new Epetra_MultiVector (Copy, mv, &tmpind[0], index.size()));
802  // return Teuchos::rcp (new Epetra_MultiVector (::Copy, mv, &tmpind[0], index.size()));
803  }
804 
806  CloneCopy (const Epetra_MultiVector& mv, const Teuchos::Range1D& index)
807  {
808  const int inNumVecs = GetNumberVecs (mv);
809  const int outNumVecs = index.size();
810  const bool validRange = outNumVecs > 0 && index.lbound() >= 0 &&
811  index.ubound() < inNumVecs;
812  if (! validRange)
813  {
814  std::ostringstream os;
815  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::Clone(mv,"
816  "index=[" << index.lbound() << ", " << index.ubound() << "]): ";
817  TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
818  os.str() << "Column index range must be nonempty.");
819  TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
820  os.str() << "Column index range must be nonnegative.");
821  TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= inNumVecs, std::invalid_argument,
822  os.str() << "Column index range must not exceed "
823  "number of vectors " << inNumVecs << " in the "
824  "input multivector.");
825  }
826  return Teuchos::rcp (new Epetra_MultiVector (Copy, mv, index.lbound(), index.size()));
827  }
828 
835  CloneViewNonConst (Epetra_MultiVector& mv, const std::vector<int>& index)
836  {
837  const int inNumVecs = GetNumberVecs (mv);
838  const int outNumVecs = index.size();
839 
840  // Simple, inexpensive tests of the index vector.
841  TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
842  "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
843  "CloneViewNonConst(mv, index = {}): The output view "
844  "must have at least one column.");
845  if (outNumVecs > inNumVecs)
846  {
847  std::ostringstream os;
848  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
849  "CloneViewNonConst(mv, index = {";
850  for (int k = 0; k < outNumVecs - 1; ++k)
851  os << index[k] << ", ";
852  os << index[outNumVecs-1] << "}): There are " << outNumVecs
853  << " indices to view, but only " << inNumVecs << " columns of mv.";
854  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
855  }
856 #ifdef TEUCHOS_DEBUG
857  // In debug mode, we perform more expensive tests of the index
858  // vector, to ensure all the elements are in range.
859  // Dereferencing the iterator is valid because index has length
860  // > 0.
861  const int minIndex = *std::min_element (index.begin(), index.end());
862  const int maxIndex = *std::max_element (index.begin(), index.end());
863 
864  if (minIndex < 0)
865  {
866  std::ostringstream os;
867  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
868  "CloneViewNonConst(mv, index = {";
869  for (int k = 0; k < outNumVecs - 1; ++k)
870  os << index[k] << ", ";
871  os << index[outNumVecs-1] << "}): Indices must be nonnegative, but "
872  "the smallest index " << minIndex << " is negative.";
873  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
874  }
875  if (maxIndex >= inNumVecs)
876  {
877  std::ostringstream os;
878  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::"
879  "CloneViewNonConst(mv, index = {";
880  for (int k = 0; k < outNumVecs - 1; ++k)
881  os << index[k] << ", ";
882  os << index[outNumVecs-1] << "}): Indices must be strictly less than "
883  "the number of vectors " << inNumVecs << " in mv; the largest index "
884  << maxIndex << " is out of bounds.";
885  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
886  }
887 #endif // TEUCHOS_DEBUG
888  // Cast to nonconst, because Epetra_MultiVector's constructor
889  // wants a nonconst int array argument. It doesn't actually
890  // change the entries of the array.
891  std::vector<int>& tmpind = const_cast< std::vector<int>& > (index);
892  return Teuchos::rcp (new Epetra_MultiVector (View, mv, &tmpind[0], index.size()));
893  }
894 
896  CloneViewNonConst (Epetra_MultiVector& mv, const Teuchos::Range1D& index)
897  {
898  const bool validRange = index.size() > 0 &&
899  index.lbound() >= 0 &&
900  index.ubound() < mv.NumVectors();
901  if (! validRange)
902  {
903  std::ostringstream os;
904  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::CloneView"
905  "NonConst(mv,index=[" << index.lbound() << ", " << index.ubound()
906  << "]): ";
907  TEUCHOS_TEST_FOR_EXCEPTION(index.size() == 0, std::invalid_argument,
908  os.str() << "Column index range must be nonempty.");
909  TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
910  os.str() << "Column index range must be nonnegative.");
911  TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= mv.NumVectors(),
912  std::invalid_argument,
913  os.str() << "Column index range must not exceed "
914  "number of vectors " << mv.NumVectors() << " in "
915  "the input multivector.");
916  }
917  return Teuchos::rcp (new Epetra_MultiVector (View, mv, index.lbound(), index.size()));
918  }
919 
926  CloneView (const Epetra_MultiVector& mv, const std::vector<int>& index)
927  {
928  const int inNumVecs = GetNumberVecs (mv);
929  const int outNumVecs = index.size();
930 
931  // Simple, inexpensive tests of the index vector.
932  TEUCHOS_TEST_FOR_EXCEPTION(outNumVecs == 0, std::invalid_argument,
933  "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
934  "CloneView(mv, index = {}): The output view "
935  "must have at least one column.");
936  if (outNumVecs > inNumVecs)
937  {
938  std::ostringstream os;
939  os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
940  "CloneView(mv, index = {";
941  for (int k = 0; k < outNumVecs - 1; ++k)
942  os << index[k] << ", ";
943  os << index[outNumVecs-1] << "}): There are " << outNumVecs
944  << " indices to view, but only " << inNumVecs << " columns of mv.";
945  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
946  }
947 #ifdef TEUCHOS_DEBUG
948  // In debug mode, we perform more expensive tests of the index
949  // vector, to ensure all the elements are in range.
950  // Dereferencing the iterator is valid because index has length
951  // > 0.
952  const int minIndex = *std::min_element (index.begin(), index.end());
953  const int maxIndex = *std::max_element (index.begin(), index.end());
954 
955  if (minIndex < 0)
956  {
957  std::ostringstream os;
958  os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
959  "CloneView(mv, index = {";
960  for (int k = 0; k < outNumVecs - 1; ++k)
961  os << index[k] << ", ";
962  os << index[outNumVecs-1] << "}): Indices must be nonnegative, but "
963  "the smallest index " << minIndex << " is negative.";
964  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
965  }
966  if (maxIndex >= inNumVecs)
967  {
968  std::ostringstream os;
969  os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
970  "CloneView(mv, index = {";
971  for (int k = 0; k < outNumVecs - 1; ++k)
972  os << index[k] << ", ";
973  os << index[outNumVecs-1] << "}): Indices must be strictly less than "
974  "the number of vectors " << inNumVecs << " in mv; the largest index "
975  << maxIndex << " is out of bounds.";
976  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
977  }
978 #endif // TEUCHOS_DEBUG
979  // Cast to nonconst, because Epetra_MultiVector's constructor
980  // wants a nonconst int array argument. It doesn't actually
981  // change the entries of the array.
982  std::vector<int>& tmpind = const_cast< std::vector<int>& > (index);
983  return Teuchos::rcp (new Epetra_MultiVector (View, mv, &tmpind[0], index.size()));
984  }
985 
987  CloneView (const Epetra_MultiVector& mv, const Teuchos::Range1D& index)
988  {
989  const bool validRange = index.size() > 0 &&
990  index.lbound() >= 0 &&
991  index.ubound() < mv.NumVectors();
992  if (! validRange)
993  {
994  std::ostringstream os;
995  os << "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::CloneView"
996  "(mv,index=[" << index.lbound() << ", " << index.ubound()
997  << "]): ";
998  TEUCHOS_TEST_FOR_EXCEPTION(index.size() == 0, std::invalid_argument,
999  os.str() << "Column index range must be nonempty.");
1000  TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
1001  os.str() << "Column index range must be nonnegative.");
1002  TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= mv.NumVectors(),
1003  std::invalid_argument,
1004  os.str() << "Column index range must not exceed "
1005  "number of vectors " << mv.NumVectors() << " in "
1006  "the input multivector.");
1007  }
1008  return Teuchos::rcp (new Epetra_MultiVector(View, mv, index.lbound(), index.size()));
1009  }
1010 
1012 
1014 
1015 
1017  static int GetVecLength( const Epetra_MultiVector& mv )
1018  { return mv.GlobalLength(); }
1019 
1021  static int GetNumberVecs( const Epetra_MultiVector& mv )
1022  { return mv.NumVectors(); }
1023 
1024  static bool HasConstantStride( const Epetra_MultiVector& mv )
1025  { return mv.ConstantStride(); }
1027 
1029 
1030 
1033  static void MvTimesMatAddMv( double alpha, const Epetra_MultiVector& A,
1035  double beta, Epetra_MultiVector& mv )
1036  {
1037  Epetra_LocalMap LocalMap(B.numRows(), 0, mv.Map().Comm());
1038  Epetra_MultiVector B_Pvec(::View, LocalMap, B.values(), B.stride(), B.numCols());
1039 
1040  TEUCHOS_TEST_FOR_EXCEPTION( mv.Multiply( 'N', 'N', alpha, A, B_Pvec, beta )!=0, EpetraMultiVecFailure,
1041  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvNorm call to Epetra_MultiVector::Multiply() returned a nonzero value.");
1042  }
1043 
1046  static void MvAddMv( double alpha, const Epetra_MultiVector& A, double beta, const Epetra_MultiVector& B, Epetra_MultiVector& mv )
1047  {
1048  // epetra mv.Update(alpha,A,beta,B,gamma) will check
1049  // alpha == 0.0
1050  // and
1051  // beta == 0.0
1052  // and based on this will call
1053  // mv.Update(beta,B,gamma)
1054  // or
1055  // mv.Update(alpha,A,gamma)
1056  //
1057  // mv.Update(alpha,A,gamma)
1058  // will then check for one of
1059  // gamma == 0
1060  // or
1061  // gamma == 1
1062  // or
1063  // alpha == 1
1064  // in that order. however, it will not look for the combination
1065  // alpha == 1 and gamma = 0
1066  // which is a common use case when we wish to assign
1067  // mv = A (in which case alpha == 1, beta == gamma == 0)
1068  // or
1069  // mv = B (in which case beta == 1, alpha == gamma == 0)
1070  //
1071  // therefore, we will check for these use cases ourselves
1072  if (beta == 0.0) {
1073  if (alpha == 1.0) {
1074  // assign
1075  mv = A;
1076  }
1077  else {
1078  // single update
1079  TEUCHOS_TEST_FOR_EXCEPTION( mv.Update( alpha, A, 0.0 )!=0, EpetraMultiVecFailure,
1080  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvAddMv call to Epetra_MultiVector::Update(alpha,A,0.0) returned a nonzero value.");
1081  }
1082  }
1083  else if (alpha == 0.0) {
1084  if (beta == 1.0) {
1085  // assign
1086  mv = B;
1087  }
1088  else {
1089  // single update
1090  TEUCHOS_TEST_FOR_EXCEPTION( mv.Update( beta, B, 0.0 )!=0, EpetraMultiVecFailure,
1091  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvAddMv call to Epetra_MultiVector::Update(beta,B,0.0) returned a nonzero value.");
1092  }
1093  }
1094  else {
1095  // double update
1096  TEUCHOS_TEST_FOR_EXCEPTION( mv.Update( alpha, A, beta, B, 0.0 )!=0, EpetraMultiVecFailure,
1097  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvAddMv call to Epetra_MultiVector::Update(alpha,A,beta,B,0.0) returned a nonzero value.");
1098  }
1099  }
1100 
1103  static void MvTransMv( double alpha, const Epetra_MultiVector& A, const Epetra_MultiVector& mv, Teuchos::SerialDenseMatrix<int,double>& B
1104 #ifdef HAVE_ANASAZI_EXPERIMENTAL
1105  , ConjType conj = Anasazi::CONJ
1106 #endif
1107  )
1108  {
1109  Epetra_LocalMap LocalMap(B.numRows(), 0, mv.Map().Comm());
1110  Epetra_MultiVector B_Pvec(::View, LocalMap, B.values(), B.stride(), B.numCols());
1111 
1112  TEUCHOS_TEST_FOR_EXCEPTION( B_Pvec.Multiply( 'T', 'N', alpha, A, mv, 0.0 )!=0, EpetraMultiVecFailure,
1113  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvTransMv call to Epetra_MultiVector::Multiply() returned a nonzero value.");
1114  }
1115 
1118  static void MvDot( const Epetra_MultiVector& A, const Epetra_MultiVector& B, std::vector<double> &b
1119 #ifdef HAVE_ANASAZI_EXPERIMENTAL
1120  , ConjType conj = Anasazi::CONJ
1121 #endif
1122  )
1123  {
1124 #ifdef TEUCHOS_DEBUG
1125  TEUCHOS_TEST_FOR_EXCEPTION(A.NumVectors() != B.NumVectors(),std::invalid_argument,
1126  "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::MvDot(A,B,b): A and B must have the same number of vectors.");
1127  TEUCHOS_TEST_FOR_EXCEPTION(b.size() != (unsigned int)A.NumVectors(),std::invalid_argument,
1128  "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::MvDot(A,B,b): b must have room for all dot products.");
1129 #endif
1130  TEUCHOS_TEST_FOR_EXCEPTION( A.Dot( B, &b[0] )!=0, EpetraMultiVecFailure,
1131  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvDot(A,B,b) call to Epetra_MultiVector::Dot() returned a nonzero value.");
1132  }
1133 
1135 
1137 
1141  static void MvNorm( const Epetra_MultiVector& mv, std::vector<double> &normvec )
1142  {
1143 #ifdef TEUCHOS_DEBUG
1144  TEUCHOS_TEST_FOR_EXCEPTION((unsigned int)mv.NumVectors() != normvec.size(),std::invalid_argument,
1145  "Anasazi::MultiVecTraits<double,Epetra_MultiVector>::MvNorm(mv,normvec): normvec must be the same size of mv.");
1146 #endif
1147  TEUCHOS_TEST_FOR_EXCEPTION( mv.Norm2(&normvec[0])!=0, EpetraMultiVecFailure,
1148  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvNorm call to Epetra_MultiVector::Norm2() returned a nonzero value.");
1149  }
1150 
1152 
1154 
1155 
1157  static void
1158  SetBlock (const Epetra_MultiVector& A,
1159  const std::vector<int>& index,
1160  Epetra_MultiVector& mv)
1161  {
1162  const int inNumVecs = GetNumberVecs (A);
1163  const int outNumVecs = index.size();
1164 
1165  // FIXME (mfh 13 Jan 2011) Belos allows A to have more columns
1166  // than index.size(), in which case we just take the first
1167  // index.size() columns of A. Anasazi requires that A have the
1168  // same number of columns as index.size(). Changing Anasazi's
1169  // behavior should not break existing Anasazi solvers, but the
1170  // tests need to be done.
1171  if (inNumVecs != outNumVecs)
1172  {
1173  std::ostringstream os;
1174  os << "Belos::MultiVecTraits<double,Epetra_MultiVector>::"
1175  "SetBlock(A, mv, index = {";
1176  if (outNumVecs > 0)
1177  {
1178  for (int k = 0; k < outNumVecs - 1; ++k)
1179  os << index[k] << ", ";
1180  os << index[outNumVecs-1];
1181  }
1182  os << "}): A has only " << inNumVecs << " columns, but there are "
1183  << outNumVecs << " indices in the index vector.";
1184  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, os.str());
1185  }
1186  // Make a view of the columns of mv indicated by the index std::vector.
1187  Teuchos::RCP<Epetra_MultiVector> mv_view = CloneViewNonConst (mv, index);
1188 
1189  // View of columns [0, outNumVecs-1] of the source multivector A.
1190  // If A has fewer columns than mv_view, then create a view of
1191  // the first outNumVecs columns of A.
1193  if (outNumVecs == inNumVecs)
1194  A_view = Teuchos::rcpFromRef (A); // Const, non-owning RCP
1195  else
1196  A_view = CloneView (A, Teuchos::Range1D(0, outNumVecs - 1));
1197 
1198  // Assignment calls Epetra_MultiVector::Assign(), which deeply
1199  // copies the data directly, ignoring the underlying
1200  // Epetra_Map(s). If A and mv don't have the same data
1201  // distribution (Epetra_Map), this may result in incorrect or
1202  // undefined behavior. Epetra_MultiVector::Update() also
1203  // ignores the Epetra_Maps, so we might as well just use the
1204  // (perhaps slightly cheaper) Assign() method via operator=().
1205  *mv_view = *A_view;
1206  }
1207 
1208  static void
1209  SetBlock (const Epetra_MultiVector& A,
1210  const Teuchos::Range1D& index,
1211  Epetra_MultiVector& mv)
1212  {
1213  const int numColsA = A.NumVectors();
1214  const int numColsMv = mv.NumVectors();
1215  // 'index' indexes into mv; it's the index set of the target.
1216  const bool validIndex = index.lbound() >= 0 && index.ubound() < numColsMv;
1217  // We can't take more columns out of A than A has.
1218  const bool validSource = index.size() <= numColsA;
1219 
1220  if (! validIndex || ! validSource)
1221  {
1222  std::ostringstream os;
1223  os << "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::SetBlock"
1224  "(A, index=[" << index.lbound() << ", " << index.ubound() << "], "
1225  "mv): ";
1226  TEUCHOS_TEST_FOR_EXCEPTION(index.lbound() < 0, std::invalid_argument,
1227  os.str() << "Range lower bound must be nonnegative.");
1228  TEUCHOS_TEST_FOR_EXCEPTION(index.ubound() >= numColsMv, std::invalid_argument,
1229  os.str() << "Range upper bound must be less than "
1230  "the number of columns " << numColsA << " in the "
1231  "'mv' output argument.");
1232  TEUCHOS_TEST_FOR_EXCEPTION(index.size() > numColsA, std::invalid_argument,
1233  os.str() << "Range must have no more elements than"
1234  " the number of columns " << numColsA << " in the "
1235  "'A' input argument.");
1236  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Should never get here!");
1237  }
1238 
1239  // View of columns [index.lbound(), index.ubound()] of the
1240  // target multivector mv. We avoid view creation overhead by
1241  // only creating a view if the index range is different than [0,
1242  // (# columns in mv) - 1].
1244  if (index.lbound() == 0 && index.ubound()+1 == numColsMv)
1245  mv_view = Teuchos::rcpFromRef (mv); // Non-const, non-owning RCP
1246  else
1247  mv_view = CloneViewNonConst (mv, index);
1248 
1249  // View of columns [0, index.size()-1] of the source multivector
1250  // A. If A has fewer columns than mv_view, then create a view
1251  // of the first index.size() columns of A.
1253  if (index.size() == numColsA)
1254  A_view = Teuchos::rcpFromRef (A); // Const, non-owning RCP
1255  else
1256  A_view = CloneView (A, Teuchos::Range1D(0, index.size()-1));
1257 
1258  // Assignment calls Epetra_MultiVector::Assign(), which deeply
1259  // copies the data directly, ignoring the underlying
1260  // Epetra_Map(s). If A and mv don't have the same data
1261  // distribution (Epetra_Map), this may result in incorrect or
1262  // undefined behavior. Epetra_MultiVector::Update() also
1263  // ignores the Epetra_Maps, so we might as well just use the
1264  // (perhaps slightly cheaper) Assign() method via operator=().
1265  *mv_view = *A_view;
1266  }
1267 
1268  static void
1269  Assign (const Epetra_MultiVector& A,
1270  Epetra_MultiVector& mv)
1271  {
1272  const int numColsA = GetNumberVecs (A);
1273  const int numColsMv = GetNumberVecs (mv);
1274  if (numColsA > numColsMv)
1275  {
1276  std::ostringstream os;
1277  os << "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::Assign"
1278  "(A, mv): ";
1279  TEUCHOS_TEST_FOR_EXCEPTION(numColsA > numColsMv, std::invalid_argument,
1280  os.str() << "Input multivector 'A' has "
1281  << numColsA << " columns, but output multivector "
1282  "'mv' has only " << numColsMv << " columns.");
1283  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Should never get here!");
1284  }
1285  // View of the first [0, numColsA-1] columns of mv.
1287  if (numColsMv == numColsA)
1288  mv_view = Teuchos::rcpFromRef (mv); // Non-const, non-owning RCP
1289  else // numColsMv > numColsA
1290  mv_view = CloneView (mv, Teuchos::Range1D(0, numColsA - 1));
1291 
1292  // Assignment calls Epetra_MultiVector::Assign(), which deeply
1293  // copies the data directly, ignoring the underlying
1294  // Epetra_Map(s). If A and mv don't have the same data
1295  // distribution (Epetra_Map), this may result in incorrect or
1296  // undefined behavior. Epetra_MultiVector::Update() also
1297  // ignores the Epetra_Maps, so we might as well just use the
1298  // (perhaps slightly cheaper) Assign() method via operator=().
1299  *mv_view = A;
1300  }
1301 
1304  static void MvScale ( Epetra_MultiVector& mv, double alpha )
1305  {
1306  TEUCHOS_TEST_FOR_EXCEPTION( mv.Scale( alpha )!=0, EpetraMultiVecFailure,
1307  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvScale call to Epetra_MultiVector::Scale(mv,double alpha) returned a nonzero value.");
1308  }
1309 
1312  static void MvScale ( Epetra_MultiVector& mv, const std::vector<double>& alpha )
1313  {
1314  // Check to make sure the vector is as long as the multivector has columns.
1315  int numvecs = mv.NumVectors();
1316 #ifdef TEUCHOS_DEBUG
1317  TEUCHOS_TEST_FOR_EXCEPTION( alpha.size() != (unsigned int)numvecs, std::invalid_argument,
1318  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvScale(mv,vector alpha): size of alpha inconsistent with number of vectors in mv.")
1319 #endif
1320  for (int i=0; i<numvecs; i++) {
1321  TEUCHOS_TEST_FOR_EXCEPTION( mv(i)->Scale(alpha[i])!=0, EpetraMultiVecFailure,
1322  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvScale call to Epetra_MultiVector::Scale() returned a nonzero value.");
1323  }
1324  }
1325 
1328  static void MvRandom( Epetra_MultiVector& mv )
1329  {
1331  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvRandom call to Epetra_MultiVector::Random() returned a nonzero value.");
1332  }
1333 
1336  static void MvInit( Epetra_MultiVector& mv, double alpha = Teuchos::ScalarTraits<double>::zero() )
1337  {
1338  TEUCHOS_TEST_FOR_EXCEPTION( mv.PutScalar(alpha)!=0, EpetraMultiVecFailure,
1339  "Anasazi::MultiVecTraits<double, Epetra_MultiVector>::MvInit call to Epetra_MultiVector::PutScalar() returned a nonzero value.");
1340  }
1341 
1343 
1345 
1346 
1349  static void MvPrint( const Epetra_MultiVector& mv, std::ostream& os )
1350  { os << mv << std::endl; }
1351 
1353 
1354 #if defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
1355 # if defined(HAVE_TPETRA_EPETRA)
1356  typedef Epetra::TsqrAdaptor tsqr_adaptor_type;
1362 # endif // defined(HAVE_TPETRA_EPETRA)
1363 #endif // defined(HAVE_ANASAZI_TPETRA) && defined(HAVE_ANASAZI_TSQR)
1364  };
1365 
1367  //
1368  // Implementation of the Anasazi::OperatorTraits for Epetra::Operator.
1369  //
1371 
1383  template <>
1384  class OperatorTraits < double, Epetra_MultiVector, Epetra_Operator >
1385  {
1386  public:
1387 
1391  static void Apply ( const Epetra_Operator& Op,
1392  const Epetra_MultiVector& x,
1393  Epetra_MultiVector& y )
1394  {
1395 #ifdef TEUCHOS_DEBUG
1396  TEUCHOS_TEST_FOR_EXCEPTION(x.NumVectors() != y.NumVectors(),std::invalid_argument,
1397  "Anasazi::OperatorTraits<double,Epetra_MultiVector,Epetra_Operator>::Apply(Op,x,y): x and y must have the same number of columns.");
1398 #endif
1399  int ret = Op.Apply(x,y);
1401  "Anasazi::OperatorTraits<double,Epetra_Multivector,Epetra_Operator>::Apply(): Error in Epetra_Operator::Apply(). Code " << ret);
1402  }
1403 
1404  };
1405 
1406  template<>
1407  class MultiVecTraitsExt<double, Epetra_MultiVector>
1408  {
1409  public:
1411 
1412 
1415  static ptrdiff_t GetGlobalLength( const Epetra_MultiVector& mv )
1416  {
1417  if (mv.Map().GlobalIndicesLongLong())
1418  return static_cast<ptrdiff_t>( mv.GlobalLength64() );
1419  else
1420  return static_cast<ptrdiff_t>( mv.GlobalLength() );
1421  }
1422 
1424  };
1425 
1426 } // end of Anasazi namespace
1427 
1428 #endif
1429 // end of file ANASAZI_EPETRA_ADAPTER_HPP
ScalarType * values() const
void MvRandom()
Fill the vectors in *this with random numbers.
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
Adapter class for creating an operators often used in solving generalized eigenproblems.
EpetraMultiVecAccessor is an interfaceto allow any Anasazi::MultiVec implementation that is based on ...
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
static void MvAddMv(double alpha, const Epetra_MultiVector &A, double beta, const Epetra_MultiVector &B, Epetra_MultiVector &mv)
Replace mv with .
void MvInit(double alpha)
Replace each element of the vectors in *this with alpha.
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...
virtual ~EpetraMultiVecAccessor()
Destructor.
Adapter class for creating a weighted symmetric operator from an Epetra_MultiVector and Epetra_Operat...
static void MvInit(Epetra_MultiVector &mv, double alpha=Teuchos::ScalarTraits< double >::zero())
Replace each element of the vectors in mv with alpha.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Virtual base class which defines basic traits for the operator type.
const char * Label() const
Returns a character string describing the operator.
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 th...
virtual Epetra_MultiVector * GetEpetraMultiVec()
Return the pointer to the Epetra_MultiVector object.
static void MvPrint(const Epetra_MultiVector &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
static void MvRandom(Epetra_MultiVector &mv)
Replace the vectors in mv with random vectors.
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 .
int GetVecLength() const
Obtain the number of vectors in *this.
An exception class parent to all Anasazi exceptions.
Interface for multivectors used by Anasazi&#39; linear solvers.
Ordinal ubound() const
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
Basic adapter class for Anasazi::Operator that uses Epetra_Operator.
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 ...
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]...
ptrdiff_t GetGlobalLength() const
ConjType
Enumerated types used to specify conjugation arguments.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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...
Epetra_MultiVector * GetEpetraMultiVec()
Return the pointer to the Epetra_MultiVector object.
bool HasNormInf() const
Returns true if this object can provide an approximate inf-norm [always false for this operator]...
int GetNumberVecs() const
The number of vectors (i.e., columns) in the multivector.
View
static void MvScale(Epetra_MultiVector &mv, const std::vector< double > &alpha)
Scale each element of the i-th vector in mv with alpha[i].
const Epetra_Comm & Comm() const
Returns the Epetra_Comm communicator associated with this operator.
static void MvTimesMatAddMv(double alpha, const Epetra_MultiVector &A, const Teuchos::SerialDenseMatrix< int, double > &B, double beta, Epetra_MultiVector &mv)
Update mv with .
Traits class which defines basic operations on multivectors.
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)...
Adapter class for creating a weighted operator from an Epetra_MultiVector and Epetra_Operator.
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
bool UseTranspose() const
Returns the current UseTranspose setting [always false for this operator].
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
const Epetra_MultiVector * GetEpetraMultiVec() const
Return the pointer to the Epetra_MultiVector object.
static Teuchos::RCP< Epetra_MultiVector > Clone(const Epetra_MultiVector &mv, const int outNumVecs)
Creates a new empty Epetra_MultiVector containing numVecs columns.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
double NormInf() const
Returns the infinity norm of the global matrix [not functional for this operator].
int SetUseTranspose(bool)
If set true, the transpose of this operator will be applied [not functional for this operator]...
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
Adapter class for creating a symmetric operator from an Epetra_Operator.
void MvScale(double alpha)
Scale each element of the vectors in *this with alpha.
static void MvScale(Epetra_MultiVector &mv, double alpha)
Scale each element of the vectors in mv with alpha.
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 ...
Ordinal lbound() const
OrdinalType numCols() const
const Epetra_Comm & Comm() const
Returns the Epetra_Comm communicator associated with this operator.
Templated virtual class for creating operators that can interface with the Anasazi::OperatorTraits cl...
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)...
EpetraMultiVecFailure is thrown when a return value from an Epetra call on an Epetra_MultiVector is n...
Ordinal size() const
Types and exceptions used within Anasazi solvers and interfaces.
Copy
bool UseTranspose() const
Returns the current UseTranspose setting [always false for this operator].
static int GetVecLength(const Epetra_MultiVector &mv)
Obtain the vector length of mv.
virtual const Epetra_MultiVector * GetEpetraMultiVec() const
Return the pointer to the Epetra_MultiVector object.
Interface for multivectors used by Anasazi&#39;s linear solvers.
Adapter class for creating a symmetric operator from an Epetra_MultiVector.
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 int GetNumberVecs(const Epetra_MultiVector &mv)
Obtain the number of vectors in mv.
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)...
Anasazi&#39;s templated virtual class for constructing an operator that can interface with the OperatorTr...
virtual ~EpetraMultiVec()
Destructor.
int SetUseTranspose(bool)
If set true, the transpose of this operator will be applied [not functional for this operator]...
double NormInf() const
Returns the infinity norm of the global matrix [not functional for this operator].
OrdinalType stride() const
OrdinalType numRows() const
EpetraOpFailure is thrown when a return value from an Epetra call on an Epetra_Operator is non-zero...
void MvPrint(std::ostream &os) const
Print *this EpetraMultiVec.
Exceptions thrown to signal error in operator application.
Basic adapter class for Anasazi::MultiVec that uses Epetra_MultiVector.