Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_MixedScalarMultiplyOp.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_MIXEDSCALARMULTIPLYOP_HPP
11#define TPETRA_MIXEDSCALARMULTIPLYOP_HPP
12
17
18#include "Tpetra_Operator.hpp"
19#include "Tpetra_Util.hpp"
22
23namespace Tpetra {
24
39template <class Scalar,
40 class OpScalar,
41 class LocalOrdinal,
42 class GlobalOrdinal,
43 class Node>
44class MixedScalarMultiplyOp : public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
45 public:
47 using op_type =
51
52 public:
54
55
60 MixedScalarMultiplyOp(const Teuchos::RCP<const op_type>& A)
61 : op_(A) {
62 Allocate(1);
63 }
64
66 ~MixedScalarMultiplyOp() override = default;
67
69
71
74 void
77 Teuchos::ETransp mode = Teuchos::NO_TRANS,
78 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
79 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override {
80 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
81 Teuchos::typeName(*this) << "::apply(X,Y): X and Y must have the same number of vectors.");
82
83 if (X.getNumVectors() != X_->getNumVectors()) {
84 Allocate(X.getNumVectors());
85 }
86
87 Tpetra::deep_copy(*X_, X);
88 op_->apply(*X_, *Y_, mode, Teuchos::as<OpScalar>(alpha), Teuchos::as<OpScalar>(beta));
89 Tpetra::deep_copy(Y, *Y_);
90 }
91
97 bool hasTransposeApply() const override {
98 return true;
99 }
100
102 Teuchos::RCP<const map_type> getDomainMap() const override {
103 return op_->getDomainMap();
104 }
105
107 Teuchos::RCP<const map_type> getRangeMap() const override {
108 return op_->getRangeMap();
109 }
110
112
113 protected:
115
117 const Teuchos::RCP<const op_type> op_;
118 mutable Teuchos::RCP<MV> X_, Y_;
119
120 void
121 Allocate(int numVecs) const {
122 X_ = rcp(new MV(op_->getDomainMap(), numVecs));
123 Y_ = rcp(new MV(op_->getRangeMap(), numVecs));
124 }
125};
126
134template <class Scalar,
135 class OpScalar,
136 class LocalOrdinal,
137 class GlobalOrdinal,
138 class Node>
139Teuchos::RCP<
140 MixedScalarMultiplyOp<Scalar, OpScalar, LocalOrdinal, GlobalOrdinal, Node> >
144 GlobalOrdinal, Node>
145 op_type;
146 return Teuchos::rcp(new op_type(A));
147}
148
149} // end of namespace Tpetra
150
151#endif // TPETRA_MIXEDSCALARMULTIPLYOP_HPP
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
A class for wrapping an Operator of one Scalar type into an Operator of another Scalar type.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this Operator.
const Teuchos::RCP< const op_type > op_
The underlying CrsMatrix object.
Teuchos::RCP< MixedScalarMultiplyOp< Scalar, OpScalar, LocalOrdinal, GlobalOrdinal, Node > > createMixedScalarMultiplyOp(const Teuchos::RCP< const Operator< OpScalar, LocalOrdinal, GlobalOrdinal, Node > > &A)
Non-member function to create a MixedScalarMultiplyOp.
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 override
Compute Y = beta*Y + alpha*Op(A)*X, where Op(A) is either A, , or .
MixedScalarMultiplyOp(const Teuchos::RCP< const op_type > &A)
Constructor.
~MixedScalarMultiplyOp() override=default
Destructor (virtual for memory safety of derived classes).
bool hasTransposeApply() const override
Whether this Operator's apply() method can apply the transpose or conjugate transpose.
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this Operator.
Abstract interface for operators (e.g., matrices and preconditioners).
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.