43 #ifndef BELOS_STATUS_TEST_USER_OUTPUT_HPP
44 #define BELOS_STATUS_TEST_USER_OUTPUT_HPP
69 template <
class ScalarType,
class MV,
class OP>
102 taggedTests_(taggedTests),
104 headerPrinted_(false),
105 stateTest_(printStates),
144 TEUCHOS_TEST_FOR_EXCEPTION(iterTest_ == Teuchos::null,
StatusTestError,
"StatusTestUserOutput::checkStatus(): iteration test pointer is null.");
145 TEUCHOS_TEST_FOR_EXCEPTION(resTestVec_.size() == 0,
StatusTestError,
"StatusTestUserOutput::checkStatus(): residual test pointer is null.");
146 state_ = test_->checkStatus(solver);
155 currNumRHS_ = currIdx_.size();
157 numIterDgts_ = (int)std::floor(std::log10((
double)iterTest_->getMaxIters()))+1;
160 if (((iterTest_->getNumIters() % modTest_ == 0) && (iterTest_->getNumIters()!=lastNumIters_)) || (state_ ==
Passed)) {
161 lastNumIters_ = iterTest_->getNumIters();
162 if ( (state_ & stateTest_) == state_) {
166 else if ( printer_->isVerbosity(
Debug) ) {
200 Teuchos::RCP<StatusTestCombo_t> comboTest = Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(test);
201 TEUCHOS_TEST_FOR_EXCEPTION(comboTest == Teuchos::null,
StatusTestError,
"StatusTestUserOutput::setChild: The parameter \"test\" must be a Belos::StatusTestCombo.");
202 std::vector<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > > tmpVec = comboTest->getStatusTests();
205 int numTests = tmpVec.size();
208 for (
int i=0; i<numTests; ++i) {
211 Teuchos::RCP<StatusTestMaxIters_t> tmpItrTest = Teuchos::rcp_dynamic_cast<StatusTestMaxIters_t>(tmpVec[i]);
212 if (tmpItrTest != Teuchos::null) {
213 iterTest_ = tmpItrTest;
220 Teuchos::RCP<StatusTestResNorm_t> tmpResTest = Teuchos::rcp_dynamic_cast<StatusTestResNorm_t>(tmpVec[i]);
222 if (tmpResTest != Teuchos::null) {
223 resTestVec_.resize( 1 );
224 resTestVec_[0] = tmpResTest;
225 resTestNamesVec_.resize( 1 );
226 resTestNamesVec_[0] =
"IMPLICIT RES";
233 Teuchos::RCP<StatusTestCombo_t> tmpComboTest = Teuchos::rcp_dynamic_cast<StatusTestCombo_t>(tmpVec[i]);
234 TEUCHOS_TEST_FOR_EXCEPTION(tmpComboTest == Teuchos::null,
StatusTestError,
"StatusTestUserOutput(): test must be Belos::StatusTest[MaxIters|ResNorm|Combo].");
235 tmpVec = tmpComboTest->getStatusTests();
236 comboType_ = tmpComboTest->getComboType();
240 typename std::map<std::string,Teuchos::RCP<StatusTest<ScalarType,MV,OP> > >::iterator it;
241 for (
size_t j=0; j<tmpVec.size(); ++j) {
242 tmpResTest = Teuchos::rcp_dynamic_cast<StatusTestResNorm_t>(tmpVec[j]);
244 if(tmpResTest == Teuchos::null)
continue;
247 for(it = taggedTests_->begin(); it != taggedTests_->end(); ++it) {
248 if(tmpVec[j] == it->second) { bFound =
true;
break; }
251 resTestVec_.push_back(tmpResTest);
252 resTestNamesVec_.push_back(
"IMPLICIT RES");
257 for(it = taggedTests_->begin(); it != taggedTests_->end(); ++it) {
258 resTestVec_.push_back(it->second);
259 resTestNamesVec_.push_back(it->first);
270 Teuchos::RCP<StatusTest<ScalarType,MV,OP> >
getChild()
const {
276 void setSolverDesc(
const std::string& solverDesc) { solverDesc_ = solverDesc; }
280 void setPrecondDesc(
const std::string& precondDesc) { precondDesc_ = precondDesc; }
295 headerPrinted_ =
false;
310 void print(std::ostream& os,
int indent = 0)
const {
311 std::string ind(indent,
' ');
312 std::string starLine(55,
'*');
313 std::string starFront(5,
'*');
315 std::ios_base::fmtflags osFlags(os.flags());
317 os.setf(std::ios::scientific, std::ios::floatfield);
321 if (!headerPrinted_) {
322 os << std::endl << ind << starLine << std::endl;
323 os << ind << starFront <<
" Belos Iterative Solver: " << solverDesc_ << std::endl;
324 if (precondDesc_ !=
"")
325 os << ind << starFront <<
" Preconditioner: " << precondDesc_ << std::endl;
326 os << ind << starFront <<
" Maximum Iterations: " << iterTest_->getMaxIters() << std::endl;
327 os << ind << starFront <<
" Block Size: " << blockSize_ << std::endl;
328 os << ind << starFront <<
" Status tests: " << std::endl;
329 test_->print(os,indent + 3);
330 os << ind << starLine << std::endl;
331 os.setf(std::ios_base::right, std::ios_base::adjustfield);
332 std::string indheader( 7 + numIterDgts_,
' ' );
334 for (
int i=0; i<currNumRHS_; ++i) {
335 if ( i > 0 && currIdx_[i]!=-1 ) {
337 os << ind << indheader;
339 os <<
"[" << std::setw(numLSDgts_) << currIdx_[i]+1 <<
"] : ";
340 for (
size_t j=0; j<resTestVec_.size(); ++j) {
341 os << std::setw(15) << resTestNamesVec_[j];
345 headerPrinted_ =
true;
349 os.setf(std::ios_base::right, std::ios_base::adjustfield);
350 std::string ind2( 7 + numIterDgts_,
' ' );
351 os << ind <<
"Iter " << std::setw(numIterDgts_) << iterTest_->getNumIters() <<
", ";
352 for (
int i=0; i<currNumRHS_; ++i) {
353 if ( i > 0 && currIdx_[i]!=-1 ) {
357 os <<
"[" << std::setw(numLSDgts_) << currIdx_[i]+1 <<
"] : ";
358 for (
size_t j=0; j<resTestVec_.size(); ++j) {
361 Teuchos::RCP<StatusTestResNorm_t> tempResTest = Teuchos::rcp_dynamic_cast<StatusTestResNorm_t>(resTestVec_[j]);
362 if(tempResTest != Teuchos::null)
363 os << std::setw(15) << (*tempResTest->getTestValue())[currIdx_[i]];
366 os << std::setw(15) <<
"Passed";
368 os << std::setw(15) <<
"Failed";
369 else os << std::setw(15) <<
"Undefined";
372 os << std::setw(15) <<
"---";
385 Teuchos::RCP<OutputManager<ScalarType> > printer_;
388 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > test_;
391 Teuchos::RCP<std::map<std::string,Teuchos::RCP<StatusTest<ScalarType,MV,OP> > > > taggedTests_;
394 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > iterTest_;
397 std::vector<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > > resTestVec_;
400 std::vector<std::string> resTestNamesVec_;
402 std::string solverDesc_;
403 std::string precondDesc_;
404 std::vector<int> currIdx_;
406 mutable bool headerPrinted_;
407 int stateTest_, modTest_;
408 int lastNumIters_, comboType_;
410 int currNumRHS_, currLSNum_;
411 int numLSDgts_, numIterDgts_;