42 #include "Teuchos_UnitTestHarness.hpp" 43 #include "Teuchos_CommandLineProcessor.hpp" 63 template<
class ScalarType,
class FactoryType,
class SolverBaseType,
class SolverImplType>
65 testSolver (
bool& success, Teuchos::FancyOStream& out,
const std::string& solverName)
67 using Teuchos::ParameterEntry;
68 using Teuchos::ParameterList;
69 using Teuchos::parameterList;
72 using Teuchos::rcp_dynamic_cast;
73 using Teuchos::TypeNameTraits;
75 typedef ScalarType ST;
76 typedef SolverBaseType solver_base_type;
77 typedef SolverImplType solver_impl_type;
78 typedef FactoryType factory_type;
79 typedef typename Teuchos::ScalarTraits<ST>::magnitudeType MT;
81 const bool testOutputFreq =
false;
83 Teuchos::OSTab tab0 (out);
84 out <<
"Test Belos::SolverFactory::create for solver \"" << solverName <<
"\"" << endl;
85 Teuchos::OSTab tab1 (out);
87 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
88 <<
"FactoryType: " << TypeNameTraits<FactoryType>::name () << endl
89 <<
"SolverBaseType: " << TypeNameTraits<SolverBaseType>::name () << endl
90 <<
"SolverImplType: " << TypeNameTraits<SolverImplType>::name () << endl;
92 RCP<factory_type> pFactory;
93 RCP<solver_base_type> solver;
95 out <<
"Test whether creating a Belos::SolverFactory works" << endl;
97 pFactory = rcp (
new factory_type ());
99 catch (std::exception& e) {
100 out <<
"Belos::SolverFactory constructor threw an exception: " 101 << e.what () << endl;
106 out <<
"Belos::SolverFactory constructor threw an exception not a subclass " 107 "of std::exception" << endl;
111 factory_type& factory = *pFactory;
113 out <<
"Test whether factory works when input ParameterList is null" << endl;
116 TEST_NOTHROW( solver = factory.create (solverName, Teuchos::null) );
117 TEST_ASSERT( ! solver.is_null () );
118 if (! solver.is_null ()) {
120 RCP<solver_impl_type> solverImpl = rcp_dynamic_cast<solver_impl_type> (solver);
121 TEST_ASSERT( ! solverImpl.is_null () );
124 out <<
"Test whether factory works when input ParameterList is nonnull" << endl;
128 RCP<ParameterList> plist = parameterList (
"Belos");
130 const int maxNumIters = 42;
133 const int outputFreq = 3;
136 plist->set (
"Convergence Tolerance", tol);
137 plist->set (
"Maximum Iterations", maxNumIters);
138 plist->set (
"Verbosity", verbosity);
139 plist->set (
"Output Style", outputStyle);
140 if (testOutputFreq) {
141 plist->set (
"Output Frequency", outputFreq);
143 TEST_ASSERT( ! plist->getEntry (
"Convergence Tolerance").isUsed () );
144 TEST_ASSERT( ! plist->getEntry (
"Maximum Iterations").isUsed () );
145 TEST_ASSERT( ! plist->getEntry (
"Verbosity").isUsed () );
146 TEST_ASSERT( ! plist->getEntry (
"Output Style").isUsed () );
147 if (testOutputFreq) {
148 TEST_ASSERT( ! plist->getEntry (
"Output Frequency").isUsed () );
151 out <<
"Input ParameterList: " << endl;
153 Teuchos::OSTab tab2 (out);
158 solver = factory.create (solverName, plist);
159 TEST_ASSERT( ! solver.is_null () );
160 if (! solver.is_null ()) {
162 RCP<solver_impl_type> solverImpl = rcp_dynamic_cast<solver_impl_type> (solver);
163 TEST_ASSERT( ! solverImpl.is_null () );
166 TEST_ASSERT( plist->getEntry (
"Convergence Tolerance").isUsed () );
167 TEST_ASSERT( plist->getEntry (
"Maximum Iterations").isUsed () );
168 TEST_ASSERT( plist->getEntry (
"Verbosity").isUsed () );
169 TEST_ASSERT( plist->getEntry (
"Output Style").isUsed () );
170 if (testOutputFreq) {
171 TEST_ASSERT( plist->getEntry (
"Output Frequency").isUsed () );
175 RCP<const ParameterList> curParams = solver->getCurrentParameters ();
176 TEST_ASSERT( ! curParams.is_null () );
177 if (! curParams.is_null ()) {
179 MT curTol = Teuchos::ScalarTraits<MT>::zero ();
180 TEST_NOTHROW( curTol = curParams->get<MT> (
"Convergence Tolerance") );
181 TEST_EQUALITY( curTol, tol );
182 int curMaxNumIters = 0;
183 TEST_NOTHROW( curMaxNumIters = curParams->get<
int> (
"Maximum Iterations") );
184 TEST_EQUALITY( curMaxNumIters, maxNumIters );
185 int curVerbosity = 0;
186 TEST_NOTHROW( curVerbosity = curParams->get<
int> (
"Verbosity") );
187 TEST_EQUALITY( curVerbosity, verbosity );
188 int curOutputStyle = 0;
189 TEST_NOTHROW( curOutputStyle = curParams->get<
int> (
"Output Style") );
190 TEST_EQUALITY( curOutputStyle, outputStyle );
191 if (testOutputFreq) {
192 int curOutputFreq = 0;
193 TEST_NOTHROW( curOutputFreq = curParams->get<
int> (
"Output Frequency") );
194 TEST_EQUALITY( curOutputFreq, outputFreq );
211 #define BELOS_TEST_SOLVER( SOLVER_NAME ) \ 213 const std::string solverName (SOLVER_NAME); \ 215 bool curSuccess = true; \ 216 testSolver<ST, factory_type, solver_base_type, solver_impl_type> (curSuccess, out, solverName); \ 217 if (! curSuccess) { \ 218 failedSolvers.push_back (solverName); \ 220 success = success && curSuccess; \ 221 } catch (std::exception& e) { \ 222 out << "*** Solver \"" << solverName << "\" threw an exception: " \ 223 << e.what () << std::endl; \ 225 failedSolvers.push_back (solverName); \ 242 Teuchos::OSTab tab0 (out);
243 out <<
"Test for Bug 6383" << endl;
244 Teuchos::OSTab tab1 (out);
247 std::vector<std::string> failedSolvers;
320 out << endl <<
"Test SUCCEEDED!" << endl;
323 out << endl <<
"Test FAILED!" << endl
324 <<
"Solvers that failed: [";
325 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
326 out <<
"\"" << failedSolvers[k] <<
"\"";
327 if (k + 1 < failedSolvers.size ()) {
335 out << endl <<
"*** Solvers that failed: ";
337 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
338 out <<
"\"" << failedSolvers[k] <<
"\"";
339 if (k + 1 < failedSolvers.size ()) {
358 Teuchos::OSTab tab0 (out);
359 out <<
"Test for Bug 6383" << endl;
360 Teuchos::OSTab tab1 (out);
363 std::vector<std::string> failedSolvers;
436 out << endl <<
"Test SUCCEEDED!" << endl;
439 out << endl <<
"Test FAILED!" << endl
440 <<
"Solvers that failed: [";
441 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
442 out <<
"\"" << failedSolvers[k] <<
"\"";
443 if (k + 1 < failedSolvers.size ()) {
451 out << endl <<
"*** Solvers that failed: ";
453 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
454 out <<
"\"" << failedSolvers[k] <<
"\"";
455 if (k + 1 < failedSolvers.size ()) {
The Belos::FixedPointSolMgr provides a powerful and fully-featured solver manager over the FixedPoint...
The Belos::PseudoBlockCGSolMgr provides a solver manager for the BlockCG linear solver.
Implementation of the RCG (Recycling Conjugate Gradient) iterative linear solver. ...
The Belos::BlockCGSolMgr provides a powerful and fully-featured solver manager over the CG and BlockC...
The Belos::FixedPointSolMgr provides a solver manager for the FixedPoint linear solver.
Declaration and definition of Belos::PCPGSolMgr (PCPG iterative linear solver).
Interface to Block GMRES and Flexible GMRES.
#define BELOS_TEST_SOLVER(SOLVER_NAME)
TEUCHOS_UNIT_TEST(Factory, Bug6383)
The Belos::PseudoBlockCGSolMgr provides a powerful and fully-featured solver manager over the pseudo-...
Declaration and definition of Belos::GCRODRSolMgr, which implements the GCRODR (recycling GMRES) solv...
Alternative run-time polymorphic interface for operators.
The Belos::BlockGmresSolMgr provides a solver manager for the BlockGmres linear solver.
The Belos::BiCGStabSolMgr provides a solver manager for the BiCGStab linear solver.
Class which describes the linear problem to be solved by the iterative solver.
void testSolver(bool &success, Teuchos::FancyOStream &out, const std::string &solverName)
Implementation of the GCRODR (Recycling GMRES) iterative linear solver.
Interface to standard and "pseudoblock" GMRES.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
The Belos::BlockCGSolMgr provides a solver manager for the BlockCG linear solver. ...
LSQRSolMgr: interface to the LSQR method.
The Belos::BiCGStabSolMgr provides a powerful and fully-featured solver manager over the pseudo-block...
PCPG iterative linear solver.
Interface for multivectors used by Belos' linear solvers.
LSQR method (for linear systems and linear least-squares problems).
The Belos::RCGSolMgr provides a solver manager for the RCG (Recycling Conjugate Gradient) linear solv...
The Belos::PseudoBlockGmresSolMgr provides a solver manager for the BlockGmres linear solver...
typename ::Belos::Impl::SolverFactorySelector< SC, MV, OP >::type SolverFactory