Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_ProductContainerImp.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) 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 Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 template <typename coeff_type>
45  map_(),
46  coeff_()
47 {
48 }
49 
50 template <typename coeff_type>
53  map_(theMap),
54  coeff_(map_->NumMyElements())
55 {
56 }
57 
58 template <typename coeff_type>
61  const typename traits_type::cloner_type& cloner) :
62  map_(theMap),
63  coeff_(map_->NumMyElements())
64 {
66  for (ordinal_type i=0; i<sz; i++)
67  coeff_[i] = cloner.clone(i);
68 }
69 
70 template <typename coeff_type>
73  map_(v.map_),
74  coeff_(v.coeff_)
75 {
76 }
77 
78 template <typename coeff_type>
81 {
82 }
83 
84 template <typename coeff_type>
88 {
89  if (this != &v) {
90  map_ = v.map_;
91  coeff_ = v.coeff_;
92  }
93  return *this;
94 }
95 
96 template <typename coeff_type>
97 void
100 {
101  map_ = theMap;
102  ordinal_type sz = map_->NumMyElements();
103  coeff_.resize(sz);
104 }
105 
106 template <typename coeff_type>
107 void
110  const typename traits_type::cloner_type& cloner)
111 {
112  map_ = theMap;
113  ordinal_type sz = map_->NumMyElements();
114  coeff_.resize(sz);
115  for (ordinal_type i=0; i<sz; i++)
116  coeff_[i] = cloner.clone(i);
117 }
118 
119 template <typename coeff_type>
120 void
123 {
124  map_ = theMap;
125  coeff_.resize(map_->NumMyElements());
126 }
127 
128 template <typename coeff_type>
129 void
132 {
133  coeff_.reserve(sz);
134 }
135 
136 template <typename coeff_type>
139 size() const
140 {
141  return coeff_.size();
142 }
143 
144 template <typename coeff_type>
147 map() const
148 {
149  return map_;
150 }
151 
152 template <typename coeff_type>
156 {
157  return coeff_;
158 }
159 
160 template <typename coeff_type>
164 {
165  return coeff_;
166 }
167 
168 template <typename coeff_type>
172 {
173  return coeff_[i];
174 }
175 
176 template <typename coeff_type>
180 {
181  return coeff_[i];
182 }
183 
184 template <typename coeff_type>
185 void
188 {
189  coeff_[i] = c;
190 }
191 
192 template <typename coeff_type>
193 coeff_type&
196 {
197  return *(coeff_[i]);
198 }
199 
200 template <typename coeff_type>
201 const coeff_type&
204 {
205  return *(coeff_[i]);
206 }
207 
208 template <typename coeff_type>
209 bool
211 myGID(int i) const
212 {
213  return map_->MyGID(i);
214 }
215 
216 template <typename coeff_type>
217 void
220 {
221  ordinal_type sz = coeff_.size();
222  for (ordinal_type i=0; i<sz; i++)
223  traits_type::init(*(coeff_[i]), val);
224 }
225 
226 template <typename coeff_type>
227 std::ostream&
229 print(std::ostream& os) const
230 {
232  ordinal_type sz = coeff_.size();
233  os << "Stokhos::ProductContainer of global size " << map_->NumGlobalElements()
234  << ", local size " << sz << ":" << std::endl;
235  for (ordinal_type i=0; i<sz; i++) {
236  os << "Term " << map_->GID(i) << ":" << std::endl;
237  traits_type::print(os, *(coeff_[i]));
238  }
239 
240  return os;
241 }
Teuchos::RCP< const Epetra_BlockMap > map() const
Return container map.
void setCoeffPtr(ordinal_type i, const Teuchos::RCP< coeff_type > &c)
Set coefficient i to c.
bool myGID(int i) const
Return whether global index i resides on this processor.
ProductContainer & operator=(const ProductContainer &)
Assignment.
void init(const value_type &val)
Initialize coefficients.
coeff_type & operator[](ordinal_type i)
Array access.
int NumMyElements() const
Teuchos::RCP< const Epetra_BlockMap > map_
Container map.
const Teuchos::Array< Teuchos::RCP< coeff_type > > & getCoefficients() const
Return array of coefficients.
void reset(const Teuchos::RCP< const Epetra_BlockMap > &map)
Resize to new map map.
Teuchos::Array< Teuchos::RCP< coeff_type > > coeff_
Array of polynomial coefficients.
Teuchos::RCP< coeff_type > getCoeffPtr(ordinal_type i)
Return ref-count pointer to coefficient i.
A product (in the mathematical sense) container class whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
traits_type::ordinal_type ordinal_type
Typename of ordinals.
expr val()
size_type size() const
std::ostream & print(std::ostream &os) const
Print polynomial.
traits_type::value_type value_type
Typename of values.
void reserve(ordinal_type sz)
Reserve space for a size sz container.
ordinal_type size() const
Return size.
void resize(const Teuchos::RCP< const Epetra_BlockMap > &map)
Resize to map map.