10 #ifndef THYRA_GENERAL_SOLVE_CRITERIA_BELOS_STATUS_TEST_DEF_HPP
11 #define THYRA_GENERAL_SOLVE_CRITERIA_BELOS_STATUS_TEST_DEF_HPP
13 #include "Thyra_GeneralSolveCriteriaBelosStatusTest.hpp"
14 #include "Thyra_VectorSpaceBase.hpp"
15 #include "Thyra_MultiVectorBase.hpp"
16 #include "Thyra_VectorBase.hpp"
17 #include "Thyra_MultiVectorStdOps.hpp"
18 #include "Thyra_VectorStdOps.hpp"
20 #include "Teuchos_DebugDefaultAsserts.hpp"
21 #include "Teuchos_VerbosityLevel.hpp"
22 #include "Teuchos_as.hpp"
31 template<
class Scalar>
33 :convergenceTestFrequency_(-1),
43 template<
class Scalar>
46 const int convergenceTestFrequency
51 typedef ScalarTraits<ScalarMag> SMT;
62 solveCriteria_ = solveCriteria;
63 convergenceTestFrequency_ = convergenceTestFrequency;
69 compute_x_ = (compute_r_ ||
75 template<
class Scalar>
76 ArrayView<const typename ScalarTraits<Scalar>::magnitudeType>
79 return lastAchievedTol_;
86 template <
class Scalar>
99 const int currIter = iSolver->getNumIters();
101 if (currIter == 0 || currIter % convergenceTestFrequency_ != 0) {
110 const int numRhs = lp.
getRHS()->domain()->dim();
125 RCP<MV> X_update = iSolver->getCurrentUpdate();
132 R = createMembers(lp.
getOperator()->range(), X->domain());
138 lastNumerator_.resize(numRhs);
139 lastDenominator_.resize(numRhs);
141 for (
int j = 0; j < numRhs; ++j) {
144 lastNumerator_[j] = computeReductionFunctional(
145 solveCriteria_.solveMeasureType.numerator,
146 solveCriteria_.numeratorReductionFunc.ptr(),
148 lastDenominator_[j] = computeReductionFunctional(
149 solveCriteria_.solveMeasureType.denominator,
150 solveCriteria_.denominatorReductionFunc.ptr(),
156 bool systemsAreConverged =
true;
157 lastAchievedTol_.resize(numRhs);
159 for (
int j = 0; j < numRhs; ++j) {
160 const ScalarMag convRatio = lastNumerator_[j] / lastDenominator_[j];
161 lastAchievedTol_[j] = convRatio;
162 const bool sys_converged_j = (convRatio <= solveCriteria_.requestedTol);
164 printRhsStatus(currIter, j, *out);
166 if (!sys_converged_j) {
167 systemsAreConverged =
false;
172 lastCurrIter_ = currIter;
174 return lastRtnStatus_;
178 template <
class Scalar>
182 return lastRtnStatus_;
186 template <
class Scalar>
191 lastNumerator_.clear();
192 lastDenominator_.clear();
193 lastAchievedTol_.clear();
199 template <
class Scalar>
201 std::ostream& os,
int indent
204 const int numRhs = lastNumerator_.size();
205 for (
int j = 0; j < numRhs; ++j) {
206 printRhsStatus(lastCurrIter_, j, os, indent);
214 template <
class Scalar>
223 typedef ScalarTraits<ScalarMag> SMT;
224 ScalarMag rtn = -SMT::one();
225 Ptr<const VectorBase<Scalar> > v;
226 switch(measureType) {
239 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "ToDo: Handle ||b||!)");
242 if (rtn >= SMT::zero()) {
245 else if (
nonnull(v) && rtn < SMT::zero()) {
247 rtn = reductFunc->reduce(*v);
258 template <
class Scalar>
260 GeneralSolveCriteriaBelosStatusTest<Scalar>::printRhsStatus(
261 const int currIter,
const int j, std::ostream &out,
265 const ScalarMag convRatio = lastNumerator_[j] / lastDenominator_[j];
266 const bool sys_converged_j = (convRatio <= solveCriteria_.requestedTol);
267 for (
int i = 0; i < indent; ++i) { out <<
" "; }
269 <<
"["<<currIter<<
"] "
270 <<
"gN(vN("<<j<<
"))/gD(vD("<<j<<
")) = "
271 << lastNumerator_[j] <<
"/" << lastDenominator_[j] <<
" = "
272 << convRatio <<
" <= " << solveCriteria_.requestedTol <<
" : "
273 << (sys_converged_j ?
" true" :
"false")
281 #endif // THYRA_GENERAL_SOLVE_CRITERIA_BELOS_STATUS_TEST_DEF_HPP
GeneralSolveCriteriaBelosStatusTest()
Subclass of Belos::StatusTest that implements every possible form of SolveCriteria that exists by for...
ArrayView< const ScalarMag > achievedTol() const
#define TEUCHOS_SWITCH_DEFAULT_DEBUG_ASSERT()
bool contains(ESolveMeasureNormType measure) const
virtual Teuchos::RCP< MV > updateSolution(const Teuchos::RCP< MV > &update=Teuchos::null, bool updateLP=false, ScalarType scale=Teuchos::ScalarTraits< ScalarType >::one())
virtual Belos::StatusType getStatus() const
#define TEUCHOS_ASSERT_INEQUALITY(val1, comp, val2)
Teuchos::RCP< const MV > getRHS() const
Thyra specializations of MultiVecTraits and OperatorTraits.
virtual Belos::StatusType checkStatus(Belos::Iteration< Scalar, MV, OP > *iSolver)
ESolveMeasureNormType numerator
Teuchos::RCP< const OP > getOperator() const
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
#define TEUCHOS_IF_ELSE_DEBUG_ASSERT()
ScalarTraits< Scalar >::magnitudeType ScalarMag
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
bool nonnull(const boost::shared_ptr< T > &p)
virtual void computeCurrResVec(MV *R, const MV *X=0, const MV *B=0) const
RCP< const ReductionFunctional< Scalar > > numeratorReductionFunc
void setSolveCriteria(const SolveCriteria< Scalar > &solveCriteria, const int convergenceTestFrequency)
TypeTo as(const TypeFrom &t)
RCP< const ReductionFunctional< Scalar > > denominatorReductionFunc
SolveMeasureType solveMeasureType
#define TEUCHOS_ASSERT(assertion_test)
virtual void print(std::ostream &os, int indent) const