44 #include "Thyra_BelosLinearOpWithSolveFactory.hpp"
45 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
46 #include "Thyra_MultiVectorStdOps.hpp"
47 #include "Thyra_VectorBase.hpp"
48 #include "Thyra_VectorStdOps.hpp"
50 #include "EpetraExt_readEpetraLinearSystem.h"
51 #include "Epetra_SerialComm.h"
66 const std::string matrixFileName =
"nos1.mtx";
69 RCP<const LinearOpBase<double> > getFwdLinearOp()
71 static RCP<const LinearOpBase<double> > fwdLinearOp;
74 EpetraExt::readEpetraLinearSystem( matrixFileName, Epetra_SerialComm(), &epetraCrsMatrix );
75 fwdLinearOp = epetraLinearOp(epetraCrsMatrix);
82 template<
class Scalar>
92 {
return norm_inf(v); }
107 template<
class Scalar>
108 RCP<MockNormInfReductionFunctional<Scalar> >
117 template<
class Scalar>
129 return std::max(norm_inf(v), ScalarTraits<ScalarMag>::eps());
145 template<
class Scalar>
146 RCP<MockMaxNormInfEpsReductionFunctional<Scalar> >
153 template<
class Scalar>
154 void runGeneralSolveCriteriaBelosStatusTestCase(
155 const SolveCriteria<Scalar> &solveCriteria,
156 const Ptr<
RCP<
const VectorBase<Scalar> > > &x_out,
157 const Ptr<
RCP<
const VectorBase<Scalar> > > &r_out,
163 using Teuchos::describe;
using Teuchos::optInArg;
using Teuchos::rcpFromRef;
166 typedef ScalarTraits<Scalar>
ST;
167 typedef typename ST::magnitudeType ScalarMag;
174 V_S(b.
ptr(), ST::one());
179 out <<
"\nsolveCriteria:\n" << solveCriteria;
185 const int convergenceTestFrequency = 10;
188 "<ParameterList name=\"Belos\">"
189 " <Parameter name=\"Solver Type\" type=\"string\" value=\"Pseudo Block GMRES\"/>"
190 " <Parameter name=\"Convergence Test Frequency\" type=\"int\" value=\""+
toString(convergenceTestFrequency)+
"\"/>"
191 " <ParameterList name=\"Solver Types\">"
192 " <ParameterList name=\"Pseudo Block GMRES\">"
193 " <Parameter name=\"Block Size\" type=\"int\" value=\"1\"/>"
194 " <Parameter name=\"Convergence Tolerance\" type=\"double\" value=\"1e-13\"/>"
195 " <Parameter name=\"Output Frequency\" type=\"int\" value=\""+
toString(convergenceTestFrequency)+
"\"/>"
196 " <Parameter name=\"Show Maximum Residual Norm Only\" type=\"bool\" value=\"1\"/>"
197 " <Parameter name=\"Maximum Iterations\" type=\"int\" value=\"400\"/>"
198 " <Parameter name=\"Verbosity\" type=\"int\" value=\"1\"/>"
203 out <<
"\n\npl:\n" << *pl;
207 lowsFactory.setOStream(rcpFromRef(out));
219 V_S(x.ptr(), ST::zero());
220 SolveStatus<Scalar> solveStatus = solve<Scalar>(*lows,
NOTRANS, *b, x.
ptr(),
221 optInArg(solveCriteria));
222 out <<
"\nsolveStatus:\n" << solveStatus;
224 TEST_COMPARE( solveStatus.achievedTol, <=, solveCriteria.requestedTol );
229 fwdOp->apply(NOTRANS, *x, r.
ptr(), ST::one(), -ST::one());
243 TEUCHOS_UNIT_TEST( GeneralSolveCriteriaBelosStatusTest, norm_inf_r_over_norm_inf_r0 )
246 using Teuchos::outArg;
248 typedef double Scalar;
249 typedef ScalarTraits<Scalar>
ST;
250 typedef ST::magnitudeType ScalarMag;
252 SolveCriteria<Scalar> solveCriteria;
253 solveCriteria.solveMeasureType.numerator = SOLVE_MEASURE_NORM_RESIDUAL;
254 solveCriteria.numeratorReductionFunc = createMockNormReductionFunctional<Scalar>();
255 solveCriteria.solveMeasureType.denominator = SOLVE_MEASURE_NORM_SOLUTION;
256 solveCriteria.denominatorReductionFunc = createMockMaxNormInfEpsReductionFunctional<Scalar>();
257 solveCriteria.requestedTol = 0.9;
259 RCP<const VectorBase<Scalar> > x, r;
260 runGeneralSolveCriteriaBelosStatusTestCase(solveCriteria, outArg(x), outArg(r),
263 out <<
"\nChecking convergence ...\n\n";
265 const ScalarMag r_nrm_inf = norm_inf(*r);
266 const ScalarMag x_nrm_inf = norm_inf(*x);
268 out <<
"||r||inf = " << r_nrm_inf <<
"\n";
269 out <<
"||x||inf = " << x_nrm_inf <<
"\n";
271 TEST_COMPARE( r_nrm_inf / x_nrm_inf, <=, solveCriteria.requestedTol );
279 using Teuchos::outArg;
281 typedef double Scalar;
282 typedef ScalarTraits<Scalar>
ST;
283 typedef ST::magnitudeType ScalarMag;
285 SolveCriteria<Scalar> solveCriteria;
286 solveCriteria.solveMeasureType.numerator = SOLVE_MEASURE_NORM_RESIDUAL;
287 solveCriteria.numeratorReductionFunc = createMockNormReductionFunctional<Scalar>();
288 solveCriteria.solveMeasureType.denominator = SOLVE_MEASURE_ONE;
289 solveCriteria.requestedTol = 0.9;
291 RCP<const VectorBase<Scalar> > x, r;
292 runGeneralSolveCriteriaBelosStatusTestCase(solveCriteria, outArg(x), outArg(r),
295 out <<
"\nChecking convergence ...\n\n";
297 const ScalarMag r_nrm_inf = norm_inf(*r);
298 const ScalarMag x_nrm_inf = norm_inf(*x);
300 out <<
"||r||inf = " << r_nrm_inf <<
"\n";
301 out <<
"||x||inf = " << x_nrm_inf <<
"\n";
303 TEST_COMPARE( r_nrm_inf, <=, solveCriteria.requestedTol );
virtual bool isCompatibleImpl(const VectorBase< Scalar > &v) const
const std::string toString(const EAdjointEpetraOp adjointEpetraOp)
bool is_null(const boost::shared_ptr< T > &p)
RCP< MockNormInfReductionFunctional< Scalar > > createMockNormReductionFunctional()
Non-member constructor.
virtual bool isCompatibleImpl(const VectorBase< Scalar > &v) const
TEUCHOS_UNIT_TEST(EpetraOperatorWrapper, basic)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Mock max(NormInf, eps) ReductionFunctional subclass used for unit testing.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::string toString(const HashSet< Key > &h)
Mock NormInf ReductionFunctional subclass used for unit testing.
LinearOpWithSolveFactoryBase subclass implemented in terms of Belos.
virtual ScalarTraits< Scalar >::magnitudeType reduceImpl(const VectorBase< Scalar > &v) const
basic_FancyOStream< char > FancyOStream
RCP< MockMaxNormInfEpsReductionFunctional< Scalar > > createMockMaxNormInfEpsReductionFunctional()
Non-member constructor.
virtual ScalarTraits< Scalar >::magnitudeType reduceImpl(const VectorBase< Scalar > &v) const
#define TEST_COMPARE(v1, comp, v2)