Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_ModelEvaluatorDelegatorBase.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
11 #define THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
12 
13 
14 #include "Thyra_ModelEvaluatorDefaultBase.hpp"
15 #include "Teuchos_ConstNonconstObjectContainer.hpp"
16 #include "Teuchos_TimeMonitor.hpp"
17 #include "Teuchos_StandardParameterEntryValidators.hpp"
18 
19 
20 namespace Thyra {
21 
22 
49 template<class Scalar>
51  : virtual public ModelEvaluatorDefaultBase<Scalar>
52 {
53 public:
54 
57 
60 
63  const RCP<ModelEvaluator<Scalar> > &model
64  );
65 
68  const RCP<const ModelEvaluator<Scalar> > &model
69  );
70 
72  void initialize(
73  const RCP<ModelEvaluator<Scalar> > &model
74  );
75 
77  void initialize(
78  const RCP<const ModelEvaluator<Scalar> > &model
79  );
80 
82  void uninitialize();
83 
85 
88 
90  virtual bool isUnderlyingModelConst() const;
91 
94 
97 
99 
102 
133 #ifdef Thyra_BUILD_HESSIAN_SUPPORT
134 
135  RCP<LinearOpBase<Scalar> > create_hess_g_pp( int j, int l1, int l2 ) const;
136 #endif // ifdef Thyra_BUILD_HESSIAN_SUPPORT
137 
140  void reportFinalPoint(
141  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
142  const bool wasSolved
143  );
144 
146 
147 protected:
148 
151 
154  ParameterList *paramList
155  ) const;
156 
159  ParameterList &paramList
160  ) const;
161 
163 
164 private:
165 
168 
170  RCP<LinearOpBase<Scalar> > create_DfDp_op_impl(int l) const;
172  RCP<LinearOpBase<Scalar> > create_DgDx_dot_op_impl(int j) const;
174  RCP<LinearOpBase<Scalar> > create_DgDx_op_impl(int j) const;
176  RCP<LinearOpBase<Scalar> > create_DgDp_op_impl( int j, int l ) const;
178  ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
179 
181 
182 private: // Data members
183 
185 
186  static
187  RCP<
190  >
191  > LocalVerbosityLevel_validator_;
192  static const std::string LocalVerbosityLevel_name_;
193  static const Teuchos::EVerbosityLevel LocalVerbosityLevel_enum_default_;
194  static const std::string LocalVerbosityLevel_default_;
195 
196 };
197 
198 
199 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,LOCALVERBLEVEL) \
200  \
201  using Teuchos::includesVerbLevel; \
202  using Teuchos::RCP; \
203  using Teuchos::EVerbosityLevel; \
204  const std::string blahblah_classNameStr \
205  = std::string(CLASS_NAME)+"<"+Teuchos::ScalarTraits<Scalar>::name()+">"; \
206  const std::string blahblah_classFuncNameStr \
207  = blahblah_classNameStr+"::evalModel(...)"; \
208  THYRA_FUNC_TIME_MONITOR(blahblah_classFuncNameStr); \
209  \
210  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &blahblah_outArgs = (OUTARGS); \
211  \
212  Teuchos::Time totalTimer(""); \
213  totalTimer.start(true); \
214  \
215  const RCP<Teuchos::FancyOStream> out = this->getOStream(); \
216  const EVerbosityLevel verbLevel = this->getVerbLevel(); \
217  const EVerbosityLevel localVerbLevelInput = (LOCALVERBLEVEL); \
218  const EVerbosityLevel localVerbLevel = \
219  ( localVerbLevelInput==Teuchos::VERB_DEFAULT ? verbLevel : localVerbLevelInput ); \
220  Teuchos::OSTab tab(out); \
221  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
222  *out << "\nEntering " << blahblah_classFuncNameStr << " ...\n"; \
223  \
224  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
225  *out \
226  << "\ninArgs =\n" << Teuchos::describe((INARGS),localVerbLevel) \
227  << "\noutArgs on input =\n" << Teuchos::describe((OUTARGS),Teuchos::VERB_LOW); \
228  \
229  const RCP<const Thyra::ModelEvaluator<Scalar> > \
230  thyraModel = (UNDERLYINGMODEL); \
231  \
232  typedef Teuchos::VerboseObjectTempState<Thyra::ModelEvaluatorBase> VOTSME; \
233  VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel)
234 
235 
236 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,LOCALVERBLEVEL) \
237  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel(),LOCALVERBLEVEL)
238 
239 
240 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL) \
241  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,Teuchos::VERB_DEFAULT)
242 
243 
244 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(CLASS_NAME,INARGS,OUTARGS) \
245  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel())
246 
247 
248 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END() \
249  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
250  *out \
251  << "\noutArgs on output =\n" << Teuchos::describe(blahblah_outArgs,localVerbLevel); \
252  \
253  totalTimer.stop(); \
254  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
255  *out \
256  << "\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<" sec\n" \
257  << "\nLeaving " << blahblah_classFuncNameStr << " ...\n"
258 
259 
260 // /////////////////////////////////
261 // Implementations
262 
263 
264 // Static class data members
265 
266 
267 template<class Scalar>
268 RCP<
271  >
272 >
274 
275 template<class Scalar>
276 const std::string
278 = "Local Verbosity Level";
279 
280 template<class Scalar>
284 
285 template<class Scalar>
286 const std::string
288 = getVerbosityLevelParameterValueName(
290  );
291 
292 
293 // Constructors/initializers
294 
295 
296 template<class Scalar>
298 {}
299 
300 
301 template<class Scalar>
303  const RCP<ModelEvaluator<Scalar> > &model
304  )
305 {
306  this->initialize(model);
307 }
308 
309 
310 template<class Scalar>
312  const RCP<const ModelEvaluator<Scalar> > &model
313  )
314 {
315  this->initialize(model);
316 }
317 
318 
319 template<class Scalar>
321  const RCP<ModelEvaluator<Scalar> > &model
322  )
323 {
324  model_.initialize(model);
325 }
326 
327 
328 template<class Scalar>
330  const RCP<const ModelEvaluator<Scalar> > &model
331  )
332 {
333  model_.initialize(model);
334 }
335 
336 
337 template<class Scalar>
339 {
340  model_.uninitialize();
341 }
342 
343 
344 // Virtual functions that can overridden
345 
346 
347 template<class Scalar>
349 {
350  return model_.isConst();
351 }
352 
353 
354 template<class Scalar>
357 {
358  return model_.getNonconstObj();
359 }
360 
361 
362 template<class Scalar>
365 {
366  return model_.getConstObj();
367 }
368 
369 
370 // Overridden from ModelEvaulator.
371 
372 
373 template<class Scalar>
376 {
377  return getUnderlyingModel()->get_x_space();
378 }
379 
380 
381 template<class Scalar>
384 {
385  return getUnderlyingModel()->get_f_space();
386 }
387 
388 
389 template<class Scalar>
392 {
393  return getUnderlyingModel()->get_f_multiplier_space();
394 }
395 
396 
397 template<class Scalar>
400 {
401  return getUnderlyingModel()->get_p_space(l);
402 }
403 
404 
405 template<class Scalar>
408 {
409  return getUnderlyingModel()->get_p_names(l);
410 }
411 
412 
413 template<class Scalar>
416 {
417  return getUnderlyingModel()->get_g_space(j);
418 }
419 
420 
421 template<class Scalar>
424 {
425  return getUnderlyingModel()->get_g_multiplier_space(j);
426 }
427 
428 
429 template<class Scalar>
432 {
433  return getUnderlyingModel()->get_g_names(j);
434 }
435 
436 
437 template<class Scalar>
440 {
441  return getUnderlyingModel()->getNominalValues();
442 }
443 
444 
445 template<class Scalar>
448 {
449  return getUnderlyingModel()->getLowerBounds();
450 }
451 
452 
453 template<class Scalar>
456 {
457  return getUnderlyingModel()->getUpperBounds();
458 }
459 
460 
461 template<class Scalar>
464 {
465  return getUnderlyingModel()->create_W();
466 }
467 
468 
469 template<class Scalar>
472 {
473  return getUnderlyingModel()->create_W_op();
474 }
475 
476 
477 template<class Scalar>
480 {
481  return getUnderlyingModel()->create_W_prec();
482 }
483 
484 
485 template<class Scalar>
488 {
489  return getUnderlyingModel()->get_W_factory();
490 }
491 
492 
493 #ifdef Thyra_BUILD_HESSIAN_SUPPORT
494 template<class Scalar>
496 ModelEvaluatorDelegatorBase<Scalar>::create_hess_g_pp( int j, int l1, int l2 ) const
497 {
498  return getUnderlyingModel()->create_hess_g_pp(j, l1, l2);
499 }
500 #endif // ifdef Thyra_BUILD_HESSIAN_SUPPORT
501 
502 
503 template<class Scalar>
504 ModelEvaluatorBase::InArgs<Scalar>
506 {
507  ModelEvaluatorBase::InArgsSetup<Scalar> inArgs = getUnderlyingModel()->createInArgs();
508  inArgs.setModelEvalDescription(this->description());
509  return std::move(inArgs);
510 }
511 
512 
513 template<class Scalar>
515  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint
516  ,const bool wasSolved
517  )
518 {
519  getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
520 }
521 
522 
523 // protected
524 
525 
526 // Producted utility functions to be called by subclasses
527 
528 
529 template<class Scalar>
531  ParameterList *paramList
532  ) const
533 {
534  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
535  if (is_null(LocalVerbosityLevel_validator_))
536  LocalVerbosityLevel_validator_ =
537  Teuchos::verbosityLevelParameterEntryValidator(
538  LocalVerbosityLevel_name_
539  );
540  paramList->set(
541  LocalVerbosityLevel_name_, LocalVerbosityLevel_default_,
542  "Overriding verbosity level for this model evaluator object.\n"
543  "This level will not propagate to nested model evaluator objects\n"
544  "The value of \"default\" result in the object verbosity level being\n"
545  "used instead.",
546  LocalVerbosityLevel_validator_
547  );
548 }
549 
550 
551 template<class Scalar>
554  ParameterList &paramList
555  ) const
556 {
557  return LocalVerbosityLevel_validator_->getIntegralValue(
558  paramList, LocalVerbosityLevel_name_, LocalVerbosityLevel_default_ );
559 }
560 
561 
562 // private
563 
564 
565 // Producted functions overridden from ModelEvaluatorDefaultBase
566 
567 
568 template<class Scalar>
571 {
572  return getUnderlyingModel()->create_DfDp_op(l);
573 }
574 
575 
576 template<class Scalar>
577 RCP<LinearOpBase<Scalar> >
578 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_dot_op_impl(
579  int j
580  ) const
581 {
582  return getUnderlyingModel()->create_DgDx_dot_op(j);
583 }
584 
585 
586 template<class Scalar>
587 RCP<LinearOpBase<Scalar> >
588 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_op_impl(
589  int j
590  ) const
591 {
592  return getUnderlyingModel()->create_DgDx_op(j);
593 }
594 
595 
596 template<class Scalar>
597 RCP<LinearOpBase<Scalar> >
598 ModelEvaluatorDelegatorBase<Scalar>::create_DgDp_op_impl(
599  int j, int l
600  ) const
601 {
602  return getUnderlyingModel()->create_DgDp_op(j,l);
603 }
604 
605 
606 template<class Scalar>
607 ModelEvaluatorBase::OutArgs<Scalar>
608 ModelEvaluatorDelegatorBase<Scalar>::createOutArgsImpl() const
609 {
610  ModelEvaluatorBase::OutArgsSetup<Scalar>
611  outArgs = getUnderlyingModel()->createOutArgs();
612  outArgs.setModelEvalDescription(this->description());
613  return std::move(outArgs);
614 }
615 
616 
617 } // namespace Thyra
618 
619 #endif // THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
Protected subclass of InArgs that only ModelEvaluator subclasses can access to set up the selection o...
void initialize(int *argc, char ***argv)
Pure abstract base interface for evaluating a stateless &quot;model&quot; that can be mapped into a number of d...
Default base class for concrete model evaluators.
bool is_null(const boost::shared_ptr< T > &p)
RCP< const VectorSpaceBase< Scalar > > get_x_space() const
RCP< LinearOpBase< Scalar > > create_DfDp_op(int l) const
virtual RCP< const ModelEvaluator< Scalar > > getUnderlyingModel() const
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
RCP< PreconditionerBase< Scalar > > create_W_prec() const
void setModelEvalDescription(const std::string &modelEvalDescription)
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
ModelEvaluatorDelegatorBase()
Constructs to uninitialized.
RCP< const VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::ArrayView< const std::string > get_g_names(int j) const
RCP< const VectorSpaceBase< Scalar > > get_f_multiplier_space() const
RCP< const VectorSpaceBase< Scalar > > get_p_space(int l) const
void reportFinalPoint(const ModelEvaluatorBase::InArgs< Scalar > &finalPoint, const bool wasSolved)
RCP< LinearOpWithSolveBase< Scalar > > create_W() const
virtual RCP< ModelEvaluator< Scalar > > getNonconstUnderlyingModel()
RCP< LinearOpBase< Scalar > > create_W_op() const
RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::EVerbosityLevel readLocalVerbosityLevelValidatedParameter(ParameterList &paramList) const
Read the local verbosity level parameter.
ModelEvaluatorBase::InArgs< Scalar > getUpperBounds() const
RCP< const VectorSpaceBase< Scalar > > get_g_space(int j) const
RCP< const VectorSpaceBase< Scalar > > get_g_multiplier_space(int j) const
ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
ModelEvaluatorBase::InArgs< Scalar > getLowerBounds() const
ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
RCP< const LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void setLocalVerbosityLevelValidatedParameter(ParameterList *paramList) const
Set a valid parameter for reading the local verbosity level.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...