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
39 template <class Scalar,
40 class OpScalar,
41 class LocalOrdinal,
42 class GlobalOrdinal,
43 class Node>
45 public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>
46 {
47 public:
49 using op_type =
53
54 public:
56
57
62 MixedScalarMultiplyOp (const Teuchos::RCP<const op_type>& A) :
63 op_ (A)
64 {
65 Allocate(1);
66 }
67
69 ~MixedScalarMultiplyOp () override = default;
70
72
74
77 void
80 Teuchos::ETransp mode = Teuchos::NO_TRANS,
81 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one (),
82 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero ()) const override
83 {
84 TEUCHOS_TEST_FOR_EXCEPTION
85 (X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
86 Teuchos::typeName (*this) << "::apply(X,Y): X and Y must have the same number of vectors.");
87
88 if (X.getNumVectors() != X_->getNumVectors()) {
89 Allocate(X.getNumVectors());
90 }
91
92 Tpetra::deep_copy(*X_, X);
93 op_->apply (*X_, *Y_, mode, Teuchos::as<OpScalar>(alpha), Teuchos::as<OpScalar>(beta));
94 Tpetra::deep_copy(Y, *Y_);
95 }
96
102 bool hasTransposeApply() const override {
103 return true;
104 }
105
107 Teuchos::RCP<const map_type> getDomainMap () const override {
108 return op_->getDomainMap ();
109 }
110
112 Teuchos::RCP<const map_type> getRangeMap () const override {
113 return op_->getRangeMap ();
114 }
115
117
118 protected:
120
122 const Teuchos::RCP<const op_type> op_;
123 mutable Teuchos::RCP<MV> X_, Y_;
124
125 void
126 Allocate(int numVecs) const {
127 X_ = rcp(new MV(op_->getDomainMap(),numVecs));
128 Y_ = rcp(new MV(op_->getRangeMap(),numVecs));
129 }
130
131 };
132
140 template <class Scalar,
141 class OpScalar,
142 class LocalOrdinal,
143 class GlobalOrdinal,
144 class Node>
145 Teuchos::RCP<
146 MixedScalarMultiplyOp<Scalar, OpScalar, LocalOrdinal, GlobalOrdinal, Node> >
147 createMixedScalarMultiplyOp (const Teuchos::RCP<
149 {
150 typedef MixedScalarMultiplyOp<Scalar, OpScalar, LocalOrdinal,
151 GlobalOrdinal, Node> op_type;
152 return Teuchos::rcp (new op_type (A));
153 }
154
155} // end of namespace Tpetra
156
157#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.
A parallel distribution of indices over processes.
Operator< OpScalar, LocalOrdinal, GlobalOrdinal, Node > op_type
The specialization of CrsMatrix which this class wraps.
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.
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The specialization of Map which this class uses.
~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.
One or more distributed dense vectors.
size_t getNumVectors() const
Number of columns in the multivector.
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.