Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
42template <typename coeff_type>
45 map_(),
46 coeff_()
47{
48}
49
50template <typename coeff_type>
52ProductContainer(const Teuchos::RCP<const Epetra_BlockMap>& theMap) :
53 map_(theMap),
54 coeff_(map_->NumMyElements())
55{
56}
57
58template <typename coeff_type>
60ProductContainer(const Teuchos::RCP<const Epetra_BlockMap>& theMap,
61 const typename traits_type::cloner_type& cloner) :
62 map_(theMap),
63 coeff_(map_->NumMyElements())
64{
65 ordinal_type sz = map_->NumMyElements();
66 for (ordinal_type i=0; i<sz; i++)
67 coeff_[i] = cloner.clone(i);
68}
69
70template <typename coeff_type>
73 map_(v.map_),
74 coeff_(v.coeff_)
75{
76}
77
78template <typename coeff_type>
81{
82}
84template <typename coeff_type>
88{
89 if (this != &v) {
90 map_ = v.map_;
91 coeff_ = v.coeff_;
92 }
93 return *this;
94}
95
96template <typename coeff_type>
97void
99reset(const Teuchos::RCP<const Epetra_BlockMap>& theMap)
101 map_ = theMap;
102 ordinal_type sz = map_->NumMyElements();
103 coeff_.resize(sz);
104}
105
106template <typename coeff_type>
107void
109reset(const Teuchos::RCP<const Epetra_BlockMap>& theMap,
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}
119template <typename coeff_type>
120void
122resize(const Teuchos::RCP<const Epetra_BlockMap>& theMap)
123{
124 map_ = theMap;
125 coeff_.resize(map_->NumMyElements());
126}
127
128template <typename coeff_type>
129void
132{
133 coeff_.reserve(sz);
135
136template <typename coeff_type>
139size() const
140{
141 return coeff_.size();
142}
143
144template <typename coeff_type>
145Teuchos::RCP<const Epetra_BlockMap>
147map() const
148{
149 return map_;
150}
151
152template <typename coeff_type>
153const Teuchos::Array<Teuchos::RCP<coeff_type> >&
155getCoefficients() const
157 return coeff_;
158}
160template <typename coeff_type>
161Teuchos::Array<Teuchos::RCP<coeff_type> >&
164{
165 return coeff_;
166}
167
168template <typename coeff_type>
169Teuchos::RCP<coeff_type>
172{
173 return coeff_[i];
174}
175
176template <typename coeff_type>
177Teuchos::RCP<const coeff_type>
180{
181 return coeff_[i];
182}
183
184template <typename coeff_type>
185void
187setCoeffPtr(ordinal_type i, const Teuchos::RCP<coeff_type>& c)
188{
189 coeff_[i] = c;
190}
191
192template <typename coeff_type>
193coeff_type&
196{
197 return *(coeff_[i]);
198}
199
200template <typename coeff_type>
201const coeff_type&
204{
205 return *(coeff_[i]);
206}
207
208template <typename coeff_type>
209bool
211myGID(int i) const
212{
213 return map_->MyGID(i);
214}
215
216template <typename coeff_type>
217void
219init(const value_type& val)
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
226template <typename coeff_type>
227std::ostream&
229print(std::ostream& os) const
230{
231 Teuchos::Array<ordinal_type> trm;
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}
expr val()
A product (in the mathematical sense) container class whose coefficients are vectors,...
traits_type::value_type value_type
Typename of values.
traits_type::ordinal_type ordinal_type
Typename of ordinals.
Teuchos::RCP< const Epetra_BlockMap > map() const
Return container map.
Teuchos::Array< Teuchos::RCP< coeff_type > > coeff_
Array of polynomial coefficients.
void reserve(ordinal_type sz)
Reserve space for a size sz container.
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.
std::ostream & print(std::ostream &os) const
Print polynomial.
Teuchos::RCP< coeff_type > getCoeffPtr(ordinal_type i)
Return ref-count pointer to coefficient i.
void init(const value_type &val)
Initialize coefficients.
ProductContainer & operator=(const ProductContainer &)
Assignment.
ordinal_type size() const
Return size.
void resize(const Teuchos::RCP< const Epetra_BlockMap > &map)
Resize to map map.
coeff_type & operator[](ordinal_type i)
Array access.
Teuchos::RCP< const Epetra_BlockMap > map_
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.