Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_SpmdLocalDataAccess_def.hpp
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_SPMD_LOCAL_DATA_ACCESS_DEF_HPP
11 #define THYRA_SPMD_LOCAL_DATA_ACCESS_DEF_HPP
12 
13 
14 #include "Thyra_SpmdLocalDataAccess_decl.hpp"
15 #include "Thyra_ProductVectorBase.hpp"
16 #include "Thyra_ProductVectorSpaceBase.hpp"
17 #include "Thyra_SpmdVectorBase.hpp"
18 #include "Thyra_SpmdMultiVectorBase.hpp"
19 
20 
21 template<class Scalar>
24  const RCP<VectorBase<Scalar> > &vec)
25 {
26  const RCP<SpmdVectorBase<Scalar> > spmd_v =
27  Teuchos::rcp_dynamic_cast<SpmdVectorBase<Scalar> >(vec);
28  if (nonnull(spmd_v)) {
29  return spmd_v->getNonconstLocalSubVector();
30  }
31  const RCP<ProductVectorBase<Scalar> > p_v =
32  Teuchos::rcp_dynamic_cast<ProductVectorBase<Scalar> >(vec, true);
34  !(p_v->productSpace()->numBlocks() == 1),
35  std::logic_error,
36  "Error, the function getNonconstLocalSubVectorView() can only return"
37  " a contiguous view of local SPMD data from a product vector with a single"
38  " block (which also must be able to give up a product view.");
39  return getNonconstLocalSubVectorView<Scalar>(p_v->getNonconstVectorBlock(0));
40 }
41 
42 
43 template<class Scalar>
46  const RCP<const VectorBase<Scalar> > &vec)
47 {
48  const RCP<const SpmdVectorBase<Scalar> > spmd_v =
49  Teuchos::rcp_dynamic_cast<const SpmdVectorBase<Scalar> >(vec);
50  if (nonnull(spmd_v)) {
51  return spmd_v->getLocalSubVector();
52  }
54  Teuchos::rcp_dynamic_cast<const ProductVectorBase<Scalar> >(vec, true);
56  !(p_v->productSpace()->numBlocks() == 1),
57  std::logic_error,
58  "Error, the function getLocalSubVectorView() can only return"
59  " a contiguous view of local SPMD data from a product vector with a single"
60  " block (which also must be able to give up a product view.");
61  return getLocalSubVectorView<Scalar>(p_v->getVectorBlock(0));
62 }
63 
64 
65 template<class Scalar>
68  const RCP<MultiVectorBase<Scalar> > &multivec)
69 {
70  const RCP<SpmdMultiVectorBase<Scalar> > spmd_mv =
71  Teuchos::rcp_dynamic_cast<SpmdMultiVectorBase<Scalar> >(multivec);
72  if (nonnull(spmd_mv)) {
73  return spmd_mv->getNonconstLocalSubMultiVector();
74  }
76  Teuchos::rcp_dynamic_cast<ProductMultiVectorBase<Scalar> >(multivec, true);
78  !(p_mv->productSpace()->numBlocks() == 1),
79  std::logic_error,
80  "Error, the function getNonconstLocalSubVectorView() can only return"
81  " a contiguous view of local SPMD data from a product vector with a single"
82  " block (which also must be able to give up a product view.");
83  return getNonconstLocalSubMultiVectorView<Scalar>(p_mv->getNonconstMultiVectorBlock(0));
84 }
85 
86 
87 template<class Scalar>
90  const RCP<const MultiVectorBase<Scalar> > &multivec)
91 {
92  const RCP<const SpmdMultiVectorBase<Scalar> > spmd_mv =
93  Teuchos::rcp_dynamic_cast<const SpmdMultiVectorBase<Scalar> >(multivec);
94  if (nonnull(spmd_mv)) {
95  return spmd_mv->getLocalSubMultiVector();
96  }
98  Teuchos::rcp_dynamic_cast<const ProductMultiVectorBase<Scalar> >(multivec, true);
100  !(p_mv->productSpace()->numBlocks() == 1),
101  std::logic_error,
102  "Error, the function getLocalSubVectorView() can only return"
103  " a contiguous view of local SPMD data from a product vector with a single"
104  " block (which also must be able to give up a product view.");
105  return getLocalSubMultiVectorView<Scalar>(p_mv->getMultiVectorBlock(0));
106 }
107 
108 
109 //
110 // Explicit instantiation macro
111 //
112 
113 
114 #define THYRA_SPMD_LOCAL_DATA_ACCESS_INSTANT(SCALAR) \
115  \
116  template RTOpPack::SubVectorView<SCALAR> \
117  getNonconstLocalSubVectorView(const RCP<VectorBase<SCALAR> > &vec); \
118  \
119  template RTOpPack::ConstSubVectorView<SCALAR> \
120  getLocalSubVectorView(const RCP<const VectorBase<SCALAR> > &vec); \
121  \
122  template RTOpPack::SubMultiVectorView<SCALAR> \
123  getNonconstLocalSubMultiVectorView(const RCP<MultiVectorBase<SCALAR> > &vec); \
124  \
125  template RTOpPack::ConstSubMultiVectorView<SCALAR> \
126  getLocalSubMultiVectorView(const RCP<const MultiVectorBase<SCALAR> > &vec); \
127 
128 
129 #endif // THYRA_SPMD_LOCAL_DATA_ACCESS_DEF_HPP
Base interface for product multi-vectors.
Base interface for product vectors.
Base interface class for SPMD multi-vectors.
Base class for SPMD vectors that can provide views of contiguous elements in a process.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Interface for a collection of column vectors called a multi-vector.
Abstract interface for finite-dimensional dense vectors.
bool nonnull(const boost::shared_ptr< T > &p)
RTOpPack::ConstSubVectorView< Scalar > getLocalSubVectorView(const RCP< const VectorBase< Scalar > > &vec)
Return a contiguous const semi-persisting view of the local process data of a VectorBase object...
RTOpPack::SubMultiVectorView< Scalar > getNonconstLocalSubMultiVectorView(const RCP< MultiVectorBase< Scalar > > &multivec)
Return a contiguous non-const semi-persisting view of the local process data of a MultiVectorBase obj...
RTOpPack::ConstSubMultiVectorView< Scalar > getLocalSubMultiVectorView(const RCP< const MultiVectorBase< Scalar > > &multivec)
Return a contiguous const semi-persisting view of the local process data of a MultiVectorBase object...
RTOpPack::SubVectorView< Scalar > getNonconstLocalSubVectorView(const RCP< VectorBase< Scalar > > &vec)
Return a contiguous non-const semi-persisting view of the local process data of a VectorBase object...