41#include "Teuchos_TimeMonitor.hpp"
42#include "Teuchos_TestForException.hpp"
44template <
typename ordinal_type,
typename value_type,
typename ordering_type>
47 const Teuchos::Array< Teuchos::RCP<
const OneDOrthogPolyBasis<ordinal_type, value_type> > >& bases_,
48 const value_type& sparse_tol_,
50 const ordering_type& coeff_compare) :
55 sparse_tol(sparse_tol_),
57 basis_set(coeff_compare),
62 for (ordinal_type i=0; i<d; i++) {
63 if (index[i] != bases[i]->order())
64 bases[i] = bases[i]->cloneWithOrder(index[i]);
69 for (ordinal_type i=0; i<d; i++) {
70 max_orders[i] = bases[i]->order();
71 if (max_orders[i] > p)
76 MultiIndex<ordinal_type> orders(d);
77 for (ordinal_type i=0; i<d; ++i)
78 orders[i] = bases[i]->order();
79 TensorProductIndexSet<ordinal_type> index_set(orders);
80 ProductBasisUtils::buildProductBasis(index_set, basis_set, basis_map);
81 sz = basis_map.size();
86 for (ordinal_type k=0; k<sz; k++) {
88 for (ordinal_type i=0; i<d; i++)
89 nrm = nrm * bases[i]->norm_squared(basis_map[k][i]);
94 name =
"Tensor product basis (";
95 for (ordinal_type i=0; i<d-1; i++)
96 name += bases[i]->getName() +
", ";
97 name += bases[d-1]->getName() +
")";
100 basis_eval_tmp.resize(d);
101 for (ordinal_type
j=0;
j<d;
j++)
102 basis_eval_tmp[
j].resize(max_orders[
j]+1);
105template <
typename ordinal_type,
typename value_type,
typename ordering_type>
111template <
typename ordinal_type,
typename value_type,
typename ordering_type>
119template <
typename ordinal_type,
typename value_type,
typename ordering_type>
127template <
typename ordinal_type,
typename value_type,
typename ordering_type>
135template <
typename ordinal_type,
typename value_type,
typename ordering_type>
136const Teuchos::Array<value_type>&
143template <
typename ordinal_type,
typename value_type,
typename ordering_type>
151template <
typename ordinal_type,
typename value_type,
typename ordering_type>
152Teuchos::RCP< Stokhos::Sparse3Tensor<ordinal_type, value_type> >
156#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
157 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: Total Triple-Product Tensor Fill Time");
160 TensorProductPredicate<ordinal_type> predicate(max_orders);
162 return ProductBasisUtils::computeTripleProductTensor(
163 bases, basis_set, basis_map, predicate, predicate, sparse_tol);
166template <
typename ordinal_type,
typename value_type,
typename ordering_type>
167Teuchos::RCP< Stokhos::Sparse3Tensor<ordinal_type, value_type> >
171#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
172 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: Total Triple-Product Tensor Fill Time");
175 TensorProductPredicate<ordinal_type> predicate(max_orders);
176 TotalOrderPredicate<ordinal_type> k_predicate(1, max_orders);
178 return ProductBasisUtils::computeTripleProductTensor(
179 bases, basis_set, basis_map, predicate, k_predicate, sparse_tol);
182template <
typename ordinal_type,
typename value_type,
typename ordering_type>
189 value_type z = value_type(1.0);
190 for (ordinal_type
j=0;
j<d;
j++)
191 z = z * bases[
j]->evaluate(value_type(0.0), basis_map[i][
j]);
196template <
typename ordinal_type,
typename value_type,
typename ordering_type>
199evaluateBases(
const Teuchos::ArrayView<const value_type>& point,
200 Teuchos::Array<value_type>& basis_vals)
const
202 for (ordinal_type
j=0;
j<d;
j++)
203 bases[
j]->evaluateBases(point[
j], basis_eval_tmp[
j]);
206 for (ordinal_type i=0; i<sz; i++) {
207 value_type t = value_type(1.0);
208 for (ordinal_type
j=0;
j<d;
j++)
209 t *= basis_eval_tmp[
j][basis_map[i][
j]];
214template <
typename ordinal_type,
typename value_type,
typename ordering_type>
217print(std::ostream& os)
const
219 os <<
"Tensor product basis of order " << p <<
", dimension " << d
220 <<
", and size " << sz <<
". Component bases:\n";
221 for (ordinal_type i=0; i<d; i++)
223 os <<
"Basis vector norms (squared):\n\t";
224 for (ordinal_type i=0; i<static_cast<ordinal_type>(norms.size()); i++)
225 os << norms[i] <<
" ";
229template <
typename ordinal_type,
typename value_type,
typename ordering_type>
232term(ordinal_type i)
const
237template <
typename ordinal_type,
typename value_type,
typename ordering_type>
240index(
const MultiIndex<ordinal_type>& term)
const
242 typename coeff_set_type::const_iterator it = basis_set.find(term);
243 TEUCHOS_TEST_FOR_EXCEPTION(it == basis_set.end(), std::logic_error,
244 "Invalid term " << term);
248template <
typename ordinal_type,
typename value_type,
typename ordering_type>
256template <
typename ordinal_type,
typename value_type,
typename ordering_type>
257Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type, value_type> > >
264template <
typename ordinal_type,
typename value_type,
typename ordering_type>
A multidimensional index.
ordinal_type dimension() const
Dimension.
virtual const std::string & getName() const
Return string name of basis.
virtual const MultiIndex< ordinal_type > & term(ordinal_type i) const
Get orders of each coordinate polynomial given an index i.
virtual ordinal_type size() const
Return total size of basis.
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeLinearTripleProductTensor() const
Compute linear triple product tensor where k = 0,1,..,d.
virtual void evaluateBases(const Teuchos::ArrayView< const value_type > &point, Teuchos::Array< value_type > &basis_vals) const
Evaluate basis polynomials at given point point.
TensorProductBasis(const Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > &bases, const value_type &sparse_tol=1.0e-12, const MultiIndex< ordinal_type > &index=MultiIndex< ordinal_type >(), const coeff_compare_type &coeff_compare=coeff_compare_type())
Constructor.
virtual ~TensorProductBasis()
Destructor.
virtual const Teuchos::Array< value_type > & norm_squared() const
Return array storing norm-squared of each basis polynomial.
virtual ordinal_type index(const MultiIndex< ordinal_type > &term) const
Get index of the multivariate polynomial given orders of each coordinate.
virtual value_type evaluateZero(ordinal_type i) const
Evaluate basis polynomial i at zero.
Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > getCoordinateBases() const
Return coordinate bases.
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
ordinal_type order() const
Return order of basis.
ordinal_type dimension() const
Return dimension of basis.
virtual MultiIndex< ordinal_type > getMaxOrders() const
Return maximum order allowable for each coordinate basis.
virtual void print(std::ostream &os) const
Print basis to stream os.