Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_EpetraOperatorWrapper.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Teko: A package for block and physics based preconditioning
4 //
5 // Copyright 2010 NTESS and the Teko contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef __Teko_EpetraOperatorWrapper_hpp__
11 #define __Teko_EpetraOperatorWrapper_hpp__
12 
13 #include "Thyra_LinearOpBase.hpp"
14 #include "Epetra_Map.h"
15 #include "Epetra_Comm.h"
16 #include "Epetra_MultiVector.h"
17 #include "Epetra_Operator.h"
18 
19 #include <string>
20 
21 namespace Teko {
22 namespace Epetra {
23 using Teuchos::RCP;
24 
25 class EpetraOperatorWrapper;
26 
29  public:
30  virtual ~MappingStrategy() {}
31 
40  virtual void copyEpetraIntoThyra(
41  const Epetra_MultiVector& epetraX,
42  const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyraX) const = 0;
43  // const EpetraOperatorWrapper & eow) const = 0;
44 
53  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> >& thyraX,
54  Epetra_MultiVector& epetraX) const = 0;
55  // const EpetraOperatorWrapper & eow) const = 0;
56 
58  virtual const RCP<const Epetra_Map> domainMap() const = 0;
59 
61  virtual const RCP<const Epetra_Map> rangeMap() const = 0;
62 
64  virtual std::string toString() const = 0;
65 };
66 
69  public:
73  InverseMappingStrategy(const RCP<const MappingStrategy>& forward) : forwardStrategy_(forward) {}
74 
75  virtual ~InverseMappingStrategy() {}
76 
77  virtual void copyEpetraIntoThyra(
78  const Epetra_MultiVector& epetraX,
79  const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyraX) const
80  // const EpetraOperatorWrapper & eow) const
81  {
82  forwardStrategy_->copyEpetraIntoThyra(epetraX, thyraX);
83  }
84 
85  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> >& thyraX,
86  Epetra_MultiVector& epetraX) const
87  // const EpetraOperatorWrapper & eow) const
88  {
89  forwardStrategy_->copyThyraIntoEpetra(thyraX, epetraX);
90  }
91 
93  virtual const RCP<const Epetra_Map> domainMap() const { return forwardStrategy_->rangeMap(); }
94 
96  virtual const RCP<const Epetra_Map> rangeMap() const { return forwardStrategy_->domainMap(); }
97 
99  virtual std::string toString() const {
100  return std::string("InverseMapping(") + forwardStrategy_->toString() + std::string(")");
101  }
102 
103  protected:
105  const RCP<const MappingStrategy> forwardStrategy_;
106 
107  private:
110 };
111 
114  public:
116  DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<double> >& thyraOp,
117  const Epetra_Comm& comm);
118 
119  virtual ~DefaultMappingStrategy() {}
120 
129  virtual void copyEpetraIntoThyra(
130  const Epetra_MultiVector& epetraX,
131  const Teuchos::Ptr<Thyra::MultiVectorBase<double> >& thyraX) const;
132  // const EpetraOperatorWrapper & eow) const;
133 
142  virtual void copyThyraIntoEpetra(const RCP<const Thyra::MultiVectorBase<double> >& thyraX,
143  Epetra_MultiVector& epetraX) const;
144  // const EpetraOperatorWrapper & eow) const;
145 
147  virtual const RCP<const Epetra_Map> domainMap() const { return domainMap_; }
148 
150  virtual const RCP<const Epetra_Map> rangeMap() const { return rangeMap_; }
151 
153  virtual std::string toString() const { return std::string("DefaultMappingStrategy"); }
154 
155  protected:
156  RCP<const Thyra::VectorSpaceBase<double> > domainSpace_;
157  RCP<const Thyra::VectorSpaceBase<double> > rangeSpace_;
158 
159  RCP<const Epetra_Map> domainMap_;
160  RCP<const Epetra_Map> rangeMap_;
161 };
162 
169 class EpetraOperatorWrapper : public Epetra_Operator {
170  public:
172  EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> >& thyraOp);
173  EpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<double> >& thyraOp,
174  const RCP<const MappingStrategy>& mapStrategy);
175  EpetraOperatorWrapper(const RCP<const MappingStrategy>& mapStrategy);
176 
178  virtual ~EpetraOperatorWrapper() { ; }
179 
181  int SetUseTranspose(bool useTranspose) {
182  useTranspose_ = useTranspose;
183  return 0;
184  }
185 
187  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
188 
190  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
191 
193  double NormInf() const;
194 
196  const char* Label() const { return label_.c_str(); }
197 
199  bool UseTranspose() const { return useTranspose_; }
200 
202  bool HasNormInf() const { return false; }
203 
205  const Epetra_Comm& Comm() const { return *comm_; }
206 
208  const Epetra_Map& OperatorDomainMap() const { return *mapStrategy_->domainMap(); }
209 
211  const Epetra_Map& OperatorRangeMap() const { return *mapStrategy_->rangeMap(); }
212 
214  const RCP<const Thyra::LinearOpBase<double> > getThyraOp() const { return thyraOp_; }
215 
217  const RCP<const MappingStrategy> getMapStrategy() const { return mapStrategy_; }
218 
220  virtual int GetBlockRowCount();
221 
223  virtual int GetBlockColCount();
224 
226  Teuchos::RCP<const Epetra_Operator> GetBlock(int i, int j) const;
227 
228  protected:
231 
233  RCP<const Epetra_Comm> getEpetraComm(const Thyra::LinearOpBase<double>& inOp) const;
234 
236  void SetOperator(const RCP<const Thyra::LinearOpBase<double> >& thyraOp, bool buildMap = true);
237 
239  void SetMapStrategy(const RCP<const MappingStrategy>& mapStrategy) { mapStrategy_ = mapStrategy; }
240 
242  RCP<const MappingStrategy> mapStrategy_;
243 
245  RCP<const Thyra::LinearOpBase<double> > thyraOp_;
246 
248  bool useTranspose_;
249 
251  RCP<const Epetra_Comm> comm_;
252 
254  std::string label_;
255 };
256 } // end namespace Epetra
257 } // end namespace Teko
258 
259 #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.