44 #include "Stokhos_Ensemble_Sizes.hpp"
52 #include "Tpetra_Core.hpp"
53 #include "Tpetra_Map.hpp"
54 #include "Tpetra_MultiVector.hpp"
55 #include "Tpetra_Vector.hpp"
56 #include "Tpetra_CrsGraph.hpp"
57 #include "Tpetra_CrsMatrix.hpp"
61 #ifdef HAVE_STOKHOS_BELOS
63 #include "BelosLinearProblem.hpp"
64 #include "BelosPseudoBlockGmresSolMgr.hpp"
65 #include "BelosPseudoBlockCGSolMgr.hpp"
69 #ifdef HAVE_STOKHOS_IFPACK2
71 #include "Ifpack2_Factory.hpp"
75 #ifdef HAVE_STOKHOS_MUELU
77 #include "MueLu_CreateTpetraPreconditioner.hpp"
81 #ifdef HAVE_STOKHOS_AMESOS2
83 #include "Amesos2_Factory.hpp"
86 template <
typename scalar,
typename ordinal>
90 const ordinal iColFEM,
91 const ordinal iStoch )
93 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
94 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
95 return X_fem + X_stoch;
99 template <
typename scalar,
typename ordinal>
103 const ordinal nStoch,
104 const ordinal iColFEM,
106 const ordinal iStoch)
108 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
109 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
110 const scalar X_col = 0.01 + scalar(iVec) / scalar(nVec);
111 return X_fem + X_stoch + X_col;
137 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
138 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
141 if ( !Kokkos::is_initialized() )
142 Kokkos::initialize();
145 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
149 RCP<const Tpetra_Map> map =
150 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
152 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
153 const size_t num_my_row = myGIDs.size();
156 RCP<Tpetra_Vector> x1 = Tpetra::createVector<Scalar>(map);
157 RCP<Tpetra_Vector> x2 = Tpetra::createVector<Scalar>(map);
158 ArrayRCP<Scalar> x1_view = x1->get1dViewNonConst();
159 ArrayRCP<Scalar> x2_view = x2->get1dViewNonConst();
161 for (
size_t i=0; i<num_my_row; ++i) {
164 val1.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(nrow,
VectorSize, row,
j);
165 val2.fastAccessCoeff(
j) = 0.12345 * generate_vector_coefficient<BaseScalar,size_t>(nrow,
VectorSize, row,
j);
176 RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
177 y->update(alpha, *x1, beta, *x2,
Scalar(0.0));
183 ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
185 BaseScalar tol = 1.0e-14;
186 for (
size_t i=0; i<num_my_row; ++i) {
189 BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
191 val.fastAccessCoeff(
j) = alpha.coeff(
j)*v + 0.12345*beta.coeff(
j)*v;
215 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
216 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
217 typedef typename Tpetra_Vector::dot_type dot_type;
220 if ( !Kokkos::is_initialized() )
221 Kokkos::initialize();
224 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
228 RCP<const Tpetra_Map> map =
229 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
231 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
232 const size_t num_my_row = myGIDs.size();
235 RCP<Tpetra_Vector> x1 = Tpetra::createVector<Scalar>(map);
236 RCP<Tpetra_Vector> x2 = Tpetra::createVector<Scalar>(map);
237 ArrayRCP<Scalar> x1_view = x1->get1dViewNonConst();
238 ArrayRCP<Scalar> x2_view = x2->get1dViewNonConst();
240 for (
size_t i=0; i<num_my_row; ++i) {
243 val1.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(nrow,
VectorSize, row,
j);
244 val2.fastAccessCoeff(
j) = 0.12345 * generate_vector_coefficient<BaseScalar,size_t>(nrow,
VectorSize, row,
j);
253 dot_type
dot = x1->dot(*x2);
257 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
260 dot_type local_val(0);
261 for (
size_t i=0; i<num_my_row; ++i) {
264 BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
266 local_val += 0.12345 * v * v;
273 Teuchos::outArg(val));
279 for (
size_t i=0; i<num_my_row; ++i) {
282 BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
284 local_val.fastAccessCoeff(
j) += 0.12345 * v * v;
291 Teuchos::outArg(val));
295 out <<
"dot = " << dot <<
" expected = " << val << std::endl;
297 BaseScalar tol = 1.0e-14;
317 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
318 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
321 if ( !Kokkos::is_initialized() )
322 Kokkos::initialize();
325 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
329 RCP<const Tpetra_Map> map =
330 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
332 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
333 const size_t num_my_row = myGIDs.size();
337 RCP<Tpetra_MultiVector> x1 = Tpetra::createMultiVector<Scalar>(map, ncol);
338 RCP<Tpetra_MultiVector> x2 = Tpetra::createMultiVector<Scalar>(map, ncol);
339 ArrayRCP< ArrayRCP<Scalar> > x1_view = x1->get2dViewNonConst();
340 ArrayRCP< ArrayRCP<Scalar> > x2_view = x2->get2dViewNonConst();
342 for (
size_t i=0; i<num_my_row; ++i) {
344 for (
size_t j=0;
j<ncol; ++
j) {
347 generate_multi_vector_coefficient<BaseScalar,size_t>(
349 val1.fastAccessCoeff(k) = v;
350 val2.fastAccessCoeff(k) = 0.12345 * v;
352 x1_view[
j][i] = val1;
353 x2_view[
j][i] = val2;
362 RCP<Tpetra_MultiVector> y = Tpetra::createMultiVector<Scalar>(map, ncol);
363 y->update(alpha, *x1, beta, *x2,
Scalar(0.0));
369 ArrayRCP< ArrayRCP<Scalar> > y_view = y->get2dViewNonConst();
371 BaseScalar tol = 1.0e-14;
372 for (
size_t i=0; i<num_my_row; ++i) {
374 for (
size_t j=0;
j<ncol; ++
j) {
376 BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
378 val.fastAccessCoeff(k) = alpha.coeff(k)*v + 0.12345*beta.coeff(k)*v;
383 val.fastAccessCoeff(k), tol );
404 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
405 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
406 typedef typename Tpetra_MultiVector::dot_type dot_type;
409 if ( !Kokkos::is_initialized() )
410 Kokkos::initialize();
413 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
417 RCP<const Tpetra_Map> map =
418 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
420 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
421 const size_t num_my_row = myGIDs.size();
425 RCP<Tpetra_MultiVector> x1 = Tpetra::createMultiVector<Scalar>(map, ncol);
426 RCP<Tpetra_MultiVector> x2 = Tpetra::createMultiVector<Scalar>(map, ncol);
427 ArrayRCP< ArrayRCP<Scalar> > x1_view = x1->get2dViewNonConst();
428 ArrayRCP< ArrayRCP<Scalar> > x2_view = x2->get2dViewNonConst();
430 for (
size_t i=0; i<num_my_row; ++i) {
432 for (
size_t j=0;
j<ncol; ++
j) {
435 generate_multi_vector_coefficient<BaseScalar,size_t>(
437 val1.fastAccessCoeff(k) = v;
438 val2.fastAccessCoeff(k) = 0.12345 * v;
440 x1_view[
j][i] = val1;
441 x2_view[
j][i] = val2;
448 Array<dot_type> dots(ncol);
449 x1->dot(*x2, dots());
453 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
456 Array<dot_type> local_vals(ncol, dot_type(0));
457 for (
size_t i=0; i<num_my_row; ++i) {
459 for (
size_t j=0;
j<ncol; ++
j) {
461 BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
463 local_vals[
j] += 0.12345 * v * v;
469 Array<dot_type> vals(ncol, dot_type(0));
471 local_vals.getRawPtr(), vals.getRawPtr());
476 Array<dot_type> local_vals(ncol, dot_type(
VectorSize, 0.0));
477 for (
size_t i=0; i<num_my_row; ++i) {
479 for (
size_t j=0;
j<ncol; ++
j) {
481 BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
483 local_vals[
j].fastAccessCoeff(k) += 0.12345 * v * v;
489 Array<dot_type> vals(ncol, dot_type(
VectorSize, 0.0));
491 local_vals.getRawPtr(), vals.getRawPtr());
495 BaseScalar tol = 1.0e-14;
496 for (
size_t j=0;
j<ncol; ++
j) {
497 out <<
"dots(" <<
j <<
") = " << dots[
j]
498 <<
" expected(" <<
j <<
") = " << vals[
j] << std::endl;
519 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
520 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
521 typedef typename Tpetra_MultiVector::dot_type dot_type;
524 if ( !Kokkos::is_initialized() )
525 Kokkos::initialize();
528 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
532 RCP<const Tpetra_Map> map =
533 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
535 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
536 const size_t num_my_row = myGIDs.size();
540 RCP<Tpetra_MultiVector> x1 = Tpetra::createMultiVector<Scalar>(map, ncol);
541 RCP<Tpetra_MultiVector> x2 = Tpetra::createMultiVector<Scalar>(map, ncol);
542 ArrayRCP< ArrayRCP<Scalar> > x1_view = x1->get2dViewNonConst();
543 ArrayRCP< ArrayRCP<Scalar> > x2_view = x2->get2dViewNonConst();
545 for (
size_t i=0; i<num_my_row; ++i) {
547 for (
size_t j=0;
j<ncol; ++
j) {
550 generate_multi_vector_coefficient<BaseScalar,size_t>(
552 val1.fastAccessCoeff(k) = v;
553 val2.fastAccessCoeff(k) = 0.12345 * v;
555 x1_view[
j][i] = val1;
556 x2_view[
j][i] = val2;
565 cols[0] = 4; cols[1] = 2;
566 RCP<const Tpetra_MultiVector> x1_sub = x1->subView(cols());
567 RCP<const Tpetra_MultiVector> x2_sub = x2->subView(cols());
570 Array<dot_type> dots(ncol_sub);
571 x1_sub->dot(*x2_sub, dots());
575 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
578 Array<dot_type> local_vals(ncol_sub, dot_type(0));
579 for (
size_t i=0; i<num_my_row; ++i) {
581 for (
size_t j=0;
j<ncol_sub; ++
j) {
583 BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
585 local_vals[
j] += 0.12345 * v * v;
591 Array<dot_type> vals(ncol_sub, dot_type(0));
593 Teuchos::as<int>(ncol_sub), local_vals.getRawPtr(),
599 Array<dot_type> local_vals(ncol_sub, dot_type(
VectorSize, 0.0));
600 for (
size_t i=0; i<num_my_row; ++i) {
602 for (
size_t j=0;
j<ncol_sub; ++
j) {
604 BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
606 local_vals[
j].fastAccessCoeff(k) += 0.12345 * v * v;
612 Array<dot_type> vals(ncol_sub, dot_type(
VectorSize, 0.0));
614 Teuchos::as<int>(ncol_sub), local_vals.getRawPtr(),
619 BaseScalar tol = 1.0e-14;
620 for (
size_t j=0;
j<ncol_sub; ++
j) {
621 out <<
"dots(" <<
j <<
") = " << dots[
j]
622 <<
" expected(" <<
j <<
") = " << vals[
j] << std::endl;
643 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
644 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
645 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
646 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
649 if ( !Kokkos::is_initialized() )
650 Kokkos::initialize();
654 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
655 RCP<const Tpetra_Map> map =
656 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
658 RCP<Tpetra_CrsGraph> graph =
659 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
660 Array<GlobalOrdinal> columnIndices(2);
661 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
662 const size_t num_my_row = myGIDs.size();
663 for (
size_t i=0; i<num_my_row; ++i) {
665 columnIndices[0] = row;
668 columnIndices[1] = row+1;
671 graph->insertGlobalIndices(row, columnIndices(0,ncol));
673 graph->fillComplete();
674 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
677 Array<Scalar> vals(2);
679 for (
size_t i=0; i<num_my_row; ++i) {
681 columnIndices[0] = row;
683 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
689 columnIndices[1] = row+1;
691 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
696 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
698 matrix->fillComplete();
701 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
702 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
703 for (
size_t i=0; i<num_my_row; ++i) {
706 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
719 RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
720 matrix->apply(*x, *y);
726 ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
727 BaseScalar tol = 1.0e-14;
728 for (
size_t i=0; i<num_my_row; ++i) {
731 BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
733 val.fastAccessCoeff(
j) = v*v;
737 BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
739 val.fastAccessCoeff(
j) += v*v;
764 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
765 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
766 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
767 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
770 if ( !Kokkos::is_initialized() )
771 Kokkos::initialize();
775 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
776 RCP<const Tpetra_Map> map =
777 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
779 RCP<Tpetra_CrsGraph> graph =
780 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
781 Array<GlobalOrdinal> columnIndices(2);
782 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
783 const size_t num_my_row = myGIDs.size();
784 for (
size_t i=0; i<num_my_row; ++i) {
786 columnIndices[0] = row;
789 columnIndices[1] = row+1;
792 graph->insertGlobalIndices(row, columnIndices(0,ncol));
794 graph->fillComplete();
795 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
798 Array<Scalar> vals(2);
800 for (
size_t i=0; i<num_my_row; ++i) {
802 columnIndices[0] = row;
804 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
810 columnIndices[1] = row+1;
812 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
817 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
819 matrix->fillComplete();
823 RCP<Tpetra_MultiVector> x = Tpetra::createMultiVector<Scalar>(map, ncol);
824 ArrayRCP< ArrayRCP<Scalar> > x_view = x->get2dViewNonConst();
825 for (
size_t i=0; i<num_my_row; ++i) {
827 for (
size_t j=0;
j<ncol; ++
j) {
830 generate_multi_vector_coefficient<BaseScalar,size_t>(
832 val.fastAccessCoeff(k) = v;
846 RCP<Tpetra_MultiVector> y = Tpetra::createMultiVector<Scalar>(map, ncol);
847 matrix->apply(*x, *y);
853 ArrayRCP< ArrayRCP<Scalar> > y_view = y->get2dViewNonConst();
854 BaseScalar tol = 1.0e-14;
855 for (
size_t i=0; i<num_my_row; ++i) {
857 for (
size_t j=0;
j<ncol; ++
j) {
859 BaseScalar v1 = generate_vector_coefficient<BaseScalar,size_t>(
861 BaseScalar v2 = generate_multi_vector_coefficient<BaseScalar,size_t>(
863 val.fastAccessCoeff(k) = v1*v2;
867 BaseScalar v1 = generate_vector_coefficient<BaseScalar,size_t>(
869 BaseScalar v2 = generate_multi_vector_coefficient<BaseScalar,size_t>(
871 val.fastAccessCoeff(k) += v1*v2;
877 val.fastAccessCoeff(k), tol );
898 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
899 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
900 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
901 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
903 typedef Tpetra::Vector<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> Flat_Tpetra_Vector;
904 typedef Tpetra::CrsMatrix<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> Flat_Tpetra_CrsMatrix;
907 if ( !Kokkos::is_initialized() )
908 Kokkos::initialize();
912 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
913 RCP<const Tpetra_Map> map =
914 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
916 RCP<Tpetra_CrsGraph> graph =
917 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
918 Array<GlobalOrdinal> columnIndices(2);
919 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
920 const size_t num_my_row = myGIDs.size();
921 for (
size_t i=0; i<num_my_row; ++i) {
923 columnIndices[0] = row;
926 columnIndices[1] = row+1;
929 graph->insertGlobalIndices(row, columnIndices(0,ncol));
931 graph->fillComplete();
932 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
935 Array<Scalar> vals(2);
937 for (
size_t i=0; i<num_my_row; ++i) {
939 columnIndices[0] = row;
941 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
947 columnIndices[1] = row+1;
949 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
954 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
956 matrix->fillComplete();
959 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
960 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
961 for (
size_t i=0; i<num_my_row; ++i) {
964 val.fastAccessCoeff(
j) = generate_vector_coefficient<BaseScalar,size_t>(
970 RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
971 matrix->apply(*x, *y);
974 RCP<const Tpetra_Map> flat_x_map, flat_y_map;
975 RCP<const Tpetra_CrsGraph> flat_graph =
977 RCP<Flat_Tpetra_CrsMatrix> flat_matrix =
981 RCP<Tpetra_Vector> y2 = Tpetra::createVector<Scalar>(map);
982 RCP<Flat_Tpetra_Vector> flat_x =
984 RCP<Flat_Tpetra_Vector> flat_y =
986 flat_matrix->apply(*flat_x, *flat_y);
992 BaseScalar tol = 1.0e-14;
993 ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
994 ArrayRCP<Scalar> y2_view = y2->get1dViewNonConst();
995 for (
size_t i=0; i<num_my_row; ++i) {
1021 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1022 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1023 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1024 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1027 if ( !Kokkos::is_initialized() )
1028 Kokkos::initialize();
1032 BaseScalar h = 1.0 /
static_cast<BaseScalar
>(nrow-1);
1033 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1034 RCP<const Tpetra_Map> map =
1035 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1037 RCP<Tpetra_CrsGraph> graph =
1038 rcp(
new Tpetra_CrsGraph(map,
size_t(3), Tpetra::StaticProfile));
1039 Array<GlobalOrdinal> columnIndices(3);
1040 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1041 const size_t num_my_row = myGIDs.size();
1042 for (
size_t i=0; i<num_my_row; ++i) {
1044 if (row == 0 || row == nrow-1) {
1045 columnIndices[0] = row;
1046 graph->insertGlobalIndices(row, columnIndices(0,1));
1049 columnIndices[0] = row-1;
1050 columnIndices[1] = row;
1051 columnIndices[2] = row+1;
1052 graph->insertGlobalIndices(row, columnIndices(0,3));
1055 graph->fillComplete();
1056 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
1059 Array<Scalar> vals(3);
1062 a_val.fastAccessCoeff(
j) =
1063 BaseScalar(1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1065 for (
size_t i=0; i<num_my_row; ++i) {
1067 if (row == 0 || row == nrow-1) {
1068 columnIndices[0] = row;
1070 matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1073 columnIndices[0] = row-1;
1074 columnIndices[1] = row;
1075 columnIndices[2] = row+1;
1076 vals[0] =
Scalar(-1.0) * a_val;
1077 vals[1] =
Scalar(2.0) * a_val;
1078 vals[2] =
Scalar(-1.0) * a_val;
1079 matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
1082 matrix->fillComplete();
1084 matrix->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
1088 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1089 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1090 Scalar b_val(VectorSize, BaseScalar(0.0));
1092 b_val.fastAccessCoeff(
j) =
1093 BaseScalar(-1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1095 for (
size_t i=0; i<num_my_row; ++i) {
1097 if (row == 0 || row == nrow-1)
1100 b_view[i] = -
Scalar(b_val * h * h);
1104 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1105 typedef Kokkos::Details::ArithTraits<BaseScalar> BST;
1106 typedef typename BST::mag_type base_mag_type;
1107 typedef typename Tpetra_Vector::mag_type mag_type;
1108 base_mag_type btol = 1e-9;
1109 mag_type tol = btol;
1112 out.getOStream().get());
1120 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1121 Scalar
val(VectorSize, BaseScalar(0.0));
1122 for (
size_t i=0; i<num_my_row; ++i) {
1124 BaseScalar xx = row * h;
1126 val.fastAccessCoeff(
j) =
1127 BaseScalar(0.5) * (b_val.coeff(
j)/a_val.coeff(
j)) * xx * (xx - BaseScalar(1.0));
1132 Scalar v = x_view[i];
1135 v.fastAccessCoeff(
j) = BaseScalar(0.0);
1137 val.fastAccessCoeff(
j) = BaseScalar(0.0);
1146 #if defined(HAVE_STOKHOS_MUELU) && defined(HAVE_STOKHOS_AMESOS2) && defined(HAVE_STOKHOS_IFPACK2)
1160 using Teuchos::getParametersFromXmlFile;
1166 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1167 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1168 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1169 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1172 if ( !Kokkos::is_initialized() )
1173 Kokkos::initialize();
1177 BaseScalar h = 1.0 /
static_cast<BaseScalar
>(nrow-1);
1178 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1179 RCP<const Tpetra_Map> map =
1180 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1182 RCP<Tpetra_CrsGraph> graph =
1183 rcp(
new Tpetra_CrsGraph(map,
size_t(3), Tpetra::StaticProfile));
1184 Array<GlobalOrdinal> columnIndices(3);
1185 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1186 const size_t num_my_row = myGIDs.size();
1187 for (
size_t i=0; i<num_my_row; ++i) {
1189 if (row == 0 || row == nrow-1) {
1190 columnIndices[0] = row;
1191 graph->insertGlobalIndices(row, columnIndices(0,1));
1194 columnIndices[0] = row-1;
1195 columnIndices[1] = row;
1196 columnIndices[2] = row+1;
1197 graph->insertGlobalIndices(row, columnIndices(0,3));
1200 graph->fillComplete();
1201 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
1204 Array<Scalar> vals(3);
1207 a_val.fastAccessCoeff(
j) =
1208 BaseScalar(1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1210 for (
size_t i=0; i<num_my_row; ++i) {
1212 if (row == 0 || row == nrow-1) {
1213 columnIndices[0] = row;
1215 matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1218 columnIndices[0] = row-1;
1219 columnIndices[1] = row;
1220 columnIndices[2] = row+1;
1221 vals[0] =
Scalar(-1.0) * a_val;
1222 vals[1] =
Scalar(2.0) * a_val;
1223 vals[2] =
Scalar(-1.0) * a_val;
1224 matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
1227 matrix->fillComplete();
1230 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1231 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1232 Scalar b_val(VectorSize, BaseScalar(0.0));
1234 b_val.fastAccessCoeff(
j) =
1235 BaseScalar(-1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1237 for (
size_t i=0; i<num_my_row; ++i) {
1239 if (row == 0 || row == nrow-1)
1242 b_view[i] = -
Scalar(b_val * h * h);
1246 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1247 RCP<OP> matrix_op = matrix;
1248 RCP<ParameterList> muelu_params =
1249 getParametersFromXmlFile(
"muelu_cheby.xml");
1251 MueLu::CreateTpetraPreconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrix_op, *muelu_params);
1254 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1255 typedef Kokkos::Details::ArithTraits<BaseScalar> BST;
1256 typedef typename BST::mag_type base_mag_type;
1257 typedef typename Tpetra_Vector::mag_type mag_type;
1258 base_mag_type btol = 1e-9;
1259 mag_type tol = btol;
1262 out.getOStream().get());
1270 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1271 Scalar
val(VectorSize, BaseScalar(0.0));
1272 for (
size_t i=0; i<num_my_row; ++i) {
1274 BaseScalar xx = row * h;
1276 val.fastAccessCoeff(
j) =
1277 BaseScalar(0.5) * (b_val.coeff(
j)/a_val.coeff(
j)) * xx * (xx - BaseScalar(1.0));
1282 Scalar v = x_view[i];
1284 if (BST::magnitude(v.coeff(
j)) < btol)
1285 v.fastAccessCoeff(
j) = BaseScalar(0.0);
1286 if (BST::magnitude(
val.coeff(
j)) < btol)
1287 val.fastAccessCoeff(
j) = BaseScalar(0.0);
1303 #if defined(HAVE_STOKHOS_BELOS)
1322 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1323 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1324 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1325 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1328 if ( !Kokkos::is_initialized() )
1329 Kokkos::initialize();
1333 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1334 RCP<const Tpetra_Map> map =
1335 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1337 RCP<Tpetra_CrsGraph> graph =
1338 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
1339 Array<GlobalOrdinal> columnIndices(2);
1340 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1341 const size_t num_my_row = myGIDs.size();
1342 for (
size_t i=0; i<num_my_row; ++i) {
1344 columnIndices[0] = row;
1346 if (row != nrow-1) {
1347 columnIndices[1] = row+1;
1350 graph->insertGlobalIndices(row, columnIndices(0,ncol));
1352 graph->fillComplete();
1353 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
1356 Array<Scalar> vals(2);
1357 Scalar
val(VectorSize, BaseScalar(0.0));
1358 for (
size_t i=0; i<num_my_row; ++i) {
1360 columnIndices[0] = row;
1362 val.fastAccessCoeff(
j) =
j+1;
1366 if (row != nrow-1) {
1367 columnIndices[1] = row+1;
1369 val.fastAccessCoeff(
j) =
j+1;
1373 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
1375 matrix->fillComplete();
1378 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1379 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1380 for (
size_t i=0; i<num_my_row; ++i) {
1386 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1387 typedef BaseScalar BelosScalar;
1389 typedef Scalar BelosScalar;
1391 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1392 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1393 typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1394 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1395 RCP< BLinProb > problem =
rcp(
new BLinProb(matrix, x, b));
1396 RCP<ParameterList> belosParams =
rcp(
new ParameterList);
1397 typename ST::magnitudeType tol = 1e-9;
1398 belosParams->set(
"Flexible Gmres",
false);
1399 belosParams->set(
"Num Blocks", 100);
1400 belosParams->set(
"Convergence Tolerance", BelosScalar(tol));
1401 belosParams->set(
"Maximum Iterations", 100);
1402 belosParams->set(
"Verbosity", 33);
1403 belosParams->set(
"Output Style", 1);
1404 belosParams->set(
"Output Frequency", 1);
1405 belosParams->set(
"Output Stream", out.getOStream());
1406 RCP<Belos::SolverManager<BelosScalar,MV,OP> > solver =
1407 rcp(
new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
1408 problem->setProblem();
1409 Belos::ReturnType ret = solver->solve();
1422 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1423 for (
size_t i=0; i<num_my_row; ++i) {
1427 val.fastAccessCoeff(
j) = BaseScalar(1.0) / BaseScalar(
j+1);
1431 val =
Scalar(VectorSize, BaseScalar(0.0));
1435 Scalar v = x_view[i];
1437 if (ST::magnitude(v.coeff(
j)) < tol)
1438 v.fastAccessCoeff(
j) = BaseScalar(0.0);
1454 #if defined(HAVE_STOKHOS_BELOS) && defined(HAVE_STOKHOS_IFPACK2)
1474 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1475 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1476 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1477 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1480 if ( !Kokkos::is_initialized() )
1481 Kokkos::initialize();
1485 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1486 RCP<const Tpetra_Map> map =
1487 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1489 RCP<Tpetra_CrsGraph> graph =
1490 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
1491 Array<GlobalOrdinal> columnIndices(2);
1492 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1493 const size_t num_my_row = myGIDs.size();
1494 for (
size_t i=0; i<num_my_row; ++i) {
1496 columnIndices[0] = row;
1498 if (row != nrow-1) {
1499 columnIndices[1] = row+1;
1502 graph->insertGlobalIndices(row, columnIndices(0,ncol));
1504 graph->fillComplete();
1505 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
1508 Array<Scalar> vals(2);
1509 Scalar
val(VectorSize, BaseScalar(0.0));
1510 for (
size_t i=0; i<num_my_row; ++i) {
1512 columnIndices[0] = row;
1514 val.fastAccessCoeff(
j) =
j+1;
1518 if (row != nrow-1) {
1519 columnIndices[1] = row+1;
1521 val.fastAccessCoeff(
j) =
j+1;
1525 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
1527 matrix->fillComplete();
1530 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1531 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1532 for (
size_t i=0; i<num_my_row; ++i) {
1537 typedef Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> Prec;
1538 Ifpack2::Factory factory;
1539 RCP<Prec> M = factory.create<Tpetra_CrsMatrix>(
"RILUK", matrix);
1545 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1546 typedef BaseScalar BelosScalar;
1548 typedef Scalar BelosScalar;
1550 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1551 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1552 typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1553 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1554 RCP< BLinProb > problem =
rcp(
new BLinProb(matrix, x, b));
1555 problem->setRightPrec(M);
1556 problem->setProblem();
1557 RCP<ParameterList> belosParams =
rcp(
new ParameterList);
1558 typename ST::magnitudeType tol = 1e-9;
1559 belosParams->set(
"Flexible Gmres",
false);
1560 belosParams->set(
"Num Blocks", 100);
1561 belosParams->set(
"Convergence Tolerance", BelosScalar(tol));
1562 belosParams->set(
"Maximum Iterations", 100);
1563 belosParams->set(
"Verbosity", 33);
1564 belosParams->set(
"Output Style", 1);
1565 belosParams->set(
"Output Frequency", 1);
1566 belosParams->set(
"Output Stream", out.getOStream());
1568 RCP<Belos::SolverManager<BelosScalar,MV,OP> > solver =
1569 rcp(
new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
1570 Belos::ReturnType ret = solver->solve();
1583 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1584 for (
size_t i=0; i<num_my_row; ++i) {
1588 val.fastAccessCoeff(
j) = BaseScalar(1.0) / BaseScalar(
j+1);
1592 val =
Scalar(VectorSize, BaseScalar(0.0));
1596 Scalar v = x_view[i];
1598 if (ST::magnitude(v.coeff(
j)) < tol)
1599 v.fastAccessCoeff(
j) = BaseScalar(0.0);
1615 #if defined(HAVE_STOKHOS_BELOS) && defined(HAVE_STOKHOS_IFPACK2) && defined(HAVE_STOKHOS_MUELU) && defined(HAVE_STOKHOS_AMESOS2)
1629 using Teuchos::getParametersFromXmlFile;
1635 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1636 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1637 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1638 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1641 if ( !Kokkos::is_initialized() )
1642 Kokkos::initialize();
1646 BaseScalar h = 1.0 /
static_cast<BaseScalar
>(nrow-1);
1647 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1648 RCP<const Tpetra_Map> map =
1649 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1651 RCP<Tpetra_CrsGraph> graph =
1652 rcp(
new Tpetra_CrsGraph(map,
size_t(3), Tpetra::StaticProfile));
1653 Array<GlobalOrdinal> columnIndices(3);
1654 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1655 const size_t num_my_row = myGIDs.size();
1656 for (
size_t i=0; i<num_my_row; ++i) {
1658 if (row == 0 || row == nrow-1) {
1659 columnIndices[0] = row;
1660 graph->insertGlobalIndices(row, columnIndices(0,1));
1663 columnIndices[0] = row-1;
1664 columnIndices[1] = row;
1665 columnIndices[2] = row+1;
1666 graph->insertGlobalIndices(row, columnIndices(0,3));
1669 graph->fillComplete();
1670 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
1673 Array<Scalar> vals(3);
1674 Scalar a_val(VectorSize, BaseScalar(0.0));
1676 a_val.fastAccessCoeff(
j) =
1677 BaseScalar(1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1679 for (
size_t i=0; i<num_my_row; ++i) {
1681 if (row == 0 || row == nrow-1) {
1682 columnIndices[0] = row;
1684 matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1687 columnIndices[0] = row-1;
1688 columnIndices[1] = row;
1689 columnIndices[2] = row+1;
1690 vals[0] =
Scalar(-1.0) * a_val;
1691 vals[1] =
Scalar(2.0) * a_val;
1692 vals[2] =
Scalar(-1.0) * a_val;
1693 matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
1696 matrix->fillComplete();
1699 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1700 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1701 Scalar b_val(VectorSize, BaseScalar(0.0));
1703 b_val.fastAccessCoeff(
j) =
1704 BaseScalar(-1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1706 for (
size_t i=0; i<num_my_row; ++i) {
1708 if (row == 0 || row == nrow-1)
1711 b_view[i] = -
Scalar(b_val * h * h);
1715 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1716 RCP<ParameterList> muelu_params =
1717 getParametersFromXmlFile(
"muelu_cheby.xml");
1718 RCP<OP> matrix_op = matrix;
1720 MueLu::CreateTpetraPreconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrix_op, *muelu_params);
1724 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1725 typedef BaseScalar BelosScalar;
1727 typedef Scalar BelosScalar;
1729 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1730 typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1731 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1732 RCP< BLinProb > problem =
rcp(
new BLinProb(matrix, x, b));
1733 problem->setRightPrec(M);
1734 problem->setProblem();
1735 RCP<ParameterList> belosParams =
rcp(
new ParameterList);
1736 typename ST::magnitudeType tol = 1e-9;
1737 belosParams->set(
"Num Blocks", 100);
1738 belosParams->set(
"Convergence Tolerance", BelosScalar(tol));
1739 belosParams->set(
"Maximum Iterations", 100);
1740 belosParams->set(
"Verbosity", 33);
1741 belosParams->set(
"Output Style", 1);
1742 belosParams->set(
"Output Frequency", 1);
1743 belosParams->set(
"Output Stream", out.getOStream());
1746 belosParams->set(
"Implicit Residual Scaling",
"None");
1748 RCP<Belos::PseudoBlockCGSolMgr<BelosScalar,MV,OP,true> > solver =
1749 rcp(
new Belos::PseudoBlockCGSolMgr<BelosScalar,MV,OP,true>(problem, belosParams));
1750 Belos::ReturnType ret = solver->solve();
1753 #ifndef HAVE_STOKHOS_ENSEMBLE_REDUCT
1755 std::vector<int> ensemble_iterations =
1756 solver->getResidualStatusTest()->getEnsembleIterations();
1757 out <<
"Ensemble iterations = ";
1759 out << ensemble_iterations[i] <<
" ";
1768 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1769 Scalar
val(VectorSize, BaseScalar(0.0));
1770 for (
size_t i=0; i<num_my_row; ++i) {
1772 BaseScalar xx = row * h;
1774 val.fastAccessCoeff(
j) =
1775 BaseScalar(0.5) * (b_val.coeff(
j)/a_val.coeff(
j)) * xx * (xx - BaseScalar(1.0));
1780 Scalar v = x_view[i];
1782 if (ST::magnitude(v.coeff(
j)) < tol)
1783 v.fastAccessCoeff(
j) = BaseScalar(0.0);
1784 if (ST::magnitude(
val.coeff(
j)) < tol)
1785 val.fastAccessCoeff(
j) = BaseScalar(0.0);
1802 #if defined(HAVE_STOKHOS_AMESOS2)
1821 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1822 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1823 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
1824 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1825 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1828 if ( !Kokkos::is_initialized() )
1829 Kokkos::initialize();
1833 BaseScalar h = 1.0 /
static_cast<BaseScalar
>(nrow-1);
1834 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1835 RCP<const Tpetra_Map> map =
1836 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1838 RCP<Tpetra_CrsGraph> graph = Tpetra::createCrsGraph(map,
size_t(3));
1839 Array<GlobalOrdinal> columnIndices(3);
1840 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1841 const size_t num_my_row = myGIDs.size();
1842 for (
size_t i=0; i<num_my_row; ++i) {
1844 if (row == 0 || row == nrow-1) {
1845 columnIndices[0] = row;
1846 graph->insertGlobalIndices(row, columnIndices(0,1));
1849 columnIndices[0] = row-1;
1850 columnIndices[1] = row;
1851 columnIndices[2] = row+1;
1852 graph->insertGlobalIndices(row, columnIndices(0,3));
1855 graph->fillComplete();
1856 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
1859 Array<Scalar> vals(3);
1860 Scalar a_val(VectorSize, BaseScalar(0.0));
1862 a_val.fastAccessCoeff(
j) =
1863 BaseScalar(1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1865 for (
size_t i=0; i<num_my_row; ++i) {
1867 if (row == 0 || row == nrow-1) {
1868 columnIndices[0] = row;
1870 matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1873 columnIndices[0] = row-1;
1874 columnIndices[1] = row;
1875 columnIndices[2] = row+1;
1876 vals[0] =
Scalar(-1.0) * a_val;
1877 vals[1] =
Scalar(2.0) * a_val;
1878 vals[2] =
Scalar(-1.0) * a_val;
1879 matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
1882 matrix->fillComplete();
1885 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1886 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1887 Scalar b_val(VectorSize, BaseScalar(0.0));
1889 b_val.fastAccessCoeff(
j) =
1890 BaseScalar(-1.0) + BaseScalar(
j) / BaseScalar(VectorSize);
1892 for (
size_t i=0; i<num_my_row; ++i) {
1894 if (row == 0 || row == nrow-1)
1897 b_view[i] = -
Scalar(b_val * h * h);
1901 typedef Amesos2::Solver<Tpetra_CrsMatrix,Tpetra_MultiVector> Solver;
1902 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1903 std::string solver_name;
1904 #if defined(HAVE_AMESOS2_BASKER)
1905 solver_name =
"basker";
1906 #elif defined(HAVE_AMESOS2_KLU2)
1907 solver_name =
"klu2";
1908 #elif defined(HAVE_AMESOS2_SUPERLUDIST)
1909 solver_name =
"superlu_dist";
1910 #elif defined(HAVE_AMESOS2_SUPERLUMT)
1911 solver_name =
"superlu_mt";
1912 #elif defined(HAVE_AMESOS2_SUPERLU)
1913 solver_name =
"superlu";
1914 #elif defined(HAVE_AMESOS2_PARDISO_MKL)
1915 solver_name =
"pardisomkl";
1916 #elif defined(HAVE_AMESOS2_LAPACK)
1917 solver_name =
"lapack";
1918 #elif defined(HAVE_AMESOS2_CHOLMOD) && defined (HAVE_AMESOS2_EXPERIMENTAL)
1919 solver_name =
"lapack";
1925 out <<
"Solving linear system with " << solver_name << std::endl;
1926 RCP<Solver> solver = Amesos2::create<Tpetra_CrsMatrix,Tpetra_MultiVector>(
1927 solver_name, matrix, x, b);
1935 typename ST::magnitudeType tol = 1e-9;
1936 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1937 Scalar
val(VectorSize, BaseScalar(0.0));
1938 for (
size_t i=0; i<num_my_row; ++i) {
1940 BaseScalar xx = row * h;
1942 val.fastAccessCoeff(
j) =
1943 BaseScalar(0.5) * (b_val.coeff(
j)/a_val.coeff(
j)) * xx * (xx - BaseScalar(1.0));
1948 Scalar v = x_view[i];
1950 if (ST::magnitude(v.coeff(
j)) < tol)
1951 v.fastAccessCoeff(
j) = BaseScalar(0.0);
1952 if (ST::magnitude(
val.coeff(
j)) < tol)
1953 val.fastAccessCoeff(
j) = BaseScalar(0.0);
1969 #define CRSMATRIX_MP_VECTOR_TESTS_SLGN(S, LO, GO, N) \
1970 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, VectorAdd, S, LO, GO, N ) \
1971 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, VectorDot, S, LO, GO, N ) \
1972 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MultiVectorAdd, S, LO, GO, N ) \
1973 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MultiVectorDot, S, LO, GO, N ) \
1974 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MultiVectorDotSub, S, LO, GO, N ) \
1975 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MatrixVectorMultiply, S, LO, GO, N ) \
1976 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MatrixMultiVectorMultiply, S, LO, GO, N ) \
1977 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, Flatten, S, LO, GO, N ) \
1978 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, SimpleCG, S, LO, GO, N ) \
1979 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, SimplePCG_Muelu, S, LO, GO, N ) \
1980 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES, S, LO, GO, N ) \
1981 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES_RILUK, S, LO, GO, N ) \
1982 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosCG_Muelu, S, LO, GO, N ) \
1983 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, Amesos2, S, LO, GO, N )
1985 #define CRSMATRIX_MP_VECTOR_TESTS_N_SFS(N) \
1986 typedef Stokhos::DeviceForNode<N>::type Device; \
1987 typedef Stokhos::StaticFixedStorage<int,double,VectorSize,Device::execution_space> SFS; \
1988 CRSMATRIX_MP_VECTOR_TESTS_SLGN(SFS, int, int, N)
1990 #define CRSMATRIX_MP_VECTOR_TESTS_N(N) \
1991 CRSMATRIX_MP_VECTOR_TESTS_N_SFS(N)
bool CG_Solve(const Matrix &A, Vector &x, const Vector &b, typename Vector::mag_type tol, Ordinal max_its, std::ostream *out=0)
scalar generate_multi_vector_coefficient(const ordinal nFEM, const ordinal nVec, const ordinal nStoch, const ordinal iColFEM, const ordinal iVec, const ordinal iStoch)
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Tpetra_CrsMatrix_MP, VectorAdd, Storage, LocalOrdinal, GlobalOrdinal, Node)
#define TEST_EQUALITY_CONST(v1, v2)
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< YD, YP...> >::value, typename Kokkos::Details::InnerProductSpaceTraits< typename Kokkos::View< XD, XP...>::non_const_value_type >::dot_type >::type dot(const Kokkos::View< XD, XP...> &x, const Kokkos::View< YD, YP...> &y)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Tpetra::MultiVector< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_vector_view(const Tpetra::MultiVector< Sacado::MP::Vector< Storage >, LocalOrdinal, GlobalOrdinal, Node > &vec_const, const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_map)
bool PCG_Solve(const Matrix &A, Vector &x, const Vector &b, const Prec &M, typename Vector::mag_type tol, Ordinal max_its, std::ostream *out=0)
KokkosClassic::DefaultNode::DefaultNodeType Node
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > create_flat_mp_graph(const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_domain_map, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_range_map, const LocalOrdinal block_size)
Teuchos::RCP< Tpetra::CrsMatrix< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_matrix(const Tpetra::CrsMatrix< Sacado::MP::Vector< Storage >, LocalOrdinal, GlobalOrdinal, Node > &mat, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &flat_graph, const LocalOrdinal block_size)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
#define TEST_EQUALITY(v1, v2)
const unsigned VectorSize