Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_TpetraOperator.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_TPETRAOPERATOR_HPP
47 #define XPETRA_TPETRAOPERATOR_HPP
48 
50 
51 #include <Tpetra_Operator.hpp>
52 #include <Tpetra_Details_residual.hpp>
53 
54 #include "Xpetra_Map.hpp"
55 #include "Xpetra_TpetraMap.hpp"
56 #include "Xpetra_MultiVector.hpp"
57 #include "Xpetra_TpetraMultiVector.hpp"
58 #include "Xpetra_Operator.hpp"
59 
60 #include "Xpetra_Utils.hpp"
61 
62 namespace Xpetra {
63 
64 template <class Scalar,
65  class LocalOrdinal,
66  class GlobalOrdinal,
67  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
68 class TpetraOperator : public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
69  public:
71 
73  virtual const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
74  XPETRA_MONITOR("TpetraOperator::getDomainMap()");
75  return toXpetra(op_->getDomainMap());
76  }
77 
79  virtual const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
80  XPETRA_MONITOR("TpetraOperator::getRangeMap()");
81  return toXpetra(op_->getRangeMap());
82  }
83 
85 
90  virtual void
93  Teuchos::ETransp mode = Teuchos::NO_TRANS,
94  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
95  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {
96  op_->apply(toTpetra(X), toTpetra(Y), mode, alpha, beta);
97  }
98 
100  virtual bool hasTransposeApply() const {
101  return op_->hasTransposeApply();
102  }
103 
105 
107 
108 
110  std::string description() const {
111  XPETRA_MONITOR("TpetraOperator::description");
112  return op_->description();
113  }
114 
116  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
117  XPETRA_MONITOR("TpetraOperator::describe");
118  op_->describe(out, verbLevel);
119  }
120 
122 
124 
125 
127 
129  TpetraOperator(const Teuchos::RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &op)
130  : op_(op) {} // TODO removed const
131 
133  virtual RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() { return op_; }
134 
136  virtual RCP<const Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperatorConst() const { return op_; }
137 
142  Tpetra::Details::residual(*op_, toTpetra(X), toTpetra(B), toTpetra(R));
143  }
144 
146 
147  private:
149  RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > op_;
150 
151 }; // TpetraOperator class
152 
153 #if ((!defined(HAVE_TPETRA_INST_SERIAL)) && (!defined(HAVE_TPETRA_INST_INT_INT)) && defined(HAVE_XPETRA_EPETRA))
154 // specialization for Tpetra Map on EpetraNode and GO=int
155 template <>
156 class TpetraOperator<double, int, int, EpetraNode>
157  : public Operator<double, int, int, EpetraNode> {
158  public:
159  typedef double Scalar;
160  typedef int GlobalOrdinal;
161  typedef int LocalOrdinal;
162  typedef EpetraNode Node;
163 
165 
167  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
168  return Teuchos::null;
169  }
170 
172  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
173  return Teuchos::null;
174  }
175 
177 
182  virtual void
185  Teuchos::ETransp mode = Teuchos::NO_TRANS,
186  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
187  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {}
188 
190  virtual bool hasTransposeApply() const { return false; }
191 
193 
195 
196 
198  std::string description() const { return std::string(""); }
199 
201  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
202 
204 
206 
207 
209  TpetraOperator(const Teuchos::RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &op) {}
210 
212  RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() { return Teuchos::null; }
213 
217  }
218 
220 
221 }; // TpetraOperator class
222 #endif
223 
224 #if ((!defined(HAVE_TPETRA_INST_SERIAL)) && (!defined(HAVE_TPETRA_INST_INT_LONG_LONG)) && defined(HAVE_XPETRA_EPETRA))
225 // specialization for Tpetra Map on EpetraNode and GO=int
226 template <>
227 class TpetraOperator<double, int, long long, EpetraNode>
228  : public Operator<double, int, long long, EpetraNode> {
229  public:
230  typedef double Scalar;
231  typedef long long GlobalOrdinal;
232  typedef int LocalOrdinal;
233  typedef EpetraNode Node;
234 
236 
238  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
239  return Teuchos::null;
240  }
241 
243  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
244  return Teuchos::null;
245  }
246 
248 
253  virtual void
256  Teuchos::ETransp mode = Teuchos::NO_TRANS,
257  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
258  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {}
259 
261  virtual bool hasTransposeApply() const { return false; }
262 
264 
266 
267 
269  std::string description() const { return std::string(""); }
270 
272  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
273 
275 
277 
278 
280  TpetraOperator(const Teuchos::RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &op) {}
281 
283  RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() { return Teuchos::null; }
284 
288  }
290 
291 }; // TpetraOperator class
292 #endif
293 
294 } // namespace Xpetra
295 
296 #define XPETRA_TPETRAOPERATOR_SHORT
297 #endif // XPETRA_TPETRAOPERATOR_HPP
virtual void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
virtual Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
The Map associated with the range of this operator, which must be compatible with Y...
std::string description() const
A simple one-line description of this object.
virtual const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
The Map associated with the range of this operator, which must be compatible with Y...
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
virtual Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
The Map associated with the domain of this operator, which must be compatible with X...
virtual RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator()
Gets the operator out.
std::string description() const
A simple one-line description of this object.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
void residual(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
virtual RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperatorConst() const
Gets the operator out.
void residual(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
void residual(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
virtual Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
The Map associated with the domain of this operator, which must be compatible with X...
TpetraOperator(const Teuchos::RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &op)
TpetraOperator constructor to wrap a Tpetra::Operator object.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
virtual void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > op_
The Tpetra::Operator which this class wraps.
TpetraOperator(const Teuchos::RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &op)
TpetraOperator constructor to wrap a Tpetra::Operator object.
std::string description() const
A simple one-line description of this object.
virtual void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator()
Gets the operator out.
#define XPETRA_MONITOR(funcName)
virtual const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
The Map associated with the domain of this operator, which must be compatible with X...
TpetraOperator(const Teuchos::RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &op)
TpetraOperator constructor to wrap a Tpetra::Operator object.
RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator()
Gets the operator out.
virtual Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
The Map associated with the range of this operator, which must be compatible with Y...
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)