42 #ifndef STOKHOS_LINEAR_SPARSE_3_TENSOR_HPP
43 #define STOKHOS_LINEAR_SPARSE_3_TENSOR_HPP
45 #include "Kokkos_Core.hpp"
61 template<
typename ValueType ,
class ExecutionSpace ,
int BlockSize >
66 typedef typename execution_space::size_type
size_type ;
118 KOKKOS_INLINE_FUNCTION
122 KOKKOS_INLINE_FUNCTION
126 KOKKOS_INLINE_FUNCTION
131 KOKKOS_INLINE_FUNCTION
136 KOKKOS_INLINE_FUNCTION
141 KOKKOS_INLINE_FUNCTION
146 KOKKOS_INLINE_FUNCTION
150 template <
typename OrdinalType>
166 tensor.
m_nnz = symmetric ? 2 : 3 ;
170 typename value_array_type::HostMirror
176 bases[0]->computeTripleProductTensor();
178 host_value(0) = (*cijk)(0,0,0);
179 host_value(1) = (*cijk)(0,1,1);
181 host_value(2) = (*cijk)(1,1,1);
194 template<
class Device ,
typename OrdinalType ,
typename ValueType ,
int BlockSize >
195 LinearSparse3Tensor<ValueType, Device,BlockSize>
202 basis, Cijk, params );
205 template <
typename ValueType,
typename Device,
int BlockSize >
213 template<
typename MatrixValue ,
typename VectorValue >
214 KOKKOS_INLINE_FUNCTION
216 const MatrixValue *
const a ,
217 const VectorValue *
const x ,
218 VectorValue *
const y )
220 const size_type block_size = tensor_type::block_size;
224 const ValueType c0 = tensor.
value(0);
225 const ValueType c1 = tensor.
value(1);
226 const ValueType a0 = a[0];
227 const ValueType x0 = x[0];
229 if (block_size > 1) {
231 TV vc0(c0), vc1(c1), va0(a0), vx0(x0), vy0;
234 const MatrixValue *aa = a;
235 const VectorValue *xx = x;
239 const size_type nBlock = dim / block_size;
240 const size_type iEnd = nBlock * block_size;
245 for ( ; i < iEnd; i+=block_size,aa+=block_size,xx+=block_size,yy+=block_size) {
258 yi.aligned_scatter(yy);
261 ai2.times_equal(vc1);
264 ValueType y0 = vy0.sum();
267 for ( ; i < dim; ++i) {
268 const ValueType ai = *aa++;
269 const ValueType xi = *xx++;
270 *yy++ += c1*(a0*xi + ai*x0);
273 y[0] += y0 + (c0-3.0*c1)*a0*x0;
277 const ValueType c2 = tensor.
value(2);
280 for ( ; i < iEnd; i+=block_size,aa+=block_size,xx+=block_size,yy+=block_size) {
296 yi.aligned_scatter(yy);
299 ai2.times_equal(vc1);
302 ValueType y0 = vy0.sum();
305 for ( ; i < dim; ++i) {
306 const ValueType ai = *aa++;
307 const ValueType xi = *xx++;
308 const ValueType aixi = ai*xi;
309 *yy++ += c1*(a0*xi + ai*x0) + c2*aixi;
312 y[0] += y0 + (c0-3.0*c1-c2)*a0*x0;
320 ValueType y0 = c0*a0*x0;
325 const ValueType ai = a[i];
326 const ValueType xi = x[i];
327 y[i] += c1*(a0*xi + ai*x0);
335 const ValueType c2 = tensor.
value(2);
337 const ValueType ai = a[i];
338 const ValueType xi = x[i];
339 const ValueType aixi = ai*xi;
340 y[i] += c1*(a0*xi + ai*x0) + c2*aixi;
351 KOKKOS_INLINE_FUNCTION
355 KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION size_type entry_count() const
Number of sparse entries.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
T & get(ParameterList &l, const std::string &name)
static LinearSparse3Tensor create(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::Sparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms)
KOKKOS_INLINE_FUNCTION size_type num_non_zeros() const
Number of non-zero's.
Kokkos::View< value_type[], execution_space > value_array_type
Device::size_type size_type
static KOKKOS_INLINE_FUNCTION size_type matrix_size(const tensor_type &tensor)
KOKKOS_INLINE_FUNCTION size_type dimension() const
Dimension of the tensor.
KOKKOS_INLINE_FUNCTION bool symmetric() const
Is tensor built from symmetric PDFs.
ExecutionSpace execution_space
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
execution_space::size_type size_type
static KOKKOS_INLINE_FUNCTION void apply(const tensor_type &tensor, const MatrixValue *const a, const VectorValue *const x, VectorValue *const y)
LinearSparse3Tensor< ValueType, Device, BlockSize > tensor_type
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
LinearSparse3Tensor & operator=(const LinearSparse3Tensor &rhs)
virtual Teuchos::Array< Teuchos::RCP< const OneDOrthogPolyBasis< ordinal_type, value_type > > > getCoordinateBases() const =0
Return array of coordinate bases.
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)
KOKKOS_INLINE_FUNCTION size_type aligned_dimension() const
Dimension of the tensor.
LinearSparse3Tensor(const LinearSparse3Tensor &rhs)
KOKKOS_INLINE_FUNCTION const value_type & value(const size_type entry) const
Value for entry 'entry'.
static const int block_size
KOKKOS_INLINE_FUNCTION size_type num_flops() const
Number flop's per multiply-add.
static KOKKOS_INLINE_FUNCTION size_type vector_size(const tensor_type &tensor)
LinearSparse3Tensor< ValueType, Device, BlockSize > create_linear_sparse_3_tensor(const Stokhos::ProductBasis< OrdinalType, ValueType > &basis, const Stokhos::Sparse3Tensor< OrdinalType, ValueType > &Cijk, const Teuchos::ParameterList ¶ms)
virtual ordinal_type size() const =0
Return total size of basis.
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)