Teko Version of the Day
Teko_EpetraOperatorWrapper.hpp
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 
00078      virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
00079                                       const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const = 0;
00080                                       // const EpetraOperatorWrapper & eow) const = 0;
00081 
00090      virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
00091                                       Epetra_MultiVector& epetraX) const = 0;
00092                                       // const EpetraOperatorWrapper & eow) const = 0;
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                                       // const EpetraOperatorWrapper & eow) const
00119      { forwardStrategy_->copyEpetraIntoThyra(epetraX,thyraX); }
00120 
00121      virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
00122                                       Epetra_MultiVector& epetraX) const
00123                                       // const EpetraOperatorWrapper & eow) const
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                                       // const EpetraOperatorWrapper & eow) const;
00165 
00174      virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
00175                                       Epetra_MultiVector& epetraX) const;
00176                                       // const EpetraOperatorWrapper & eow) const;
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 } // end namespace Epetra 
00291 } // end namespace Teko
00292 
00293 #endif 
 All Classes Files Functions Variables