10 #include "Thyra_BelosLinearOpWithSolveFactory.hpp"
11 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
12 #include "Thyra_MultiVectorStdOps.hpp"
13 #include "Thyra_VectorBase.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "EpetraExt_readEpetraLinearSystem.h"
17 #include "Epetra_SerialComm.h"
32 const std::string matrixFileName =
"nos1.mtx";
35 RCP<const LinearOpBase<double> > getFwdLinearOp()
37 static RCP<const LinearOpBase<double> > fwdLinearOp;
40 EpetraExt::readEpetraLinearSystem( matrixFileName, Epetra_SerialComm(), &epetraCrsMatrix );
41 fwdLinearOp = epetraLinearOp(epetraCrsMatrix);
48 template<
class Scalar>
58 {
return norm_inf(v); }
73 template<
class Scalar>
74 RCP<MockNormInfReductionFunctional<Scalar> >
83 template<
class Scalar>
95 return std::max(norm_inf(v), ScalarTraits<ScalarMag>::eps());
111 template<
class Scalar>
112 RCP<MockMaxNormInfEpsReductionFunctional<Scalar> >
119 template<
class Scalar>
120 void runGeneralSolveCriteriaBelosStatusTestCase(
121 const SolveCriteria<Scalar> &solveCriteria,
122 const Ptr<
RCP<
const VectorBase<Scalar> > > &x_out,
123 const Ptr<
RCP<
const VectorBase<Scalar> > > &r_out,
129 using Teuchos::describe;
using Teuchos::optInArg;
using Teuchos::rcpFromRef;
132 typedef ScalarTraits<Scalar>
ST;
139 V_S(b.
ptr(), ST::one());
144 out <<
"\nsolveCriteria:\n" << solveCriteria;
150 const int convergenceTestFrequency = 10;
153 "<ParameterList name=\"Belos\">"
154 " <Parameter name=\"Solver Type\" type=\"string\" value=\"Pseudo Block GMRES\"/>"
155 " <Parameter name=\"Convergence Test Frequency\" type=\"int\" value=\""+
toString(convergenceTestFrequency)+
"\"/>"
156 " <ParameterList name=\"Solver Types\">"
157 " <ParameterList name=\"Pseudo Block GMRES\">"
158 " <Parameter name=\"Block Size\" type=\"int\" value=\"1\"/>"
159 " <Parameter name=\"Convergence Tolerance\" type=\"double\" value=\"1e-13\"/>"
160 " <Parameter name=\"Output Frequency\" type=\"int\" value=\""+
toString(convergenceTestFrequency)+
"\"/>"
161 " <Parameter name=\"Show Maximum Residual Norm Only\" type=\"bool\" value=\"1\"/>"
162 " <Parameter name=\"Maximum Iterations\" type=\"int\" value=\"400\"/>"
163 " <Parameter name=\"Verbosity\" type=\"int\" value=\"1\"/>"
168 out <<
"\n\npl:\n" << *pl;
172 lowsFactory.setOStream(rcpFromRef(out));
184 V_S(x.ptr(), ST::zero());
185 SolveStatus<Scalar> solveStatus = solve<Scalar>(*lows,
NOTRANS, *b, x.
ptr(),
186 optInArg(solveCriteria));
187 out <<
"\nsolveStatus:\n" << solveStatus;
189 TEST_COMPARE( solveStatus.achievedTol, <=, solveCriteria.requestedTol );
194 fwdOp->apply(NOTRANS, *x, r.
ptr(), ST::one(), -ST::one());
208 TEUCHOS_UNIT_TEST( GeneralSolveCriteriaBelosStatusTest, norm_inf_r_over_norm_inf_r0 )
211 using Teuchos::outArg;
213 typedef double Scalar;
214 typedef ScalarTraits<Scalar>
ST;
215 typedef ST::magnitudeType ScalarMag;
217 SolveCriteria<Scalar> solveCriteria;
218 solveCriteria.solveMeasureType.numerator = SOLVE_MEASURE_NORM_RESIDUAL;
219 solveCriteria.numeratorReductionFunc = createMockNormReductionFunctional<Scalar>();
220 solveCriteria.solveMeasureType.denominator = SOLVE_MEASURE_NORM_SOLUTION;
221 solveCriteria.denominatorReductionFunc = createMockMaxNormInfEpsReductionFunctional<Scalar>();
222 solveCriteria.requestedTol = 0.9;
224 RCP<const VectorBase<Scalar> > x, r;
225 runGeneralSolveCriteriaBelosStatusTestCase(solveCriteria, outArg(x), outArg(r),
228 out <<
"\nChecking convergence ...\n\n";
230 const ScalarMag r_nrm_inf = norm_inf(*r);
231 const ScalarMag x_nrm_inf = norm_inf(*x);
233 out <<
"||r||inf = " << r_nrm_inf <<
"\n";
234 out <<
"||x||inf = " << x_nrm_inf <<
"\n";
236 TEST_COMPARE( r_nrm_inf / x_nrm_inf, <=, solveCriteria.requestedTol );
244 using Teuchos::outArg;
246 typedef double Scalar;
247 typedef ScalarTraits<Scalar>
ST;
248 typedef ST::magnitudeType ScalarMag;
250 SolveCriteria<Scalar> solveCriteria;
251 solveCriteria.solveMeasureType.numerator = SOLVE_MEASURE_NORM_RESIDUAL;
252 solveCriteria.numeratorReductionFunc = createMockNormReductionFunctional<Scalar>();
253 solveCriteria.solveMeasureType.denominator = SOLVE_MEASURE_ONE;
254 solveCriteria.requestedTol = 0.9;
256 RCP<const VectorBase<Scalar> > x, r;
257 runGeneralSolveCriteriaBelosStatusTestCase(solveCriteria, outArg(x), outArg(r),
260 out <<
"\nChecking convergence ...\n\n";
262 const ScalarMag r_nrm_inf = norm_inf(*r);
263 const ScalarMag x_nrm_inf = norm_inf(*x);
265 out <<
"||r||inf = " << r_nrm_inf <<
"\n";
266 out <<
"||x||inf = " << x_nrm_inf <<
"\n";
268 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)