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 namespace Teko {
59 namespace Epetra {
60 using Teuchos::RCP;
61 
62 class EpetraOperatorWrapper;
63 
66  public:
67  virtual ~MappingStrategy() {}
68 
77  virtual void copyEpetraIntoThyra(
78  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) : forwardStrategy_(forward) {}
111 
112  virtual ~InverseMappingStrategy() {}
113 
114  virtual void copyEpetraIntoThyra(
115  const Epetra_MultiVector& epetraX,
116  const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyraX) const
117  // const EpetraOperatorWrapper & eow) const
118  {
119  forwardStrategy_->copyEpetraIntoThyra(epetraX, thyraX);
120  }
121 
122  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> >& thyraX,
123  Epetra_MultiVector& epetraX) const
124  // const EpetraOperatorWrapper & eow) const
125  {
126  forwardStrategy_->copyThyraIntoEpetra(thyraX, epetraX);
127  }
128 
130  virtual const RCP<const Epetra_Map> domainMap() const { return forwardStrategy_->rangeMap(); }
131 
133  virtual const RCP<const Epetra_Map> rangeMap() const { return forwardStrategy_->domainMap(); }
134 
136  virtual std::string toString() const {
137  return std::string("InverseMapping(") + forwardStrategy_->toString() + std::string(")");
138  }
139 
140  protected:
142  const RCP<const MappingStrategy> forwardStrategy_;
143 
144  private:
147 };
148 
151  public:
153  DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<double> >& thyraOp,
154  const Epetra_Comm& comm);
155 
156  virtual ~DefaultMappingStrategy() {}
157 
166  virtual void copyEpetraIntoThyra(
167  const Epetra_MultiVector& epetraX,
168  const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyraX) const;
169  // const EpetraOperatorWrapper & eow) const;
170 
179  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> >& thyraX,
180  Epetra_MultiVector& epetraX) const;
181  // const EpetraOperatorWrapper & eow) const;
182 
184  virtual const RCP<const Epetra_Map> domainMap() const { return domainMap_; }
185 
187  virtual const RCP<const Epetra_Map> rangeMap() const { return rangeMap_; }
188 
190  virtual std::string toString() const { return std::string("DefaultMappingStrategy"); }
191 
192  protected:
193  RCP<const Thyra::VectorSpaceBase<double> > domainSpace_;
194  RCP<const Thyra::VectorSpaceBase<double> > rangeSpace_;
195 
196  RCP<const Epetra_Map> domainMap_;
197  RCP<const Epetra_Map> rangeMap_;
198 };
199 
206 class EpetraOperatorWrapper : public Epetra_Operator {
207  public:
209  EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> >& thyraOp);
210  EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> >& thyraOp,
211  const RCP<const MappingStrategy>& mapStrategy);
212  EpetraOperatorWrapper(const RCP<const MappingStrategy>& mapStrategy);
213 
215  virtual ~EpetraOperatorWrapper() { ; }
216 
218  int SetUseTranspose(bool useTranspose) {
219  useTranspose_ = useTranspose;
220  return 0;
221  }
222 
224  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
225 
227  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
228 
230  double NormInf() const;
231 
233  const char* Label() const { return label_.c_str(); }
234 
236  bool UseTranspose() const { return useTranspose_; }
237 
239  bool HasNormInf() const { return false; }
240 
242  const Epetra_Comm& Comm() const { return *comm_; }
243 
245  const Epetra_Map& OperatorDomainMap() const { return *mapStrategy_->domainMap(); }
246 
248  const Epetra_Map& OperatorRangeMap() const { return *mapStrategy_->rangeMap(); }
249 
251  const RCP<const Thyra::LinearOpBase<double> > getThyraOp() const { return thyraOp_; }
252 
254  const RCP<const MappingStrategy> getMapStrategy() const { return mapStrategy_; }
255 
257  virtual int GetBlockRowCount();
258 
260  virtual int GetBlockColCount();
261 
263  Teuchos::RCP<const Epetra_Operator> GetBlock(int i, int j) const;
264 
265  protected:
268 
270  RCP<const Epetra_Comm> getEpetraComm(const Thyra::LinearOpBase<double>& inOp) const;
271 
273  void SetOperator(const RCP<const Thyra::LinearOpBase<double> >& thyraOp, bool buildMap = true);
274 
276  void SetMapStrategy(const RCP<const MappingStrategy>& mapStrategy) { 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.