Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_EpetraOperator.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_EPETRAOPERATOR_HPP
11#define XPETRA_EPETRAOPERATOR_HPP
12
14
15#include <Epetra_Operator.h>
16#include <Epetra_Map.h>
17
18#include "Xpetra_Map.hpp"
19#include "Xpetra_EpetraMap.hpp"
20#include "Xpetra_MultiVector.hpp"
22#include "Xpetra_Operator.hpp"
23
24#include "Xpetra_Utils.hpp"
25
26#if defined(XPETRA_ENABLE_DEPRECATED_CODE)
27#ifdef __GNUC__
28#if defined(Xpetra_SHOW_DEPRECATED_WARNINGS)
29#warning "The header file Trilinos/packages/xpetra/src/Operator/Xpetra_EpetraOperator.hpp is deprecated."
30#endif
31#endif
32#else
33#error "The header file Trilinos/packages/xpetra/src/Operator/Xpetra_EpetraOperator.hpp is deprecated."
34#endif
35
36namespace Xpetra {
37
38template <class EpetraGlobalOrdinal, class Node>
39class XPETRA_DEPRECATED EpetraOperator : public Operator<double, int, EpetraGlobalOrdinal, Node> {
40 typedef double Scalar;
41 typedef int LocalOrdinal;
42 typedef EpetraGlobalOrdinal GlobalOrdinal;
43
44 public:
46
49 XPETRA_MONITOR("EpetraOperator::getDomainMap()");
50 return toXpetra<GlobalOrdinal, Node>(op_->OperatorDomainMap());
51 }
52
55 XPETRA_MONITOR("EpetraOperator::getRangeMap()");
56 return toXpetra<GlobalOrdinal, Node>(op_->OperatorRangeMap());
57 }
58
60
65 virtual void
71 XPETRA_MONITOR("EpetraOperator::apply");
72
73 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraOperator->apply(): cannot cast input to Xpetra::EpetraMultiVectorT");
74 XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraOperator->apply(): cannot cast input to Xpetra::EpetraMultiVectorT");
75
77 "Xpetra::EpetraOperator->apply(): can only accept mode == NO_TRANS or mode == TRANS");
79 "Xpetra::EpetraOperator->apply(): cannot apply transpose as underlying Epetra operator does not support it");
80
81 // Helper vector for string A*X
82 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
84 tmp->PutScalar(0.0);
85
86 op_->SetUseTranspose(mode == Teuchos::TRANS);
87 XPETRA_ERR_CHECK(op_->Apply(*eX.getEpetra_MultiVector(), *tmp));
88
89 // calculate alpha * A * x + beta * y
90 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
91 }
92
94 virtual bool hasTransposeApply() const {
95 // We do not currently use transpose, try setting it
96 int err = op_->SetUseTranspose(true);
97 op_->SetUseTranspose(false);
98 return (err == 0);
99 }
100
102
104
105
107 std::string description() const {
108 XPETRA_MONITOR("EpetraOperator::description");
109 return "Epetra_Operator";
110 }
111
114 XPETRA_MONITOR("EpetraOperator::describe");
115 out << "Epetra_Operator" << std::endl;
116 }
117
119
121
122
125 : op_(op) {} // TODO removed const
126
132 R.update(STS::one(), B, STS::zero());
133 this->apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
134 }
135
137
138 private:
141
142}; // EpetraOperator class
143
144template <class EpetraGlobalOrdinal, class Node>
145class EpetraInverseOperator : public Operator<double, int, EpetraGlobalOrdinal, Node> {
146 typedef double Scalar;
147 typedef int LocalOrdinal;
148 typedef EpetraGlobalOrdinal GlobalOrdinal;
149
150 public:
152
155 XPETRA_MONITOR("EpetraOperator::getDomainMap()");
156 return toXpetra<GlobalOrdinal, Node>(op_->OperatorDomainMap());
157 }
158
161 XPETRA_MONITOR("EpetraOperator::getRangeMap()");
162 return toXpetra<GlobalOrdinal, Node>(op_->OperatorRangeMap());
163 }
164
166
171 virtual void
177 XPETRA_MONITOR("EpetraOperator::apply");
178
179 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraOperator->apply(): cannot cast input to Xpetra::EpetraMultiVectorT");
180 XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraOperator->apply(): cannot cast input to Xpetra::EpetraMultiVectorT");
181
183 "Xpetra::EpetraOperator->apply(): can only accept mode == NO_TRANS or mode == TRANS");
185 "Xpetra::EpetraOperator->apply(): cannot apply transpose as underlying Epetra operator does not support it");
186
187 // Helper vector for string A*X
188 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
190 tmp->PutScalar(0.0);
191
192 op_->SetUseTranspose(mode == Teuchos::TRANS);
193 XPETRA_ERR_CHECK(op_->ApplyInverse(*eX.getEpetra_MultiVector(), *tmp));
194
195 // calculate alpha * A * x + beta * y
196 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
197 }
198
200 virtual bool hasTransposeApply() const {
201 // We do not currently use transpose, try setting it
202 int err = op_->SetUseTranspose(true);
203 op_->SetUseTranspose(false);
204 return (err == 0);
205 }
206
208
210
211
213 std::string description() const {
214 XPETRA_MONITOR("EpetraOperator::description");
215 return "Epetra_Operator";
216 }
217
220 XPETRA_MONITOR("EpetraOperator::describe");
221 out << "Epetra_Operator" << std::endl;
222 }
223
225
227
228
231 : op_(op) {} // TODO removed const
232
238 R.update(STS::one(), B, STS::zero());
239 this->apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
240 }
241
243
244 private:
247};
248
249} // namespace Xpetra
250
251#endif // XPETRA_EPETRAOPERATOR_HPP
#define XPETRA_MONITOR(funcName)
#define XPETRA_ERR_CHECK(arg)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
static const EVerbosityLevel verbLevel_default
virtual void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, 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< Epetra_Operator > op_
The Tpetra::Operator which this class wraps.
std::string description() const
A simple one-line description of this object.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
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....
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.
EpetraInverseOperator(const Teuchos::RCP< Epetra_Operator > &op)
EpetraOperator constructor to wrap a Epetra_Operator object.
virtual bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
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....
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
std::string description() const
A simple one-line description of this object.
virtual const 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 bool hasTransposeApply() const
Whether this operator supports applying the transpose or conjugate transpose.
virtual void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, 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.
EpetraOperator(const Teuchos::RCP< Epetra_Operator > &op)
EpetraOperator constructor to wrap a Epetra_Operator object.
EpetraGlobalOrdinal GlobalOrdinal
RCP< Epetra_Operator > op_
The Tpetra::Operator which this class wraps.
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 const 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....
Exception throws when you call an unimplemented method of Xpetra.
Exception throws to report errors in the internal logical of the program.
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)