Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_VectorSpaceDefaultBase_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_VECTOR_SPACE_DEFAULT_BASE_DEF_HPP
11 #define THYRA_VECTOR_SPACE_DEFAULT_BASE_DEF_HPP
12 
13 #include "Thyra_VectorSpaceDefaultBase_decl.hpp"
14 #include "Thyra_VectorSpaceFactoryBase.hpp"
15 #include "Thyra_VectorSpaceBase.hpp"
16 #include "Thyra_VectorBase.hpp"
17 #include "Thyra_MultiVectorStdOps.hpp"
18 #include "Thyra_DefaultColumnwiseMultiVector.hpp"
19 
20 
21 namespace Thyra {
22 
23 
24 // Helper classes
25 
26 
27 template<class Scalar>
28 class CopyVectorViewBack {
29 public:
30  CopyVectorViewBack( const VectorBase<Scalar> *v, const RTOpPack::SubVectorView<Scalar> &raw_v )
31  :v_(v), raw_v_(raw_v)
32  {}
33  ~CopyVectorViewBack()
34  {
36  v_->acquireDetachedView(Range1D(),&sv);
37  RTOpPack::assign_entries<Scalar>( Teuchos::outArg(raw_v_), sv );
38  v_->releaseDetachedView(&sv);
39  }
40 private:
41  const VectorBase<Scalar> *v_;
43 };
44 
45 
46 template<class Scalar>
47 class CopyMultiVectorViewBack {
48 public:
49  CopyMultiVectorViewBack( const MultiVectorBase<Scalar> *mv, const RTOpPack::SubMultiVectorView<Scalar> &raw_mv )
50  :mv_(mv), raw_mv_(raw_mv)
51  {}
52  ~CopyMultiVectorViewBack()
53  {
55  mv_->acquireDetachedView(Range1D(),Range1D(),&smv);
56  RTOpPack::assign_entries<Scalar>( Teuchos::outArg(raw_mv_), smv );
57  mv_->releaseDetachedView(&smv);
58  }
59 private:
60  const MultiVectorBase<Scalar> *mv_;
62 };
63 
64 
65 // Overridden protected functions from VectorSpaceBase
66 
67 
68 template<class Scalar>
71 {
72  return Teuchos::rcp(
74  Teuchos::rcp(this,false),
75  this->smallVecSpcFcty()->createVecSpc(numMembers)));
76  // ToDo: Use the "self object-reference" idiom ot fix this!
77 }
78 
79 
80 template<class Scalar>
83  const RTOpPack::SubVectorView<Scalar> &raw_v ) const
84 {
85 #ifdef TEUCHOS_DEBUG
86  TEUCHOS_TEST_FOR_EXCEPT( raw_v.subDim() != this->dim() );
87 #endif
88  // Create a vector
89  RCP<VectorBase<Scalar> > v = this->createMember();
90  // Copy initial values in raw_v into vector
92  v->acquireDetachedView(Range1D(),&sv);
93  RTOpPack::assign_entries<Scalar>(
94  Teuchos::ptr_implicit_cast<const RTOpPack::SubVectorView<Scalar> >(Teuchos::outArg(sv)),
96  v->commitDetachedView(&sv);
97  // Setup smart pointer to vector to copy view back out just before vector is destroyed
98  Teuchos::set_extra_data(
99  Teuchos::rcp(new CopyVectorViewBack<Scalar>(&*v,raw_v)),
100  "CopyVectorViewBack",
101  Teuchos::outArg(v),
102  Teuchos::PRE_DESTROY
103  );
104  return v;
105 }
106 
107 
108 template<class Scalar>
111 {
112 #ifdef TEUCHOS_DEBUG
113  TEUCHOS_TEST_FOR_EXCEPT( raw_v.subDim() != this->dim() );
114 #endif
115  // Create a vector
116  RCP<VectorBase<Scalar> > v = this->createMember();
117  // Copy initial values in raw_v into vector
119  v->acquireDetachedView(Range1D(),&sv);
120  RTOpPack::assign_entries<Scalar>(
121  Teuchos::ptr_implicit_cast<const RTOpPack::SubVectorView<Scalar> >(Teuchos::outArg(sv)),
122  raw_v );
123  v->commitDetachedView(&sv);
124  return v;
125 }
126 
127 
128 template<class Scalar>
131  const RTOpPack::SubMultiVectorView<Scalar> &raw_mv ) const
132 {
133 #ifdef TEUCHOS_DEBUG
134  TEUCHOS_TEST_FOR_EXCEPT( raw_mv.subDim() != this->dim() );
135 #endif
136  // Create a multi-vector
137  RCP< MultiVectorBase<Scalar> > mv = this->createMembers(raw_mv.numSubCols());
138  // Copy initial values in raw_mv into multi-vector
140  mv->acquireDetachedView(Range1D(),Range1D(),&smv);
141  RTOpPack::assign_entries<Scalar>(
142  Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)),
143  raw_mv
144  );
145  mv->commitDetachedView(&smv);
146  // Setup smart pointer to multi-vector to copy view back out just before multi-vector is destroyed
147  Teuchos::set_extra_data(
148  Teuchos::rcp(new CopyMultiVectorViewBack<Scalar>(&*mv,raw_mv)),
149  "CopyMultiVectorViewBack",
150  Teuchos::outArg(mv),
151  Teuchos::PRE_DESTROY
152  );
153  return mv;
154 }
155 
156 
157 template<class Scalar>
160  const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv ) const
161 {
162 #ifdef TEUCHOS_DEBUG
163  TEUCHOS_TEST_FOR_EXCEPT( raw_mv.subDim() != this->dim() );
164 #endif
165  // Create a multi-vector
167  this->createMembers(raw_mv.numSubCols());
168  // Copy values in raw_mv into multi-vector
170  mv->acquireDetachedView(Range1D(),Range1D(),&smv);
171  RTOpPack::assign_entries<Scalar>(
172  Ptr<const RTOpPack::SubMultiVectorView<Scalar> >(Teuchos::outArg(smv)),
173  raw_mv );
174  mv->commitDetachedView(&smv);
175  return mv;
176 }
177 
178 
179 } // end namespace Thyra
180 
181 
182 #endif // THYRA_VECTOR_SPACE_DEFAULT_BASE_DEF_HPP
RCP< VectorBase< Scalar > > createMemberView(const RTOpPack::SubVectorView< Scalar > &raw_v) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Default subclass for MultiVectorBase implemented using columns of separate abstract vectors...
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
RCP< MultiVectorBase< Scalar > > createMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Teuchos::Range1D Range1D