10 #ifndef STOKHOS_KOKKOS_CORE_KERNELS_UNIT_TEST_HPP
11 #define STOKHOS_KOKKOS_CORE_KERNELS_UNIT_TEST_HPP
19 #include "EpetraExt_BlockUtility.h"
28 #include "Kokkos_Macros.hpp"
44 #ifdef HAVE_STOKHOS_KOKKOSLINALG
45 #include "KokkosSparse_CrsMatrix.hpp"
46 #include "KokkosSparse_spmv.hpp"
47 #include "KokkosBlas1_update.hpp"
50 namespace KokkosKernelsUnitTest {
57 template<
typename IntType >
64 return k + N * ( j + N * i );
67 template <
typename ordinal >
70 std::vector< std::vector<ordinal> > & graph )
72 graph.resize( N * N * N , std::vector<ordinal>() );
76 for (
int i = 0 ; i < (int) N ; ++i ) {
77 for (
int j = 0 ;
j < (int) N ; ++
j ) {
78 for (
int k = 0 ; k < (int) N ; ++k ) {
82 graph[row].reserve(27);
84 for (
int ii = -1 ; ii < 2 ; ++ii ) {
85 for (
int jj = -1 ; jj < 2 ; ++jj ) {
86 for (
int kk = -1 ; kk < 2 ; ++kk ) {
87 if ( 0 <= i + ii && i + ii < (
int) N &&
88 0 <=
j + jj &&
j + jj < (
int) N &&
89 0 <= k + kk && k + kk < (
int) N ) {
92 graph[row].push_back(col);
95 total += graph[row].size();
101 template <
typename scalar,
typename ordinal>
104 const ordinal nStoch ,
105 const ordinal iRowFEM ,
106 const ordinal iColFEM ,
107 const ordinal iStoch )
109 const scalar A_fem = ( 10.0 + scalar(iRowFEM) / scalar(nFEM) ) +
110 ( 5.0 + scalar(iColFEM) / scalar(nFEM) );
112 const scalar A_stoch = ( 1.0 + scalar(iStoch) / scalar(nStoch) );
114 return A_fem + A_stoch ;
118 template <
typename scalar,
typename ordinal>
121 const ordinal nStoch ,
122 const ordinal iColFEM ,
123 const ordinal iStoch )
125 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
126 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
127 return X_fem + X_stoch ;
131 template <
typename Device>
152 void setup(
int p_ = 5,
int d_ = 2) {
176 for (
int i=0; i<
d; i++)
180 Cijk =
basis->computeTripleProductTensor();
201 rcp(EpetraExt::BlockUtility::GenerateBlockMap(
202 *x_map, *stoch_row_map, *sg_comm));
207 for (
int i=0; i<num_my_GIDs; ++i) {
208 int row = my_GIDs[i];
218 x_map, x_map, sg_x_map, sg_x_map,
225 basis, sg_A_overlap_map, x_map, x_map, sg_x_map, sg_comm));
229 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM <
fem_length ; ++iRowFEM ) {
230 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM <
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
231 const int iColFEM =
fem_graph[iRowFEM][iRowEntryFEM] ;
233 double v = generate_matrix_coefficient<double>(
239 A_sg_blocks->setCoeffPtr(i, A);
244 basis, stoch_row_map, x_map, sg_x_map, sg_comm));
246 basis, stoch_row_map, x_map, sg_x_map, sg_comm));
249 for (
int iColFEM=0; iColFEM <
fem_length; ++iColFEM ) {
250 for (
int iColStoch=0 ; iColStoch <
stoch_length; ++iColStoch ) {
251 (*sg_x)[iColStoch][iColFEM] = generate_vector_coefficient<double>(
262 x_map, stoch_row_map, sg_comm));
268 typedef typename Kokkos::ViewTraits<value_type,Device,void,void>::host_mirror_space host_device;
271 host_device > stoch_tensor_type ;
273 stoch_tensor_type tensor =
274 Stokhos::create_stochastic_product_tensor< tensor_type >( *
basis, *
Cijk );
281 for (
int j=0;
j<
d; ++
j)
282 term[
j] = tensor.bases_degree(i,
j);
283 int idx = basis->
index(term);
289 template <
typename vec_type>
295 double diff =
std::abs( (*
sg_y)[block][i] - y[block][i] );
299 out <<
"y_expected[" << block <<
"][" << i <<
"] - "
300 <<
"y[" << block <<
"][" << i <<
"] = " << (*sg_y)[block][i]
301 <<
" - " << y[block][i] <<
" == "
302 << diff <<
" < " << tol <<
" : failed"
305 success = success && s;
312 template <
typename multi_vec_type>
318 double diff =
std::abs( (*
sg_y)[block][i] - y(i,block) );
322 out <<
"y_expected[" << block <<
"][" << i <<
"] - "
323 <<
"y(" << i <<
"," << block <<
") = " << (*sg_y)[block][i]
324 <<
" - " << y(i,block) <<
" == "
325 << diff <<
" < " << tol <<
" : failed"
328 success = success && s;
335 template <
typename vec_type>
346 out <<
"y_expected[" << block <<
"][" << i <<
"] - "
347 <<
"y(" << b <<
"," << i <<
") = " << (*sg_y)[block][i]
348 <<
" - " << y(b,i) <<
" == "
349 << diff <<
" < " << tol <<
" : failed"
352 success = success && s;
359 template <
typename vec_type>
370 out <<
"y_expected[" << block <<
"][" << i <<
"] - "
371 <<
"y(" << b <<
"," << i <<
") = " << (*sg_y)[block][i] <<
" - "
373 << diff <<
" < " << tol <<
" : failed"
376 success = success && s;
383 template <
typename vec_type>
390 double diff =
std::abs( (*
sg_y)[block][i] - y(i*stoch_length+b) );
394 out <<
"y_expected[" << block <<
"][" << i <<
"] - "
395 <<
"y(" << b <<
"," << i <<
") == "
396 << diff <<
" < " << tol <<
" : failed"
399 success = success && s;
406 template <
typename vec_type>
413 double diff =
std::abs( (*
sg_y)[block][i] - y(b*fem_length+i) );
417 out <<
"y_expected[" << block <<
"][" << i <<
"] - "
418 <<
"y(" << b <<
"," << i <<
") == "
419 << diff <<
" < " << tol <<
" : failed"
422 success = success && s;
431 template <
typename value_type,
typename Device,
typename SparseMatOps>
435 typedef typename matrix_type::values_type matrix_values_type;
436 typedef typename matrix_type::graph_type matrix_graph_type;
437 typedef Kokkos::View<value_type*,Device>
vec_type;
447 matrix[block].graph = Kokkos::create_staticcrsgraph<matrix_graph_type>(
448 std::string(
"testing") , setup.
fem_graph );
450 matrix[block].values =
457 typename matrix_values_type::HostMirror hM =
460 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.
fem_length ; ++iRowFEM ) {
461 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
462 const int iColFEM = setup.
fem_graph[iRowFEM][iRowEntryFEM] ;
464 hM(iEntryFEM) = generate_matrix_coefficient<value_type>(
471 typename vec_type::HostMirror hx =
473 typename vec_type::HostMirror hy =
476 for (
int i = 0 ; i < setup.
fem_length ; ++i ) {
477 hx(i) = generate_vector_coefficient<value_type>(
489 setup.
Cijk->k_begin();
493 k_it!=k_end; ++k_it) {
494 int nj = setup.
Cijk->num_j(k_it);
498 setup.
Cijk->j_begin(k_it);
500 setup.
Cijk->j_end(k_it);
501 std::vector<vec_type> xx(nj), yy(nj);
514 j_it != j_end; ++j_it) {
516 setup.
Cijk->i_begin(j_it);
518 setup.
Cijk->i_end(j_it);
531 std::vector<typename vec_type::HostMirror> hy(setup.
stoch_length);
541 template <
typename value_type,
typename Device,
typename SparseMatOps>
545 typedef typename matrix_type::values_type matrix_values_type;
546 typedef typename matrix_type::graph_type matrix_graph_type;
547 typedef Kokkos::View<value_type*, Kokkos::LayoutLeft, Device, Kokkos::MemoryUnmanaged>
vec_type;
548 typedef Kokkos::View<value_type**, Kokkos::LayoutLeft, Device> multi_vec_type;
562 matrix[block].graph = Kokkos::create_staticcrsgraph<matrix_graph_type>(
563 std::string(
"testing") , setup.
fem_graph );
565 matrix[block].values =
568 typename matrix_values_type::HostMirror hM =
571 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.
fem_length ; ++iRowFEM ) {
572 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
573 const int iColFEM = setup.
fem_graph[iRowFEM][iRowEntryFEM] ;
575 hM(iEntryFEM) = generate_matrix_coefficient<value_type>(
582 for (
int i = 0 ; i < setup.
fem_length ; ++i ) {
583 hx(i, block) = generate_vector_coefficient<value_type>(
598 k_iterator k_begin = setup.
Cijk->k_begin();
599 k_iterator k_end = setup.
Cijk->k_end();
600 for (k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
601 unsigned nj = setup.
Cijk->num_j(k_it);
604 kj_iterator j_begin = setup.
Cijk->j_begin(k_it);
605 kj_iterator j_end = setup.
Cijk->j_end(k_it);
606 std::vector<int> j_indices(nj);
608 for (kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
610 vec_type xx = Kokkos::subview( x, Kokkos::ALL(), j );
611 vec_type tt = Kokkos::subview( tmp_x, Kokkos::ALL(), jdx++ );
614 multi_vec_type tmp_x_view =
615 Kokkos::subview( tmp_x, Kokkos::ALL(),
616 std::make_pair(0u,nj));
617 multi_vec_type tmp_y_view =
618 Kokkos::subview( tmp_y, Kokkos::ALL(),
619 std::make_pair(0u,nj));
622 for (kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
623 vec_type tmp_y_view =
624 Kokkos::subview( tmp_y, Kokkos::ALL(), jdx++ );
625 kji_iterator i_begin = setup.
Cijk->i_begin(j_it);
626 kji_iterator i_end = setup.
Cijk->i_end(j_it);
627 for (kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
630 vec_type y_view = Kokkos::subview( y, Kokkos::ALL(), i );
643 #ifdef HAVE_STOKHOS_KOKKOSLINALG
645 template <
typename value_type,
typename Device>
649 typedef KokkosSparse::CrsMatrix<value_type,ordinal_type,Device> matrix_type;
650 typedef typename matrix_type::values_type matrix_values_type;
651 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
652 typedef Kokkos::View<value_type*, Kokkos::LayoutLeft, Device, Kokkos::MemoryUnmanaged>
vec_type;
653 typedef Kokkos::View<value_type**, Kokkos::LayoutLeft, Device> multi_vec_type;
657 std::vector<matrix_type> matrix( setup.stoch_length ) ;
658 multi_vec_type x(
"x", setup.fem_length, setup.stoch_length ) ;
659 multi_vec_type y(
"y", setup.fem_length, setup.stoch_length ) ;
660 multi_vec_type tmp_x(
"tmp_x", setup.fem_length, setup.stoch_length ) ;
661 multi_vec_type tmp_y(
"tmp_y", setup.fem_length, setup.stoch_length ) ;
666 for (
int block=0; block<setup.stoch_length; ++block) {
667 matrix_graph_type matrix_graph =
668 Kokkos::create_staticcrsgraph<matrix_graph_type>(
669 std::string(
"test crs graph"), setup.fem_graph);
670 matrix_values_type matrix_values =
671 matrix_values_type(
"matrix" , setup.fem_graph_length );
672 typename matrix_values_type::HostMirror hM =
675 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.fem_length ; ++iRowFEM ) {
676 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
677 const int iColFEM = setup.fem_graph[iRowFEM][iRowEntryFEM] ;
679 hM(iEntryFEM) = generate_matrix_coefficient<value_type>(
680 setup.fem_length , setup.stoch_length , iRowFEM , iColFEM , block );
685 matrix[block] = matrix_type(
"matrix", setup.fem_length, matrix_values,
688 for (
int i = 0 ; i < setup.fem_length ; ++i ) {
689 hx(i, block) = generate_vector_coefficient<value_type>(
690 setup.fem_length , setup.stoch_length , i , block );
705 for (k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
710 kj_iterator j_end = setup.
Cijk->
j_end(k_it);
712 for (kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
714 vec_type xx = Kokkos::subview( x, Kokkos::ALL(), j );
715 vec_type tt = Kokkos::subview( tmp_x, Kokkos::ALL(), jdx++ );
718 multi_vec_type tmp_x_view =
719 Kokkos::subview( tmp_x, Kokkos::ALL(),
720 std::make_pair(0u,jdx));
721 multi_vec_type tmp_y_view =
722 Kokkos::subview( tmp_y, Kokkos::ALL(),
723 std::make_pair(0u,jdx));
726 for (kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
727 vec_type tmp_y_view =
728 Kokkos::subview( tmp_y, Kokkos::ALL(), jdx++ );
730 kji_iterator i_end = setup.
Cijk->
i_end(j_it);
731 for (kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
734 vec_type y_view = Kokkos::subview( y, Kokkos::ALL(), i );
743 bool success = setup.test_original(hy, out);
750 template<
typename ScalarType ,
class Device >
756 typedef Kokkos::View< value_type**, Kokkos::LayoutLeft , Device > block_vector_type ;
762 typedef typename matrix_type::graph_type graph_type ;
769 for (k_iterator k_it=setup.
Cijk->k_begin();
770 k_it!=setup.
Cijk->k_end(); ++k_it) {
772 for (kj_iterator j_it = setup.
Cijk->j_begin(k_it);
773 j_it != setup.
Cijk->j_end(k_it); ++j_it) {
775 for (kji_iterator i_it = setup.
Cijk->i_begin(j_it);
776 i_it != setup.
Cijk->i_end(j_it); ++i_it) {
778 double c = value(i_it);
779 dense_cijk(i,j,k) = c;
787 block_vector_type x =
789 block_vector_type y =
794 for (
int iColFEM = 0 ; iColFEM < setup.
fem_length ; ++iColFEM ) {
795 for (
int iColStoch = 0 ; iColStoch < setup.
stoch_length ; ++iColStoch ) {
796 hx(iColStoch,iColFEM) =
797 generate_vector_coefficient<ScalarType>(
811 matrix.graph = Kokkos::create_staticcrsgraph<graph_type>(
812 std::string(
"test crs graph") , setup.
fem_graph );
813 matrix.values = block_vector_type(
817 typename block_vector_type::HostMirror hM =
820 for (
int iRowStoch = 0 ; iRowStoch < setup.
stoch_length ; ++iRowStoch ) {
821 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.
fem_length ; ++iRowFEM ) {
823 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
824 const int iColFEM = setup.
fem_graph[iRowFEM][iRowEntryFEM];
826 for (
int iColStoch = 0 ; iColStoch < setup.
stoch_length ; ++iColStoch ) {
828 const size_t offset =
829 matrix.block.matrix_offset( iRowStoch , iColStoch );
831 ScalarType value = 0 ;
834 value += dense_cijk( iRowStoch , iColStoch , k ) *
835 generate_matrix_coefficient<ScalarType>(
839 hM( offset , iEntryFEM ) = value ;
861 template<
typename ScalarType ,
class Device >
867 typedef Kokkos::View< value_type* , Device > vector_type ;
872 typedef typename matrix_type::values_type matrix_values_type;
873 typedef typename matrix_type::graph_type matrix_graph_type;
876 std::vector< std::vector< int > > stoch_graph( setup.
stoch_length );
881 stoch_graph[i].resize(len);
891 for (k_iterator k_it=setup.
Cijk->k_begin();
892 k_it!=setup.
Cijk->k_end(); ++k_it) {
894 for (kj_iterator j_it = setup.
Cijk->j_begin(k_it);
895 j_it != setup.
Cijk->j_end(k_it); ++j_it) {
897 for (kji_iterator i_it = setup.
Cijk->i_begin(j_it);
898 i_it != setup.
Cijk->i_end(j_it); ++i_it) {
900 double c = value(i_it);
901 dense_cijk(i,j,k) = c;
911 std::vector< std::vector<int> > flat_graph( flat_length );
913 for (
int iOuterRow = 0 ; iOuterRow < setup.
fem_length ; ++iOuterRow ) {
915 const size_t iOuterRowNZ = setup.
fem_graph[iOuterRow].size();
917 for (
int iInnerRow = 0 ; iInnerRow < setup.
stoch_length ; ++iInnerRow ) {
919 const size_t iInnerRowNZ = stoch_graph[ iInnerRow ].size(); ;
920 const int iFlatRowNZ = iOuterRowNZ * iInnerRowNZ ;
921 const int iFlatRow = iInnerRow + iOuterRow * setup.
stoch_length ;
923 flat_graph[iFlatRow].resize( iFlatRowNZ );
927 for (
size_t iOuterEntry = 0 ; iOuterEntry < iOuterRowNZ ; ++iOuterEntry ) {
929 const int iOuterCol = setup.
fem_graph[iOuterRow][iOuterEntry];
931 for (
size_t iInnerEntry = 0 ; iInnerEntry < iInnerRowNZ ; ++iInnerEntry ) {
933 const int iInnerCol = stoch_graph[iInnerRow][iInnerEntry] ;
934 const int iFlatColumn = iInnerCol + iOuterCol * setup.
stoch_length ;
936 flat_graph[iFlatRow][iFlatEntry] = iFlatColumn ;
946 vector_type x = vector_type(
"x" , flat_length );
947 vector_type y = vector_type(
"y" , flat_length );
951 for (
int iColFEM = 0 ; iColFEM < setup.
fem_length ; ++iColFEM ) {
952 for (
int iColStoch = 0 ; iColStoch < setup.
stoch_length ; ++iColStoch ) {
954 generate_vector_coefficient<ScalarType>(
965 matrix.graph = Kokkos::create_staticcrsgraph<matrix_graph_type>(
966 std::string(
"testing") , flat_graph );
968 const size_t flat_graph_length = matrix.graph.entries.extent(0);
970 matrix.values = matrix_values_type(
"matrix" , flat_graph_length );
972 typename matrix_values_type::HostMirror hM =
975 for (
int iRow = 0 , iEntry = 0 ; iRow < flat_length ; ++iRow ) {
979 for (
size_t iRowEntry = 0 ; iRowEntry < flat_graph[ iRow ].size() ; ++iRowEntry , ++iEntry ) {
980 const int iCol = flat_graph[ iRow ][ iRowEntry ];
986 const double A_fem_k =
987 generate_matrix_coefficient<ScalarType>(
989 value += dense_cijk(iRowStoch,iColStoch,k) * A_fem_k ;
991 hM( iEntry ) = value ;
1010 template<
typename ScalarType ,
class Device >
1016 typedef Kokkos::View< value_type* , Device > vector_type ;
1021 typedef typename matrix_type::values_type matrix_values_type;
1022 typedef typename matrix_type::graph_type matrix_graph_type;
1025 std::vector< std::vector< int > > stoch_graph( setup.
stoch_length );
1030 stoch_graph[i].resize(len);
1040 for (k_iterator k_it=setup.
Cijk->k_begin();
1041 k_it!=setup.
Cijk->k_end(); ++k_it) {
1042 int k = index(k_it);
1043 for (kj_iterator j_it = setup.
Cijk->j_begin(k_it);
1044 j_it != setup.
Cijk->j_end(k_it); ++j_it) {
1045 int j = index(j_it);
1046 for (kji_iterator i_it = setup.
Cijk->i_begin(j_it);
1047 i_it != setup.
Cijk->i_end(j_it); ++i_it) {
1048 int i = index(i_it);
1049 double c = value(i_it);
1050 dense_cijk(i,j,k) = c;
1060 std::vector< std::vector<int> > flat_graph( flat_length );
1062 for (
int iOuterRow = 0 ; iOuterRow < setup.
stoch_length ; ++iOuterRow ) {
1064 const size_t iOuterRowNZ = stoch_graph[iOuterRow].size();
1066 for (
int iInnerRow = 0 ; iInnerRow < setup.
fem_length ; ++iInnerRow ) {
1068 const size_t iInnerRowNZ = setup.
fem_graph[iInnerRow].size();
1069 const int iFlatRowNZ = iOuterRowNZ * iInnerRowNZ ;
1070 const int iFlatRow = iInnerRow + iOuterRow * setup.
fem_length ;
1072 flat_graph[iFlatRow].resize( iFlatRowNZ );
1074 int iFlatEntry = 0 ;
1076 for (
size_t iOuterEntry = 0 ; iOuterEntry < iOuterRowNZ ; ++iOuterEntry ) {
1078 const int iOuterCol = stoch_graph[ iOuterRow ][ iOuterEntry ];
1080 for (
size_t iInnerEntry = 0 ; iInnerEntry < iInnerRowNZ ; ++iInnerEntry ) {
1082 const int iInnerCol = setup.
fem_graph[ iInnerRow][iInnerEntry];
1083 const int iFlatColumn = iInnerCol + iOuterCol * setup.
fem_length ;
1085 flat_graph[iFlatRow][iFlatEntry] = iFlatColumn ;
1094 vector_type x = vector_type(
"x" , flat_length );
1095 vector_type y = vector_type(
"y" , flat_length );
1099 for (
size_t iCol = 0 ; iCol < flat_length ; ++iCol ) {
1100 const int iColStoch = iCol / setup.
fem_length ;
1101 const int iColFEM = iCol % setup.
fem_length ;
1103 hx(iCol) = generate_vector_coefficient<ScalarType>(
1111 matrix_type matrix ;
1113 matrix.graph = Kokkos::create_staticcrsgraph<matrix_graph_type>( std::string(
"testing") , flat_graph );
1115 const size_t flat_graph_length = matrix.graph.entries.extent(0);
1117 matrix.values = matrix_values_type(
"matrix" , flat_graph_length );
1119 typename matrix_values_type::HostMirror hM =
1122 for (
size_t iRow = 0 , iEntry = 0 ; iRow < flat_length ; ++iRow ) {
1123 const int iRowStoch = iRow / setup.
fem_length ;
1124 const int iRowFEM = iRow % setup.
fem_length ;
1126 for (
size_t iRowEntry = 0 ; iRowEntry < flat_graph[ iRow ].size() ; ++iRowEntry , ++iEntry ) {
1127 const int iCol = flat_graph[ iRow ][ iRowEntry ];
1128 const int iColStoch = iCol / setup.
fem_length ;
1129 const int iColFEM = iCol % setup.
fem_length ;
1133 const double A_fem_k =
1134 generate_matrix_coefficient<ScalarType>(
1136 iRowFEM , iColFEM , k );
1137 value += dense_cijk(iRowStoch,iColStoch,k) * A_fem_k ;
1139 hM( iEntry ) = value ;
1157 template<
typename ScalarType ,
typename TensorType,
class Device >
1163 typedef Kokkos::View< value_type** , Kokkos::LayoutLeft ,
1164 Device > block_vector_type ;
1169 typedef typename matrix_type::graph_type graph_type ;
1174 block_vector_type x =
1176 block_vector_type y =
1179 typename block_vector_type::HostMirror hx =
1182 for (
int iColFEM = 0 ; iColFEM < setup.
fem_length ; ++iColFEM ) {
1183 for (
int iColStoch = 0 ; iColStoch < setup.
stoch_length ; ++iColStoch ) {
1184 hx(setup.
perm[iColStoch],iColFEM) =
1185 generate_vector_coefficient<ScalarType>(
1194 matrix_type matrix ;
1197 Stokhos::create_stochastic_product_tensor< TensorType >( *setup.
basis,
1201 matrix.graph = Kokkos::create_staticcrsgraph<graph_type>(
1202 std::string(
"test crs graph") , setup.
fem_graph );
1204 matrix.values = block_vector_type(
1207 typename block_vector_type::HostMirror hM =
1210 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.
fem_length ; ++iRowFEM ) {
1211 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
1212 const int iColFEM = setup.
fem_graph[iRowFEM][iRowEntryFEM] ;
1215 hM(setup.
perm[k],iEntryFEM) =
1216 generate_matrix_coefficient<ScalarType>(
1237 template<
typename ScalarType ,
class Device ,
int BlockSize >
1240 const bool symmetric) {
1242 typedef Kokkos::View< value_type** , Kokkos::LayoutLeft ,
1243 Device > block_vector_type ;
1248 typedef typename matrix_type::graph_type graph_type ;
1251 matrix_type matrix ;
1254 params.
set(
"Symmetric",symmetric);
1256 Stokhos::create_stochastic_product_tensor< TensorType >( *setup.
basis,
1259 int aligned_stoch_length = matrix.block.tensor().aligned_dimension();
1264 block_vector_type x =
1265 block_vector_type(
"x" , aligned_stoch_length , setup.
fem_length );
1266 block_vector_type y =
1267 block_vector_type(
"y" , aligned_stoch_length , setup.
fem_length );
1269 typename block_vector_type::HostMirror hx =
1272 for (
int iColFEM = 0 ; iColFEM < setup.
fem_length ; ++iColFEM ) {
1273 for (
int iColStoch = 0 ; iColStoch < setup.
stoch_length ; ++iColStoch ) {
1274 hx(iColStoch,iColFEM) =
1275 generate_vector_coefficient<ScalarType>(
1285 matrix.graph = Kokkos::create_staticcrsgraph<graph_type>(
1286 std::string(
"test crs graph") , setup.
fem_graph );
1288 matrix.values = block_vector_type(
1291 typename block_vector_type::HostMirror hM =
1294 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.
fem_length ; ++iRowFEM ) {
1295 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
1296 const int iColFEM = setup.
fem_graph[iRowFEM][iRowEntryFEM] ;
1300 generate_matrix_coefficient<ScalarType>(
1321 template<
typename ScalarType ,
class Device >
1326 typedef Kokkos::View< value_type** , Kokkos::LayoutLeft ,
1327 Device > block_vector_type ;
1332 typedef typename matrix_type::graph_type graph_type ;
1337 block_vector_type x =
1339 block_vector_type y =
1342 typename block_vector_type::HostMirror hx =
1345 for (
int iColFEM = 0 ; iColFEM < setup.
fem_length ; ++iColFEM ) {
1346 for (
int iColStoch = 0 ; iColStoch < setup.
stoch_length ; ++iColStoch ) {
1347 hx(iColStoch,iColFEM) =
1348 generate_vector_coefficient<ScalarType>(
1357 matrix_type matrix ;
1369 const bool symmetric =
true;
1374 Stokhos::create_stochastic_product_tensor< TensorType >( *setup.
basis,
1377 matrix.graph = Kokkos::create_staticcrsgraph<graph_type>(
1378 std::string(
"test crs graph") , setup.
fem_graph );
1380 matrix.values = block_vector_type(
1383 typename block_vector_type::HostMirror hM =
1386 for (
int iRowFEM = 0 , iEntryFEM = 0 ; iRowFEM < setup.
fem_length ; ++iRowFEM ) {
1387 for (
size_t iRowEntryFEM = 0 ; iRowEntryFEM < setup.
fem_graph[iRowFEM].size() ; ++iRowEntryFEM , ++iEntryFEM ) {
1388 const int iColFEM = setup.
fem_graph[iRowFEM][iRowEntryFEM] ;
1392 generate_matrix_coefficient<ScalarType>(
RCP< const Epetra_Comm > globalComm
IntType map_fem_graph_coord(const IntType &N, const IntType &i, const IntType &j, const IntType &k)
Stokhos::Sparse3Tensor< int, value_type > Cijk_type
An Epetra operator representing the block stochastic Galerkin operator.
Bases defined by combinatorial product of polynomial bases.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
k_iterator k_begin() const
Iterator pointing to first k entry.
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
int NumGlobalIndices(long long Row) const
bool test_lexo_block_tensor(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
ordinal_type num_j(const k_iterator &k) const
Number of j entries in C(i,j,k) for given k.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
int MyGlobalElements(int *MyGlobalElementList) const
void init(const value_type &val)
Initialize coefficients.
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
bool test_crs_product_tensor(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out, const Teuchos::ParameterList ¶ms=Teuchos::ParameterList())
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
RCP< Stokhos::EpetraVectorOrthogPoly > sg_y
bool test_crs_flat_commuted(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
bool test_original_flat(const vec_type &y, Teuchos::FancyOStream &out) const
bool test_commuted(const vec_type &y, Teuchos::FancyOStream &out) const
Stokhos::OneDOrthogPolyBasis< int, value_type > abstract_basis_type
Symmetric diagonal storage for a dense matrix.
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
Teuchos::Array< ordinal_type > index
index terms
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Stokhos::TotalOrderBasis< int, value_type, less_type > product_basis_type
Teuchos::RCP< LTBSparse3Tensor< ordinal_type, value_type > > computeTripleProductTensorLTBBlockLeaf(const TotalOrderBasis< ordinal_type, value_type, LexographicLess< MultiIndex< ordinal_type > > > &product_basis, bool symmetric=false)
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
Teuchos::RCP< const Epetra_Comm > getStochasticComm() const
Get stochastic comm.
int FillComplete(bool OptimizeDataStorage=true)
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > getEpetraCijk() const
Get Epetra Cijk.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Bi-directional iterator for traversing a sparse array.
bool test_linear_tensor(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out, const bool symmetric)
void multiply(const CrsMatrix< MatrixValue, Device, Layout > &A, const InputMultiVectorType &x, OutputMultiVectorType &y, const std::vector< OrdinalType > &col_indices, SingleColumnMultivectorMultiply)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
void setup(int p_=5, int d_=2)
int NumMyElements() const
A multidimensional index.
RCP< Stokhos::EpetraVectorOrthogPoly > sg_x
RCP< Stokhos::ProductEpetraVector > sg_y_commuted
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_BlockMap > getStochasticRowMap() const
Get stochastic row map.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
UnitTestSetup< int, double > setup
A container class for products of Epetra_Vector's.
bool test_crs_flat_original(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
virtual int Apply(const Epetra_MultiVector &Input, Epetra_MultiVector &Result) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector Input in Result as described ...
void resize(size_type new_size, const value_type &x=value_type())
bool test_original(const std::vector< vec_type > &y, Teuchos::FancyOStream &out) const
Stokhos::LexographicLess< Stokhos::MultiIndex< int > > less_type
k_iterator k_end() const
Iterator pointing to last k entry.
Legendre polynomial basis.
RCP< product_basis_type > basis
std::vector< std::vector< int > > fem_graph
scalar generate_matrix_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iRowFEM, const ordinal iColFEM, const ordinal iStoch)
bool test_original(const multi_vec_type &y, Teuchos::FancyOStream &out) const
Abstract base class for 1-D orthogonal polynomials.
Teuchos::Array< int > inv_perm
Teuchos::RCP< Epetra_CrsGraph > sparse3Tensor2CrsGraph(const Stokhos::OrthogPolyBasis< ordinal_type, value_type > &basis, const Stokhos::Sparse3Tensor< ordinal_type, value_type > &Cijk, const Epetra_Comm &comm)
Build an Epetra_CrsGraph from a sparse 3 tensor.
ordinal generate_fem_graph(ordinal N, std::vector< std::vector< ordinal > > &graph)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< YD, YP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< ZD, ZP...> >::value >::type update(const typename Kokkos::View< XD, XP...>::array_type::non_const_value_type &alpha, const Kokkos::View< XD, XP...> &x, const typename Kokkos::View< YD, YP...>::array_type::non_const_value_type &beta, const Kokkos::View< YD, YP...> &y, const typename Kokkos::View< ZD, ZP...>::array_type::non_const_value_type &gamma, const Kokkos::View< ZD, ZP...> &z)
CRS matrix of dense blocks.
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< InputType, InputP... > >::value &&Kokkos::is_view_uq_pce< Kokkos::View< OutputType, OutputP... > >::value >::type spmv(KokkosKernels::Experimental::Controls, const char mode[], const AlphaType &a, const MatrixType &A, const Kokkos::View< InputType, InputP... > &x, const BetaType &b, const Kokkos::View< OutputType, OutputP... > &y, const RANK_ONE)
A comparison functor implementing a strict weak ordering based lexographic ordering.
Teuchos::RCP< const Epetra_Comm > getSpatialComm() const
Get spatial comm.
Stokhos::LegendreBasis< int, value_type > basis_type
Sacado::MP::Vector< storage_type > vec_type
Teuchos::Array< int > perm
int ExtractGlobalRowCopy(int_type Row, int LenOfIndices, int &NumIndices, int_type *Indices) const
virtual void setupOperator(const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &poly)
Setup operator.
bool test_commuted_perm(const vec_type &y, Teuchos::FancyOStream &out) const
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
virtual int ReplaceGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)
bool test_commuted_flat(const vec_type &y, Teuchos::FancyOStream &out) const
bool test_crs_matrix_free(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
RCP< Stokhos::Sparse3Tensor< int, double > > Cijk
bool test_crs_matrix_free_view(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)
bool test_crs_dense_block(const UnitTestSetup< Device > &setup, Teuchos::FancyOStream &out)