Tpetra parallel linear algebra  Version of the Day
Tpetra_MixedScalarMultiplyOp.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_MIXEDSCALARMULTIPLYOP_HPP
43 #define TPETRA_MIXEDSCALARMULTIPLYOP_HPP
44 
49 
50 #include "Tpetra_Operator.hpp"
51 #include "Tpetra_Util.hpp"
54 
55 namespace Tpetra {
56 
71  template <class Scalar,
72  class OpScalar,
73  class LocalOrdinal,
74  class GlobalOrdinal,
75  class Node>
77  public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>
78  {
79  public:
81  using op_type =
85 
86  public:
88 
89 
94  MixedScalarMultiplyOp (const Teuchos::RCP<const op_type>& A) :
95  op_ (A)
96  {
97  Allocate(1);
98  }
99 
101  ~MixedScalarMultiplyOp () override = default;
102 
104 
106 
109  void
112  Teuchos::ETransp mode = Teuchos::NO_TRANS,
113  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one (),
114  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero ()) const override
115  {
116  TEUCHOS_TEST_FOR_EXCEPTION
117  (X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
118  Teuchos::typeName (*this) << "::apply(X,Y): X and Y must have the same number of vectors.");
119 
120  if (X.getNumVectors() != X_->getNumVectors()) {
121  Allocate(X.getNumVectors());
122  }
123 
124  Tpetra::deep_copy(*X_, X);
125  op_->apply (*X_, *Y_, mode, Teuchos::as<OpScalar>(alpha), Teuchos::as<OpScalar>(beta));
126  Tpetra::deep_copy(Y, *Y_);
127  }
128 
134  bool hasTransposeApply() const override {
135  return true;
136  }
137 
139  Teuchos::RCP<const map_type> getDomainMap () const override {
140  return op_->getDomainMap ();
141  }
142 
144  Teuchos::RCP<const map_type> getRangeMap () const override {
145  return op_->getRangeMap ();
146  }
147 
149 
150  protected:
152 
154  const Teuchos::RCP<const op_type> op_;
155  mutable Teuchos::RCP<MV> X_, Y_;
156 
157  void
158  Allocate(int numVecs) const {
159  X_ = rcp(new MV(op_->getDomainMap(),numVecs));
160  Y_ = rcp(new MV(op_->getRangeMap(),numVecs));
161  }
162 
163  };
164 
172  template <class Scalar,
173  class OpScalar,
174  class LocalOrdinal,
175  class GlobalOrdinal,
176  class Node>
177  Teuchos::RCP<
178  MixedScalarMultiplyOp<Scalar, OpScalar, LocalOrdinal, GlobalOrdinal, Node> >
179  createMixedScalarMultiplyOp (const Teuchos::RCP<
181  {
182  typedef MixedScalarMultiplyOp<Scalar, OpScalar, LocalOrdinal,
183  GlobalOrdinal, Node> op_type;
184  return Teuchos::rcp (new op_type (A));
185  }
186 
187 } // end of namespace Tpetra
188 
189 #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.
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 .
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this Operator.
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.
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.