Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_VectorOrthogPolyImp.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
43
44template <typename coeff_type>
51
52template <typename coeff_type>
55 const Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type, value_type> >& theBasis,
56 const Teuchos::RCP<const Epetra_BlockMap>& theMap) :
57 ProductContainer<coeff_type>(theMap),
58 basis_(theBasis)
59{
60}
61
62template <typename coeff_type>
65 const Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type, value_type> >& theBasis,
66 const Teuchos::RCP<const Epetra_BlockMap>& theMap,
67 const typename traits_type::cloner_type& cloner)
68 : ProductContainer<coeff_type>(theMap, cloner),
69 basis_(theBasis)
70{
71}
72
73template <typename coeff_type>
76 ProductContainer<coeff_type>(v),
77 basis_(v.basis_)
78{
79}
80
81template <typename coeff_type>
86
87template <typename coeff_type>
91{
92 if (this != &v) {
94 basis_ = v.basis_;
95 }
96 return *this;
97}
98
99template <typename coeff_type>
100void
103 const Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type, value_type> >& new_basis,
104 const Teuchos::RCP<const Epetra_BlockMap>& new_map,
105 const typename traits_type::cloner_type& cloner)
106{
107 basis_ = new_basis;
109}
110
111template <typename coeff_type>
112Teuchos::RCP<const Stokhos::OrthogPolyBasis<typename Stokhos::VectorOrthogPoly<coeff_type>::ordinal_type, typename Stokhos::VectorOrthogPoly<coeff_type>::value_type> >
114basis() const
115{
116 return basis_;
117}
118
119
120template <typename coeff_type>
121coeff_type&
123term(ordinal_type dimension, ordinal_type order)
125 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
126 product_basis = Teuchos::rcp_dynamic_cast< const Stokhos::ProductBasis<ordinal_type, value_type> >(basis_, true);
127 ordinal_type d = product_basis->dimension();
128 MultiIndex<ordinal_type> theTerm(d);
129 theTerm[dimension] = order;
130 ordinal_type index = product_basis->index(theTerm);
131 return *(this->coeff_[this->map_->LID(index)]);
132}
134template <typename coeff_type>
135const coeff_type&
137term(ordinal_type dimension, ordinal_type order) const
138{
139 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
140 product_basis = Teuchos::rcp_dynamic_cast< const Stokhos::ProductBasis<ordinal_type, value_type> >(basis_, true);
141 ordinal_type d = product_basis->dimension();
142 MultiIndex<ordinal_type> theTerm(d);
143 theTerm[dimension] = order;
144 ordinal_type index = product_basis->index(theTerm);
145 return *(this->coeff_[this->map_->LID(index)]);
146}
147
148template <typename coeff_type>
149void
151evaluate(const Teuchos::Array<value_type>& basis_values, coeff_type& result) const
152{
153 traits_type::init(result, value_type(0));
154 ordinal_type sz = this->coeff_.size();
155 for (ordinal_type i=0; i<sz; i++)
156 traits_type::update(result, basis_values[i], *(this->coeff_[i]));
157}
158
159template <typename coeff_type>
160void
162sumIntoAllTerms(const value_type& weight,
163 const Teuchos::Array<value_type>& basis_values,
164 const Teuchos::Array<value_type>& basis_norms,
165 const coeff_type& vec)
166{
167 ordinal_type sz = this->coeff_.size();
168 int i_gid;
169 for (ordinal_type i=0; i<sz; i++) {
170 i_gid = this->map_->GID(i);
171 traits_type::update(*(this->coeff_[i]),
172 weight*basis_values[i_gid]/basis_norms[i_gid],
173 vec);
174 }
175}
176
177template <typename coeff_type>
178std::ostream&
180print(std::ostream& os) const
181{
182 ordinal_type sz = this->coeff_.size();
183 os << "Stokhos::VectorOrthogPoly of global size "
184 << this->map_->NumGlobalElements() << ", local size " << sz << " in basis "
185 << "\n" << basis_->getName() << ":" << std::endl;
186
187 Teuchos::RCP< const Stokhos::ProductBasis<ordinal_type, value_type> >
188 product_basis = Teuchos::rcp_dynamic_cast< const Stokhos::ProductBasis<ordinal_type, value_type> >(basis_);
189
190 if (product_basis != Teuchos::null) {
191 for (ordinal_type i=0; i<sz; i++) {
192 const MultiIndex<ordinal_type>& trm = product_basis->term(i);
193 os << "Term " << i << " (";
194 for (ordinal_type j=0; j<static_cast<ordinal_type>(trm.size())-1; j++)
195 os << trm[j] << ", ";
196 os << trm[trm.size()-1] << "):" << std::endl;
197 traits_type::print(os, *(this->coeff_[this->map_->LID(i)]));
198 }
199 }
200 else {
201 for (ordinal_type i=0; i<sz; i++) {
202 os << "Term " << this->map_->GID(i) << ":" << std::endl;
203 traits_type::print(os, *(this->coeff_[i]));
204 }
205 }
206
207 return os;
208}
Abstract base class for multivariate orthogonal polynomials.
A product (in the mathematical sense) container class whose coefficients are vectors,...
A container class storing an orthogonal polynomial whose coefficients are vectors,...
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis() const
Get basis.
VectorOrthogPoly & operator=(const VectorOrthogPoly &)
Assignment.
void sumIntoAllTerms(const value_type &weight, const Teuchos::Array< value_type > &basis_values, const Teuchos::Array< value_type > &basis_norms, const coeff_type &vec)
Evaluate polynomial at supplied basis values.
ProductContainer< coeff_type >::ordinal_type ordinal_type
Typename of ordinals.
std::ostream & print(std::ostream &os) const
Print polynomial.
void reset(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > &new_basis, const Teuchos::RCP< const Epetra_BlockMap > &new_map, const typename traits_type::cloner_type &cloner)
Reset to a new basis.
ProductContainer< coeff_type >::value_type value_type
Typename of values.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis_
Basis.
VectorOrthogPoly()
Constructor with no basis.
void evaluate(const Teuchos::Array< value_type > &basis_values, coeff_type &result) const
Evaluate polynomial at supplied basis values.
coeff_type & term(ordinal_type dimension, ordinal_type order)
Get term for dimension dimension and order order.