Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
42 #include "Stokhos_ProductBasis.hpp"
43 
44 template <typename coeff_type>
47  ProductContainer<coeff_type>(),
48  basis_()
49 {
50 }
51 
52 template <typename coeff_type>
57  ProductContainer<coeff_type>(theMap),
58  basis_(theBasis)
59 {
60 }
61 
62 template <typename coeff_type>
67  const typename traits_type::cloner_type& cloner)
68  : ProductContainer<coeff_type>(theMap, cloner),
69  basis_(theBasis)
70 {
71 }
72 
73 template <typename coeff_type>
76  ProductContainer<coeff_type>(v),
77  basis_(v.basis_)
78 {
79 }
80 
81 template <typename coeff_type>
84 {
85 }
86 
87 template <typename coeff_type>
91 {
92  if (this != &v) {
94  basis_ = v.basis_;
95  }
96  return *this;
97 }
98 
99 template <typename coeff_type>
100 void
105  const typename traits_type::cloner_type& cloner)
106 {
107  basis_ = new_basis;
108  ProductContainer<coeff_type>::reset(new_map, cloner);
109 }
110 
111 template <typename coeff_type>
114 basis() const
115 {
116  return basis_;
117 }
118 
119 
120 template <typename coeff_type>
121 coeff_type&
123 term(ordinal_type dimension, ordinal_type order)
124 {
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 }
133 
134 template <typename coeff_type>
135 const coeff_type&
137 term(ordinal_type dimension, ordinal_type order) const
138 {
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 
148 template <typename coeff_type>
149 void
151 evaluate(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 
159 template <typename coeff_type>
160 void
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 
177 template <typename coeff_type>
178 std::ostream&
180 print(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 
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 }
ProductContainer< coeff_type >::ordinal_type ordinal_type
Typename of ordinals.
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 & operator=(const ProductContainer &)
Assignment.
ordinal_type size() const
Size.
VectorOrthogPoly()
Constructor with no basis.
std::ostream & print(std::ostream &os) const
Print polynomial.
VectorOrthogPoly & operator=(const VectorOrthogPoly &)
Assignment.
Abstract base class for multivariate orthogonal polynomials.
void reset(const Teuchos::RCP< const Epetra_BlockMap > &map)
Resize to new map map.
Abstract base class for multivariate orthogonal polynomials generated from tensor products of univari...
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis_
Basis.
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.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
void evaluate(const Teuchos::Array< value_type > &basis_values, coeff_type &result) const
Evaluate polynomial at supplied basis values.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis() const
Get basis.
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.
coeff_type & term(ordinal_type dimension, ordinal_type order)
Get term for dimension dimension and order order.
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)
ProductContainer< coeff_type >::value_type value_type
Typename of values.