Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DetachedSpmdVectorView.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_DETACHED_SPMD_VECTOR_VIEW_HPP
11 #define THYRA_DETACHED_SPMD_VECTOR_VIEW_HPP
12 
13 
14 #include "Thyra_SpmdVectorBase.hpp"
15 #include "Teuchos_Assert.hpp"
16 
17 
18 namespace Thyra {
19 
20 
29 template<class Scalar>
31 public:
34  {
35  using Teuchos::rcp_dynamic_cast;
36  if (!is_null(v)) {
37  const RCP<const SpmdVectorBase<Scalar> > spmd_v =
38  rcp_dynamic_cast<const SpmdVectorBase<Scalar> >(v, true);
39  v_ = spmd_v;
40  sv_ = spmd_v->getLocalSubVector();
41  }
42  else {
43  v_ = Teuchos::null;
45  }
46  }
49  {}
52  { if (!is_null(v_)) return v_->spmdSpace(); return Teuchos::null; }
54  const RTOpPack::ConstSubVectorView<Scalar>& sv() const { return sv_; }
56  Teuchos_Ordinal globalOffset() const { return sv_.globalOffset(); }
58  Teuchos_Ordinal subDim() const { return sv_.subDim(); }
60  const ArrayRCP<const Scalar> values() const { return sv_.values(); }
62  ptrdiff_t stride() const { return sv_.stride(); }
64  const Scalar& operator[](Teuchos_Ordinal i) const { return sv_[i]; }
66  const Scalar& operator()(Teuchos_Ordinal i) const { return sv_(i); }
67 private:
70  // Not defined and not to be called
75 };
76 
77 
86 template<class Scalar>
88 public:
91  {
92  using Teuchos::rcp_dynamic_cast;
93  if (!is_null(v)) {
94  const RCP<SpmdVectorBase<Scalar> > spmd_v =
95  rcp_dynamic_cast<SpmdVectorBase<Scalar> >(v, true);
96  v_ = spmd_v;
97  sv_ = spmd_v->getNonconstLocalSubVector();
98  }
99  else {
100  v_ = Teuchos::null;
102  }
103  }
106  {}
109  { if (!is_null(v_)) return v_->spmdSpace(); return Teuchos::null; }
111  const RTOpPack::SubVectorView<Scalar>& sv() const { return sv_; }
113  Teuchos_Ordinal globalOffset() const { return sv_.globalOffset(); }
115  Teuchos_Ordinal subDim() const { return sv_.subDim(); }
117  const ArrayRCP<const Scalar> values() const { return sv_.values(); }
119  ptrdiff_t stride() const { return sv_.stride(); }
121  Scalar& operator[](Teuchos_Ordinal i) const { return sv_[i]; }
123  Scalar& operator()(Teuchos_Ordinal i) const { return sv_(i); }
124 private:
127  // Not defined and not to be called
130  DetachedSpmdVectorView<Scalar>& operator==(
132 };
133 
134 
135 } // namespace Thyra
136 
137 
138 #endif // THYRA_DETACHED_SPMD_VECTOR_VIEW_HPP
Create an explicit detached mutable (non-const) view of all of the local elements on this process of ...
bool is_null(const boost::shared_ptr< T > &p)
const Scalar & operator[](Teuchos_Ordinal i) const
ConstDetachedSpmdVectorView(const Teuchos::RCP< const VectorBase< Scalar > > &v)
Base class for SPMD vectors that can provide views of contiguous elements in a process.
const RTOpPack::SubVectorView< Scalar > & sv() const
const RTOpPack::ConstSubVectorView< Scalar > & sv() const
Abstract interface for finite-dimensional dense vectors.
DetachedSpmdVectorView(const Teuchos::RCP< VectorBase< Scalar > > &v)
const Scalar & operator()(Teuchos_Ordinal i) const
const RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpace() const
const RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpace() const
const ArrayRCP< const Scalar > values() const
Scalar & operator()(Teuchos_Ordinal i) const
Scalar & operator[](Teuchos_Ordinal i) const
Create an explicit detached non-mutable (const) view of all of the local elements on this process of ...
const ArrayRCP< const Scalar > values() const