10 #ifndef THYRA_DEFAULT_EVALUATION_LOGGER_MODEL_EVALUATOR_HPP
11 #define THYRA_DEFAULT_EVALUATION_LOGGER_MODEL_EVALUATOR_HPP
13 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
14 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
15 #include "Teuchos_Time.hpp"
27 template<
class Scalar>
90 mutable bool headerPrinted_;
91 mutable bool supports_f_;
92 mutable bool supports_W_;
94 static const int flt_width_;
95 static const int flt_sciPrec_;
96 static const int flt_prec_;
97 static const char flt_line_[];
98 static const int int_width_;
99 static const char int_line_[];
111 template<
class Scalar>
113 template<
class Scalar>
115 template<
class Scalar>
117 template<
class Scalar>
119 template<
class Scalar>
121 template<
class Scalar>
124 template<
class Scalar>
126 :timer_(
""),headerPrinted_(false)
129 template<
class Scalar>
134 :timer_(
""),headerPrinted_(false), supports_f_(false), supports_W_(false)
139 template<
class Scalar>
147 tableOut_ = tableOut;
149 headerPrinted_ =
false;
156 template<
class Scalar>
160 thyraModel = this->getUnderlyingModel();
161 std::ostringstream oss;
162 oss <<
"Thyra::DefaultEvaluationLoggerModelEvaluator{";
163 oss <<
"thyraModel=";
165 oss <<
"\'"<<thyraModel->description()<<
"\'";
176 template<
class Scalar>
183 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
184 "Thyra::DefaultEvaluationLoggerModelEvaluator",inArgs,outArgs
187 thyraModel->evalModel(inArgs,outArgs);
189 if(!headerPrinted_) {
190 printHeader(outArgs);
191 headerPrinted_ =
true;
195 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
203 template<
class Scalar>
204 void DefaultEvaluationLoggerModelEvaluator<Scalar>::printHeader(
205 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
210 using std::setprecision;
213 typedef ModelEvaluatorBase MEB;
215 supports_f_ = outArgs.supports(MEB::OUT_ARG_f);
216 supports_W_ = outArgs.supports(MEB::OUT_ARG_W);
218 const int Ng = outArgs.Ng();
222 <<
"\n*** Table of function evaluations vs. CPU time"
226 <<
"\nModel Evaluator Description:\n" << Teuchos::describe(*
this,
Teuchos::VERB_LOW);
229 *tableOut_ <<
" " << left << setw(flt_width_) <<
"time(s)";
230 for(
int j = 0; j < Ng; ++j ) {
231 std::ostringstream oss;
232 oss <<
"||g("<<j<<
")||";
233 *tableOut_ <<
" " << left << setw(flt_width_) << oss.str();
236 *tableOut_ <<
" " << left << setw(flt_width_) <<
"||f||";
238 *tableOut_ <<
" " << left << setw(int_width_) <<
"Calc W";
241 *tableOut_ <<
" " << left << setw(flt_width_) << flt_line_;
242 for(
int j = 0; j < Ng; ++j )
243 *tableOut_ <<
" " << left << setw(flt_width_) << flt_line_;
245 *tableOut_ <<
" " << left << setw(flt_width_) << flt_line_;
247 *tableOut_ <<
" " << left << setw(int_width_) << int_line_;
252 template<
class Scalar>
253 void DefaultEvaluationLoggerModelEvaluator<Scalar>::printLine(
254 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
260 using std::setprecision;
263 const int Ng = outArgs.Ng();
265 RCP<const VectorBase<Scalar> > f, g_j;
267 *tableOut_ <<
" " << setprecision(flt_prec_) << right << setw(flt_width_) << timer_.totalElapsedTime(
true);
268 for(
int j = 0; j < Ng; ++j ) {
269 if((g_j=outArgs.get_g(j)).
get())
270 *tableOut_ <<
" " << setprecision(flt_sciPrec_) << right << setw(flt_width_) << norm(*g_j);
272 *tableOut_ <<
" " << right << setw(flt_width_) <<
"-";
275 if((f=outArgs.get_f()).
get())
276 *tableOut_ <<
" " << setprecision(flt_sciPrec_) << right << setw(flt_width_) << norm(*f);
278 *tableOut_ <<
" " << right << setw(flt_width_) <<
"-";
281 if(outArgs.get_W().get())
282 *tableOut_ <<
" " << right << setw(int_width_) <<
"1";
284 *tableOut_ <<
" " << right << setw(int_width_) <<
"-";
292 #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...