Testing Program for the Amesos/Thyra Linear Solver Adapters
[Assorted Amesos to Thyra Linear Solver Adapter Example Code]

Here we show a testing program that takes the Amesos/%Thyra adatpers through the paces. More...
Below is a complete listing of the testing function with line numbers:

00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //                Amesos: Direct Sparse Solver Package
00006 //                 Copyright (2004) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #include "test_single_amesos_thyra_solver.hpp"
00032 
00033 #ifndef __sun
00034 
00035 #include "Thyra_AmesosLinearOpWithSolveFactory.hpp"
00036 #include "Thyra_EpetraLinearOp.hpp"
00037 #include "Thyra_LinearOpTester.hpp"
00038 #include "Thyra_LinearOpWithSolveTester.hpp"
00039 #include "EpetraExt_readEpetraLinearSystem.h"
00040 #include "Epetra_SerialComm.h"
00041 
00042 #endif // __sun
00043 
00044 bool Thyra::test_single_amesos_thyra_solver(
00045   const std::string                       matrixFile
00046   ,const Amesos::ESolverType              solverType
00047   ,const Amesos::ERefactorizationPolicy   refactorizationPolicy
00048   ,const bool                             testTranspose
00049   ,const int                              numRandomVectors
00050   ,const double                           maxFwdError
00051   ,const double                           maxError
00052   ,const double                           maxResid
00053   ,const bool                             showAllTests
00054   ,const bool                             dumpAll
00055   ,std::ostream                           *out
00056   )
00057 {
00058   bool result, success = true;
00059 
00060 #ifndef __sun
00061 
00062   if(out) {
00063     *out << "\n***"
00064          << "\n*** Testing Thyra::AmesosLinearOpWithSolveFactory (and Thyra::AmesosLinearOpWithSolve)"
00065          << "\n***\n"
00066          << "\nEchoing input options:"
00067          << "\n  matrixFile             = " << matrixFile
00068          << "\n  solverType             = " << toString(solverType)
00069          << "\n  refactorizationPolicy  = " << toString(refactorizationPolicy)
00070          << "\n  testTranspose          = " << testTranspose
00071          << "\n  numRandomVectors       = " << numRandomVectors
00072          << "\n  maxFwdError            = " << maxFwdError
00073          << "\n  maxError               = " << maxError
00074          << "\n  maxResid               = " << maxResid
00075          << "\n  showAllTests           = " << showAllTests
00076          << "\n  dumpAll                = " << dumpAll
00077          << std::endl;
00078   }
00079   
00080   if(out) *out << "\nA) Reading in an epetra matrix A from the file \'"<<matrixFile<<"\' ...\n";
00081   
00082   const std::string indentSpacer = "  ";
00083   
00084   Epetra_SerialComm comm;
00085   Teuchos::RefCountPtr<Epetra_CrsMatrix> epetra_A;
00086   EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
00087 
00088   Teuchos::RefCountPtr<LinearOpBase<double> >
00089     A = Teuchos::rcp(new EpetraLinearOp(epetra_A));
00090 
00091   if(out && dumpAll) *out << "\ndescribe(A) =\n" << describe(*A,Teuchos::VERB_EXTREME,indentSpacer,indentSpacer);
00092 
00093   if(out) *out << "\nB) Creating a AmesosLinearOpWithSolveFactory object opFactory ...\n";
00094 
00095   Teuchos::RefCountPtr<const LinearOpWithSolveFactoryBase<double> >
00096     opFactory = Teuchos::rcp(new AmesosLinearOpWithSolveFactory(solverType,refactorizationPolicy));
00097 
00098   if(out) *out << "\nC) Creating a AmesosLinearOpWithSolve object nsA ...\n";
00099 
00100   Teuchos::RefCountPtr<LinearOpWithSolveBase<double> >
00101     nsA = opFactory->createOp();
00102 
00103   opFactory->initializeOp( A, &*nsA );
00104 
00105   if(out) *out << "\nD) Testing the LinearOpBase interface of nsA ...\n";
00106 
00107   Thyra::seed_randomize<double>(0);
00108 
00109   LinearOpTester<double> linearOpTester;
00110   linearOpTester.check_adjoint(testTranspose);
00111   linearOpTester.num_random_vectors(numRandomVectors);
00112   linearOpTester.set_all_error_tol(maxFwdError);
00113   linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
00114   linearOpTester.show_all_tests(showAllTests);
00115   linearOpTester.dump_all(dumpAll);
00116   result = linearOpTester.check(*nsA,out,indentSpacer,indentSpacer);
00117   if(!result) success = false;
00118 
00119   if(out) *out << "\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
00120     
00121   LinearOpWithSolveTester<double> linearOpWithSolveTester;
00122   linearOpWithSolveTester.turn_off_all_tests();
00123   linearOpWithSolveTester.check_forward_default(true);
00124   linearOpWithSolveTester.forward_default_residual_error_tol(1.1*maxResid);
00125   linearOpWithSolveTester.forward_default_residual_warning_tol(2.0*maxResid);
00126   linearOpWithSolveTester.check_forward_residual(true);
00127   linearOpWithSolveTester.forward_residual_solve_tol(maxResid);
00128   linearOpWithSolveTester.forward_residual_slack_error_tol(1e-1*maxResid);
00129   linearOpWithSolveTester.forward_residual_slack_warning_tol(maxResid);
00130   linearOpWithSolveTester.check_forward_solution_error(true);
00131   linearOpWithSolveTester.forward_solution_error_solve_tol(maxError);
00132   linearOpWithSolveTester.forward_solution_error_slack_error_tol(1e-1*maxError);
00133   linearOpWithSolveTester.forward_solution_error_slack_warning_tol(maxError);
00134   if(testTranspose) {
00135     linearOpWithSolveTester.check_adjoint_default(true);
00136     linearOpWithSolveTester.adjoint_default_residual_error_tol(1.1*maxResid);
00137     linearOpWithSolveTester.adjoint_default_residual_warning_tol(2.0*maxResid);
00138     linearOpWithSolveTester.check_adjoint_residual(true);
00139     linearOpWithSolveTester.adjoint_residual_solve_tol(maxResid);
00140     linearOpWithSolveTester.adjoint_residual_slack_error_tol(1e-1*maxResid);
00141     linearOpWithSolveTester.adjoint_residual_slack_warning_tol(maxResid);
00142     linearOpWithSolveTester.check_adjoint_solution_error(true);
00143     linearOpWithSolveTester.adjoint_solution_error_solve_tol(maxError);
00144     linearOpWithSolveTester.adjoint_solution_error_slack_error_tol(1e-1*maxError);
00145     linearOpWithSolveTester.adjoint_solution_error_slack_warning_tol(maxError);
00146   }
00147   linearOpWithSolveTester.num_random_vectors(numRandomVectors);
00148   linearOpWithSolveTester.show_all_tests(showAllTests);
00149   linearOpWithSolveTester.dump_all(dumpAll);
00150   result = linearOpWithSolveTester.check(*nsA,out,indentSpacer,indentSpacer);
00151   if(!result) success = false;
00152 
00153   if(out) *out << "\nF) Uninitialize the matrix object nsA, scale the epetra_A object by 2.5, and then refactor nsA with epetra_A ...\n";
00154 
00155   opFactory->uninitializeOp(&*nsA); // Optional call but a good idea if changing the operator
00156   epetra_A->Scale(2.5);
00157   opFactory->initializeOp(A,&*nsA);
00158   
00159   if(out) *out << "\nG) Testing the LinearOpBase interface of nsA ...\n";
00160 
00161   Thyra::seed_randomize<double>(0);
00162 
00163   result = linearOpTester.check(*nsA,out,indentSpacer,indentSpacer);
00164   if(!result) success = false;
00165 
00166   if(out) *out << "\nH) Testing the LinearOpWithSolveBase interface of nsA ...\n";
00167     
00168   result = linearOpWithSolveTester.check(*nsA,out,indentSpacer,indentSpacer);
00169   if(!result) success = false;
00170 
00171   if(out) *out << "\nI) Uninitialize the matrix object nsA, create a scaled (by 2.5) copy  epetra_A2 of epetra_A, and then refactor nsA with epetra_A2 ...\n";
00172 
00173   Teuchos::RefCountPtr<Epetra_CrsMatrix>
00174     epetra_A2 = Teuchos::rcp(new Epetra_CrsMatrix(*epetra_A));
00175   epetra_A2->Scale(2.5);
00176   Teuchos::RefCountPtr<LinearOpBase<double> >
00177     A2 = Teuchos::rcp(new EpetraLinearOp(epetra_A2));
00178   opFactory->initializeOp(A2,&*nsA);
00179   
00180   if(out) *out << "\nJ) Testing the LinearOpBase interface of nsA ...\n";
00181 
00182   Thyra::seed_randomize<double>(0);
00183 
00184   result = linearOpTester.check(*nsA,out,indentSpacer,indentSpacer);
00185   if(!result) success = false;
00186 
00187   if(out) *out << "\nK) Testing the LinearOpWithSolveBase interface of nsA ...\n";
00188     
00189   result = linearOpWithSolveTester.check(*nsA,out,indentSpacer,indentSpacer);
00190   if(!result) success = false;
00191 
00192   if(out) *out << "\nL) Create an implicitly scaled (by 2.5) and transposed matrix A3 = scale(2.5,transpose(A)) and initialize nsA2 ...\n";
00193 
00194   Teuchos::RefCountPtr<const LinearOpBase<double> >
00195     A3 = scale(2.5,transpose(A));
00196   Teuchos::RefCountPtr<LinearOpWithSolveBase<double> >
00197     nsA2 = createAndInitializeLinearOpWithSolve(*opFactory,A3);
00198   
00199   if(out) *out << "\nM) Testing the LinearOpBase interface of nsA2 ...\n";
00200 
00201   Thyra::seed_randomize<double>(0);
00202 
00203   result = linearOpTester.check(*nsA2,out,indentSpacer,indentSpacer);
00204   if(!result) success = false;
00205 
00206   if(out) *out << "\nN) Testing the LinearOpWithSolveBase interface of nsA2 ...\n";
00207     
00208   result = linearOpWithSolveTester.check(*nsA2,out,indentSpacer,indentSpacer);
00209   if(!result) success = false;
00210   
00211   if(out) *out << "\nO) Testing that LinearOpBase interfaces of transpose(nsA) == nsA2 ...\n";
00212 
00213   result = linearOpTester.compare(
00214     *transpose(Teuchos::rcp_implicit_cast<const LinearOpBase<double> >(nsA)),*nsA2
00215     ,out,indentSpacer,indentSpacer
00216     );
00217   if(!result) success = false;
00218 
00219 #else // __sun
00220   
00221   if(out) *out << "\nTest failed since is was not even compiled since __sun was defined!\n";
00222   success = false;
00223 
00224 #endif // __sun
00225 
00226   return success;
00227 
00228 }

Generated on Thu Sep 18 12:39:28 2008 for Amesos/Thyra Linear Solver Adapter Software by doxygen 1.3.9.1