Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_EpetraOperatorWrapper.hpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #ifndef __Teko_EpetraOperatorWrapper_hpp__
48 #define __Teko_EpetraOperatorWrapper_hpp__
49 
50 #include "Thyra_LinearOpBase.hpp"
51 #include "Epetra_Map.h"
52 #include "Epetra_Comm.h"
53 #include "Epetra_MultiVector.h"
54 #include "Epetra_Operator.h"
55 
56 #include <string>
57 
58 
59 namespace Teko {
60 namespace Epetra {
61  using Teuchos::RCP;
62 
63  class EpetraOperatorWrapper;
64 
67  public:
68  virtual ~MappingStrategy() {}
69 
78  virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
79  const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const = 0;
80  // const EpetraOperatorWrapper & eow) const = 0;
81 
90  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
91  Epetra_MultiVector& epetraX) const = 0;
92  // const EpetraOperatorWrapper & eow) const = 0;
93 
95  virtual const RCP<const Epetra_Map> domainMap() const = 0;
96 
98  virtual const RCP<const Epetra_Map> rangeMap() const = 0;
99 
101  virtual std::string toString() const = 0;
102  };
103 
106  public:
110  InverseMappingStrategy(const RCP<const MappingStrategy> & forward)
111  : forwardStrategy_(forward)
112  { }
113 
114  virtual ~InverseMappingStrategy() {}
115 
116  virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
117  const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const
118  // const EpetraOperatorWrapper & eow) const
119  { forwardStrategy_->copyEpetraIntoThyra(epetraX,thyraX); }
120 
121  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
122  Epetra_MultiVector& epetraX) const
123  // const EpetraOperatorWrapper & eow) const
124  { forwardStrategy_->copyThyraIntoEpetra(thyraX,epetraX); }
125 
127  virtual const RCP<const Epetra_Map> domainMap() const
128  { return forwardStrategy_->rangeMap(); }
129 
131  virtual const RCP<const Epetra_Map> rangeMap() const
132  { return forwardStrategy_->domainMap(); }
133 
135  virtual std::string toString() const
136  { return std::string("InverseMapping(")+forwardStrategy_->toString()+std::string(")"); }
137  protected:
139  const RCP<const MappingStrategy> forwardStrategy_;
140 
141  private:
144  };
145 
148  public:
150  DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,const Epetra_Comm & comm);
151 
152  virtual ~DefaultMappingStrategy() {}
153 
162  virtual void copyEpetraIntoThyra(const Epetra_MultiVector& epetraX,
163  const Teuchos::Ptr<Thyra::MultiVectorBase<double> > & thyraX) const;
164  // const EpetraOperatorWrapper & eow) const;
165 
174  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> > & thyraX,
175  Epetra_MultiVector& epetraX) const;
176  // const EpetraOperatorWrapper & eow) const;
177 
179  virtual const RCP<const Epetra_Map> domainMap() const { return domainMap_; }
180 
182  virtual const RCP<const Epetra_Map> rangeMap() const { return rangeMap_; }
183 
185  virtual std::string toString() const
186  { return std::string("DefaultMappingStrategy"); }
187 
188  protected:
189  RCP<const Thyra::VectorSpaceBase<double> > domainSpace_;
190  RCP<const Thyra::VectorSpaceBase<double> > rangeSpace_;
191 
192  RCP<const Epetra_Map> domainMap_;
193  RCP<const Epetra_Map> rangeMap_;
194  };
195 
202  class EpetraOperatorWrapper : public Epetra_Operator
203  {
204  public:
206  EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp);
207  EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,
208  const RCP<const MappingStrategy> & mapStrategy);
209  EpetraOperatorWrapper(const RCP<const MappingStrategy> & mapStrategy);
210 
212  virtual ~EpetraOperatorWrapper() {;}
213 
215  int SetUseTranspose(bool useTranspose) {
216  useTranspose_ = useTranspose;
217  return 0;
218  }
219 
221  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ;
222 
224  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ;
225 
227  double NormInf() const ;
228 
230  const char* Label() const {return label_.c_str();}
231 
233  bool UseTranspose() const {return useTranspose_;}
234 
236  bool HasNormInf() const {return false;}
237 
239  const Epetra_Comm & Comm() const {return *comm_;}
240 
242  const Epetra_Map& OperatorDomainMap() const {return *mapStrategy_->domainMap();}
243 
245  const Epetra_Map& OperatorRangeMap() const {return *mapStrategy_->rangeMap();}
246 
248  const RCP<const Thyra::LinearOpBase<double> > getThyraOp() const
249  { return thyraOp_; }
250 
252  const RCP<const MappingStrategy> getMapStrategy() const
253  { return mapStrategy_; }
254 
256  virtual int GetBlockRowCount();
257 
259  virtual int GetBlockColCount();
260 
262  Teuchos::RCP<const Epetra_Operator> GetBlock(int i,int j) const;
263 
264  protected:
267 
269  RCP<const Epetra_Comm> getEpetraComm(const Thyra::LinearOpBase<double> & inOp) const;
270 
272  void SetOperator(const RCP<const Thyra::LinearOpBase<double> > & thyraOp,bool buildMap=true);
273 
275  void SetMapStrategy(const RCP<const MappingStrategy> & mapStrategy)
276  { mapStrategy_ = mapStrategy; }
277 
279  RCP<const MappingStrategy> mapStrategy_;
280 
282  RCP<const Thyra::LinearOpBase<double> > thyraOp_;
283 
285  bool useTranspose_;
286 
288  RCP<const Epetra_Comm> comm_;
289 
291  std::string label_;
292  };
293 } // end namespace Epetra
294 } // end namespace Teko
295 
296 #endif
RCP< const Thyra::VectorSpaceBase< double > > domainSpace_
Domain space object.
RCP< const Epetra_Map > domainMap_
Pointer to the constructed domain map.
virtual int GetBlockColCount()
Get the number of block columns in this operator.
RCP< const Epetra_Map > rangeMap_
Pointer to the constructed range map.
virtual const RCP< const Epetra_Map > rangeMap() const
Range map for this strategy.
virtual void copyEpetraIntoThyra(const Epetra_MultiVector &epetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< double > > &thyraX) const
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual std::string toString() const =0
Identifier string.
virtual const RCP< const Epetra_Map > rangeMap() const
Range map for this strategy.
virtual void copyEpetraIntoThyra(const Epetra_MultiVector &epetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< double > > &thyraX) const
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
const RCP< const MappingStrategy > forwardStrategy_
Forward mapping strategy object.
Teuchos::RCP< const Epetra_Operator > GetBlock(int i, int j) const
Grab the i,j block.
virtual std::string toString() const
Identifier string.
virtual int GetBlockRowCount()
Get the number of block rows in this operator.
virtual const RCP< const Epetra_Map > domainMap() const =0
Domain map for this strategy.
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...
virtual std::string toString() const
Identifier string.
virtual void copyEpetraIntoThyra(const Epetra_MultiVector &epetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< double > > &thyraX) const =0
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
Flip a mapping strategy object around to give the &quot;inverse&quot; mapping strategy.
const RCP< const MappingStrategy > getMapStrategy() const
Get the mapping strategy for this wrapper (translate between Thyra and Epetra)
virtual const RCP< const Epetra_Map > domainMap() const
Domain map for this strategy.
virtual const RCP< const Epetra_Map > rangeMap() const =0
Range map for this strategy.
virtual void copyThyraIntoEpetra(const RCP< const Thyra::MultiVectorBase< double > > &thyraX, Epetra_MultiVector &epetraX) const =0
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
virtual void copyThyraIntoEpetra(const RCP< const Thyra::MultiVectorBase< double > > &thyraX, Epetra_MultiVector &epetraX) const
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
virtual void copyThyraIntoEpetra(const RCP< const Thyra::MultiVectorBase< double > > &thyraX, Epetra_MultiVector &epetraX) const
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
InverseMappingStrategy(const RCP< const MappingStrategy > &forward)
Constructor to build a inverse MappingStrategy from a forward map.
default mapping strategy for the basic EpetraOperatorWrapper
const RCP< const Thyra::LinearOpBase< double > > getThyraOp() const
Return the thyra operator associated with this wrapper.
RCP< const Thyra::VectorSpaceBase< double > > rangeSpace_
Range space object.
Abstract Mapping strategy for an EpetraOperatorWrapper.
virtual const RCP< const Epetra_Map > domainMap() const
Domain map for this strategy.