Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_single_stratimikos_solver.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stratimikos: Thyra-based strategies for linear solvers
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
44 #include "Thyra_EpetraLinearOp.hpp"
45 #include "Thyra_LinearOpTester.hpp"
46 #include "Thyra_LinearOpWithSolveTester.hpp"
47 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
48 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
49 #include "EpetraExt_readEpetraLinearSystem.h"
51 
52 #ifdef HAVE_MPI
53 # include "Epetra_MpiComm.h"
54 #else
55 # include "Epetra_SerialComm.h"
56 #endif
57 
59  Teuchos::ParameterList *paramList_inout
60  ,const bool dumpAll
62  )
63 {
64 
65  using Teuchos::rcp;
66  using Teuchos::RCP;
67  using Teuchos::OSTab;
69  using Teuchos::getParameter;
70  typedef double Scalar;
71 
72  bool success = true, result = false;
73 
74  try {
75 
76  TEUCHOS_TEST_FOR_EXCEPT(!paramList_inout);
77 
79  paramList = rcp(paramList_inout,false);
80 
81  if(out) {
82  *out << "\nEchoing input parameters ...\n";
83  paramList->print(*out,1,true,false);
84  }
85 
86  // Create list of valid parameter sublists
87  Teuchos::ParameterList validParamList("test_single_stratimikos_solver");
88  validParamList.set("Matrix File","fileName");
89  validParamList.set("Solve Adjoint",false);
90  validParamList.sublist("Linear Solver Builder").disableRecursiveValidation();
91  validParamList.sublist("LinearOpWithSolveTester").disableRecursiveValidation();
92 
93  if(out) *out << "\nValidating top-level input parameters ...\n";
94  paramList->validateParametersAndSetDefaults(validParamList);
95 
96  const std::string
97  &matrixFile = getParameter<std::string>(*paramList,"Matrix File");
98  const bool
99  solveAdjoint = getParameter<bool>(*paramList,"Solve Adjoint");
101  solverBuilderSL = sublist(paramList,"Linear Solver Builder",true),
102  lowsTesterSL = sublist(paramList,"LinearOpWithSolveTester",true);
103 
104  if(out) *out << "\nReading in an epetra matrix A from the file \'"<<matrixFile<<"\' ...\n";
105 
106 #ifdef HAVE_MPI
107  Epetra_MpiComm comm(MPI_COMM_WORLD);
108 #else
109  Epetra_SerialComm comm;
110 #endif
111  RCP<Epetra_CrsMatrix> epetra_A;
112  EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
113 
115  A = Thyra::epetraLinearOp(epetra_A);
116 
117  if(out) *out << "\nCreating a Stratimikos::DefaultLinearSolverBuilder object ...\n";
118 
120  linearSolverBuilder = rcp(new Stratimikos::DefaultLinearSolverBuilder);
121 
122  if(out) {
123  *out << "\nValid parameters for DefaultLinearSolverBuilder ...\n";
124  linearSolverBuilder->getValidParameters()->print(*out,1,true,false);
125  }
126 
127  linearSolverBuilder->setParameterList(solverBuilderSL);
128 
129  if(out) *out << "\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n";
131  lowsFactory = createLinearSolveStrategy(*linearSolverBuilder);
132  if(out) *out << "\nlowsFactory described as:\n" << describe(*lowsFactory,Teuchos::VERB_MEDIUM) << std::endl;
133 
134  if(out) *out << "\nRunning example use cases for not externally preconditioned ...\n";
135 
136  TEUCHOS_ASSERT(out != NULL);
137  nonExternallyPreconditionedLinearSolveUseCases(
138  *A, *lowsFactory, solveAdjoint, *out
139  );
140 
141  Thyra::LinearOpWithSolveTester<Scalar> linearOpWithSolveTester;
142  linearOpWithSolveTester.setParameterList(lowsTesterSL);
143  linearOpWithSolveTester.turn_off_all_tests();
144  linearOpWithSolveTester.check_forward_default(true);
145  linearOpWithSolveTester.check_forward_residual(true);
146  if (solveAdjoint) {
147  linearOpWithSolveTester.check_adjoint_default(true);
148  linearOpWithSolveTester.check_adjoint_residual(true);
149  }
150  // ToDo: Use parameter lists for the above
151 
152  if(out) *out << "\nChecking the LOWSB interface ...\n";
154  lowsA = Thyra::linearOpWithSolve<Scalar>(*lowsFactory, A);
155  result = linearOpWithSolveTester.check(*lowsA, out);
156  if (!result) success = false;
157 
158  if(out) {
159  *out << "\nPrinting the parameter list (showing what was used) ...\n";
160  paramList->print(*out,1,true,true);
161  }
162 
163  }
164  catch( const std::exception &excpt ) {
165  std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
166  success = false;
167  }
168 
169  return success;
170 
171 }
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Concrete subclass of Thyra::LinearSolverBuilderBase for creating LinearOpWithSolveFactoryBase objects...
bool test_single_stratimikos_solver(Teuchos::ParameterList *paramList, const bool dumpAll, Teuchos::FancyOStream *out)
Testing function for a single stratimikos solver for a single matrix.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)