42 #ifndef STOKHOS_TPETRA_UTILITIES_HPP 43 #define STOKHOS_TPETRA_UTILITIES_HPP 47 #include "Tpetra_CrsMatrix.hpp" 55 template <
class ViewType>
63 mean_vals = ViewType(
"mean-values", vals.dimension_0());
76 template <
class Storage,
class ... P>
88 typename Scalar::cijk_type mean_cijk =
89 Stokhos::create_mean_based_product_tensor<execution_space, typename Storage::ordinal_type, typename Storage::value_type>();
90 mean_vals = Kokkos::make_view<ViewType>(
"mean-values", mean_cijk, nnz, 1);
91 Kokkos::parallel_for( nnz, *
this );
94 KOKKOS_INLINE_FUNCTION
96 mean_vals(i) = vals(i).fastAccessCoeff(0);
109 template <
class Storage,
class ... P>
122 const size_type nnz = vals.dimension_0();
124 Kokkos::parallel_for( nnz, *
this );
127 KOKKOS_INLINE_FUNCTION
132 s += vals(i).fastAccessCoeff(
j);
144 template <
typename Scalar,
typename LO,
typename GO,
typename N>
145 Teuchos::RCP< Tpetra::CrsMatrix<Scalar,LO,GO,N> >
150 typedef Tpetra::CrsMatrix<Scalar,LO,GO,N> MatrixType;
151 typedef Tpetra::Map<LO,GO,N> Map;
153 typedef typename MatrixType::local_matrix_type KokkosMatrixType;
155 typedef typename KokkosMatrixType::StaticCrsGraphType KokkosGraphType;
156 typedef typename KokkosMatrixType::values_type KokkosMatrixValuesType;
158 RCP< const Map > rmap = A.getRowMap();
159 RCP< const Map > cmap = A.getColMap();
161 KokkosMatrixType kokkos_matrix = A.getLocalMatrix();
162 KokkosGraphType kokkos_graph = kokkos_matrix.graph;
163 KokkosMatrixValuesType matrix_values = kokkos_matrix.values;
164 const size_t ncols = kokkos_matrix.numCols();
166 typedef typename MeanFunc::MeanViewType KokkosMeanMatrixValuesType;
167 MeanFunc meanfunc(matrix_values);
168 KokkosMeanMatrixValuesType mean_matrix_values = meanfunc.getMeanValues();
173 KokkosMatrixType mean_kokkos_matrix(
174 "mean-matrix", ncols, mean_matrix_values, kokkos_graph);
175 RCP < MatrixType > mean_matrix =
176 rcp(
new MatrixType(rmap, cmap, mean_kokkos_matrix) );
182 #endif // STOKHOS_TPETRA_UTILITIES_HPP
Teuchos::RCP< Tpetra::CrsMatrix< Scalar, LO, GO, N > > build_mean_matrix(const Tpetra::CrsMatrix< Scalar, LO, GO, N > &A)
Stokhos::StandardStorage< int, double > Storage
ViewType::execution_space execution_space
ViewType::size_type size_type
GetMeanValsFunc(const ViewType &vals_)
MeanViewType getMeanValues() const
Kokkos::DefaultExecutionSpace execution_space
MeanViewType getMeanValues() const
ViewType::execution_space execution_space
Sacado::UQ::PCE< Storage > Scalar
Kokkos::View< Scalar *, P... > ViewType
ViewType::size_type size_type
Sacado::MP::Vector< Storage > Scalar
MeanViewType getMeanValues() const
Kokkos::View< Scalar *, P... > ViewType
GetMeanValsFunc(const ViewType &vals)
Top-level namespace for Stokhos classes and functions.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P... > >::value, unsigned >::type dimension_scalar(const View< T, P... > &view)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
ViewType::size_type size_type
Get mean values matrix for mean-based preconditioning.
GetMeanValsFunc(const ViewType &vals_)
ViewType::execution_space execution_space