Stratimikos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
test_tpetra_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
43#include "Tpetra_Core.hpp"
44#include "Tpetra_CrsMatrix.hpp"
46#include "Thyra_TpetraThyraWrappers.hpp"
47#include "Thyra_LinearOpTester.hpp"
48#include "Thyra_LinearOpWithSolveTester.hpp"
49#include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
50#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
51#include "MatrixMarket_Tpetra.hpp"
52#include "Teuchos_ParameterList.hpp"
53
55 Teuchos::ParameterList *paramList_inout
56 ,const bool dumpAll
57 ,Teuchos::FancyOStream *out
58 )
59{
60
61 using Teuchos::rcp;
62 using Teuchos::RCP;
63 using Teuchos::OSTab;
64 using Teuchos::ParameterList;
65 using Teuchos::getParameter;
66 typedef double Scalar;
67 typedef Tpetra::Map<>::local_ordinal_type LO;
68 typedef Tpetra::Map<>::global_ordinal_type GO;
69 typedef Tpetra::Map<>::node_type NO;
70
71 bool success = true, result = false;
72
73 try {
74
75 TEUCHOS_TEST_FOR_EXCEPT(!paramList_inout);
76
77 RCP<ParameterList>
78 paramList = rcp(paramList_inout,false);
79
80 if(out) {
81 *out << "\nEchoing input parameters ...\n";
82 paramList->print(*out,1,true,false);
83 }
84
85 // Create list of valid parameter sublists
86 Teuchos::ParameterList validParamList("test_tpetra_stratimikos_solver");
87 validParamList.set("Matrix File","fileName");
88 validParamList.set("Solve Adjoint",false);
89 validParamList.sublist("Linear Solver Builder").disableRecursiveValidation();
90 validParamList.sublist("LinearOpWithSolveTester").disableRecursiveValidation();
91
92 if(out) *out << "\nValidating top-level input parameters ...\n";
93 paramList->validateParametersAndSetDefaults(validParamList);
94
95 const std::string
96 &matrixFile = getParameter<std::string>(*paramList,"Matrix File");
97 const bool
98 solveAdjoint = getParameter<bool>(*paramList,"Solve Adjoint");
99 RCP<ParameterList>
100 solverBuilderSL = sublist(paramList,"Linear Solver Builder",true),
101 lowsTesterSL = sublist(paramList,"LinearOpWithSolveTester",true);
102
103 if(out) *out << "\nReading in an tpetra matrix A from the file \'"<<matrixFile<<"\' ...\n";
104
105 RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
106 RCP<const Tpetra::CrsMatrix<Scalar, LO, GO, NO>> tpetra_A = Tpetra::MatrixMarket::Reader<Tpetra::CrsMatrix<Scalar, LO, GO, NO>>::readSparseFile( matrixFile, comm );
107
108 RCP<const LinearOpBase<double> >
109 A = Thyra::createConstLinearOp(Teuchos::rcp_dynamic_cast<const Tpetra::Operator<Scalar,LO,GO,NO>>(tpetra_A));
110
111 if(out) *out << "\nCreating a Stratimikos::DefaultLinearSolverBuilder object ...\n";
112
113 RCP<Thyra::LinearSolverBuilderBase<double> >
114 linearSolverBuilder = rcp(new Stratimikos::DefaultLinearSolverBuilder);
115
116 if(out) {
117 *out << "\nValid parameters for DefaultLinearSolverBuilder ...\n";
118 linearSolverBuilder->getValidParameters()->print(*out,1,true,false);
119 }
120
121 linearSolverBuilder->setParameterList(solverBuilderSL);
122
123 if(out) *out << "\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n";
124 RCP<LinearOpWithSolveFactoryBase<double> >
125 lowsFactory = createLinearSolveStrategy(*linearSolverBuilder);
126 if(out) *out << "\nlowsFactory described as:\n" << describe(*lowsFactory,Teuchos::VERB_MEDIUM) << std::endl;
127
128 if(out) *out << "\nRunning example use cases for not externally preconditioned ...\n";
129
130 TEUCHOS_ASSERT(out != NULL);
131 nonExternallyPreconditionedLinearSolveUseCases(
132 *A, *lowsFactory, solveAdjoint, *out
133 );
134
135 Thyra::LinearOpWithSolveTester<Scalar> linearOpWithSolveTester;
136 linearOpWithSolveTester.setParameterList(lowsTesterSL);
137 linearOpWithSolveTester.turn_off_all_tests();
138 linearOpWithSolveTester.check_forward_default(true);
139 linearOpWithSolveTester.check_forward_residual(true);
140 if (solveAdjoint) {
141 linearOpWithSolveTester.check_adjoint_default(true);
142 linearOpWithSolveTester.check_adjoint_residual(true);
143 }
144 // ToDo: Use parameter lists for the above
145
146 if(out) *out << "\nChecking the LOWSB interface ...\n";
147 RCP<Thyra::LinearOpWithSolveBase<Scalar> >
148 lowsA = Thyra::linearOpWithSolve<Scalar>(*lowsFactory, A);
149 result = linearOpWithSolveTester.check(*lowsA, out);
150 if (!result) success = false;
151
152 if(out) {
153 *out << "\nPrinting the parameter list (showing what was used) ...\n";
154 paramList->print(*out,1,true,true);
155 }
156
157 }
158 catch( const std::exception &excpt ) {
159 std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
160 success = false;
161 }
162
163 return success;
164
165}
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.
LinearSolverBuilder< double > DefaultLinearSolverBuilder
map_type::global_ordinal_type GO
map_type::local_ordinal_type LO