|
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_stratimikos_solver.hpp" 00043 #include "Stratimikos_DefaultLinearSolverBuilder.hpp" 00044 #include "Thyra_EpetraLinearOp.hpp" 00045 #include "Thyra_LinearOpTester.hpp" 00046 #include "Thyra_LinearOpWithSolveTester.hpp" 00047 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp" 00048 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp" 00049 #include "EpetraExt_readEpetraLinearSystem.h" 00050 #include "Teuchos_ParameterList.hpp" 00051 00052 #ifdef HAVE_MPI 00053 # include "Epetra_MpiComm.h" 00054 #else 00055 # include "Epetra_SerialComm.h" 00056 #endif 00057 00058 bool Thyra::test_single_stratimikos_solver( 00059 Teuchos::ParameterList *paramList_inout 00060 ,const bool dumpAll 00061 ,Teuchos::FancyOStream *out 00062 ) 00063 { 00064 00065 using Teuchos::rcp; 00066 using Teuchos::RCP; 00067 using Teuchos::OSTab; 00068 using Teuchos::ParameterList; 00069 using Teuchos::getParameter; 00070 typedef double Scalar; 00071 00072 bool success = true, result = false; 00073 00074 try { 00075 00076 TEUCHOS_TEST_FOR_EXCEPT(!paramList_inout); 00077 00078 RCP<ParameterList> 00079 paramList = rcp(paramList_inout,false); 00080 00081 if(out) { 00082 *out << "\nEchoing input parameters ...\n"; 00083 paramList->print(*out,1,true,false); 00084 } 00085 00086 // Create list of valid parameter sublists 00087 Teuchos::ParameterList validParamList("test_single_stratimikos_solver"); 00088 validParamList.set("Matrix File","fileName"); 00089 validParamList.set("Solve Adjoint",false); 00090 validParamList.sublist("Linear Solver Builder").disableRecursiveValidation(); 00091 validParamList.sublist("LinearOpWithSolveTester").disableRecursiveValidation(); 00092 00093 if(out) *out << "\nValidating top-level input parameters ...\n"; 00094 paramList->validateParametersAndSetDefaults(validParamList); 00095 00096 const std::string 00097 &matrixFile = getParameter<std::string>(*paramList,"Matrix File"); 00098 const bool 00099 solveAdjoint = getParameter<bool>(*paramList,"Solve Adjoint"); 00100 RCP<ParameterList> 00101 solverBuilderSL = sublist(paramList,"Linear Solver Builder",true), 00102 lowsTesterSL = sublist(paramList,"LinearOpWithSolveTester",true); 00103 00104 if(out) *out << "\nReading in an epetra matrix A from the file \'"<<matrixFile<<"\' ...\n"; 00105 00106 #ifdef HAVE_MPI 00107 Epetra_MpiComm comm(MPI_COMM_WORLD); 00108 #else 00109 Epetra_SerialComm comm; 00110 #endif 00111 RCP<Epetra_CrsMatrix> epetra_A; 00112 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A ); 00113 00114 RCP<const LinearOpBase<double> > 00115 A = Thyra::epetraLinearOp(epetra_A); 00116 00117 if(out) *out << "\nCreating a Stratimikos::DefaultLinearSolverBuilder object ...\n"; 00118 00119 RCP<Thyra::LinearSolverBuilderBase<double> > 00120 linearSolverBuilder = rcp(new Stratimikos::DefaultLinearSolverBuilder); 00121 00122 if(out) { 00123 *out << "\nValid parameters for DefaultLinearSolverBuilder ...\n"; 00124 linearSolverBuilder->getValidParameters()->print(*out,1,true,false); 00125 } 00126 00127 linearSolverBuilder->setParameterList(solverBuilderSL); 00128 00129 if(out) *out << "\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n"; 00130 RCP<LinearOpWithSolveFactoryBase<double> > 00131 lowsFactory = createLinearSolveStrategy(*linearSolverBuilder); 00132 if(out) *out << "\nlowsFactory described as:\n" << describe(*lowsFactory,Teuchos::VERB_MEDIUM) << std::endl; 00133 00134 if(out) *out << "\nRunning example use cases for not externally preconditioned ...\n"; 00135 00136 TEUCHOS_ASSERT(out != NULL); 00137 nonExternallyPreconditionedLinearSolveUseCases( 00138 *A, *lowsFactory, solveAdjoint, *out 00139 ); 00140 00141 Thyra::LinearOpWithSolveTester<Scalar> linearOpWithSolveTester; 00142 linearOpWithSolveTester.setParameterList(lowsTesterSL); 00143 linearOpWithSolveTester.turn_off_all_tests(); 00144 linearOpWithSolveTester.check_forward_default(true); 00145 linearOpWithSolveTester.check_forward_residual(true); 00146 if (solveAdjoint) { 00147 linearOpWithSolveTester.check_adjoint_default(true); 00148 linearOpWithSolveTester.check_adjoint_residual(true); 00149 } 00150 // ToDo: Use parameter lists for the above 00151 00152 if(out) *out << "\nChecking the LOWSB interface ...\n"; 00153 RCP<Thyra::LinearOpWithSolveBase<Scalar> > 00154 lowsA = Thyra::linearOpWithSolve<Scalar>(*lowsFactory, A); 00155 result = linearOpWithSolveTester.check(*lowsA, out); 00156 if (!result) success = false; 00157 00158 if(out) { 00159 *out << "\nPrinting the parameter list (showing what was used) ...\n"; 00160 paramList->print(*out,1,true,true); 00161 } 00162 00163 } 00164 catch( const std::exception &excpt ) { 00165 std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl; 00166 success = false; 00167 } 00168 00169 return success; 00170 00171 }
1.7.6.1