00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef __Teko_EpetraOperatorWrapper_hpp__
00048 #define __Teko_EpetraOperatorWrapper_hpp__
00049
00050 #include "Thyra_LinearOpBase.hpp"
00051 #include "Epetra_Map.h"
00052 #include "Epetra_Comm.h"
00053 #include "Epetra_MultiVector.h"
00054 #include "Epetra_Operator.h"
00055
00056 #include <string>
00057
00058
00059 namespace Teko {
00060 namespace Epetra {
00061 using Teuchos::RCP;
00062
00063 class EpetraOperatorWrapper;
00064
00066 class MappingStrategy {
00067 public:
00068 virtual ~MappingStrategy() {}
00069
00078 virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
00079 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const = 0;
00080
00081
00090 virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
00091 Epetra_MultiVector& epetraX) const = 0;
00092
00093
00095 virtual const RCP<const Epetra_Map> domainMap() const = 0;
00096
00098 virtual const RCP<const Epetra_Map> rangeMap() const = 0;
00099
00101 virtual std::string toString() const = 0;
00102 };
00103
00105 class InverseMappingStrategy : public MappingStrategy {
00106 public:
00110 InverseMappingStrategy(const RCP<const MappingStrategy> & forward)
00111 : forwardStrategy_(forward)
00112 { }
00113
00114 virtual ~InverseMappingStrategy() {}
00115
00116 virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
00117 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const
00118
00119 { forwardStrategy_->copyEpetraIntoThyra(epetraX,thyraX); }
00120
00121 virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
00122 Epetra_MultiVector& epetraX) const
00123
00124 { forwardStrategy_->copyThyraIntoEpetra(thyraX,epetraX); }
00125
00127 virtual const RCP<const Epetra_Map> domainMap() const
00128 { return forwardStrategy_->rangeMap(); }
00129
00131 virtual const RCP<const Epetra_Map> rangeMap() const
00132 { return forwardStrategy_->domainMap(); }
00133
00135 virtual std::string toString() const
00136 { return std::string("InverseMapping(")+forwardStrategy_->toString()+std::string(")"); }
00137 protected:
00139 const RCP<const MappingStrategy> forwardStrategy_;
00140
00141 private:
00142 InverseMappingStrategy();
00143 InverseMappingStrategy(const InverseMappingStrategy &);
00144 };
00145
00147 class DefaultMappingStrategy : public MappingStrategy {
00148 public:
00150 DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,const Epetra_Comm & comm);
00151
00152 virtual ~DefaultMappingStrategy() {}
00153
00162 virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
00163 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const;
00164
00165
00174 virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
00175 Epetra_MultiVector& epetraX) const;
00176
00177
00179 virtual const RCP<const Epetra_Map> domainMap() const { return domainMap_; }
00180
00182 virtual const RCP<const Epetra_Map> rangeMap() const { return rangeMap_; }
00183
00185 virtual std::string toString() const
00186 { return std::string("DefaultMappingStrategy"); }
00187
00188 protected:
00189 RCP<const Thyra::VectorSpaceBase<double> > domainSpace_;
00190 RCP<const Thyra::VectorSpaceBase<double> > rangeSpace_;
00191
00192 RCP<const Epetra_Map> domainMap_;
00193 RCP<const Epetra_Map> rangeMap_;
00194 };
00195
00202 class EpetraOperatorWrapper : public Epetra_Operator
00203 {
00204 public:
00206 EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp);
00207 EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,
00208 const RCP<const MappingStrategy> & mapStrategy);
00209 EpetraOperatorWrapper(const RCP<const MappingStrategy> & mapStrategy);
00210
00212 virtual ~EpetraOperatorWrapper() {;}
00213
00215 int SetUseTranspose(bool UseTranspose) {useTranspose_ = UseTranspose; return 0;}
00216
00218 int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ;
00219
00221 int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ;
00222
00224 double NormInf() const ;
00225
00227 const char* Label() const {return label_.c_str();}
00228
00230 bool UseTranspose() const {return useTranspose_;}
00231
00233 bool HasNormInf() const {return false;}
00234
00236 const Epetra_Comm & Comm() const {return *comm_;}
00237
00239 const Epetra_Map& OperatorDomainMap() const {return *mapStrategy_->domainMap();}
00240
00242 const Epetra_Map& OperatorRangeMap() const {return *mapStrategy_->rangeMap();}
00243
00245 const RCP<const Thyra::LinearOpBase<double> > getThyraOp() const
00246 { return thyraOp_; }
00247
00249 const RCP<const MappingStrategy> getMapStrategy() const
00250 { return mapStrategy_; }
00251
00253 virtual int GetBlockRowCount();
00254
00256 virtual int GetBlockColCount();
00257
00259 Teuchos::RCP<const Epetra_Operator> GetBlock(int i,int j) const;
00260
00261 protected:
00263 EpetraOperatorWrapper();
00264
00266 RCP<const Epetra_Comm> getEpetraComm(const Thyra::LinearOpBase<double> & inOp) const;
00267
00269 void SetOperator(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,bool buildMap=true);
00270
00272 void SetMapStrategy(const RCP<const MappingStrategy> & mapStrategy)
00273 { mapStrategy_ = mapStrategy; }
00274
00276 RCP<const MappingStrategy> mapStrategy_;
00277
00279 RCP<const Thyra::LinearOpBase<double> > thyraOp_;
00280
00282 bool useTranspose_;
00283
00285 RCP<const Epetra_Comm> comm_;
00286
00288 std::string label_;
00289 };
00290 }
00291 }
00292
00293 #endif