|
Stratimikos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Stratimikos: Thyra-based strategies for linear solvers 00005 // Copyright (2006) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "test_single_amesos_thyra_solver.hpp" 00043 00044 #ifndef SUN_CXX 00045 00046 #include "Thyra_AmesosLinearOpWithSolveFactory.hpp" 00047 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp" 00048 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp" 00049 #include "Thyra_DefaultScaledAdjointLinearOp.hpp" 00050 #include "Thyra_DefaultInverseLinearOp.hpp" 00051 #include "Thyra_EpetraLinearOp.hpp" 00052 #include "Thyra_LinearOpTester.hpp" 00053 #include "Thyra_LinearOpWithSolveTester.hpp" 00054 #include "EpetraExt_readEpetraLinearSystem.h" 00055 #include "Epetra_SerialComm.h" 00056 00057 #endif // SUN_CXX 00058 00059 bool Thyra::test_single_amesos_thyra_solver( 00060 const std::string matrixFile 00061 ,Teuchos::ParameterList *amesosLOWSFPL 00062 ,const bool testTranspose_in 00063 ,const int numRandomVectors 00064 ,const double maxFwdError 00065 ,const double maxError 00066 ,const double maxResid 00067 ,const bool showAllTests 00068 ,const bool dumpAll 00069 ,Teuchos::FancyOStream *out_arg 00070 ) 00071 { 00072 00073 using Teuchos::RCP; 00074 using Teuchos::OSTab; 00075 00076 bool result, success = true; 00077 00078 RCP<Teuchos::FancyOStream> 00079 out = Teuchos::rcp(out_arg,false); 00080 00081 #ifndef SUN_CXX 00082 00083 if(out.get()) { 00084 *out 00085 << "\n***" 00086 << "\n*** Testing Thyra::AmesosLinearOpWithSolveFactory (and Thyra::AmesosLinearOpWithSolve)" 00087 << "\n***\n" 00088 << "\nEchoing input options:" 00089 << "\n matrixFile = " << matrixFile 00090 << "\n testTranspose = " << testTranspose_in 00091 << "\n numRandomVectors = " << numRandomVectors 00092 << "\n maxFwdError = " << maxFwdError 00093 << "\n maxError = " << maxError 00094 << "\n maxResid = " << maxResid 00095 << "\n showAllTests = " << showAllTests 00096 << "\n dumpAll = " << dumpAll 00097 << std::endl; 00098 if(amesosLOWSFPL) { 00099 OSTab tab(out); 00100 *out 00101 << "amesosLOWSFPL:\n"; 00102 amesosLOWSFPL->print(OSTab(out).o(),0,true); 00103 } 00104 } 00105 00106 if(out.get()) *out << "\nA) Reading in an epetra matrix A from the file \'"<<matrixFile<<"\' ...\n"; 00107 00108 Epetra_SerialComm comm; 00109 RCP<Epetra_CrsMatrix> epetra_A; 00110 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A ); 00111 00112 RCP<const LinearOpBase<double> > 00113 A = Thyra::epetraLinearOp(epetra_A); 00114 00115 if(out.get() && dumpAll) *out << "\ndescribe(A) =\n" << describe(*A,Teuchos::VERB_EXTREME); 00116 00117 if(out.get()) *out << "\nB) Creating a AmesosLinearOpWithSolveFactory object lowsFactory ...\n"; 00118 00119 RCP<LinearOpWithSolveFactoryBase<double> > 00120 lowsFactory = Teuchos::rcp(new AmesosLinearOpWithSolveFactory()); 00121 00122 lowsFactory->setParameterList(Teuchos::rcp(amesosLOWSFPL,false)); 00123 00124 if(out.get()) { 00125 *out << "\nlowsFactory.description() = " << lowsFactory->description() << std::endl; 00126 *out << "\nlowsFactory.getValidParameters() =\n"; 00127 lowsFactory->getValidParameters()->print(OSTab(out).o(),0,true,false); 00128 } 00129 00130 if(out.get()) *out << "\nC) Creating a AmesosLinearOpWithSolve object nsA ...\n"; 00131 00132 RCP<LinearOpWithSolveBase<double> > 00133 nsA = lowsFactory->createOp(); 00134 00135 initializeOp<double>(*lowsFactory, A, nsA.ptr()); 00136 00137 bool testTranspose = testTranspose_in; 00138 if (testTranspose_in && !Thyra::solveSupports(*nsA, Thyra::CONJTRANS)) { 00139 if(out.get()) *out 00140 << "\nChanging testTranspose=false since " 00141 << nsA->description() << " does not support adjoint solves!\n"; 00142 testTranspose = false; 00143 } 00144 00145 if(out.get()) *out << "\nD) Testing the LinearOpBase interface of nsA ...\n"; 00146 00147 Thyra::seed_randomize<double>(0); 00148 00149 LinearOpTester<double> linearOpTester; 00150 linearOpTester.check_adjoint(testTranspose); 00151 linearOpTester.num_random_vectors(numRandomVectors); 00152 linearOpTester.set_all_error_tol(maxFwdError); 00153 linearOpTester.set_all_warning_tol(1e-2*maxFwdError); 00154 linearOpTester.show_all_tests(showAllTests); 00155 linearOpTester.dump_all(dumpAll); 00156 result = linearOpTester.check(*nsA,out()); 00157 if(!result) success = false; 00158 00159 if(out.get()) *out << "\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n"; 00160 00161 LinearOpWithSolveTester<double> linearOpWithSolveTester; 00162 linearOpWithSolveTester.turn_off_all_tests(); 00163 linearOpWithSolveTester.check_forward_default(true); 00164 linearOpWithSolveTester.forward_default_residual_error_tol(1.1*maxResid); 00165 linearOpWithSolveTester.forward_default_residual_warning_tol(2.0*maxResid); 00166 linearOpWithSolveTester.check_forward_residual(true); 00167 linearOpWithSolveTester.forward_residual_solve_tol(maxResid); 00168 linearOpWithSolveTester.forward_residual_slack_error_tol(1e-1*maxResid); 00169 linearOpWithSolveTester.forward_residual_slack_warning_tol(maxResid); 00170 linearOpWithSolveTester.check_adjoint_default(testTranspose); 00171 linearOpWithSolveTester.adjoint_default_residual_error_tol(1.1*maxResid); 00172 linearOpWithSolveTester.adjoint_default_residual_warning_tol(2.0*maxResid); 00173 linearOpWithSolveTester.check_adjoint_residual(testTranspose); 00174 linearOpWithSolveTester.adjoint_residual_solve_tol(maxResid); 00175 linearOpWithSolveTester.adjoint_residual_slack_error_tol(1e-1*maxResid); 00176 linearOpWithSolveTester.adjoint_residual_slack_warning_tol(maxResid); 00177 linearOpWithSolveTester.num_random_vectors(numRandomVectors); 00178 linearOpWithSolveTester.show_all_tests(showAllTests); 00179 linearOpWithSolveTester.dump_all(dumpAll); 00180 00181 LinearOpWithSolveTester<double> adjLinearOpWithSolveTester(linearOpWithSolveTester); 00182 adjLinearOpWithSolveTester.check_forward_default(testTranspose); 00183 adjLinearOpWithSolveTester.check_forward_residual(testTranspose); 00184 00185 result = linearOpWithSolveTester.check(*nsA,out.get()); 00186 if(!result) success = false; 00187 00188 if(out.get()) *out << "\nF) Uninitialize the matrix object nsA, scale the epetra_A object by 2.5, and then refactor nsA with epetra_A ...\n"; 00189 00190 uninitializeOp<double>(*lowsFactory, nsA.ptr()); // Optional call but a good idea if changing the operator 00191 epetra_A->Scale(2.5); 00192 initializeOp<double>(*lowsFactory, A, nsA.ptr()); 00193 00194 if(out.get()) *out << "\nG) Testing the LinearOpBase interface of nsA ...\n"; 00195 00196 Thyra::seed_randomize<double>(0); 00197 00198 result = linearOpTester.check(*nsA, out()); 00199 if(!result) success = false; 00200 00201 if(out.get()) *out << "\nH) Testing the LinearOpWithSolveBase interface of nsA ...\n"; 00202 00203 result = linearOpWithSolveTester.check(*nsA,out.get()); 00204 if(!result) success = false; 00205 00206 if(out.get()) *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"; 00207 00208 RCP<Epetra_CrsMatrix> 00209 epetra_A2 = Teuchos::rcp(new Epetra_CrsMatrix(*epetra_A)); 00210 epetra_A2->Scale(2.5); 00211 RCP<const LinearOpBase<double> > 00212 A2 = Thyra::epetraLinearOp(epetra_A2); 00213 initializeOp<double>(*lowsFactory, A2, nsA.ptr()); 00214 00215 if(out.get()) *out << "\nJ) Testing the LinearOpBase interface of nsA ...\n"; 00216 00217 Thyra::seed_randomize<double>(0); 00218 00219 result = linearOpTester.check(*nsA, out()); 00220 if(!result) success = false; 00221 00222 if(out.get()) *out << "\nK) Testing the LinearOpWithSolveBase interface of nsA ...\n"; 00223 00224 result = linearOpWithSolveTester.check(*nsA, out.get()); 00225 if(!result) success = false; 00226 00227 if(out.get()) *out << "\nL) Create an implicitly scaled (by 2.5) and transposed matrix A3 = scale(2.5,transpose(A)) and initialize nsA2 ...\n"; 00228 00229 RCP<const LinearOpBase<double> > 00230 A3 = scale<double>(2.5,Thyra::transpose<double>(A)); 00231 RCP<LinearOpWithSolveBase<double> > 00232 nsA2 = linearOpWithSolve(*lowsFactory,A3); 00233 00234 if(out.get()) *out << "\nM) Testing the LinearOpBase interface of nsA2 ...\n"; 00235 00236 Thyra::seed_randomize<double>(0); 00237 00238 result = linearOpTester.check(*nsA2,out()); 00239 if(!result) success = false; 00240 00241 if(out.get()) *out << "\nN) Testing the LinearOpWithSolveBase interface of nsA2 ...\n"; 00242 00243 result = adjLinearOpWithSolveTester.check(*nsA2,out.get()); 00244 if(!result) success = false; 00245 00246 if(out.get()) *out << "\nO) Testing that LinearOpBase interfaces of transpose(nsA) == nsA2 ...\n"; 00247 00248 result = linearOpTester.compare( 00249 *transpose(Teuchos::rcp_implicit_cast<const LinearOpBase<double> >(nsA)),*nsA2 00250 ,out() 00251 ); 00252 if(!result) success = false; 00253 00254 if(out.get()) *out << "\nP) Running example use cases ...\n"; 00255 00256 nonExternallyPreconditionedLinearSolveUseCases( 00257 *A,*lowsFactory,true,*out 00258 ); 00259 00260 if(out.get()) *out << "\nQ) Creating a DefaultInverseLinearOp object from nsA and testing the LinearOpBase interface ...\n"; 00261 00262 RCP<const LinearOpBase<double> > 00263 invA = inverse<double>(nsA.getConst()); 00264 00265 result = linearOpTester.check(*invA,out()); 00266 if(!result) success = false; 00267 00268 #else // SUN_CXX 00269 00270 if(out.get()) *out << "\nTest failed since is was not even compiled since SUN_CXX was defined!\n"; 00271 success = false; 00272 00273 #endif // SUN_CXX 00274 00275 return success; 00276 00277 }
1.7.6.1