31 template<
class ScalarType,
class FactoryType,
class SolverBaseType,
class SolverImplType>
37 using Teuchos::parameterList;
40 using Teuchos::rcp_dynamic_cast;
43 typedef ScalarType ST;
44 typedef SolverBaseType solver_base_type;
45 typedef SolverImplType solver_impl_type;
46 typedef FactoryType factory_type;
49 const bool testOutputFreq =
false;
52 out <<
"Test Belos::SolverFactory::create for solver \"" << solverName <<
"\"" << endl;
55 out <<
"ScalarType: " << TypeNameTraits<ScalarType>::name () << endl
56 <<
"FactoryType: " << TypeNameTraits<FactoryType>::name () << endl
57 <<
"SolverBaseType: " << TypeNameTraits<SolverBaseType>::name () << endl
58 <<
"SolverImplType: " << TypeNameTraits<SolverImplType>::name () << endl;
60 RCP<factory_type> pFactory;
61 RCP<solver_base_type> solver;
63 out <<
"Test whether creating a Belos::SolverFactory works" << endl;
65 pFactory =
rcp (
new factory_type ());
67 catch (std::exception& e) {
68 out <<
"Belos::SolverFactory constructor threw an exception: "
74 out <<
"Belos::SolverFactory constructor threw an exception not a subclass "
75 "of std::exception" << endl;
79 factory_type& factory = *pFactory;
81 out <<
"Test whether factory works when input ParameterList is null" << endl;
86 if (! solver.is_null ()) {
88 RCP<solver_impl_type> solverImpl = rcp_dynamic_cast<solver_impl_type> (solver);
92 out <<
"Test whether factory works when input ParameterList is nonnull" << endl;
96 RCP<ParameterList> plist = parameterList (
"Belos");
98 const int maxNumIters = 42;
101 const int outputFreq = 3;
104 plist->set (
"Convergence Tolerance", tol);
105 plist->set (
"Maximum Iterations", maxNumIters);
106 plist->set (
"Verbosity", verbosity);
107 plist->set (
"Output Style", outputStyle);
108 if (testOutputFreq) {
109 plist->set (
"Output Frequency", outputFreq);
111 TEST_ASSERT( ! plist->getEntry (
"Convergence Tolerance").isUsed () );
112 TEST_ASSERT( ! plist->getEntry (
"Maximum Iterations").isUsed () );
113 TEST_ASSERT( ! plist->getEntry (
"Verbosity").isUsed () );
114 TEST_ASSERT( ! plist->getEntry (
"Output Style").isUsed () );
115 if (testOutputFreq) {
116 TEST_ASSERT( ! plist->getEntry (
"Output Frequency").isUsed () );
119 out <<
"Input ParameterList: " << endl;
126 solver = factory.create (solverName, plist);
128 if (! solver.is_null ()) {
130 RCP<solver_impl_type> solverImpl = rcp_dynamic_cast<solver_impl_type> (solver);
134 TEST_ASSERT( plist->getEntry (
"Convergence Tolerance").isUsed () );
135 TEST_ASSERT( plist->getEntry (
"Maximum Iterations").isUsed () );
136 TEST_ASSERT( plist->getEntry (
"Verbosity").isUsed () );
137 TEST_ASSERT( plist->getEntry (
"Output Style").isUsed () );
138 if (testOutputFreq) {
139 TEST_ASSERT( plist->getEntry (
"Output Frequency").isUsed () );
143 RCP<const ParameterList> curParams = solver->getCurrentParameters ();
145 if (! curParams.is_null ()) {
148 TEST_NOTHROW( curTol = curParams->get<MT> (
"Convergence Tolerance") );
150 int curMaxNumIters = 0;
151 TEST_NOTHROW( curMaxNumIters = curParams->get<
int> (
"Maximum Iterations") );
153 int curVerbosity = 0;
154 TEST_NOTHROW( curVerbosity = curParams->get<
int> (
"Verbosity") );
156 int curOutputStyle = 0;
157 TEST_NOTHROW( curOutputStyle = curParams->get<
int> (
"Output Style") );
159 if (testOutputFreq) {
160 int curOutputFreq = 0;
161 TEST_NOTHROW( curOutputFreq = curParams->get<
int> (
"Output Frequency") );
179 #define BELOS_TEST_SOLVER( SOLVER_NAME ) \
181 const std::string solverName (SOLVER_NAME); \
183 bool curSuccess = true; \
184 testSolver<ST, factory_type, solver_base_type, solver_impl_type> (curSuccess, out, solverName); \
185 if (! curSuccess) { \
186 failedSolvers.push_back (solverName); \
188 success = success && curSuccess; \
189 } catch (std::exception& e) { \
190 out << "*** Solver \"" << solverName << "\" threw an exception: " \
191 << e.what () << std::endl; \
193 failedSolvers.push_back (solverName); \
211 out <<
"Test for Bug 6383" << endl;
215 std::vector<std::string> failedSolvers;
288 out << endl <<
"Test SUCCEEDED!" << endl;
291 out << endl <<
"Test FAILED!" << endl
292 <<
"Solvers that failed: [";
293 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
294 out <<
"\"" << failedSolvers[k] <<
"\"";
295 if (k + 1 < failedSolvers.size ()) {
303 out << endl <<
"*** Solvers that failed: ";
305 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
306 out <<
"\"" << failedSolvers[k] <<
"\"";
307 if (k + 1 < failedSolvers.size ()) {
327 out <<
"Test for Bug 6383" << endl;
331 std::vector<std::string> failedSolvers;
404 out << endl <<
"Test SUCCEEDED!" << endl;
407 out << endl <<
"Test FAILED!" << endl
408 <<
"Solvers that failed: [";
409 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
410 out <<
"\"" << failedSolvers[k] <<
"\"";
411 if (k + 1 < failedSolvers.size ()) {
419 out << endl <<
"*** Solvers that failed: ";
421 for (
size_t k = 0; k < failedSolvers.size (); ++k) {
422 out <<
"\"" << failedSolvers[k] <<
"\"";
423 if (k + 1 < failedSolvers.size ()) {
#define TEST_NOTHROW(code)
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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...
#define TEST_EQUALITY(v1, v2)
typename::Belos::Impl::SolverFactorySelector< SC, MV, OP >::type SolverFactory