Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_tpetra_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 
11 #include "Tpetra_Core.hpp"
12 #include "Tpetra_CrsMatrix.hpp"
15 #include "Thyra_LinearOpTester.hpp"
16 #include "Thyra_LinearOpWithSolveTester.hpp"
17 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
18 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
19 #include "MatrixMarket_Tpetra.hpp"
21 
23  Teuchos::ParameterList *paramList_inout
24  ,const bool dumpAll
26  )
27 {
28 
29  using Teuchos::rcp;
30  using Teuchos::RCP;
31  using Teuchos::OSTab;
33  using Teuchos::getParameter;
34  typedef double Scalar;
35  typedef Tpetra::Map<>::local_ordinal_type LO;
36  typedef Tpetra::Map<>::global_ordinal_type GO;
37  typedef Tpetra::Map<>::node_type NO;
38 
39  bool success = true, result = false;
40 
41  try {
42 
43  TEUCHOS_TEST_FOR_EXCEPT(!paramList_inout);
44 
46  paramList = rcp(paramList_inout,false);
47 
48  if(out) {
49  *out << "\nEchoing input parameters ...\n";
50  paramList->print(*out,1,true,false);
51  }
52 
53  // Create list of valid parameter sublists
54  Teuchos::ParameterList validParamList("test_tpetra_stratimikos_solver");
55  validParamList.set("Matrix File","fileName");
56  validParamList.set("Solve Adjoint",false);
57  validParamList.sublist("Linear Solver Builder").disableRecursiveValidation();
58  validParamList.sublist("LinearOpWithSolveTester").disableRecursiveValidation();
59 
60  if(out) *out << "\nValidating top-level input parameters ...\n";
61  paramList->validateParametersAndSetDefaults(validParamList);
62 
63  const std::string
64  &matrixFile = getParameter<std::string>(*paramList,"Matrix File");
65  const bool
66  solveAdjoint = getParameter<bool>(*paramList,"Solve Adjoint");
68  solverBuilderSL = sublist(paramList,"Linear Solver Builder",true),
69  lowsTesterSL = sublist(paramList,"LinearOpWithSolveTester",true);
70 
71  if(out) *out << "\nReading in an tpetra matrix A from the file \'"<<matrixFile<<"\' ...\n";
72 
73  RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
74  RCP<const Tpetra::CrsMatrix<Scalar, LO, GO, NO>> tpetra_A = Tpetra::MatrixMarket::Reader<Tpetra::CrsMatrix<Scalar, LO, GO, NO>>::readSparseFile( matrixFile, comm );
75 
77  A = Thyra::createConstLinearOp(Teuchos::rcp_dynamic_cast<const Tpetra::Operator<Scalar,LO,GO,NO>>(tpetra_A));
78 
79  if(out) *out << "\nCreating a Stratimikos::DefaultLinearSolverBuilder object ...\n";
80 
82  linearSolverBuilder = rcp(new Stratimikos::DefaultLinearSolverBuilder);
83 
84  if(out) {
85  *out << "\nValid parameters for DefaultLinearSolverBuilder ...\n";
86  linearSolverBuilder->getValidParameters()->print(*out,1,true,false);
87  }
88 
89  linearSolverBuilder->setParameterList(solverBuilderSL);
90 
91  if(out) *out << "\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n";
93  lowsFactory = createLinearSolveStrategy(*linearSolverBuilder);
94  if(out) *out << "\nlowsFactory described as:\n" << describe(*lowsFactory,Teuchos::VERB_MEDIUM) << std::endl;
95 
96  if(out) *out << "\nRunning example use cases for not externally preconditioned ...\n";
97 
98  TEUCHOS_ASSERT(out != NULL);
99  nonExternallyPreconditionedLinearSolveUseCases(
100  *A, *lowsFactory, solveAdjoint, *out
101  );
102 
103  Thyra::LinearOpWithSolveTester<Scalar> linearOpWithSolveTester;
104  linearOpWithSolveTester.setParameterList(lowsTesterSL);
105  linearOpWithSolveTester.turn_off_all_tests();
106  linearOpWithSolveTester.check_forward_default(true);
107  linearOpWithSolveTester.check_forward_residual(true);
108  if (solveAdjoint) {
109  linearOpWithSolveTester.check_adjoint_default(true);
110  linearOpWithSolveTester.check_adjoint_residual(true);
111  }
112  // ToDo: Use parameter lists for the above
113 
114  if(out) *out << "\nChecking the LOWSB interface ...\n";
116  lowsA = Thyra::linearOpWithSolve<Scalar>(*lowsFactory, A);
117  result = linearOpWithSolveTester.check(*lowsA, out);
118  if (!result) success = false;
119 
120  if(out) {
121  *out << "\nPrinting the parameter list (showing what was used) ...\n";
122  paramList->print(*out,1,true,true);
123  }
124 
125  }
126  catch( const std::exception &excpt ) {
127  std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
128  success = false;
129  }
130 
131  return success;
132 
133 }
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
RCP< const LinearOpBase< Scalar > > createConstLinearOp(const RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool test_tpetra_stratimikos_solver(Teuchos::ParameterList *paramList, const bool dumpAll, Teuchos::FancyOStream *out)
Testing function for a single tpetra stratimikos solver for a single matrix.
Concrete subclass of Thyra::LinearSolverBuilderBase for creating Thyra::LinearOpWithSolveFactoryBase ...
#define TEUCHOS_ASSERT(assertion_test)
map_type::local_ordinal_type LO
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
map_type::global_ordinal_type GO