42 #ifndef THYRA_DEFAULT_EVALUATION_LOGGER_MODEL_EVALUATOR_HPP
43 #define THYRA_DEFAULT_EVALUATION_LOGGER_MODEL_EVALUATOR_HPP
45 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
46 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
47 #include "Teuchos_Time.hpp"
59 template<
class Scalar>
122 mutable bool headerPrinted_;
123 mutable bool supports_f_;
124 mutable bool supports_W_;
126 static const int flt_width_;
127 static const int flt_sciPrec_;
128 static const int flt_prec_;
129 static const char flt_line_[];
130 static const int int_width_;
131 static const char int_line_[];
143 template<
class Scalar>
145 template<
class Scalar>
147 template<
class Scalar>
149 template<
class Scalar>
151 template<
class Scalar>
153 template<
class Scalar>
156 template<
class Scalar>
158 :timer_(
""),headerPrinted_(false)
161 template<
class Scalar>
166 :timer_(
""),headerPrinted_(false), supports_f_(false), supports_W_(false)
171 template<
class Scalar>
179 tableOut_ = tableOut;
181 headerPrinted_ =
false;
188 template<
class Scalar>
192 thyraModel = this->getUnderlyingModel();
193 std::ostringstream oss;
194 oss <<
"Thyra::DefaultEvaluationLoggerModelEvaluator{";
195 oss <<
"thyraModel=";
197 oss <<
"\'"<<thyraModel->description()<<
"\'";
208 template<
class Scalar>
215 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
216 "Thyra::DefaultEvaluationLoggerModelEvaluator",inArgs,outArgs
219 thyraModel->evalModel(inArgs,outArgs);
221 if(!headerPrinted_) {
222 printHeader(outArgs);
223 headerPrinted_ =
true;
227 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
235 template<
class Scalar>
236 void DefaultEvaluationLoggerModelEvaluator<Scalar>::printHeader(
237 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
242 using std::setprecision;
245 typedef ModelEvaluatorBase MEB;
247 supports_f_ = outArgs.supports(MEB::OUT_ARG_f);
248 supports_W_ = outArgs.supports(MEB::OUT_ARG_W);
250 const int Ng = outArgs.Ng();
254 <<
"\n*** Table of function evaluations vs. CPU time"
258 <<
"\nModel Evaluator Description:\n" << Teuchos::describe(*
this,
Teuchos::VERB_LOW);
261 *tableOut_ <<
" " << left << setw(flt_width_) <<
"time(s)";
262 for(
int j = 0; j < Ng; ++j ) {
263 std::ostringstream oss;
264 oss <<
"||g("<<j<<
")||";
265 *tableOut_ <<
" " << left << setw(flt_width_) << oss.str();
268 *tableOut_ <<
" " << left << setw(flt_width_) <<
"||f||";
270 *tableOut_ <<
" " << left << setw(int_width_) <<
"Calc W";
273 *tableOut_ <<
" " << left << setw(flt_width_) << flt_line_;
274 for(
int j = 0; j < Ng; ++j )
275 *tableOut_ <<
" " << left << setw(flt_width_) << flt_line_;
277 *tableOut_ <<
" " << left << setw(flt_width_) << flt_line_;
279 *tableOut_ <<
" " << left << setw(int_width_) << int_line_;
284 template<
class Scalar>
285 void DefaultEvaluationLoggerModelEvaluator<Scalar>::printLine(
286 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
292 using std::setprecision;
295 const int Ng = outArgs.Ng();
297 RCP<const VectorBase<Scalar> > f, g_j;
299 *tableOut_ <<
" " << setprecision(flt_prec_) << right << setw(flt_width_) << timer_.totalElapsedTime(
true);
300 for(
int j = 0; j < Ng; ++j ) {
301 if((g_j=outArgs.get_g(j)).
get())
302 *tableOut_ <<
" " << setprecision(flt_sciPrec_) << right << setw(flt_width_) << norm(*g_j);
304 *tableOut_ <<
" " << right << setw(flt_width_) <<
"-";
307 if((f=outArgs.get_f()).
get())
308 *tableOut_ <<
" " << setprecision(flt_sciPrec_) << right << setw(flt_width_) << norm(*f);
310 *tableOut_ <<
" " << right << setw(flt_width_) <<
"-";
313 if(outArgs.get_W().get())
314 *tableOut_ <<
" " << right << setw(int_width_) <<
"1";
316 *tableOut_ <<
" " << right << setw(int_width_) <<
"-";
324 #endif // THYRA_DEFAULT_EVALUATION_LOGGER_MODEL_EVALUATOR_HPP
Pure abstract base interface for evaluating a stateless "model" that can be mapped into a number of d...
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
This is a base class that delegetes almost all function to a wrapped model evaluator object...
void initialize(const RCP< ModelEvaluator< Scalar > > &model)
Initialize given a non-const model evaluator.
DefaultEvaluationLoggerModelEvaluator()
void initialize(const RCP< ModelEvaluator< Scalar > > &thyraModel, const RCP< std::ostream > &tableOut)
Initalize.
std::string description() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This class wraps any ModelEvaluator object and logs the evaluation of various functions.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...