Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_epetra_stratimikos_solver.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stratimikos: Thyra-based strategies for linear solvers
4 //
5 // Copyright 2006 NTESS and the Stratimikos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 #include "Thyra_EpetraLinearOp.hpp"
13 #include "Thyra_LinearOpTester.hpp"
14 #include "Thyra_LinearOpWithSolveTester.hpp"
15 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
16 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
17 #include "EpetraExt_readEpetraLinearSystem.h"
19 
20 #ifdef HAVE_MPI
21 # include "Epetra_MpiComm.h"
22 #else
23 # include "Epetra_SerialComm.h"
24 #endif
25 
27  Teuchos::ParameterList *paramList_inout
28  ,const bool dumpAll
30  )
31 {
32 
33  using Teuchos::rcp;
34  using Teuchos::RCP;
35  using Teuchos::OSTab;
37  using Teuchos::getParameter;
38  typedef double Scalar;
39 
40  bool success = true, result = false;
41 
42  try {
43 
44  TEUCHOS_TEST_FOR_EXCEPT(!paramList_inout);
45 
47  paramList = rcp(paramList_inout,false);
48 
49  if(out) {
50  *out << "\nEchoing input parameters ...\n";
51  paramList->print(*out,1,true,false);
52  }
53 
54  // Create list of valid parameter sublists
55  Teuchos::ParameterList validParamList("test_epetra_stratimikos_solver");
56  validParamList.set("Matrix File","fileName");
57  validParamList.set("Solve Adjoint",false);
58  validParamList.sublist("Linear Solver Builder").disableRecursiveValidation();
59  validParamList.sublist("LinearOpWithSolveTester").disableRecursiveValidation();
60 
61  if(out) *out << "\nValidating top-level input parameters ...\n";
62  paramList->validateParametersAndSetDefaults(validParamList);
63 
64  const std::string
65  &matrixFile = getParameter<std::string>(*paramList,"Matrix File");
66  const bool
67  solveAdjoint = getParameter<bool>(*paramList,"Solve Adjoint");
69  solverBuilderSL = sublist(paramList,"Linear Solver Builder",true),
70  lowsTesterSL = sublist(paramList,"LinearOpWithSolveTester",true);
71 
72  if(out) *out << "\nReading in an epetra matrix A from the file \'"<<matrixFile<<"\' ...\n";
73 
74 #ifdef HAVE_MPI
75  Epetra_MpiComm comm(MPI_COMM_WORLD);
76 #else
77  Epetra_SerialComm comm;
78 #endif
79  RCP<Epetra_CrsMatrix> epetra_A;
80  EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
81 
83  A = Thyra::epetraLinearOp(epetra_A);
84 
85  if(out) *out << "\nCreating a Stratimikos::DefaultLinearSolverBuilder object ...\n";
86 
88  linearSolverBuilder = rcp(new Stratimikos::DefaultLinearSolverBuilder);
89 
90  if(out) {
91  *out << "\nValid parameters for DefaultLinearSolverBuilder ...\n";
92  linearSolverBuilder->getValidParameters()->print(*out,1,true,false);
93  }
94 
95  linearSolverBuilder->setParameterList(solverBuilderSL);
96 
97  if(out) *out << "\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n";
99  lowsFactory = createLinearSolveStrategy(*linearSolverBuilder);
100  if(out) *out << "\nlowsFactory described as:\n" << describe(*lowsFactory,Teuchos::VERB_MEDIUM) << std::endl;
101 
102  if(out) *out << "\nRunning example use cases for not externally preconditioned ...\n";
103 
104  TEUCHOS_ASSERT(out != NULL);
105  nonExternallyPreconditionedLinearSolveUseCases(
106  *A, *lowsFactory, solveAdjoint, *out
107  );
108 
109  Thyra::LinearOpWithSolveTester<Scalar> linearOpWithSolveTester;
110  linearOpWithSolveTester.setParameterList(lowsTesterSL);
111  linearOpWithSolveTester.turn_off_all_tests();
112  linearOpWithSolveTester.check_forward_default(true);
113  linearOpWithSolveTester.check_forward_residual(true);
114  if (solveAdjoint) {
115  linearOpWithSolveTester.check_adjoint_default(true);
116  linearOpWithSolveTester.check_adjoint_residual(true);
117  }
118  // ToDo: Use parameter lists for the above
119 
120  if(out) *out << "\nChecking the LOWSB interface ...\n";
122  lowsA = Thyra::linearOpWithSolve<Scalar>(*lowsFactory, A);
123  result = linearOpWithSolveTester.check(*lowsA, out);
124  if (!result) success = false;
125 
126  if(out) {
127  *out << "\nPrinting the parameter list (showing what was used) ...\n";
128  paramList->print(*out,1,true,true);
129  }
130 
131  }
132  catch( const std::exception &excpt ) {
133  std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
134  success = false;
135  }
136 
137  return success;
138 
139 }
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool test_epetra_stratimikos_solver(Teuchos::ParameterList *paramList, const bool dumpAll, Teuchos::FancyOStream *out)
Testing function for a single epetra stratimikos solver for a single matrix.
Concrete subclass of Thyra::LinearSolverBuilderBase for creating Thyra::LinearOpWithSolveFactoryBase ...
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)