|
Teko Version of the Day
|
00001 /* 00002 // @HEADER 00003 // 00004 // *********************************************************************** 00005 // 00006 // Teko: A package for block and physics based preconditioning 00007 // Copyright 2010 Sandia Corporation 00008 // 00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00010 // the U.S. Government retains certain rights in this software. 00011 // 00012 // Redistribution and use in source and binary forms, with or without 00013 // modification, are permitted provided that the following conditions are 00014 // met: 00015 // 00016 // 1. Redistributions of source code must retain the above copyright 00017 // notice, this list of conditions and the following disclaimer. 00018 // 00019 // 2. Redistributions in binary form must reproduce the above copyright 00020 // notice, this list of conditions and the following disclaimer in the 00021 // documentation and/or other materials provided with the distribution. 00022 // 00023 // 3. Neither the name of the Corporation nor the names of the 00024 // contributors may be used to endorse or promote products derived from 00025 // this software without specific prior written permission. 00026 // 00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 // 00039 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov) 00040 // 00041 // *********************************************************************** 00042 // 00043 // @HEADER 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 00079 virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX, 00080 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX, 00081 const EpetraOperatorWrapper & eow) const = 0; 00082 00092 virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX, 00093 Epetra_MultiVector& epetraX, 00094 const EpetraOperatorWrapper & eow) const = 0; 00095 00097 virtual const RCP<const Epetra_Map> domainMap() const = 0; 00098 00100 virtual const RCP<const Epetra_Map> rangeMap() const = 0; 00101 00103 virtual std::string toString() const = 0; 00104 }; 00105 00107 class InverseMappingStrategy : public MappingStrategy { 00108 public: 00112 InverseMappingStrategy(const RCP<const MappingStrategy> & forward) 00113 : forwardStrategy_(forward) 00114 { } 00115 00116 virtual ~InverseMappingStrategy() {} 00117 00118 virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX, 00119 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX, 00120 const EpetraOperatorWrapper & eow) const 00121 { forwardStrategy_->copyEpetraIntoThyra(epetraX,thyraX,eow); } 00122 00123 virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX, 00124 Epetra_MultiVector& epetraX, 00125 const EpetraOperatorWrapper & eow) const 00126 { forwardStrategy_->copyThyraIntoEpetra(thyraX,epetraX,eow); } 00127 00129 virtual const RCP<const Epetra_Map> domainMap() const 00130 { return forwardStrategy_->rangeMap(); } 00131 00133 virtual const RCP<const Epetra_Map> rangeMap() const 00134 { return forwardStrategy_->domainMap(); } 00135 00137 virtual std::string toString() const 00138 { return std::string("InverseMapping(")+forwardStrategy_->toString()+std::string(")"); } 00139 protected: 00141 const RCP<const MappingStrategy> forwardStrategy_; 00142 00143 private: 00144 InverseMappingStrategy(); 00145 InverseMappingStrategy(const InverseMappingStrategy &); 00146 }; 00147 00149 class DefaultMappingStrategy : public MappingStrategy { 00150 public: 00152 DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,const Epetra_Comm & comm); 00153 00154 virtual ~DefaultMappingStrategy() {} 00155 00165 virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX, 00166 const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX, 00167 const EpetraOperatorWrapper & eow) const; 00168 00178 virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX, 00179 Epetra_MultiVector& epetraX, 00180 const EpetraOperatorWrapper & eow) const; 00181 00183 virtual const RCP<const Epetra_Map> domainMap() const { return domainMap_; } 00184 00186 virtual const RCP<const Epetra_Map> rangeMap() const { return rangeMap_; } 00187 00189 virtual std::string toString() const 00190 { return std::string("DefaultMappingStrategy"); } 00191 00192 protected: 00193 RCP<const Thyra::VectorSpaceBase<double> > domainSpace_; 00194 RCP<const Thyra::VectorSpaceBase<double> > rangeSpace_; 00195 00196 RCP<const Epetra_Map> domainMap_; 00197 RCP<const Epetra_Map> rangeMap_; 00198 }; 00199 00206 class EpetraOperatorWrapper : public Epetra_Operator 00207 { 00208 public: 00210 EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp); 00211 EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp, 00212 const RCP<const MappingStrategy> & mapStrategy); 00213 EpetraOperatorWrapper(const RCP<const MappingStrategy> & mapStrategy); 00214 00216 virtual ~EpetraOperatorWrapper() {;} 00217 00219 int SetUseTranspose(bool UseTranspose) {useTranspose_ = UseTranspose; return 0;} 00220 00222 int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ; 00223 00225 int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ; 00226 00228 double NormInf() const ; 00229 00231 const char* Label() const {return label_.c_str();} 00232 00234 bool UseTranspose() const {return useTranspose_;} 00235 00237 bool HasNormInf() const {return false;} 00238 00240 const Epetra_Comm & Comm() const {return *comm_;} 00241 00243 const Epetra_Map& OperatorDomainMap() const {return *mapStrategy_->domainMap();} 00244 00246 const Epetra_Map& OperatorRangeMap() const {return *mapStrategy_->rangeMap();} 00247 00249 const RCP<const Thyra::LinearOpBase<double> > getThyraOp() const 00250 { return thyraOp_; } 00251 00253 const RCP<const MappingStrategy> getMapStrategy() const 00254 { return mapStrategy_; } 00255 00257 virtual int GetBlockRowCount(); 00258 00260 virtual int GetBlockColCount(); 00261 00262 protected: 00264 EpetraOperatorWrapper(); 00265 00267 RCP<const Epetra_Comm> getEpetraComm(const Thyra::LinearOpBase<double> & inOp) const; 00268 00270 void SetOperator(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,bool buildMap=true); 00271 00273 void SetMapStrategy(const RCP<const MappingStrategy> & mapStrategy) 00274 { mapStrategy_ = mapStrategy; } 00275 00277 RCP<const MappingStrategy> mapStrategy_; 00278 00280 RCP<const Thyra::LinearOpBase<double> > thyraOp_; 00281 00283 bool useTranspose_; 00284 00286 RCP<const Epetra_Comm> comm_; 00287 00289 std::string label_; 00290 }; 00291 } // end namespace Epetra 00292 } // end namespace Teko 00293 00294 #endif
1.7.4