Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_TpetraEuclideanScalarProd_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_TPETRA_EUCLIDEAN_SCALAR_PROD_DEF_HPP
11 #define THYRA_TPETRA_EUCLIDEAN_SCALAR_PROD_DEF_HPP
12 
15 #include "Thyra_TpetraVector.hpp"
16 
17 
18 namespace Thyra {
19 
20 
21 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
23  const MultiVectorBase<Scalar>& X,
24  const MultiVectorBase<Scalar>& Y,
25  const ArrayView<Scalar>& scalarProds_out
26  ) const
27 {
28  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
29  Teuchos::RCP<const TMV> X_tpetra = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(X));
30  Teuchos::RCP<const TMV> Y_tpetra = this->getConstTpetraMultiVector(Teuchos::rcpFromRef(Y));
31 
32  if (nonnull(X_tpetra) && nonnull(Y_tpetra)) {
33  // Which one do we want transposed?
34  // Tpetra transposes the argument of dot.
35  // Below is the order from TpetraVectorSpace::scalarProdsImpl,
36  // so this would transpose Y. However, Thyra::dots (which calls
37  // the RTOp) transposes the first argument, so scalarProdsImpl
38  // in EuclideanScalarProd transposes X...
39  X_tpetra->dot(*Y_tpetra, scalarProds_out);
40  } else {
41  EuclideanScalarProd<Scalar>::scalarProdsImpl(X, Y, scalarProds_out);
42  }
43 }
44 
45 
46 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
49 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> >& mv) const
50 {
51  using Teuchos::rcp_dynamic_cast;
54 
55  RCP<const TMV> tmv = rcp_dynamic_cast<const TMV>(mv);
56  if (nonnull(tmv)) {
57  return tmv->getConstTpetraMultiVector();
58  }
59 
60  RCP<const TV> tv = rcp_dynamic_cast<const TV>(mv);
61  if (nonnull(tv)) {
62  return tv->getConstTpetraVector();
63  }
64 
65  return Teuchos::null;
66 }
67 
68 
69 } // end namespace Thyra
70 
71 
72 #endif // THYRA_EUCLIDEAN_SCALAR_PROD_DEF_HPP
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
bool nonnull(const boost::shared_ptr< T > &p)
virtual void scalarProdsImpl(const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y, const ArrayView< Scalar > &scalarProds) const
If X and Y are both Tpetra wrappers, computes the pair-wise scalar products directly with Tpetra call...
Teuchos::RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector(const RCP< const MultiVectorBase< Scalar > > &mv) const