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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_VECTOR_SPACE_BASE_DEF_HPP
43 #define THYRA_VECTOR_SPACE_BASE_DEF_HPP
44 
45 #include "Thyra_VectorSpaceBase_decl.hpp"
46 #include "Thyra_VectorBase.hpp"
47 #include "Thyra_MultiVectorBase.hpp"
48 #include "Teuchos_Tuple.hpp"
49 
50 
51 #ifdef TEUCHOS_DEBUG
52 # define THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
53 #endif
54 
55 
56 namespace Thyra {
57 
58 
59 //
60 // VectorSpaceBase
61 //
62 
63 
64 
65 // Virtual functions with default implementations
66 
67 
68 template<class Scalar>
70 {
71  return false;
72 }
73 
74 
75 template<class Scalar>
77  const EViewType /* viewType */, const EStrideType /* strideType */) const
78 {
79  return false;
80 }
81 
82 
83 template<class Scalar>
86 {
87  return Teuchos::null;
88 }
89 
90 
91 } // end namespace Thyra
92 
93 
94 //
95 // Nonmember functions
96 //
97 
98 
99 template<class Scalar>
101 Thyra::makeHaveOwnership( const RCP<const VectorSpaceBase<Scalar> > &vs_in )
102 {
103  if (vs_in.has_ownership())
104  return vs_in;
105  const RCP<const VectorSpaceBase<Scalar> > vs = vs_in->clone();
107  is_null(vs), std::logic_error
108  ,"Thyra::makeHaveOwnership(vs): Error, the concrete VectorSpaceBase object identified as \'"
109  << vs->description() << "\' does not support the clone() function!"
110  );
111  return vs;
112 }
113 
114 
115 template<class Scalar>
117 Thyra::createMember(
118  const RCP<const VectorSpaceBase<Scalar> > &vs,
119  const std::string &label
120  )
121 {
122  RCP<VectorBase<Scalar> > v = vs->createMember();
123 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
124  if (vs->dim()) {
125  v->assign(ScalarTraits<Scalar>::nan());
126  }
127 #endif
128  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
129  Teuchos::outArg(v) );
130  if (label.length()) v->setObjectLabel(label);
131  return v;
132 }
133 
134 
135 template<class Scalar>
137 Thyra::createMember(
138  const VectorSpaceBase<Scalar> &vs, const std::string &label
139  )
140 {
141  return createMember(Teuchos::rcpFromRef(vs), label);
142 }
143 
144 
145 template<class Scalar>
147 Thyra::createMembers(
148  const RCP<const VectorSpaceBase<Scalar> > &vs,
149  int numMembers, const std::string &label
150  )
151 {
152  RCP<MultiVectorBase<Scalar> >
153  mv = vs->createMembers(numMembers);
154 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
155  if (vs->dim()) {
156  mv->assign(ScalarTraits<Scalar>::nan());
157  }
158 #endif
159  Teuchos::set_extra_data(makeHaveOwnership(vs), "VectorSpaceBase",
160  Teuchos::outArg(mv));
161  if(label.length()) mv->setObjectLabel(label);
162  return mv;
163 }
164 
165 
166 template<class Scalar>
168 Thyra::createMembers(
169  const RCP<const VectorSpaceBase<Scalar> > &vs,
170  const RCP<const VectorSpaceBase<Scalar> > &domain,
171  const std::string &label
172  )
173 {
174  return createMembers(vs, domain->dim(), label);
175 }
176 
177 
178 template<class Scalar>
180 Thyra::createMembers(
181  const VectorSpaceBase<Scalar> &vs, int numMembers,
182  const std::string &label
183  )
184 {
185  return createMembers(Teuchos::rcp(&vs,false), numMembers, label);
186 }
187 
188 
189 template<class Scalar>
191 Thyra::createMemberView(
192  const RCP<const VectorSpaceBase<Scalar> > &vs,
193  const RTOpPack::SubVectorView<Scalar> &raw_v,
194  const std::string &label
195  )
196 {
197  RCP<VectorBase<Scalar> >
198  v = vs->createMemberView(raw_v);
199  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
200  Teuchos::outArg(v) );
201  if (label.length()) v->setObjectLabel(label);
202  return v;
203 }
204 
205 
206 template<class Scalar>
208 Thyra::createMemberView(
209  const VectorSpaceBase<Scalar> &vs,
210  const RTOpPack::SubVectorView<Scalar> &raw_v,
211  const std::string &label
212  )
213 {
214  return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
215 }
216 
217 
218 template<class Scalar>
220 Thyra::createMemberView(
221  const RCP<const VectorSpaceBase<Scalar> > &vs,
223  const std::string &label
224  )
225 {
226  RCP<const VectorBase<Scalar> >
227  v = vs->createMemberView(raw_v);
228  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
229  Teuchos::outArg(v) );
230  if (label.length())
231  Teuchos::rcp_const_cast<VectorBase<Scalar> >(v)->setObjectLabel(label);
232  return v;
233 }
234 
235 
236 template<class Scalar>
238 Thyra::createMemberView(
239  const VectorSpaceBase<Scalar> &vs,
241  const std::string &label
242  )
243 {
244  return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
245 }
246 
247 
248 template<class Scalar>
250 Thyra::createMembersView(
251  const RCP<const VectorSpaceBase<Scalar> > &vs,
253  const std::string &label
254  )
255 {
256  RCP<MultiVectorBase<Scalar> >
257  mv = vs->createMembersView(raw_mv);
258  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
259  Teuchos::outArg(mv) );
260  if (label.length()) mv->setObjectLabel(label);
261  return mv;
262 }
263 
264 
265 template<class Scalar>
267 Thyra::createMembersView(
268  const VectorSpaceBase<Scalar> &vs,
270  const std::string &label
271  )
272 {
273  return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
274 }
275 
276 
277 template<class Scalar>
279 Thyra::createMembersView(
280  const RCP<const VectorSpaceBase<Scalar> > &vs,
282  const std::string &label
283  )
284 {
285  RCP<const MultiVectorBase<Scalar> >
286  mv = vs->createMembersView(raw_mv);
287  Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
288  Teuchos::outArg(mv) );
289  if (label.length())
290  Teuchos::rcp_const_cast<MultiVectorBase<Scalar> >(mv)->setObjectLabel(label);
291  return mv;
292 }
293 
294 
295 template<class Scalar>
297 Thyra::createMembersView( const VectorSpaceBase<Scalar> &vs,
299  const std::string &label
300  )
301 {
302  return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
303 }
304 
305 
306 
307 //
308 // Explicit instantiation macro
309 //
310 // Must be expanded from within the Thyra namespace!
311 //
312 
313 
314 #define THYRA_VECTOR_SPACE_BASE_INSTANT(SCALAR) \
315  \
316  template class VectorSpaceBase<SCALAR >; \
317  \
318  template RCP< VectorBase<SCALAR > > \
319  createMember( \
320  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
321  const std::string &label \
322  ); \
323  \
324  template RCP< VectorBase<SCALAR > > \
325  createMember( \
326  const VectorSpaceBase<SCALAR > &vs, const std::string &label \
327  ); \
328  \
329  template RCP< MultiVectorBase<SCALAR > > \
330  createMembers( \
331  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
332  int numMembers, const std::string &label \
333  ); \
334  \
335  template RCP< Thyra::MultiVectorBase<SCALAR > > \
336  createMembers( \
337  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
338  const RCP<const VectorSpaceBase<SCALAR > > &domain, \
339  const std::string &label \
340  ); \
341  \
342  template RCP< MultiVectorBase<SCALAR > > \
343  createMembers( \
344  const VectorSpaceBase<SCALAR > &vs, int numMembers, \
345  const std::string &label \
346  ); \
347  \
348  template RCP<VectorBase<SCALAR > > \
349  createMemberView( \
350  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
351  const RTOpPack::SubVectorView<SCALAR > &raw_v, \
352  const std::string &label \
353  ); \
354  \
355  template RCP<VectorBase<SCALAR > > \
356  createMemberView( \
357  const VectorSpaceBase<SCALAR > &vs, \
358  const RTOpPack::SubVectorView<SCALAR > &raw_v, \
359  const std::string &label \
360  ); \
361  \
362  template RCP<const VectorBase<SCALAR > > \
363  createMemberView( \
364  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
365  const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
366  const std::string &label \
367  ); \
368  \
369  template RCP<const VectorBase<SCALAR > > \
370  createMemberView( \
371  const VectorSpaceBase<SCALAR > &vs, \
372  const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
373  const std::string &label \
374  ); \
375  \
376  template RCP<MultiVectorBase<SCALAR > > \
377  createMembersView( \
378  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
379  const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
380  const std::string &label \
381  ); \
382  \
383  template RCP<MultiVectorBase<SCALAR > > \
384  createMembersView( \
385  const VectorSpaceBase<SCALAR > &vs, \
386  const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
387  const std::string &label \
388  ); \
389  \
390  template RCP<const MultiVectorBase<SCALAR > > \
391  createMembersView( \
392  const RCP<const VectorSpaceBase<SCALAR > > &vs, \
393  const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
394  const std::string &label \
395  ); \
396  \
397  template RCP<const MultiVectorBase<SCALAR > > \
398  createMembersView( const VectorSpaceBase<SCALAR > &vs, \
399  const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
400  const std::string &label \
401  );
402 
403 
404 #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 ...