63 template<
class ScalarType,
class FactoryType,
class SolverBaseType,
class SolverImplType>
69 using Teuchos::parameterList;
72 using Teuchos::rcp_dynamic_cast;
75 typedef ScalarType ST;
76 typedef SolverBaseType solver_base_type;
77 typedef SolverImplType solver_impl_type;
78 typedef FactoryType factory_type;
81 const bool testOutputFreq =
false;
84 out <<
"Test Belos::SolverFactory::create for solver \"" << solverName <<
"\"" << endl;
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;
118 if (! solver.is_null ()) {
120 RCP<solver_impl_type> solverImpl = rcp_dynamic_cast<solver_impl_type> (solver);
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;
158 solver = factory.create (solverName, plist);
160 if (! solver.is_null ()) {
162 RCP<solver_impl_type> solverImpl = rcp_dynamic_cast<solver_impl_type> (solver);
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 ();
177 if (! curParams.is_null ()) {
180 TEST_NOTHROW( curTol = curParams->get<MT> (
"Convergence Tolerance") );
182 int curMaxNumIters = 0;
183 TEST_NOTHROW( curMaxNumIters = curParams->get<
int> (
"Maximum Iterations") );
185 int curVerbosity = 0;
186 TEST_NOTHROW( curVerbosity = curParams->get<
int> (
"Verbosity") );
188 int curOutputStyle = 0;
189 TEST_NOTHROW( curOutputStyle = curParams->get<
int> (
"Output Style") );
191 if (testOutputFreq) {
192 int curOutputFreq = 0;
193 TEST_NOTHROW( curOutputFreq = curParams->get<
int> (
"Output Frequency") );
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); \
243 out <<
"Test for Bug 6383" << endl;
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 ()) {
#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