43 template <
typename ordinal_type,
typename value_type>
48 bool use_old_cijk_alg_,
55 sparse_tol(sparse_tol_),
56 use_old_cijk_alg(use_old_cijk_alg_),
57 deriv_coeffs(deriv_coeffs_),
83 name =
"Complete polynomial basis (";
101 template <
typename ordinal_type,
typename value_type>
107 template <
typename ordinal_type,
typename value_type>
115 template <
typename ordinal_type,
typename value_type>
123 template <
typename ordinal_type,
typename value_type>
131 template <
typename ordinal_type,
typename value_type>
139 template <
typename ordinal_type,
typename value_type>
147 template <
typename ordinal_type,
typename value_type>
152 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
155 if (use_old_cijk_alg)
156 return computeTripleProductTensorOld(sz);
158 return computeTripleProductTensorNew(sz);
161 template <
typename ordinal_type,
typename value_type>
166 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
169 if (use_old_cijk_alg)
170 return computeTripleProductTensorOld(d+1);
172 return computeTripleProductTensorNew(d+1);
175 template <
typename ordinal_type,
typename value_type>
187 Cijk_1d[i] = bases[i]->computeTripleProductTensor();
194 c *= (*Cijk_1d[l])(terms[i][l],terms[
j][l],terms[k][l]);
195 if (
std::abs(c/norms[i]) > sparse_tol)
196 Cijk->add_term(i,
j,k,c);
201 Cijk->fillComplete();
206 template <
typename ordinal_type,
typename value_type>
230 k_lim = k_lim + term[i];
236 if (k_lim <= basis_orders[i]+1)
237 Cijk_1d[i] = bases[i]->computeSparseTripleProductTensor(k_lim);
239 Cijk_1d[i] = bases[i]->computeSparseTripleProductTensor(basis_orders[i]+1);
257 k_iterators[dim] = Cijk_1d[dim]->k_begin();
258 j_iterators[dim] = Cijk_1d[dim]->j_begin(k_iterators[dim]);
259 i_iterators[dim] = Cijk_1d[dim]->i_begin(j_iterators[dim]);
260 terms_i[dim] = Stokhos::index(i_iterators[dim]);
261 terms_j[dim] = Stokhos::index(j_iterators[dim]);
262 terms_k[dim] = Stokhos::index(k_iterators[dim]);
263 sum_i += terms_i[dim];
264 sum_j += terms_j[dim];
265 sum_k += terms_k[dim];
279 if (sum_i <= p && sum_j <= p && sum_k <= p) {
281 K = CPBUtils::compute_index(terms_k, terms, num_terms, p);
284 I = CPBUtils::compute_index(terms_i, terms, num_terms, p);
286 J = CPBUtils::compute_index(terms_j, terms, num_terms, p);
289 c *= value(i_iterators[dim]);
290 if (
std::abs(c/norms[I]) > sparse_tol)
291 Cijk->add_term(I,J,K,c);
301 while (inc && cdim < d) {
305 if (i_iterators[cdim] != Cijk_1d[cdim]->i_end(j_iterators[cdim])) {
306 terms_i[cdim] = Stokhos::index(i_iterators[cdim]);
308 for (
int dim=0; dim<d; dim++)
309 sum_i += terms_i[dim];
311 if (i_iterators[cdim] == Cijk_1d[cdim]->i_end(j_iterators[cdim]) ||
315 if (j_iterators[cdim] != Cijk_1d[cdim]->j_end(k_iterators[cdim])) {
316 terms_j[cdim] = Stokhos::index(j_iterators[cdim]);
318 for (
int dim=0; dim<d; dim++)
319 sum_j += terms_j[dim];
321 if (j_iterators[cdim] == Cijk_1d[cdim]->j_end(k_iterators[cdim]) ||
325 if (k_iterators[cdim] != Cijk_1d[cdim]->k_end()) {
326 terms_k[cdim] = Stokhos::index(k_iterators[cdim]);
328 for (
int dim=0; dim<d; dim++)
329 sum_k += terms_k[dim];
331 if (k_iterators[cdim] == Cijk_1d[cdim]->k_end() || sum_k > p) {
332 k_iterators[cdim] = Cijk_1d[cdim]->k_begin();
334 terms_k[cur_dim] = Stokhos::index(k_iterators[cur_dim]);
336 for (
int dim=0; dim<d; dim++)
337 sum_k += terms_k[dim];
341 j_iterators[cur_dim] =
342 Cijk_1d[cur_dim]->j_begin(k_iterators[cur_dim]);
343 terms_j[cur_dim] = Stokhos::index(j_iterators[cur_dim]);
345 for (
int dim=0; dim<d; dim++)
346 sum_j += terms_j[dim];
350 i_iterators[cur_dim] = Cijk_1d[cur_dim]->i_begin(j_iterators[cur_dim]);
351 terms_i[cur_dim] = Stokhos::index(i_iterators[cur_dim]);
353 for (
int dim=0; dim<d; dim++)
354 sum_i += terms_i[dim];
359 if (sum_i > p || sum_j > p || sum_k > p)
369 Cijk->fillComplete();
374 template <
typename ordinal_type,
typename value_type>
393 m_it!=Cijk->k_end(); ++m_it) {
394 m = Stokhos::index(m_it);
396 j_it != Cijk->j_end(m_it); ++j_it) {
397 j = Stokhos::index(j_it);
399 i_it != Cijk->i_end(j_it); ++i_it) {
400 i = Stokhos::index(i_it);
401 c = Stokhos::value(i_it);
402 (*Dijk)(i,
j,k) += (*Bij)(m,k)*c/norms[m];
411 template <
typename ordinal_type,
typename value_type>
424 Bij_1d[i] = bases[i]->computeDerivDoubleProductTensor();
431 bool is_zero =
false;
433 if (l !=
j && terms[i][l] != terms[k][l])
436 t *= bases[l]->norm_squared(terms[k][l]);
439 c += t*(*deriv_coeffs)[
j]*(*Bij_1d[
j])(terms[k][
j],terms[i][j]);
448 template <
typename ordinal_type,
typename value_type>
457 z = z * bases[
j]->evaluate(
value_type(0.0), terms[i][
j]);
462 template <
typename ordinal_type,
typename value_type>
469 bases[
j]->evaluateBases(point[
j], basis_eval_tmp[j]);
475 t *= basis_eval_tmp[j][terms[i][j]];
480 template <
typename ordinal_type,
typename value_type>
485 os <<
"Complete basis of order " << p <<
", dimension " << d
486 <<
", and size " << sz <<
". Component bases:\n";
489 os <<
"Basis vector norms (squared):\n\t";
490 for (
ordinal_type i=0; i<static_cast<ordinal_type>(norms.size()); i++)
491 os << norms[i] <<
" ";
495 template <
typename ordinal_type,
typename value_type>
503 template <
typename ordinal_type,
typename value_type>
508 return CPBUtils::compute_index(term, terms, num_terms, p);
511 template <
typename ordinal_type,
typename value_type>
519 template <
typename ordinal_type,
typename value_type>
527 template <
typename ordinal_type,
typename value_type>
534 max_orders[i] = basis_orders[i];
ordinal_type dimension() const
Return dimension of basis.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
ordinal_type order() const
Return order of basis.
virtual Teuchos::RCP< Teuchos::SerialDenseMatrix< ordinal_type, value_type > > computeDerivDoubleProductTensor() const
Compute double product tensor where represents the derivative of in the direction ...
virtual value_type evaluateZero(ordinal_type i) const
Evaluate basis polynomial i at zero.
virtual void evaluateBases(const Teuchos::ArrayView< const value_type > &point, Teuchos::Array< value_type > &basis_vals) const
Evaluate basis polynomials at given point point.
CompletePolynomialBasis(const Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > &bases, const value_type &sparse_tol=1.0e-12, bool use_old_cijk_alg=false, const Teuchos::RCP< Teuchos::Array< value_type > > &deriv_coeffs=Teuchos::null)
Constructor.
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeLinearTripleProductTensor() const
Compute linear triple product tensor where k = 0,1,..,d.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Teuchos::Array< ordinal_type > basis_orders
Array storing order of each basis.
ordinal_type d
Total dimension of basis.
Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > getCoordinateBases() const
Return coordinate bases.
Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > bases
Array of bases.
Teuchos::Array< MultiIndex< ordinal_type > > terms
2-D array of basis terms
virtual ~CompletePolynomialBasis()
Destructor.
std::string name
Name of basis.
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensorNew(ordinal_type order) const
Compute triple product tensor using new algorithm.
Bi-directional iterator for traversing a sparse array.
Teuchos::Array< value_type > norms
Norms.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual Teuchos::RCP< Stokhos::Dense3Tensor< ordinal_type, value_type > > computeDerivTripleProductTensor(const Teuchos::RCP< const Teuchos::SerialDenseMatrix< ordinal_type, value_type > > &Bij, const Teuchos::RCP< const Stokhos::Sparse3Tensor< ordinal_type, value_type > > &Cijk) const
Compute triple product tensor where represents the derivative of in the direction ...
virtual const std::string & getName() const
Return string name of basis.
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensorOld(ordinal_type order) const
Compute triple product tensor using old algorithm.
virtual MultiIndex< ordinal_type > getMaxOrders() const
Return maximum order allowable for each coordinate basis.
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
ordinal_type sz
Total size of basis.
virtual void print(std::ostream &os) const
Print basis to stream os.
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
void resize(size_type new_size, const value_type &x=value_type())
virtual ordinal_type index(const MultiIndex< ordinal_type > &term) const
Get index of the multivariate polynomial given orders of each coordinate.
Stokhos::Sparse3Tensor< int, double > Cijk_type
Abstract base class for 1-D orthogonal polynomials.
ordinal_type p
Total order of basis.
virtual ordinal_type size() const
Return total size of basis.
Data structure storing a dense 3-tensor C(i,j,k).
virtual const MultiIndex< ordinal_type > & term(ordinal_type i) const
Get orders of each coordinate polynomial given an index i.
Teuchos::RCP< Teuchos::Array< value_type > > deriv_coeffs
Coefficients for derivative.
Teuchos::Array< ordinal_type > num_terms
Number of terms up to each order.
virtual const Teuchos::Array< value_type > & norm_squared() const
Return array storing norm-squared of each basis polynomial.
Teuchos::Array< Teuchos::Array< value_type > > basis_eval_tmp
Temporary array used in basis evaluation.
static ordinal_type compute_terms(ordinal_type p, ordinal_type d, ordinal_type &sz, Teuchos::Array< MultiIndex< ordinal_type > > &terms, Teuchos::Array< ordinal_type > &num_terms)
Compute the 2-D array of basis terms which maps a basis index into the orders for each basis dimensio...