Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_VectorSpaceBase_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_BASE_DEF_HPP
11 #define THYRA_VECTOR_SPACE_BASE_DEF_HPP
12 
13 #include "Thyra_VectorSpaceBase_decl.hpp"
14 #include "Thyra_VectorBase.hpp"
15 #include "Thyra_MultiVectorBase.hpp"
16 #include "Teuchos_Tuple.hpp"
17 
18 
19 #ifdef TEUCHOS_DEBUG
20 # define THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
21 #endif
22 
23 
24 namespace Thyra {
25 
26 
27 //
28 // VectorSpaceBase
29 //
30 
31 
32 
33 // Virtual functions with default implementations
34 
35 
36 template<class Scalar>
38 {
39  return false;
40 }
41 
42 
43 template<class Scalar>
45  const EViewType /* viewType */, const EStrideType /* strideType */) const
46 {
47  return false;
48 }
49 
50 
51 template<class Scalar>
54 {
55  return Teuchos::null;
56 }
57 
58 
59 } // end namespace Thyra
60 
61 
62 //
63 // Nonmember functions
64 //
65 
66 
67 template<class Scalar>
69 Thyra::makeHaveOwnership( const RCP<const VectorSpaceBase<Scalar> > &vs_in )
70 {
71  if (vs_in.has_ownership())
72  return vs_in;
73  const RCP<const VectorSpaceBase<Scalar> > vs = vs_in->clone();
75  is_null(vs), std::logic_error
76  ,"Thyra::makeHaveOwnership(vs): Error, the concrete VectorSpaceBase object identified as \'"
77  << vs->description() << "\' does not support the clone() function!"
78  );
79  return vs;
80 }
81 
82 
83 template<class Scalar>
85 Thyra::createMember(
86  const RCP<const VectorSpaceBase<Scalar> > &vs,
87  const std::string &label
88  )
89 {
90  RCP<VectorBase<Scalar> > v = vs->createMember();
91 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
92  if (vs->dim()) {
93  v->assign(ScalarTraits<Scalar>::nan());
94  }
95 #endif
96  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
97  Teuchos::outArg(v) );
98  if (label.length()) v->setObjectLabel(label);
99  return v;
100 }
101 
102 
103 template<class Scalar>
105 Thyra::createMember(
106  const VectorSpaceBase<Scalar> &vs, const std::string &label
107  )
108 {
109  return createMember(Teuchos::rcpFromRef(vs), label);
110 }
111 
112 
113 template<class Scalar>
115 Thyra::createMembers(
116  const RCP<const VectorSpaceBase<Scalar> > &vs,
117  int numMembers, const std::string &label
118  )
119 {
120  RCP<MultiVectorBase<Scalar> >
121  mv = vs->createMembers(numMembers);
122 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
123  if (vs->dim()) {
124  mv->assign(ScalarTraits<Scalar>::nan());
125  }
126 #endif
127  Teuchos::set_extra_data(makeHaveOwnership(vs), "VectorSpaceBase",
128  Teuchos::outArg(mv));
129  if(label.length()) mv->setObjectLabel(label);
130  return mv;
131 }
132 
133 
134 template<class Scalar>
136 Thyra::createMembers(
137  const RCP<const VectorSpaceBase<Scalar> > &vs,
138  const RCP<const VectorSpaceBase<Scalar> > &domain,
139  const std::string &label
140  )
141 {
142  return createMembers(vs, domain->dim(), label);
143 }
144 
145 
146 template<class Scalar>
148 Thyra::createMembers(
149  const VectorSpaceBase<Scalar> &vs, int numMembers,
150  const std::string &label
151  )
152 {
153  return createMembers(Teuchos::rcp(&vs,false), numMembers, label);
154 }
155 
156 
157 template<class Scalar>
159 Thyra::createMemberView(
160  const RCP<const VectorSpaceBase<Scalar> > &vs,
161  const RTOpPack::SubVectorView<Scalar> &raw_v,
162  const std::string &label
163  )
164 {
165  RCP<VectorBase<Scalar> >
166  v = vs->createMemberView(raw_v);
167  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
168  Teuchos::outArg(v) );
169  if (label.length()) v->setObjectLabel(label);
170  return v;
171 }
172 
173 
174 template<class Scalar>
176 Thyra::createMemberView(
177  const VectorSpaceBase<Scalar> &vs,
178  const RTOpPack::SubVectorView<Scalar> &raw_v,
179  const std::string &label
180  )
181 {
182  return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
183 }
184 
185 
186 template<class Scalar>
188 Thyra::createMemberView(
189  const RCP<const VectorSpaceBase<Scalar> > &vs,
191  const std::string &label
192  )
193 {
194  RCP<const VectorBase<Scalar> >
195  v = vs->createMemberView(raw_v);
196  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
197  Teuchos::outArg(v) );
198  if (label.length())
199  Teuchos::rcp_const_cast<VectorBase<Scalar> >(v)->setObjectLabel(label);
200  return v;
201 }
202 
203 
204 template<class Scalar>
206 Thyra::createMemberView(
207  const VectorSpaceBase<Scalar> &vs,
209  const std::string &label
210  )
211 {
212  return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
213 }
214 
215 
216 template<class Scalar>
218 Thyra::createMembersView(
219  const RCP<const VectorSpaceBase<Scalar> > &vs,
221  const std::string &label
222  )
223 {
224  RCP<MultiVectorBase<Scalar> >
225  mv = vs->createMembersView(raw_mv);
226  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
227  Teuchos::outArg(mv) );
228  if (label.length()) mv->setObjectLabel(label);
229  return mv;
230 }
231 
232 
233 template<class Scalar>
235 Thyra::createMembersView(
236  const VectorSpaceBase<Scalar> &vs,
238  const std::string &label
239  )
240 {
241  return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
242 }
243 
244 
245 template<class Scalar>
247 Thyra::createMembersView(
248  const RCP<const VectorSpaceBase<Scalar> > &vs,
250  const std::string &label
251  )
252 {
253  RCP<const MultiVectorBase<Scalar> >
254  mv = vs->createMembersView(raw_mv);
255  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
256  Teuchos::outArg(mv) );
257  if (label.length())
258  Teuchos::rcp_const_cast<MultiVectorBase<Scalar> >(mv)->setObjectLabel(label);
259  return mv;
260 }
261 
262 
263 template<class Scalar>
265 Thyra::createMembersView( const VectorSpaceBase<Scalar> &vs,
267  const std::string &label
268  )
269 {
270  return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
271 }
272 
273 
274 
275 //
276 // Explicit instantiation macro
277 //
278 // Must be expanded from within the Thyra namespace!
279 //
280 
281 
282 #define THYRA_VECTOR_SPACE_BASE_INSTANT(SCALAR) \
283  \
284  template class VectorSpaceBase<SCALAR >; \
285  \
286  template RCP< VectorBase<SCALAR > > \
287  createMember( \
288  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
289  const std::string &label \
290  ); \
291  \
292  template RCP< VectorBase<SCALAR > > \
293  createMember( \
294  const VectorSpaceBase<SCALAR > &vs, const std::string &label \
295  ); \
296  \
297  template RCP< MultiVectorBase<SCALAR > > \
298  createMembers( \
299  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
300  int numMembers, const std::string &label \
301  ); \
302  \
303  template RCP< Thyra::MultiVectorBase<SCALAR > > \
304  createMembers( \
305  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
306  const RCP<const VectorSpaceBase<SCALAR > > &domain, \
307  const std::string &label \
308  ); \
309  \
310  template RCP< MultiVectorBase<SCALAR > > \
311  createMembers( \
312  const VectorSpaceBase<SCALAR > &vs, int numMembers, \
313  const std::string &label \
314  ); \
315  \
316  template RCP<VectorBase<SCALAR > > \
317  createMemberView( \
318  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
319  const RTOpPack::SubVectorView<SCALAR > &raw_v, \
320  const std::string &label \
321  ); \
322  \
323  template RCP<VectorBase<SCALAR > > \
324  createMemberView( \
325  const VectorSpaceBase<SCALAR > &vs, \
326  const RTOpPack::SubVectorView<SCALAR > &raw_v, \
327  const std::string &label \
328  ); \
329  \
330  template RCP<const VectorBase<SCALAR > > \
331  createMemberView( \
332  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
333  const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
334  const std::string &label \
335  ); \
336  \
337  template RCP<const VectorBase<SCALAR > > \
338  createMemberView( \
339  const VectorSpaceBase<SCALAR > &vs, \
340  const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
341  const std::string &label \
342  ); \
343  \
344  template RCP<MultiVectorBase<SCALAR > > \
345  createMembersView( \
346  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
347  const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
348  const std::string &label \
349  ); \
350  \
351  template RCP<MultiVectorBase<SCALAR > > \
352  createMembersView( \
353  const VectorSpaceBase<SCALAR > &vs, \
354  const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
355  const std::string &label \
356  ); \
357  \
358  template RCP<const MultiVectorBase<SCALAR > > \
359  createMembersView( \
360  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
361  const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
362  const std::string &label \
363  ); \
364  \
365  template RCP<const MultiVectorBase<SCALAR > > \
366  createMembersView( const VectorSpaceBase<SCALAR > &vs, \
367  const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
368  const std::string &label \
369  );
370 
371 
372 #endif // THYRA_VECTOR_SPACE_BASE_DEF_HPP
bool is_null(const boost::shared_ptr< T > &p)
virtual RCP< const VectorSpaceBase< Scalar > > clone() const
Clone this object (if supported).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
EViewType
Determines if a view is a direct view of data or a detached copy of data.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< VectorBase< Scalar > > createMemberView(const RCP< const VectorSpaceBase< Scalar > > &vs, const RTOpPack::SubVectorView< Scalar > &raw_v, const std::string &label="")
Create a vector member that is a non-const view of raw data.
RCP< const VectorSpaceBase< Scalar > > makeHaveOwnership(const RCP< const VectorSpaceBase< Scalar > > &vs)
Helper function that clones a VectorSpaceBase object if the RCP does not have ownership.
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
EStrideType
Determine if data is unit stride or non-unit stride.
RCP< MultiVectorBase< Scalar > > createMembersView(const RCP< const VectorSpaceBase< Scalar > > &vs, const RTOpPack::SubMultiVectorView< Scalar > &raw_mv, const std::string &label="")
Create a multi-vector member that is a non-const view of raw data.
RCP< MultiVectorBase< Scalar > > createMembers(const RCP< const VectorSpaceBase< Scalar > > &vs, int numMembers, const std::string &label="")
Create a set of vector members (a MultiVectorBase) from the vector space.
virtual bool hasInCoreView(const Range1D &rng=Range1D(), const EViewType viewType=VIEW_TYPE_DETACHED, const EStrideType strideType=STRIDE_TYPE_NONUNIT) const
Returns true if this-&gt;acquireDetachedView(rng,...) returns a direct view of the range of data request...
virtual bool isEuclidean() const
Return if this vector space has a Euclidean (identity) basis in which case the scalar product is the ...