• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MLAPI_EpetraBaseOperator.h

Go to the documentation of this file.
00001 #ifndef MLAPI_EPETRAPRECONDITIONER_H
00002 #define MLAPI_EPETRAPRECONDITIONER_H
00003 
00013 /* ******************************************************************** */
00014 /* See the file COPYRIGHT for a complete copyright notice, contact      */
00015 /* person and disclaimer.                                               */        
00016 /* ******************************************************************** */
00017 
00018 #include "ml_common.h"
00019 
00020 #include "Epetra_Operator.h"
00021 #include "MLAPI_Error.h"
00022 #include "MLAPI_BaseOperator.h"
00023 #include "MLAPI_Workspace.h"
00024 #include "Epetra_MultiVector.h"
00025 #include "Epetra_Map.h"
00026 #include "Epetra_Comm.h"
00027 #include "ml_epetra.h"
00028 
00029 namespace MLAPI {
00030 
00042 class EpetraBaseOperator : public Epetra_Operator {
00043 
00044 public:
00045 
00047   EpetraBaseOperator(const Epetra_Map& Map,
00048                      const BaseOperator& Op) :
00049     Map_(Map),
00050     Op_(Op)
00051   {}
00052 
00054   virtual ~EpetraBaseOperator() {}
00055 
00057 
00059   int ApplyInverse(const Epetra_MultiVector& X_Epetra,
00060                    Epetra_MultiVector& Y_Epetra) const
00061   {
00062     return(Apply(X_Epetra, Y_Epetra));
00063   }
00064 
00066   virtual int SetUseTranspose(bool UseTranspose)
00067   {
00068     ML_CHK_ERR(-1);
00069   }
00070 
00072   virtual int Apply(const Epetra_MultiVector& X_Epetra, 
00073                     Epetra_MultiVector& Y_Epetra) const
00074   {
00075     // NOTE: no checks on maps. These checks can be
00076     // expensive, and I prefer to skip them.
00077 
00078     if (X_Epetra.NumVectors() != Y_Epetra.NumVectors())
00079       ML_THROW("X.NumVectors() != Y.NumVectors(), " +
00080                GetString(X_Epetra.NumVectors()) + " vs. " +
00081                GetString(Y_Epetra.NumVectors()), -1);
00082 
00083     // FIXME: this is not the most efficient way (though for
00084     // ML should be the same, as there is not native support
00085     // for multivectors I am using)
00086 
00087     for (int v = 0 ; v < X_Epetra.NumVectors() ; ++v) {
00088 
00089       MultiVector X_ML(Op_.GetOperatorDomainSpace(),(double**)&(X_Epetra[v]), 1);
00090 
00091       // need additional vector for AztecOO
00092       MultiVector Y_ML(Op_.GetOperatorRangeSpace(), 1);
00093 
00094       ML_CHK_ERR(Op_.Apply(X_ML,Y_ML));
00095 
00096       int n = Y_Epetra.MyLength();
00097       int incr = 1;
00098       DCOPY_F77(&n, Y_ML.GetValues(0), &incr, &(Y_Epetra[v][0]), &incr);
00099     }
00100 
00101     return(0);
00102   }
00103 
00105   virtual double NormInf() const
00106   {
00107     return(-1.0);
00108   }
00109 
00111   virtual const char* Label() const
00112   {
00113     return(Op_.GetLabel().c_str());
00114   }
00115 
00117   virtual bool UseTranspose() const
00118   {
00119     return(false);
00120   }
00121 
00123   virtual bool HasNormInf() const 
00124   {
00125     return(false);
00126   }
00127 
00129   virtual const Epetra_Comm& Comm() const
00130   {
00131     return(GetEpetra_Comm());
00132   }
00133 
00135   virtual const Epetra_Map& OperatorDomainMap() const
00136   {
00137     return(Map_);
00138   }
00139 
00141   virtual const Epetra_Map& OperatorRangeMap() const
00142   {
00143     return(Map_);
00144   }
00145 
00147   virtual const Epetra_Map& Map() const
00148   {
00149     return(Map_);
00150   }
00151 
00152   const BaseOperator& GetBaseOperator() const
00153   {
00154     return(Op_);
00155   }
00156      
00157 private:
00158 
00160   EpetraBaseOperator(const EpetraBaseOperator& rhs) :
00161     Map_(rhs.Map()),
00162     Op_(rhs.GetBaseOperator())
00163   { }
00164 
00166   EpetraBaseOperator& operator=(const EpetraBaseOperator& rhs)
00167   { 
00168     return(*this);
00169   }
00170 
00172   const Epetra_Map& Map_;
00174   const BaseOperator& Op_;
00175 
00176 }; // Epetra_MultiVector
00177 
00178 } // namespace MLAPI
00179 
00180 #endif