00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "BelosConfigDefs.hpp"
00036 #include "BelosLinearProblem.hpp"
00037 #include "BelosOutputManager.hpp"
00038 #include "BelosStatusTestMaxIters.hpp"
00039 #include "BelosStatusTestMaxRestarts.hpp"
00040 #include "BelosStatusTestResNorm.hpp"
00041 #include "BelosStatusTestOutputter.hpp"
00042 #include "BelosStatusTestCombo.hpp"
00043 #include "BelosEpetraAdapter.hpp"
00044 #include "BelosTFQMR.hpp"
00045 #include "createEpetraProblem.hpp"
00046 #include "Epetra_CrsMatrix.h"
00047 #include "Teuchos_CommandLineProcessor.hpp"
00048 #include "Teuchos_ParameterList.hpp"
00049 #include "Epetra_Map.h"
00050
00051 int main(int argc, char *argv[]) {
00052
00053 #ifdef EPETRA_MPI
00054 MPI_Init(&argc,&argv);
00055 Belos::MPIFinalize mpiFinalize;
00056 #endif
00057
00058 typedef double ST;
00059 typedef Teuchos::ScalarTraits<ST> SCT;
00060 typedef SCT::magnitudeType MT;
00061 typedef Epetra_MultiVector MV;
00062 typedef Epetra_Operator OP;
00063 typedef Belos::MultiVecTraits<ST,MV> MVT;
00064 typedef Belos::OperatorTraits<ST,MV,OP> OPT;
00065
00066 using Teuchos::ParameterList;
00067 using Teuchos::RefCountPtr;
00068 using Teuchos::rcp;
00069
00070 bool verbose = false, proc_verbose = false;
00071 int frequency = -1;
00072 int numrhs = 1;
00073 int numiters = 10;
00074 std::string filename("orsirr1.hb");
00075 MT tol = 1.0e-5;
00076
00077 Teuchos::CommandLineProcessor cmdp(false,true);
00078 cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00079 cmdp.setOption("frequency",&frequency,"Solvers frequency for printing residuals (#iters).");
00080 cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
00081 cmdp.setOption("tol",&tol,"Relative residual tolerance used by TFQMR solver.");
00082 cmdp.setOption("num-iters",&numiters,"Number of iterations allowed for TFQMR solver.");
00083 if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00084 return -1;
00085 }
00086 if (!verbose)
00087 frequency = -1;
00088
00089
00090
00091 int MyPID;
00092 RefCountPtr<Epetra_CrsMatrix> A;
00093 RefCountPtr<Epetra_MultiVector> B, X;
00094 int return_val =Belos::createEpetraProblem(filename,NULL,&A,&B,&X,&MyPID);
00095 if(return_val != 0) return return_val;
00096 const Epetra_Map &Map = A->RowMap();
00097 proc_verbose = verbose && (MyPID==0);
00098
00099
00100
00101
00102 const int NumGlobalElements = B->GlobalLength();
00103
00104
00105
00106 Belos::LinearProblem<double,MV,OP>
00107 My_LP( A, X, B );
00108 My_LP.SetBlockSize( 1 );
00109
00110
00111
00112
00113
00114 Belos::OutputManager<double> My_OM( MyPID );
00115 if (verbose)
00116 My_OM.SetVerbosity( Belos::Errors + Belos::Warnings
00117 + Belos::TimingDetails + Belos::FinalSummary );
00118
00119 typedef Belos::StatusTestCombo<double,MV,OP> StatusTestCombo_t;
00120 Belos::StatusTestMaxIters<double,MV,OP> test1( numiters );
00121 Belos::StatusTestResNorm<double,MV,OP> test2( tol );
00122 Belos::StatusTestOutputter<ST,MV,OP> test3( frequency, false );
00123 test3.set_resNormStatusTest( rcp(&test2,false) );
00124 test3.set_outputManager( rcp(&My_OM,false) );
00125 StatusTestCombo_t My_Test( StatusTestCombo_t::OR, test1, test3 );
00126
00127 Belos::TFQMR<double,MV,OP>
00128 MyTFQMR( rcp(&My_LP,false), rcp(&My_Test,false), rcp(&My_OM,false) );
00129
00130
00131
00132
00133 if (proc_verbose) {
00134 cout << endl << endl;
00135 cout << "Dimension of matrix: " << NumGlobalElements << endl;
00136 cout << "Number of right-hand sides: " << numrhs << endl;
00137 cout << "Max number of TFQMR iterations: " << numiters << endl;
00138 cout << "Relative residual tolerance: " << tol << endl;
00139 cout << endl;
00140 }
00141
00142
00143
00144 MyTFQMR.Solve();
00145
00146
00147
00148
00149 std::vector<double> actual_resids( numrhs );
00150 std::vector<double> rhs_norm( numrhs );
00151 Epetra_MultiVector resid(Map, numrhs);
00152 OPT::Apply( *A, *X, resid );
00153 MVT::MvAddMv( -1.0, resid, 1.0, *B, resid );
00154 MVT::MvNorm( resid, &actual_resids );
00155 MVT::MvNorm( *B, &rhs_norm );
00156 if (proc_verbose) {
00157 cout<< "---------- Actual Residuals (normalized) ----------"<<endl<<endl;
00158 for ( int i=0; i<numrhs; i++) {
00159 cout<<"Problem "<<i<<" : \t"<< actual_resids[i]/rhs_norm[i] <<endl;
00160 }
00161 }
00162
00163 if (My_Test.GetStatus()!=Belos::Converged) {
00164 if (proc_verbose)
00165 cout << "End Result: TEST FAILED" << endl;
00166 return -1;
00167 }
00168
00169
00170
00171 if (proc_verbose)
00172 cout << "End Result: TEST PASSED" << endl;
00173 return 0;
00174
00175 }