| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Belos: Block Linear Solvers Package |
| 4 |
// |
| 5 |
// Copyright 2004-2016 NTESS and the Belos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include "BelosLinearProblem.hpp" |
| 11 |
#include "BelosTpetraAdapter.hpp" |
| 12 |
#include "BelosBlockGmresSolMgr.hpp" |
| 13 |
|
| 14 |
#include "Tpetra_Core.hpp" |
| 15 |
#include "Tpetra_CrsMatrix.hpp" |
| 16 |
#include "Tpetra_Map.hpp" |
| 17 |
#include "Tpetra_MultiVector.hpp" |
| 18 |
#include "Tpetra_Operator.hpp" |
| 19 |
|
| 20 |
int main(int argc, char *argv[]) { |
| 21 |
using Teuchos::Array; |
| 22 |
using Teuchos::ParameterList; |
| 23 |
using Teuchos::RCP; |
| 24 |
using Teuchos::rcp; |
| 25 |
using SC = Tpetra::MultiVector<>::scalar_type; |
| 26 |
using crs_matrix_type = Tpetra::CrsMatrix<SC>; |
| 27 |
using map_type = Tpetra::Map<>; |
| 28 |
using OP = Tpetra::Operator<SC>; |
| 29 |
using MV = Tpetra::MultiVector<SC>; |
| 30 |
using LO = map_type::local_ordinal_type; // int LO; |
| 31 |
using GO = map_type::global_ordinal_type; // int GO; |
| 32 |
// typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType NO; |
| 33 |
|
| 34 |
Tpetra::ScopeGuard tpetraScope (&argc, &argv); |
| 35 |
{ |
| 36 |
auto TeuchosComm = Tpetra::getDefaultComm (); |
| 37 |
|
| 38 |
int NumMyElements = 0; |
| 39 |
if (TeuchosComm->getRank()==0) { |
| 40 |
NumMyElements = 10; |
| 41 |
} |
| 42 |
Array<GO> uniqueMapArray(NumMyElements); |
| 43 |
for (LO i=0; i<uniqueMapArray.size(); i++) { |
| 44 |
uniqueMapArray[i] = i; |
| 45 |
} |
| 46 |
|
| 47 |
const Tpetra::global_size_t INVALID = |
| 48 |
Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(); |
| 49 |
RCP<const map_type> UniqueMap = rcp (new map_type (INVALID, uniqueMapArray, 0, TeuchosComm)); |
| 50 |
|
| 51 |
RCP<crs_matrix_type> K = rcp (new crs_matrix_type (UniqueMap, 10)); |
| 52 |
|
| 53 |
for (LO i = 0; i < static_cast<LO>(UniqueMap->getLocalNumElements()); ++i) { |
| 54 |
LO numEntries = 10-i; |
| 55 |
Array<GO> indicesArray(numEntries); |
| 56 |
Array<SC> valuesArray(numEntries); |
| 57 |
for (LO k=0; k<numEntries; k++) { |
| 58 |
indicesArray[k] = k+i; |
| 59 |
valuesArray[k] = 1; |
| 60 |
} |
| 61 |
K->insertGlobalValues(UniqueMap->getGlobalElement(i), indicesArray(), |
| 62 |
valuesArray()); |
| 63 |
} |
| 64 |
K->fillComplete(); |
| 65 |
|
| 66 |
//Solve with GMRES |
| 67 |
RCP<MV> Solution = rcp(new MV(UniqueMap,1)); |
| 68 |
RCP<MV> RightHandSide = rcp(new MV(UniqueMap,1)); |
| 69 |
|
| 70 |
Solution->putScalar(0.0); |
| 71 |
RightHandSide->putScalar(1.0); |
| 72 |
|
| 73 |
using Belos::LinearProblem; |
| 74 |
RCP<LinearProblem<SC,MV,OP> > belosLinearProblem = |
| 75 |
rcp (new LinearProblem<SC,MV,OP> (K, Solution, RightHandSide)); |
| 76 |
belosLinearProblem->setProblem(); |
| 77 |
|
| 78 |
RCP<ParameterList> solverParameterList = rcp(new ParameterList()); |
| 79 |
solverParameterList->set("Convergence Tolerance",1.0e-12); |
| 80 |
solverParameterList->set("Verbosity",47); |
| 81 |
solverParameterList->set("Output Frequency",1); |
| 82 |
solverParameterList->set("Output Style",1); |
| 83 |
|
| 84 |
Belos::BlockGmresSolMgr<SC,MV,OP> solver(belosLinearProblem, |
| 85 |
solverParameterList); |
| 86 |
solver.solve(); |
| 87 |
} |
| 88 |
|
| 89 |
return(EXIT_SUCCESS); |
| 90 |
} |