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 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Stokhos_ProductBasis.hpp"
11 
12 template <typename coeff_type>
15  ProductContainer<coeff_type>(),
16  basis_()
17 {
18 }
19 
20 template <typename coeff_type>
25  ProductContainer<coeff_type>(theMap),
26  basis_(theBasis)
27 {
28 }
29 
30 template <typename coeff_type>
35  const typename traits_type::cloner_type& cloner)
36  : ProductContainer<coeff_type>(theMap, cloner),
37  basis_(theBasis)
38 {
39 }
40 
41 template <typename coeff_type>
44  ProductContainer<coeff_type>(v),
45  basis_(v.basis_)
46 {
47 }
48 
49 template <typename coeff_type>
52 {
53 }
54 
55 template <typename coeff_type>
59 {
60  if (this != &v) {
62  basis_ = v.basis_;
63  }
64  return *this;
65 }
66 
67 template <typename coeff_type>
68 void
73  const typename traits_type::cloner_type& cloner)
74 {
75  basis_ = new_basis;
76  ProductContainer<coeff_type>::reset(new_map, cloner);
77 }
78 
79 template <typename coeff_type>
82 basis() const
83 {
84  return basis_;
85 }
86 
87 
88 template <typename coeff_type>
89 coeff_type&
91 term(ordinal_type dimension, ordinal_type order)
92 {
94  product_basis = Teuchos::rcp_dynamic_cast< const Stokhos::ProductBasis<ordinal_type, value_type> >(basis_, true);
95  ordinal_type d = product_basis->dimension();
96  MultiIndex<ordinal_type> theTerm(d);
97  theTerm[dimension] = order;
98  ordinal_type index = product_basis->index(theTerm);
99  return *(this->coeff_[this->map_->LID(index)]);
100 }
101 
102 template <typename coeff_type>
103 const coeff_type&
105 term(ordinal_type dimension, ordinal_type order) const
106 {
108  product_basis = Teuchos::rcp_dynamic_cast< const Stokhos::ProductBasis<ordinal_type, value_type> >(basis_, true);
109  ordinal_type d = product_basis->dimension();
110  MultiIndex<ordinal_type> theTerm(d);
111  theTerm[dimension] = order;
112  ordinal_type index = product_basis->index(theTerm);
113  return *(this->coeff_[this->map_->LID(index)]);
114 }
115 
116 template <typename coeff_type>
117 void
119 evaluate(const Teuchos::Array<value_type>& basis_values, coeff_type& result) const
120 {
121  traits_type::init(result, value_type(0));
122  ordinal_type sz = this->coeff_.size();
123  for (ordinal_type i=0; i<sz; i++)
124  traits_type::update(result, basis_values[i], *(this->coeff_[i]));
125 }
126 
127 template <typename coeff_type>
128 void
131  const Teuchos::Array<value_type>& basis_values,
132  const Teuchos::Array<value_type>& basis_norms,
133  const coeff_type& vec)
134 {
135  ordinal_type sz = this->coeff_.size();
136  int i_gid;
137  for (ordinal_type i=0; i<sz; i++) {
138  i_gid = this->map_->GID(i);
139  traits_type::update(*(this->coeff_[i]),
140  weight*basis_values[i_gid]/basis_norms[i_gid],
141  vec);
142  }
143 }
144 
145 template <typename coeff_type>
146 std::ostream&
148 print(std::ostream& os) const
149 {
150  ordinal_type sz = this->coeff_.size();
151  os << "Stokhos::VectorOrthogPoly of global size "
152  << this->map_->NumGlobalElements() << ", local size " << sz << " in basis "
153  << "\n" << basis_->getName() << ":" << std::endl;
154 
156  product_basis = Teuchos::rcp_dynamic_cast< const Stokhos::ProductBasis<ordinal_type, value_type> >(basis_);
157 
158  if (product_basis != Teuchos::null) {
159  for (ordinal_type i=0; i<sz; i++) {
160  const MultiIndex<ordinal_type>& trm = product_basis->term(i);
161  os << "Term " << i << " (";
162  for (ordinal_type j=0; j<static_cast<ordinal_type>(trm.size())-1; j++)
163  os << trm[j] << ", ";
164  os << trm[trm.size()-1] << "):" << std::endl;
165  traits_type::print(os, *(this->coeff_[this->map_->LID(i)]));
166  }
167  }
168  else {
169  for (ordinal_type i=0; i<sz; i++) {
170  os << "Term " << this->map_->GID(i) << ":" << std::endl;
171  traits_type::print(os, *(this->coeff_[i]));
172  }
173  }
174 
175  return os;
176 }
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.