Teko Version of the Day
Loading...
Searching...
No Matches
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
59namespace Teko {
60namespace TpetraHelpers {
61 using Teuchos::RCP;
62
63 class TpetraOperatorWrapper;
64
67 public:
68 virtual ~MappingStrategy() {}
69
78 virtual void copyTpetraIntoThyra(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)
111 : forwardStrategy_(forward)
112 { }
113
114 virtual ~InverseMappingStrategy() {}
115
116 virtual void copyTpetraIntoThyra(const Tpetra::MultiVector<ST,LO,GO,NT>& tpetraX,
117 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> > & thyraX) const
118 // const TpetraOperatorWrapper & eow) const
119 { forwardStrategy_->copyTpetraIntoThyra(tpetraX,thyraX); }
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 { forwardStrategy_->copyThyraIntoTpetra(thyraX,tpetraX); }
125
127 virtual const RCP<const Tpetra::Map<LO,GO,NT> > domainMap() const
128 { return forwardStrategy_->rangeMap(); }
129
131 virtual const RCP<const Tpetra::Map<LO,GO,NT> > 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<ST> > & thyraOp,const Teuchos::Comm<Thyra::Ordinal> & comm);
151
152 virtual ~DefaultMappingStrategy() {}
153
162 virtual void copyTpetraIntoThyra(const Tpetra::MultiVector<ST,LO,GO,NT>& tpetraX,
163 const Teuchos::Ptr<Thyra::MultiVectorBase<ST> > & thyraX) const;
164 // const TpetraOperatorWrapper & eow) const;
165
174 virtual void copyThyraIntoTpetra(const RCP<const Thyra::MultiVectorBase<ST> > & thyraX,
175 Tpetra::MultiVector<ST,LO,GO,NT>& tpetraX) const;
176 // const TpetraOperatorWrapper & eow) const;
177
179 virtual const RCP<const Tpetra::Map<LO,GO,NT> > domainMap() const { return domainMap_; }
180
182 virtual const RCP<const Tpetra::Map<LO,GO,NT> > rangeMap() const { return rangeMap_; }
183
185 virtual std::string toString() const
186 { return std::string("DefaultMappingStrategy"); }
187
188 protected:
189 RCP<const Thyra::VectorSpaceBase<ST> > domainSpace_;
190 RCP<const Thyra::VectorSpaceBase<ST> > rangeSpace_;
191
192 RCP<const Tpetra::Map<LO,GO,NT> > domainMap_;
193 RCP<const Tpetra::Map<LO,GO,NT> > rangeMap_;
194 };
195
202 class TpetraOperatorWrapper : public Tpetra::Operator<ST,LO,GO,NT>
203 {
204 public:
206 TpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<ST> > & thyraOp);
207 TpetraOperatorWrapper(const RCP<const Thyra::LinearOpBase<ST> > & thyraOp,
208 const RCP<const MappingStrategy> & mapStrategy);
209 TpetraOperatorWrapper(const RCP<const MappingStrategy> & mapStrategy);
210
212 virtual ~TpetraOperatorWrapper() {;}
213
215 int SetUseTranspose(bool useTranspose) {
216 useTranspose_ = useTranspose;
217 return 0;
218 }
219
221 void apply(const Tpetra::MultiVector<ST,LO,GO,NT>& X, Tpetra::MultiVector<ST,LO,GO,NT>& Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, ST alpha=Teuchos::ScalarTraits< ST >::one(), ST beta=Teuchos::ScalarTraits< ST >::zero()) const ;
222
224 void applyInverse(const Tpetra::MultiVector<ST,LO,GO,NT>& X, Tpetra::MultiVector<ST,LO,GO,NT>& Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, ST alpha=Teuchos::ScalarTraits< ST >::one(), ST beta=Teuchos::ScalarTraits< ST >::zero()) 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 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > & Comm() const {return comm_;}
240
242 Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > getDomainMap() const {return mapStrategy_->domainMap();}
243
245 Teuchos::RCP<const Tpetra::Map<LO,GO,NT> > getRangeMap() const {return mapStrategy_->rangeMap();}
246
248 const RCP<const Thyra::LinearOpBase<ST> > 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 Tpetra::Operator<ST,LO,GO,NT> > GetBlock(int i,int j) const;
263
264 protected:
267
269 RCP<const Teuchos::Comm<Thyra::Ordinal> > getThyraComm(const Thyra::LinearOpBase<ST> & inOp) const;
270
272 void SetOperator(const RCP<const Thyra::LinearOpBase<ST> > & 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<ST> > thyraOp_;
283
285 bool useTranspose_;
286
288 RCP<const Teuchos::Comm<Thyra::Ordinal> > comm_;
289
291 std::string label_;
292 };
293} // end namespace Tpetra
294} // end namespace Teko
295
296#endif
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.
virtual std::string toString() const
Identifier string.
RCP< const Thyra::VectorSpaceBase< ST > > rangeSpace_
Range space object.
RCP< const Tpetra::Map< LO, GO, NT > > domainMap_
Pointer to the constructed domain map.
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
Copy an Epetra_MultiVector into a Thyra::MultiVectorBase.
virtual const RCP< const Tpetra::Map< LO, GO, NT > > rangeMap() const
Range map for this strategy.
RCP< const Tpetra::Map< LO, GO, NT > > rangeMap_
Pointer to the constructed range map.
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.