12 template <
typename ordinal_type,
typename value_type>
17 bool use_old_cijk_alg_,
24 sparse_tol(sparse_tol_),
25 use_old_cijk_alg(use_old_cijk_alg_),
26 deriv_coeffs(deriv_coeffs_),
52 name =
"Complete polynomial basis (";
70 template <
typename ordinal_type,
typename value_type>
76 template <
typename ordinal_type,
typename value_type>
84 template <
typename ordinal_type,
typename value_type>
92 template <
typename ordinal_type,
typename value_type>
100 template <
typename ordinal_type,
typename value_type>
108 template <
typename ordinal_type,
typename value_type>
116 template <
typename ordinal_type,
typename value_type>
121 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
124 if (use_old_cijk_alg)
125 return computeTripleProductTensorOld(sz);
127 return computeTripleProductTensorNew(sz);
130 template <
typename ordinal_type,
typename value_type>
135 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
138 if (use_old_cijk_alg)
139 return computeTripleProductTensorOld(d+1);
141 return computeTripleProductTensorNew(d+1);
144 template <
typename ordinal_type,
typename value_type>
156 Cijk_1d[i] = bases[i]->computeTripleProductTensor();
163 c *= (*Cijk_1d[l])(terms[i][l],terms[
j][l],terms[k][l]);
164 if (
std::abs(c/norms[i]) > sparse_tol)
165 Cijk->add_term(i,
j,k,c);
170 Cijk->fillComplete();
175 template <
typename ordinal_type,
typename value_type>
199 k_lim = k_lim + term[i];
205 if (k_lim <= basis_orders[i]+1)
206 Cijk_1d[i] = bases[i]->computeSparseTripleProductTensor(k_lim);
208 Cijk_1d[i] = bases[i]->computeSparseTripleProductTensor(basis_orders[i]+1);
226 k_iterators[dim] = Cijk_1d[dim]->k_begin();
227 j_iterators[dim] = Cijk_1d[dim]->j_begin(k_iterators[dim]);
228 i_iterators[dim] = Cijk_1d[dim]->i_begin(j_iterators[dim]);
229 terms_i[dim] = Stokhos::index(i_iterators[dim]);
230 terms_j[dim] = Stokhos::index(j_iterators[dim]);
231 terms_k[dim] = Stokhos::index(k_iterators[dim]);
232 sum_i += terms_i[dim];
233 sum_j += terms_j[dim];
234 sum_k += terms_k[dim];
248 if (sum_i <= p && sum_j <= p && sum_k <= p) {
250 K = CPBUtils::compute_index(terms_k, terms, num_terms, p);
253 I = CPBUtils::compute_index(terms_i, terms, num_terms, p);
255 J = CPBUtils::compute_index(terms_j, terms, num_terms, p);
258 c *= value(i_iterators[dim]);
259 if (
std::abs(c/norms[I]) > sparse_tol)
260 Cijk->add_term(I,J,K,c);
270 while (inc && cdim < d) {
274 if (i_iterators[cdim] != Cijk_1d[cdim]->i_end(j_iterators[cdim])) {
275 terms_i[cdim] = Stokhos::index(i_iterators[cdim]);
277 for (
int dim=0; dim<d; dim++)
278 sum_i += terms_i[dim];
280 if (i_iterators[cdim] == Cijk_1d[cdim]->i_end(j_iterators[cdim]) ||
284 if (j_iterators[cdim] != Cijk_1d[cdim]->j_end(k_iterators[cdim])) {
285 terms_j[cdim] = Stokhos::index(j_iterators[cdim]);
287 for (
int dim=0; dim<d; dim++)
288 sum_j += terms_j[dim];
290 if (j_iterators[cdim] == Cijk_1d[cdim]->j_end(k_iterators[cdim]) ||
294 if (k_iterators[cdim] != Cijk_1d[cdim]->k_end()) {
295 terms_k[cdim] = Stokhos::index(k_iterators[cdim]);
297 for (
int dim=0; dim<d; dim++)
298 sum_k += terms_k[dim];
300 if (k_iterators[cdim] == Cijk_1d[cdim]->k_end() || sum_k > p) {
301 k_iterators[cdim] = Cijk_1d[cdim]->k_begin();
303 terms_k[cur_dim] = Stokhos::index(k_iterators[cur_dim]);
305 for (
int dim=0; dim<d; dim++)
306 sum_k += terms_k[dim];
310 j_iterators[cur_dim] =
311 Cijk_1d[cur_dim]->j_begin(k_iterators[cur_dim]);
312 terms_j[cur_dim] = Stokhos::index(j_iterators[cur_dim]);
314 for (
int dim=0; dim<d; dim++)
315 sum_j += terms_j[dim];
319 i_iterators[cur_dim] = Cijk_1d[cur_dim]->i_begin(j_iterators[cur_dim]);
320 terms_i[cur_dim] = Stokhos::index(i_iterators[cur_dim]);
322 for (
int dim=0; dim<d; dim++)
323 sum_i += terms_i[dim];
328 if (sum_i > p || sum_j > p || sum_k > p)
338 Cijk->fillComplete();
343 template <
typename ordinal_type,
typename value_type>
362 m_it!=Cijk->k_end(); ++m_it) {
363 m = Stokhos::index(m_it);
365 j_it != Cijk->j_end(m_it); ++j_it) {
366 j = Stokhos::index(j_it);
368 i_it != Cijk->i_end(j_it); ++i_it) {
369 i = Stokhos::index(i_it);
370 c = Stokhos::value(i_it);
371 (*Dijk)(i,
j,k) += (*Bij)(m,k)*c/norms[m];
380 template <
typename ordinal_type,
typename value_type>
393 Bij_1d[i] = bases[i]->computeDerivDoubleProductTensor();
400 bool is_zero =
false;
402 if (l !=
j && terms[i][l] != terms[k][l])
405 t *= bases[l]->norm_squared(terms[k][l]);
408 c += t*(*deriv_coeffs)[
j]*(*Bij_1d[
j])(terms[k][
j],terms[i][j]);
417 template <
typename ordinal_type,
typename value_type>
426 z = z * bases[
j]->evaluate(
value_type(0.0), terms[i][
j]);
431 template <
typename ordinal_type,
typename value_type>
438 bases[
j]->evaluateBases(point[
j], basis_eval_tmp[j]);
444 t *= basis_eval_tmp[j][terms[i][j]];
449 template <
typename ordinal_type,
typename value_type>
454 os <<
"Complete basis of order " << p <<
", dimension " << d
455 <<
", and size " << sz <<
". Component bases:\n";
458 os <<
"Basis vector norms (squared):\n\t";
459 for (
ordinal_type i=0; i<static_cast<ordinal_type>(norms.size()); i++)
460 os << norms[i] <<
" ";
464 template <
typename ordinal_type,
typename value_type>
472 template <
typename ordinal_type,
typename value_type>
477 return CPBUtils::compute_index(term, terms, num_terms, p);
480 template <
typename ordinal_type,
typename value_type>
488 template <
typename ordinal_type,
typename value_type>
496 template <
typename ordinal_type,
typename value_type>
503 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...