Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultSpmdVector_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_DEFAULT_SPMD_VECTOR_DEF_HPP
43 #define THYRA_DEFAULT_SPMD_VECTOR_DEF_HPP
44 
45 
46 #include "Thyra_DefaultSpmdVector_decl.hpp"
47 #include "Thyra_SpmdVectorDefaultBase.hpp"
48 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
49 
50 
51 namespace Thyra {
52 
53 
54 // Constructors/initializers/accessors
55 
56 
57 template<class Scalar>
59  :stride_(0)
60 {}
61 
62 
63 template<class Scalar>
65  const RCP<const SpmdVectorSpaceBase<Scalar> > &spmdSpace_in,
66  const ArrayRCP<Scalar> &localValues,
67  const Ordinal stride
68  )
69 {
70  initialize(spmdSpace_in, localValues, stride);
71 }
72 
73 
74 template<class Scalar>
76  const RCP<const SpmdVectorSpaceBase<Scalar> > &spmdSpace_in
77  ,const ArrayRCP<Scalar> &localValues
78  ,const Ordinal stride
79  )
80 {
81 #ifdef TEUCHOS_DEBUG
82  TEUCHOS_TEST_FOR_EXCEPT(is_null(spmdSpace_in));
83  TEUCHOS_TEST_FOR_EXCEPT(spmdSpace_in->localSubDim() > 0 && localValues.get()==NULL);
84  TEUCHOS_TEST_FOR_EXCEPT(stride==0);
85 #endif
86  spmdSpace_ = spmdSpace_in;
87  localValues_ = localValues;
88  stride_ = stride;
89  this->updateSpmdSpace();
90 }
91 
92 
93 template<class Scalar>
95  RCP<const SpmdVectorSpaceBase<Scalar> > *spmdSpace_in
96  ,ArrayRCP<Scalar> *localValues
97  ,Ordinal *stride
98  )
99 {
100  if(spmdSpace_in) *spmdSpace_in = spmdSpace_;
101  if(localValues) *localValues = localValues_;
102  if(stride) *stride = stride_;
103 
104  spmdSpace_ = Teuchos::null;
105  localValues_ = Teuchos::null;
106  stride_ = 0;
107 
108  this->updateSpmdSpace();
109 }
110 
111 
112 // Overridden from SpmdMultiVectorBase
113 
114 
115 template<class Scalar>
118 {
119  return spmdSpace_;
120 }
121 
122 
123 // Overridden from SpmdVectorBase
124 
125 
126 template<class Scalar>
128  const Ptr<ArrayRCP<Scalar> > &localValues )
129 {
130  *localValues = localValues_;
131 }
132 
133 
134 template<class Scalar>
136  const Ptr<ArrayRCP<const Scalar> > &localValues ) const
137 {
138  *localValues = localValues_;
139 }
140 
141 
142 } // end namespace Thyra
143 
144 
145 #endif // THYRA_DEFAULT_SPMD_VECTOR_DEF_HPP
RCP< const SpmdVectorSpaceBase< Scalar > > spmdSpaceImpl() const
bool is_null(const boost::shared_ptr< T > &p)
void uninitialize(RCP< const SpmdVectorSpaceBase< Scalar > > *spmdSpace=NULL, ArrayRCP< Scalar > *localValues=NULL, Ordinal *stride=NULL)
Set to an uninitialized state.
void initialize(const RCP< const SpmdVectorSpaceBase< Scalar > > &spmdSpace, const ArrayRCP< Scalar > &localValues, const Ordinal stride)
Initialize.
void getNonconstLocalVectorDataImpl(const Ptr< ArrayRCP< Scalar > > &localValues)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
void getLocalVectorDataImpl(const Ptr< ArrayRCP< const Scalar > > &localValues) const
DefaultSpmdVector()
Construct to uninitialized.
T * get() const
Base abstract VectorSpaceBase class for all SPMD-based vector spaces.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)