8 #include "Tpetra_Core.hpp"
9 #include "Tpetra_Map.hpp"
10 #include "Tpetra_Vector.hpp"
11 #include "Tpetra_CrsGraph.hpp"
12 #include "Tpetra_CrsMatrix.hpp"
16 #ifdef HAVE_STOKHOS_BELOS
17 #include "BelosTpetraAdapter.hpp"
18 #include "BelosLinearProblem.hpp"
19 #include "BelosPseudoBlockGmresSolMgr.hpp"
32 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
33 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
34 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
35 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
39 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
40 RCP<const Tpetra_Map> map =
41 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
43 RCP<Tpetra_CrsGraph> graph =
44 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
45 Array<GlobalOrdinal> columnIndices(2);
46 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
47 const size_t num_my_row = myGIDs.size();
48 for (
size_t i=0; i<num_my_row; ++i) {
50 columnIndices[0] = row;
57 graph->insertGlobalIndices(row, columnIndices(0,ncol));
59 graph->fillComplete();
60 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
63 Array<Scalar> vals(2);
64 for (
size_t i=0; i<num_my_row; ++i) {
66 columnIndices[0] = row;
75 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
77 matrix->fillComplete();
80 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
83 matrix->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
86 x->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
90 RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
91 matrix->apply(*x, *y);
93 y->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
97 ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
98 ArrayRCP<Scalar> x_view = y->get1dViewNonConst();
99 for (
size_t i=0; i<num_my_row; ++i) {
110 #if defined(HAVE_STOKHOS_BELOS)
126 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
127 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
128 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
129 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
133 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
134 RCP<const Tpetra_Map> map =
135 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
137 RCP<Tpetra_CrsGraph> graph =
138 rcp(
new Tpetra_CrsGraph(map,
size_t(2), Tpetra::StaticProfile));
139 Array<GlobalOrdinal> columnIndices(2);
140 ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
141 const size_t num_my_row = myGIDs.size();
142 for (
size_t i=0; i<num_my_row; ++i) {
144 columnIndices[0] = row;
150 graph->insertGlobalIndices(row, columnIndices(0,ncol));
152 graph->fillComplete();
153 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
156 Array<Scalar> vals(2);
157 for (
size_t i=0; i<num_my_row; ++i) {
159 columnIndices[0] = row;
168 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
170 matrix->fillComplete();
173 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
174 ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
175 for (
size_t i=0; i<num_my_row; ++i) {
181 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
182 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
183 typedef Belos::LinearProblem<Scalar,MV,OP> BLinProb;
184 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
185 RCP< BLinProb > problem =
rcp(
new BLinProb(matrix, x, b));
186 RCP<ParameterList> belosParams =
rcp(
new ParameterList);
187 typename ST::magnitudeType tol = 1e-9;
188 belosParams->set(
"Flexible Gmres",
false);
189 belosParams->set(
"Num Blocks", 100);
190 belosParams->set(
"Convergence Tolerance",
Scalar(tol));
191 belosParams->set(
"Maximum Iterations", 100);
192 belosParams->set(
"Verbosity", 33);
193 belosParams->set(
"Output Style", 1);
194 belosParams->set(
"Output Frequency", 1);
195 belosParams->set(
"Output Stream", out.getOStream());
196 RCP<Belos::SolverManager<Scalar,MV,OP> > solver =
197 rcp(
new Belos::PseudoBlockGmresSolMgr<Scalar,MV,OP>(problem, belosParams));
198 problem->setProblem();
199 Belos::ReturnType ret = solver->solve();
211 ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
213 for (
size_t i=0; i<num_my_row; ++i) {
223 if (ST::magnitude(v) < tol)
238 typedef KokkosClassic::DefaultNode::DefaultNodeType
Node;
241 Tpetra_CrsMatrix, MatVec,
double,
int,
int, Node )
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Tpetra_CrsMatrix_MP, VectorAdd, Storage, LocalOrdinal, GlobalOrdinal, Node)
#define TEST_EQUALITY_CONST(v1, v2)
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix, MatVec, double, int, int, Node) TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix
KokkosClassic::DefaultNode::DefaultNodeType Node
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
int main(int argc, char **argv)
#define TEST_EQUALITY(v1, v2)