10 #ifndef STOKHOS_LTB_SPARSE_3_TENSOR_HPP
11 #define STOKHOS_LTB_SPARSE_3_TENSOR_HPP
24 template <
typename ordinal_type,
typename value_type>
53 void print(std::ostream& os)
const {}
62 return head->total_num_entries;
69 return head->total_num_leafs;
94 template <
typename ordinal_type,
typename value_type>
102 template <
typename ordinal_type>
138 template <
typename ordinal_type>
156 node->index_begin = index_begin;
157 node->terms.resize(my_p+1);
159 node->terms[i].resize(prev_d+1);
161 node->terms[i][
j] = term_prefix[
j];
162 node->terms[i][prev_d] = i;
167 node->block_size = my_p+1;
173 Teuchos::arrayView(&basis_orders[1],my_d-1);
174 node->children.resize(my_p+1);
175 node->index_begin = index_begin;
176 node->block_size = 0;
179 bo, total_order, index_begin+node->block_size, order_sum+i,
181 node->children[i] = child;
182 node->block_size += child->block_size;
196 bool symmetric =
false) {
197 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
209 for (
int i=0; i<d; ++i)
210 basis_orders[i] = bases[i]->order();
217 bases[i]->computeSparseTripleProductTensor(bases[i]->order()+1);
231 basis_orders_view, Cijk_1d_view, ltb, ltb, ltb, p, symmetric);
232 Cijk->setHeadNode(head);
247 const bool symmetric,
256 using Teuchos::arrayView;
265 Cijk_Iterator cijk_iterator(p_i, p_j, p_k, symmetric);
271 node->i_begin = i_ltb->index_begin;
272 node->j_begin = j_ltb->index_begin;
273 node->k_begin = k_ltb->index_begin;
274 node->i_size = i_ltb->block_size;
275 node->j_size = j_ltb->block_size;
276 node->k_size = k_ltb->block_size;
280 node->is_leaf =
true;
284 Cijk_1d[0]->getValue(cijk_iterator.i,
287 node->values.push_back(cijk*cijk_base);
288 more = cijk_iterator.increment();
290 node->my_num_entries = node->values.size();
291 node->total_num_entries = node->values.size();
292 node->total_num_leafs = 1;
297 node->is_leaf =
false;
300 arrayView(&Cijk_1d[1], my_d-1);
301 node->total_num_entries = 0;
302 node->total_num_leafs = 0;
306 Cijk_1d[0]->getValue(cijk_iterator.i,
311 i_ltb->children[cijk_iterator.i],
312 j_ltb->children[cijk_iterator.j],
313 k_ltb->children[cijk_iterator.k],
314 total_order, symmetric,
315 sum_i + cijk_iterator.i,
316 sum_j + cijk_iterator.j,
317 sum_k + cijk_iterator.k,
319 node->children.push_back(child);
320 node->total_num_entries += child->total_num_entries;
321 node->total_num_leafs += child->total_num_leafs;
322 more = cijk_iterator.increment();
324 node->my_num_entries = node->children.size();
338 bool symmetric =
false) {
339 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
351 for (
int i=0; i<d; ++i)
352 basis_orders[i] = bases[i]->order();
358 Cijk_1d[i] = bases[i]->computeTripleProductTensor();
372 basis_orders_view, Cijk_1d_view, ltb, ltb, ltb, p, symmetric);
373 Cijk->setHeadNode(head);
388 const bool symmetric,
393 const bool parent_j_equals_k =
true) {
398 using Teuchos::arrayView;
411 node->i_begin = i_ltb->index_begin;
412 node->j_begin = j_ltb->index_begin;
413 node->k_begin = k_ltb->index_begin;
414 node->i_size = i_ltb->block_size;
415 node->j_size = j_ltb->block_size;
416 node->k_size = k_ltb->block_size;
417 node->parent_j_equals_k = parent_j_equals_k;
424 node->is_leaf =
true;
425 node->values.reserve((p_i+1)*(p_j+1)*(p_k+1));
434 if (symmetric && (k0%2 != (i+
j)%2)) ++k0;
439 if (
j+node->j_begin == k+node->k_begin) cijk *= 0.5;
440 node->values.push_back(cijk*cijk_base);
444 node->my_num_entries = node->values.size();
445 node->total_num_entries = node->values.size();
446 node->total_num_leafs = 1;
451 node->is_leaf =
false;
454 arrayView(&Cijk_1d[1], my_d-1);
455 node->total_num_entries = 0;
456 node->total_num_leafs = 0;
461 if (symmetric && (k0%2 != (i+
j)%2)) ++k0;
471 total_order, symmetric,
476 parent_j_equals_k &&
j == k);
477 node->children.push_back(child);
478 node->total_num_entries += child->total_num_entries;
479 node->total_num_leafs += child->total_num_leafs;
483 node->my_num_entries = node->children.size();
489 template <
typename ordinal_type>
496 template <
typename ordinal_type,
typename value_type>
511 template <
typename ordinal_type,
typename value_type>
515 bool symmetric =
false) {
516 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
530 flat_tensor->node.reserve(ltb_tensor->num_leafs());
531 flat_tensor->cijk.reserve(ltb_tensor->num_entries());
532 flat_tensor->symmetric = symmetric;
535 typedef typename Cijk_LTB_type::CijkNode
node_type;
538 node_stack.
push_back(ltb_tensor->getHeadNode());
542 while (node_stack.
size() > 0) {
543 node = node_stack.
back();
544 child_index = index_stack.
back();
552 leaf.
p_i = node->p_i;
553 leaf.
p_j = node->p_j;
554 leaf.
p_k = node->p_k;
556 flat_tensor->node.push_back(leaf);
557 flat_tensor->cijk.insert(flat_tensor->cijk.end(),
558 node->values.begin(),
565 else if (child_index < node->children.size()) {
566 ++index_stack.
back();
567 node = node->children[child_index];
583 template <
int max_size,
typename ordinal_type,
typename value_type>
601 typedef typename cijk_type::node_const_iterator node_iterator;
602 typedef typename cijk_type::cijk_const_iterator cijk_iterator;
604 node_iterator ni_end = cijk.
node.
end();
606 for (; ni != ni_end; ++ni) {
608 const value_type *a_j_block = ca + ni->j_begin;
609 const value_type *b_k_block = cb + ni->k_begin;
610 const value_type *a_k_block = ca + ni->k_begin;
611 const value_type *b_j_block = cb + ni->j_begin;
617 ab[
j][k] = a_j_block[
j]*b_k_block[k] + a_k_block[k]*b_j_block[
j];
629 if (cijk.
symmetric && (k0%2 != (i+
j)%2)) ++k0;
633 tmp += (*ci)*ab[
j][k];
647 #endif // STOKHOS_LTB_SPARSE_3_TENSOR_HPP
Teuchos::RCP< const CijkNode > getHeadNode() const
Get the head node.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
Teuchos::RCP< LTBSparse3Tensor< ordinal_type, value_type > > computeTripleProductTensorLTB(const TotalOrderBasis< ordinal_type, value_type, LexographicLess< MultiIndex< ordinal_type > > > &product_basis, bool symmetric=false)
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
ordinal_type total_num_leafs
void init(const value_type &v)
Initialize coefficients to value.
LTBSparse3Tensor(const bool symm)
Constructor.
cijk_array_type::iterator cijk_iterator
Teuchos::Array< FlatLTBSparse3TensorNode< ordinal_type > > node_array_type
LexicographicTreeBasisNode(const LexicographicTreeBasisNode &node)
LexicographicTreeBasisNode()
Teuchos::Array< Stokhos::MultiIndex< ordinal_type > > terms
pointer coeff()
Return coefficient array.
ordinal_type num_entries() const
Return number of non-zero entries.
Teuchos::RCP< LTBSparse3Tensor< ordinal_type, value_type > > computeTripleProductTensorLTBBlockLeaf(const TotalOrderBasis< ordinal_type, value_type, LexographicLess< MultiIndex< ordinal_type > > > &product_basis, bool symmetric=false)
ordinal_type num_leafs() const
Return number of nodes.
~LTBSparse3Tensor()
Destructor.
ordinal_type my_num_entries
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
LexicographicTreeBasisNode & operator=(const LexicographicTreeBasisNode &node)
node_array_type::const_iterator node_const_iterator
cijk_array_type::const_iterator cijk_const_iterator
Data structure storing a sparse 3-tensor C(i,j,k) in a a tree-based format for lexicographically orde...
node_array_type::iterator node_iterator
Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > build_lexicographic_basis_tree(const Teuchos::ArrayView< const ordinal_type > &basis_orders, const ordinal_type total_order, const ordinal_type index_begin=ordinal_type(0), const ordinal_type order_sum=ordinal_type(0), const Stokhos::MultiIndex< ordinal_type > &term_prefix=Stokhos::MultiIndex< ordinal_type >())
Teuchos::RCP< FlatLTBSparse3Tensor< ordinal_type, value_type > > computeFlatTripleProductTensorLTB(const TotalOrderBasis< ordinal_type, value_type, LexographicLess< MultiIndex< ordinal_type > > > &product_basis, bool symmetric=false)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::ostream & operator<<(std::ostream &os, const ProductContainer< coeff_type > &vec)
Teuchos::Array< Teuchos::RCP< LexicographicTreeBasisNode > > children
void flatLTB3TensorMultiply(OrthogPolyApprox< ordinal_type, value_type > &c, const OrthogPolyApprox< ordinal_type, value_type > &a, const OrthogPolyApprox< ordinal_type, value_type > &b, const FlatLTBSparse3Tensor< ordinal_type, value_type > &cijk)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Teuchos::RCP< typename LTBSparse3Tensor< ordinal_type, value_type >::CijkNode > computeCijkLTBNode(const Teuchos::ArrayView< const ordinal_type > &basis_orders, const Teuchos::ArrayView< const Teuchos::RCP< Sparse3Tensor< ordinal_type, value_type > > > &Cijk_1d, const Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > &i_ltb, const Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > &j_ltb, const Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > &k_ltb, const ordinal_type total_order, const bool symmetric, const ordinal_type sum_i=ordinal_type(0), const ordinal_type sum_j=ordinal_type(0), const ordinal_type sum_k=ordinal_type(0), const value_type cijk_base=value_type(1))
Teuchos::RCP< typename LTBSparse3Tensor< ordinal_type, value_type >::CijkNode > computeCijkLTBNodeBlockLeaf(const Teuchos::ArrayView< const ordinal_type > &basis_orders, const Teuchos::ArrayView< const Teuchos::RCP< Dense3Tensor< ordinal_type, value_type > > > &Cijk_1d, const Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > &i_ltb, const Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > &j_ltb, const Teuchos::RCP< LexicographicTreeBasisNode< ordinal_type > > &k_ltb, const ordinal_type total_order, const bool symmetric, const ordinal_type sum_i=ordinal_type(0), const ordinal_type sum_j=ordinal_type(0), const ordinal_type sum_k=ordinal_type(0), const value_type cijk_base=value_type(1), const bool parent_j_equals_k=true)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Teuchos::RCP< CijkNode > head
std::vector< FlatLTBSparse3TensorNode< ordinal_type > >::const_iterator const_iterator
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Stokhos::Sparse3Tensor< int, double > Cijk_type
void push_back(const value_type &x)
bool symmetric() const
Return if symmetric.
Node type used in constructing the tree.
void print(std::ostream &os) const
Print tensor.
A comparison functor implementing a strict weak ordering based lexographic ordering.
Data structure storing a dense 3-tensor C(i,j,k).
ordinal_type total_num_entries
Teuchos::Array< value_type > values
void setHeadNode(const Teuchos::RCP< CijkNode > &h)
Set the head node.
Teuchos::Array< value_type > cijk_array_type
Teuchos::Array< Teuchos::RCP< CijkNode > > children
std::vector< FlatLTBSparse3TensorNode< ordinal_type > >::iterator iterator
value_type getValue(ordinal_type i, ordinal_type j, ordinal_type k) const
Get Cijk value for a given i, j, k indices.
LTBSparse3Tensor & operator=(const LTBSparse3Tensor &b)