Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_TpetraOperatorWrapper.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_TpetraOperatorWrapper_hpp__
48 #define __Teko_TpetraOperatorWrapper_hpp__
49 
50 #include "Thyra_LinearOpBase.hpp"
51 #include "Tpetra_Map.hpp"
52 #include "Tpetra_MultiVector.hpp"
53 #include "Tpetra_Operator.hpp"
54 #include "Teko_ConfigDefs.hpp"
55 
56 #include <string>
57 
58 namespace Teko {
59 namespace TpetraHelpers {
60 using Teuchos::RCP;
61 
62 class TpetraOperatorWrapper;
63 
66  public:
67  virtual ~MappingStrategy() {}
68 
77  virtual void copyTpetraIntoThyra(
78  const Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX,
79  const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyraX) const = 0;
80  // const TpetraOperatorWrapper & eow) const = 0;
81 
90  virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> >& thyraX,
91  Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX) const = 0;
92  // const TpetraOperatorWrapper & eow) const = 0;
93 
95  virtual const RCP<const Tpetra::Map<LO, GO, NT> > domainMap() const = 0;
96 
98  virtual const RCP<const Tpetra::Map<LO, GO, NT> > 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 copyTpetraIntoThyra(const Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX,
115  const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyraX) const
116  // const TpetraOperatorWrapper & eow) const
117  {
118  forwardStrategy_->copyTpetraIntoThyra(tpetraX, thyraX);
119  }
120 
121  virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> >& thyraX,
122  Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX) const
123  // const TpetraOperatorWrapper & eow) const
124  {
125  forwardStrategy_->copyThyraIntoTpetra(thyraX, tpetraX);
126  }
127 
129  virtual const RCP<const Tpetra::Map<LO, GO, NT> > domainMap() const {
130  return forwardStrategy_->rangeMap();
131  }
132 
134  virtual const RCP<const Tpetra::Map<LO, GO, NT> > rangeMap() const {
135  return forwardStrategy_->domainMap();
136  }
137 
139  virtual std::string toString() const {
140  return std::string("InverseMapping(") + forwardStrategy_->toString() + std::string(")");
141  }
142 
143  protected:
145  const RCP<const MappingStrategy> forwardStrategy_;
146 
147  private:
150 };
151 
154  public:
156  DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp,
157  const Teuchos::Comm<Thyra::Ordinal>& comm);
158 
159  virtual ~DefaultMappingStrategy() {}
160 
169  virtual void copyTpetraIntoThyra(const Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX,
170  const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyraX) const;
171  // const TpetraOperatorWrapper & eow) const;
172 
181  virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> >& thyraX,
182  Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX) const;
183  // const TpetraOperatorWrapper & eow) const;
184 
186  virtual const RCP<const Tpetra::Map<LO, GO, NT> > domainMap() const { return domainMap_; }
187 
189  virtual const RCP<const Tpetra::Map<LO, GO, NT> > rangeMap() const { return rangeMap_; }
190 
192  virtual std::string toString() const { return std::string("DefaultMappingStrategy"); }
193 
194  protected:
195  RCP<const Thyra::VectorSpaceBase<ST> > domainSpace_;
196  RCP<const Thyra::VectorSpaceBase<ST> > rangeSpace_;
197 
198  RCP<const Tpetra::Map<LO, GO, NT> > domainMap_;
199  RCP<const Tpetra::Map<LO, GO, NT> > rangeMap_;
200 };
201 
208 class TpetraOperatorWrapper : public Tpetra::Operator<ST, LO, GO, NT> {
209  public:
211  TpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp);
212  TpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp,
213  const RCP<const MappingStrategy>& mapStrategy);
214  TpetraOperatorWrapper(const RCP<const MappingStrategy>& mapStrategy);
215 
217  virtual ~TpetraOperatorWrapper() { ; }
218 
220  int SetUseTranspose(bool useTranspose) {
221  useTranspose_ = useTranspose;
222  return 0;
223  }
224 
226  void apply(const Tpetra::MultiVector<ST, LO, GO, NT>& X, Tpetra::MultiVector<ST, LO, GO, NT>& Y,
227  Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
228  ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
229 
231  void applyInverse(const Tpetra::MultiVector<ST, LO, GO, NT>& X,
232  Tpetra::MultiVector<ST, LO, GO, NT>& Y,
233  Teuchos::ETransp mode = Teuchos::NO_TRANS,
234  ST alpha = Teuchos::ScalarTraits<ST>::one(),
235  ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
236 
238  double NormInf() const;
239 
241  const char* Label() const { return label_.c_str(); }
242 
244  bool UseTranspose() const { return useTranspose_; }
245 
247  bool HasNormInf() const { return false; }
248 
250  const Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> >& Comm() const { return comm_; }
251 
253  Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getDomainMap() const {
254  return mapStrategy_->domainMap();
255  }
256 
258  Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getRangeMap() const {
259  return mapStrategy_->rangeMap();
260  }
261 
263  const RCP<const Thyra::LinearOpBase<ST> > getThyraOp() const { return thyraOp_; }
264 
266  const RCP<const MappingStrategy> getMapStrategy() const { return mapStrategy_; }
267 
269  virtual int GetBlockRowCount();
270 
272  virtual int GetBlockColCount();
273 
275  Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> > GetBlock(int i, int j) const;
276 
277  protected:
280 
282  RCP<const Teuchos::Comm<Thyra::Ordinal> > getThyraComm(const Thyra::LinearOpBase<ST>& inOp) const;
283 
285  void SetOperator(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp, bool buildMap = true);
286 
288  void SetMapStrategy(const RCP<const MappingStrategy>& mapStrategy) { mapStrategy_ = mapStrategy; }
289 
291  RCP<const MappingStrategy> mapStrategy_;
292 
294  RCP<const Thyra::LinearOpBase<ST> > thyraOp_;
295 
297  bool useTranspose_;
298 
300  RCP<const Teuchos::Comm<Thyra::Ordinal> > comm_;
301 
303  std::string label_;
304 };
305 } // namespace TpetraHelpers
306 } // end namespace Teko
307 
308 #endif
RCP< const Thyra::VectorSpaceBase< ST > > domainSpace_
Domain space object.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > domainMap() const
Domain map for this strategy.
virtual void copyTpetraIntoThyra(const Tpetra::MultiVector< ST, LO, GO, NT > &tpetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< ST > > &thyraX) const =0
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual std::string toString() const
Identifier string.
virtual void copyThyraIntoTpetra(const RCP< const Thyra::MultiVectorBase< ST > > &thyraX, Tpetra::MultiVector< ST, LO, GO, NT > &tpetraX) const
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > domainMap() const
Domain map for this strategy.
InverseMappingStrategy(const RCP< const MappingStrategy > &forward)
Constructor to build a inverse MappingStrategy from a forward map.
default mapping strategy for the basic TpetraOperatorWrapper
virtual void copyThyraIntoTpetra(const RCP< const Thyra::MultiVectorBase< ST > > &thyraX, Tpetra::MultiVector< ST, LO, GO, NT > &tpetraX) const
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
Abstract Mapping strategy for an TpetraOperatorWrapper.
RCP< const Thyra::VectorSpaceBase< ST > > rangeSpace_
Range space object.
const RCP< const Thyra::LinearOpBase< ST > > getThyraOp() const
Return the thyra operator associated with this wrapper.
virtual void copyThyraIntoTpetra(const RCP< const Thyra::MultiVectorBase< ST > > &thyraX, Tpetra::MultiVector< ST, LO, GO, NT > &tpetraX) const =0
Copy an Thyra::MultiVectorBase into a Epetra_MultiVector.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > rangeMap() const =0
Range map for this strategy.
virtual std::string toString() const
Identifier string.
const RCP< const MappingStrategy > forwardStrategy_
Forward mapping strategy object.
Flip a mapping strategy object around to give the &quot;inverse&quot; mapping strategy.
virtual void copyTpetraIntoThyra(const Tpetra::MultiVector< ST, LO, GO, NT > &tpetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< ST > > &thyraX) const
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > rangeMap() const
Range map for this strategy.
virtual std::string toString() const =0
Identifier string.
Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > GetBlock(int i, int j) const
Grab the i,j block.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > rangeMap() const
Range map for this strategy.
const RCP< const MappingStrategy > getMapStrategy() const
Get the mapping strategy for this wrapper (translate between Thyra and Epetra)
virtual void copyTpetraIntoThyra(const Tpetra::MultiVector< ST, LO, GO, NT > &tpetraX, const Teuchos::Ptr< Thyra::MultiVectorBase< ST > > &thyraX) const
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual int GetBlockRowCount()
Get the number of block rows in this operator.
virtual int GetBlockColCount()
Get the number of block columns in this operator.
RCP< const Tpetra::Map< LO, GO, NT > > rangeMap_
Pointer to the constructed range map.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > domainMap() const =0
Domain map for this strategy.
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...
RCP< const Tpetra::Map< LO, GO, NT > > domainMap_
Pointer to the constructed domain map.