65testSolver (
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 );