10 #include "sillyPowerMethod.hpp"
12 #include "Thyra_TestingTools.hpp"
20 #include "Epetra_CrsMatrix.h"
21 #include "Epetra_Map.h"
39 if(crsMatrix.MyGlobalRow(0)) {
40 const int numRowNz = crsMatrix.NumGlobalEntries(0);
42 int returndNumRowNz;
double rowValues[2];
int rowIndexes[2];
43 crsMatrix.ExtractGlobalRowCopy( 0, numRowNz, returndNumRowNz, &rowValues[0], &rowIndexes[0] );
45 for(
int k = 0; k < numRowNz; ++k)
if (rowIndexes[k] == 0) rowValues[k] *= diagScale;
46 crsMatrix.ReplaceGlobalValues( 0, numRowNz, rowValues, rowIndexes );
53 int main(
int argc,
char *argv[])
56 using Teuchos::outArg;
69 MPI_Comm mpiComm = MPI_COMM_WORLD;
77 out = Teuchos::VerboseObjectBase::getDefaultOStream();
86 CommandLineProcessor clp;
87 clp.throwExceptions(
false);
88 clp.addOutputSetupOptions(
true);
91 clp.setOption(
"global-dim", &globalDim,
"Global dimension of the linear system." );
94 clp.setOption(
"dump-all",
"no-dump", &dumpAll,
"Determines if quantities are dumped or not." );
96 CommandLineProcessor::EParseCommandLineReturn
97 parse_return = clp.parse(argc,argv);
98 if (parse_return != CommandLineProcessor::PARSE_SUCCESSFUL)
103 *out <<
"\n***\n*** Running power method example using Epetra implementation\n***\n" << std::scientific;
118 *out <<
"\n(1) Constructing tridagonal Epetra matrix A of global dimension = " << globalDim <<
" ...\n";
128 RCP<Thyra::LinearOpBase<double> >
129 A = Thyra::nonconstEpetraLinearOp(A_epetra);
131 if (dumpAll) *out <<
"\nA =\n" << *A;
136 *out <<
"\n(2) Running the power method on matrix A ...\n";
138 double tolerance = 1e-3;
139 int maxNumIters = 10*globalDim;
140 result = sillyPowerMethod<double>(*A, maxNumIters, tolerance, outArg(lambda), *out);
141 if(!result) success =
false;
142 *out <<
"\n Estimate of dominate eigenvalue lambda = " << lambda << std::endl;
147 *out <<
"\n(3) Scale the diagonal of A by a factor of 10 ...\n";
153 *out <<
"\n(4) Running the power method again on matrix A ...\n";
154 result = sillyPowerMethod<double>(*A, maxNumIters, tolerance, outArg(lambda), *out);
155 if(!result) success =
false;
156 *out <<
"\n Estimate of dominate eigenvalue lambda = " << lambda << std::endl;
162 *out <<
"\nCongratulations! All of the tests checked out!\n";
164 *out <<
"\nOh no! At least one of the tests failed!\n";
166 return success ? 0 : 1;
Teuchos::RCP< Epetra_Operator > createTridiagEpetraLinearOp(const int globalDim, const double diagScale, const bool verbose, std::ostream &out)
This function generates a tridiagonal linear operator using Epetra.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
int main(int argc, char *argv[])
void scaleFirstDiagElement(const double diagScale, Thyra::LinearOpBase< double > *A)
Teuchos::RCP< Epetra_Operator > get_Epetra_Operator(LinearOpBase< double > &op)
Full specialization for Scalar=double.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)