19 #include "Thyra_BelosLinearOpWithSolveFactory.hpp"
20 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
24 #include "Epetra_SerialComm.h"
25 #include "EpetraExt_readEpetraLinearSystem.h"
28 #ifdef HAVE_BELOS_IFPACK
36 int main(
int argc,
char* argv[])
42 out = Teuchos::VerboseObjectBase::getDefaultOStream();
47 int maxIterations = 400;
49 int gmresKrylovLength = 25;
50 int outputFrequency = 1;
51 bool outputMaxResOnly =
true;
52 double maxResid = 1e-6;
57 belosLOWSFPL->
set(
"Solver Type",
"Block GMRES");
60 belosLOWSFPL->
sublist(
"Solver Types");
63 belosLOWSFPL_solver.
sublist(
"Block GMRES");
65 belosLOWSFPL_gmres.
set(
"Maximum Iterations",
int(maxIterations));
66 belosLOWSFPL_gmres.
set(
"Convergence Tolerance",
double(maxResid));
67 belosLOWSFPL_gmres.
set(
"Maximum Restarts",
int(maxRestarts));
68 belosLOWSFPL_gmres.
set(
"Block Size",
int(blockSize));
69 belosLOWSFPL_gmres.
set(
"Num Blocks",
int(gmresKrylovLength));
70 belosLOWSFPL_gmres.
set(
"Output Frequency",
int(outputFrequency));
71 belosLOWSFPL_gmres.
set(
"Show Maximum Residual Norm Only",
bool(outputMaxResOnly));
73 #ifdef HAVE_BELOS_IFPACK
79 ifpackPFSL.
set(
"Overlap",
int(2));
80 ifpackPFSL.
set(
"Prec Type",
"ILUT");
91 std::string matrixFile =
"orsirr1.hb";
94 Epetra_SerialComm comm;
96 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
100 A = Thyra::epetraLinearOp(epetra_A);
109 #ifdef HAVE_BELOS_IFPACK
112 belosLOWSFactory->setPreconditionerFactory(
114 ,
"IfpackPreconditionerFactory"
119 belosLOWSFactory->setParameterList( belosLOWSFPL );
126 nsA = belosLOWSFactory->createOp();
129 Thyra::initializeOp<double>( *belosLOWSFactory, A, &*nsA );
133 b = Thyra::createMembers(domain, numRhs);
134 Thyra::seed_randomize<double>(0);
135 Thyra::randomize(-1.0, 1.0, &*b);
139 x = Thyra::createMembers(domain, numRhs);
140 Thyra::assign(&*x, 0.0);
144 Thyra::SolveStatus<double> solveStatus;
145 solveStatus = Thyra::solve( *nsA, Thyra::NONCONJ_ELE, *b, &*x );
148 *out <<
"\nBelos LOWS Status: "<< solveStatus << std::endl;
153 std::vector<double> norm_b(numRhs), norm_res(numRhs);
155 y = Thyra::createMembers(domain, numRhs);
158 Thyra::norms_2( *b, &norm_b[0] );
161 A->apply( Thyra::NONCONJ_ELE, *x, &*y );
164 Thyra::update( -1.0, *b, &*y );
167 Thyra::norms_2( *y, &norm_res[0] );
170 double rel_res = 0.0;
171 *out <<
"Final relative residual norms" << std::endl;
172 for (
int i=0; i<numRhs; ++i) {
173 rel_res = norm_res[i]/norm_b[i];
174 if (rel_res > maxResid)
176 *out <<
"RHS " << i+1 <<
" : "
177 << std::setw(16) << std::right << rel_res << std::endl;
180 return ( success ? 0 : 1 );
Concrete preconditioner factory subclass based on Ifpack.
int main(int argc, char *argv[])
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
LinearOpWithSolveFactoryBase subclass implemented in terms of Belos.