Teko Version of the Day
Loading...
Searching...
No Matches
Teko_TpetraOperatorWrapper.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_TpetraOperatorWrapper_hpp__
11#define __Teko_TpetraOperatorWrapper_hpp__
12
13#include "Thyra_LinearOpBase.hpp"
14#include "Tpetra_Map.hpp"
15#include "Tpetra_MultiVector.hpp"
16#include "Tpetra_Operator.hpp"
17#include "Teko_ConfigDefs.hpp"
18
19#include <string>
20
21namespace Teko {
22namespace TpetraHelpers {
23using Teuchos::RCP;
24
26
29 public:
30 virtual ~MappingStrategy() {}
31
40 virtual void copyTpetraIntoThyra(
41 const Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX,
42 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyraX) const = 0;
43 // const TpetraOperatorWrapper & eow) const = 0;
44
53 virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> >& thyraX,
54 Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX) const = 0;
55 // const TpetraOperatorWrapper & eow) const = 0;
56
58 virtual const RCP<const Tpetra::Map<LO, GO, NT> > domainMap() const = 0;
59
61 virtual const RCP<const Tpetra::Map<LO, GO, NT> > 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 copyTpetraIntoThyra(const Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX,
78 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyraX) const
79 // const TpetraOperatorWrapper & eow) const
80 {
81 forwardStrategy_->copyTpetraIntoThyra(tpetraX, thyraX);
82 }
83
84 virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> >& thyraX,
85 Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX) const
86 // const TpetraOperatorWrapper & eow) const
87 {
88 forwardStrategy_->copyThyraIntoTpetra(thyraX, tpetraX);
89 }
90
92 virtual const RCP<const Tpetra::Map<LO, GO, NT> > domainMap() const {
93 return forwardStrategy_->rangeMap();
94 }
95
97 virtual const RCP<const Tpetra::Map<LO, GO, NT> > rangeMap() const {
98 return forwardStrategy_->domainMap();
99 }
100
102 virtual std::string toString() const {
103 return std::string("InverseMapping(") + forwardStrategy_->toString() + std::string(")");
104 }
105
106 protected:
108 const RCP<const MappingStrategy> forwardStrategy_;
109
110 private:
113};
114
116class DefaultMappingStrategy : public MappingStrategy {
117 public:
119 DefaultMappingStrategy(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp,
120 const Teuchos::Comm<Thyra::Ordinal>& comm);
121
122 virtual ~DefaultMappingStrategy() {}
123
132 virtual void copyTpetraIntoThyra(const Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX,
133 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> >& thyraX) const;
134 // const TpetraOperatorWrapper & eow) const;
135
144 virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> >& thyraX,
145 Tpetra::MultiVector<ST, LO, GO, NT>& tpetraX) const;
146 // const TpetraOperatorWrapper & eow) const;
147
149 virtual const RCP<const Tpetra::Map<LO, GO, NT> > domainMap() const { return domainMap_; }
150
152 virtual const RCP<const Tpetra::Map<LO, GO, NT> > rangeMap() const { return rangeMap_; }
153
155 virtual std::string toString() const { return std::string("DefaultMappingStrategy"); }
156
157 protected:
158 RCP<const Thyra::VectorSpaceBase<ST> > domainSpace_;
159 RCP<const Thyra::VectorSpaceBase<ST> > rangeSpace_;
160
161 RCP<const Tpetra::Map<LO, GO, NT> > domainMap_;
162 RCP<const Tpetra::Map<LO, GO, NT> > rangeMap_;
163};
164
171class TpetraOperatorWrapper : public Tpetra::Operator<ST, LO, GO, NT> {
172 public:
174 TpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp);
175 TpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp,
176 const RCP<const MappingStrategy>& mapStrategy);
177 TpetraOperatorWrapper(const RCP<const MappingStrategy>& mapStrategy);
178
180 virtual ~TpetraOperatorWrapper() { ; }
181
183 int SetUseTranspose(bool useTranspose) {
184 useTranspose_ = useTranspose;
185 return 0;
186 }
187
189 void apply(const Tpetra::MultiVector<ST, LO, GO, NT>& X, Tpetra::MultiVector<ST, LO, GO, NT>& Y,
190 Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
191 ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
192
194 void applyInverse(const Tpetra::MultiVector<ST, LO, GO, NT>& X,
195 Tpetra::MultiVector<ST, LO, GO, NT>& Y,
196 Teuchos::ETransp mode = Teuchos::NO_TRANS,
197 ST alpha = Teuchos::ScalarTraits<ST>::one(),
198 ST beta = Teuchos::ScalarTraits<ST>::zero()) const;
199
201 double NormInf() const;
202
204 const char* Label() const { return label_.c_str(); }
205
207 bool UseTranspose() const { return useTranspose_; }
208
210 bool HasNormInf() const { return false; }
211
213 const Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> >& Comm() const { return comm_; }
214
216 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getDomainMap() const {
217 return mapStrategy_->domainMap();
218 }
219
221 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> > getRangeMap() const {
222 return mapStrategy_->rangeMap();
223 }
224
226 const RCP<const Thyra::LinearOpBase<ST> > getThyraOp() const { return thyraOp_; }
227
229 const RCP<const MappingStrategy> getMapStrategy() const { return mapStrategy_; }
230
232 virtual int GetBlockRowCount();
233
235 virtual int GetBlockColCount();
236
238 Teuchos::RCP<const Tpetra::Operator<ST, LO, GO, NT> > GetBlock(int i, int j) const;
239
240 protected:
243
245 RCP<const Teuchos::Comm<Thyra::Ordinal> > getThyraComm(const Thyra::LinearOpBase<ST>& inOp) const;
246
248 void SetOperator(const RCP<const Thyra::LinearOpBase<ST> >& thyraOp, bool buildMap = true);
249
251 void SetMapStrategy(const RCP<const MappingStrategy>& mapStrategy) { mapStrategy_ = mapStrategy; }
252
254 RCP<const MappingStrategy> mapStrategy_;
255
257 RCP<const Thyra::LinearOpBase<ST> > thyraOp_;
258
260 bool useTranspose_;
261
263 RCP<const Teuchos::Comm<Thyra::Ordinal> > comm_;
264
266 std::string label_;
267};
268} // namespace TpetraHelpers
269} // end namespace Teko
270
271#endif
RCP< const Tpetra::Map< LO, GO, NT > > rangeMap_
Pointer to the constructed range map.
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 std::string toString() const
Identifier string.
RCP< const Thyra::VectorSpaceBase< ST > > rangeSpace_
Range space object.
RCP< const Thyra::VectorSpaceBase< ST > > domainSpace_
Domain space object.
RCP< const Tpetra::Map< LO, GO, NT > > domainMap_
Pointer to the constructed domain map.
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
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > rangeMap() const
Range map for this strategy.
Flip a mapping strategy object around to give the "inverse" mapping strategy.
virtual std::string toString() const
Identifier string.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > domainMap() const
Domain map for this strategy.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > rangeMap() const
Range map for this strategy.
const RCP< const MappingStrategy > forwardStrategy_
Forward mapping strategy object.
InverseMappingStrategy(const RCP< const MappingStrategy > &forward)
Constructor to build a inverse MappingStrategy from a forward map.
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 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.
virtual std::string toString() const =0
Identifier string.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > domainMap() const =0
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 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.
Implements the Epetra_Operator interface with a Thyra LinearOperator. This enables the use of absrtac...
virtual int GetBlockRowCount()
Get the number of block rows in this operator.
const RCP< const MappingStrategy > getMapStrategy() const
Get the mapping strategy for this wrapper (translate between Thyra and Epetra).
Teuchos::RCP< const Tpetra::Operator< ST, LO, GO, NT > > GetBlock(int i, int j) const
Grab the i,j block.
virtual int GetBlockColCount()
Get the number of block columns in this operator.
const RCP< const Thyra::LinearOpBase< ST > > getThyraOp() const
Return the thyra operator associated with this wrapper.