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 // Xpetra: A linear algebra interface package
4 //
5 // Copyright 2012 NTESS and the Xpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef XPETRA_TPETRAOPERATOR_HPP
11 #define XPETRA_TPETRAOPERATOR_HPP
12 
14 
15 #include <Tpetra_Operator.hpp>
16 #include <Tpetra_Details_residual.hpp>
17 
18 #include "Xpetra_Map.hpp"
19 #include "Xpetra_TpetraMap.hpp"
20 #include "Xpetra_MultiVector.hpp"
21 #include "Xpetra_TpetraMultiVector.hpp"
22 #include "Xpetra_Operator.hpp"
23 
24 #include "Xpetra_Utils.hpp"
25 
26 namespace Xpetra {
27 
28 template <class Scalar,
29  class LocalOrdinal,
30  class GlobalOrdinal,
31  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
32 class TpetraOperator : public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
33  public:
35 
37  virtual const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
38  XPETRA_MONITOR("TpetraOperator::getDomainMap()");
39  return toXpetra(op_->getDomainMap());
40  }
41 
43  virtual const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
44  XPETRA_MONITOR("TpetraOperator::getRangeMap()");
45  return toXpetra(op_->getRangeMap());
46  }
47 
49 
54  virtual void
57  Teuchos::ETransp mode = Teuchos::NO_TRANS,
58  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
59  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {
60  op_->apply(toTpetra(X), toTpetra(Y), mode, alpha, beta);
61  }
62 
64  virtual bool hasTransposeApply() const {
65  return op_->hasTransposeApply();
66  }
67 
69 
71 
72 
74  std::string description() const {
75  XPETRA_MONITOR("TpetraOperator::description");
76  return op_->description();
77  }
78 
80  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
81  XPETRA_MONITOR("TpetraOperator::describe");
82  op_->describe(out, verbLevel);
83  }
84 
86 
88 
89 
91 
93  TpetraOperator(const Teuchos::RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &op)
94  : op_(op) {} // TODO removed const
95 
97  virtual RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() { return op_; }
98 
100  virtual RCP<const Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperatorConst() const { return op_; }
101 
106  Tpetra::Details::residual(*op_, toTpetra(X), toTpetra(B), toTpetra(R));
107  }
108 
110 
111  private:
113  RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > op_;
114 
115 }; // TpetraOperator class
116 
117 #if ((!defined(HAVE_TPETRA_INST_SERIAL)) && (!defined(HAVE_TPETRA_INST_INT_INT)) && defined(HAVE_XPETRA_EPETRA))
118 // specialization for Tpetra Map on EpetraNode and GO=int
119 template <>
120 class TpetraOperator<double, int, int, EpetraNode>
121  : public Operator<double, int, int, EpetraNode> {
122  public:
123  typedef double Scalar;
124  typedef int GlobalOrdinal;
125  typedef int LocalOrdinal;
126  typedef EpetraNode Node;
127 
129 
131  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
132  return Teuchos::null;
133  }
134 
136  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
137  return Teuchos::null;
138  }
139 
141 
146  virtual void
149  Teuchos::ETransp mode = Teuchos::NO_TRANS,
150  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
151  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {}
152 
154  virtual bool hasTransposeApply() const { return false; }
155 
157 
159 
160 
162  std::string description() const { return std::string(""); }
163 
165  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
166 
168 
170 
171 
173  TpetraOperator(const Teuchos::RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &op) {}
174 
176  RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() { return Teuchos::null; }
177 
181  }
182 
184 
185 }; // TpetraOperator class
186 #endif
187 
188 #if ((!defined(HAVE_TPETRA_INST_SERIAL)) && (!defined(HAVE_TPETRA_INST_INT_LONG_LONG)) && defined(HAVE_XPETRA_EPETRA))
189 // specialization for Tpetra Map on EpetraNode and GO=int
190 template <>
191 class TpetraOperator<double, int, long long, EpetraNode>
192  : public Operator<double, int, long long, EpetraNode> {
193  public:
194  typedef double Scalar;
195  typedef long long GlobalOrdinal;
196  typedef int LocalOrdinal;
197  typedef EpetraNode Node;
198 
200 
202  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
203  return Teuchos::null;
204  }
205 
207  virtual Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
208  return Teuchos::null;
209  }
210 
212 
217  virtual void
220  Teuchos::ETransp mode = Teuchos::NO_TRANS,
221  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
222  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {}
223 
225  virtual bool hasTransposeApply() const { return false; }
226 
228 
230 
231 
233  std::string description() const { return std::string(""); }
234 
236  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
237 
239 
241 
242 
244  TpetraOperator(const Teuchos::RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &op) {}
245 
247  RCP<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() { return Teuchos::null; }
248 
252  }
254 
255 }; // TpetraOperator class
256 #endif
257 
258 } // namespace Xpetra
259 
260 #define XPETRA_TPETRAOPERATOR_SHORT
261 #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)