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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
43 #define THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
44 
45 
46 #include "Thyra_ModelEvaluatorDefaultBase.hpp"
47 #include "Teuchos_ConstNonconstObjectContainer.hpp"
48 #include "Teuchos_TimeMonitor.hpp"
49 #include "Teuchos_StandardParameterEntryValidators.hpp"
50 
51 
52 namespace Thyra {
53 
54 
81 template<class Scalar>
83  : virtual public ModelEvaluatorDefaultBase<Scalar>
84 {
85 public:
86 
89 
92 
95  const RCP<ModelEvaluator<Scalar> > &model
96  );
97 
100  const RCP<const ModelEvaluator<Scalar> > &model
101  );
102 
104  void initialize(
105  const RCP<ModelEvaluator<Scalar> > &model
106  );
107 
109  void initialize(
110  const RCP<const ModelEvaluator<Scalar> > &model
111  );
112 
114  void uninitialize();
115 
117 
120 
122  virtual bool isUnderlyingModelConst() const;
123 
126 
129 
131 
134 
165 #ifdef Thyra_BUILD_HESSIAN_SUPPORT
166 
167  RCP<LinearOpBase<Scalar> > create_hess_g_pp( int j, int l1, int l2 ) const;
168 #endif // ifdef Thyra_BUILD_HESSIAN_SUPPORT
169 
172  void reportFinalPoint(
173  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
174  const bool wasSolved
175  );
176 
178 
179 protected:
180 
183 
186  ParameterList *paramList
187  ) const;
188 
191  ParameterList &paramList
192  ) const;
193 
195 
196 private:
197 
200 
202  RCP<LinearOpBase<Scalar> > create_DfDp_op_impl(int l) const;
204  RCP<LinearOpBase<Scalar> > create_DgDx_dot_op_impl(int j) const;
206  RCP<LinearOpBase<Scalar> > create_DgDx_op_impl(int j) const;
208  RCP<LinearOpBase<Scalar> > create_DgDp_op_impl( int j, int l ) const;
210  ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
211 
213 
214 private: // Data members
215 
217 
218  static
219  RCP<
222  >
223  > LocalVerbosityLevel_validator_;
224  static const std::string LocalVerbosityLevel_name_;
225  static const Teuchos::EVerbosityLevel LocalVerbosityLevel_enum_default_;
226  static const std::string LocalVerbosityLevel_default_;
227 
228 };
229 
230 
231 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,LOCALVERBLEVEL) \
232  \
233  using Teuchos::includesVerbLevel; \
234  using Teuchos::RCP; \
235  using Teuchos::EVerbosityLevel; \
236  const std::string blahblah_classNameStr \
237  = std::string(CLASS_NAME)+"<"+Teuchos::ScalarTraits<Scalar>::name()+">"; \
238  const std::string blahblah_classFuncNameStr \
239  = blahblah_classNameStr+"::evalModel(...)"; \
240  THYRA_FUNC_TIME_MONITOR(blahblah_classFuncNameStr); \
241  \
242  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &blahblah_outArgs = (OUTARGS); \
243  \
244  Teuchos::Time totalTimer(""); \
245  totalTimer.start(true); \
246  \
247  const RCP<Teuchos::FancyOStream> out = this->getOStream(); \
248  const EVerbosityLevel verbLevel = this->getVerbLevel(); \
249  const EVerbosityLevel localVerbLevelInput = (LOCALVERBLEVEL); \
250  const EVerbosityLevel localVerbLevel = \
251  ( localVerbLevelInput==Teuchos::VERB_DEFAULT ? verbLevel : localVerbLevelInput ); \
252  Teuchos::OSTab tab(out); \
253  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
254  *out << "\nEntering " << blahblah_classFuncNameStr << " ...\n"; \
255  \
256  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
257  *out \
258  << "\ninArgs =\n" << Teuchos::describe((INARGS),localVerbLevel) \
259  << "\noutArgs on input =\n" << Teuchos::describe((OUTARGS),Teuchos::VERB_LOW); \
260  \
261  const RCP<const Thyra::ModelEvaluator<Scalar> > \
262  thyraModel = (UNDERLYINGMODEL); \
263  \
264  typedef Teuchos::VerboseObjectTempState<Thyra::ModelEvaluatorBase> VOTSME; \
265  VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel)
266 
267 
268 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,LOCALVERBLEVEL) \
269  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel(),LOCALVERBLEVEL)
270 
271 
272 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL) \
273  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,Teuchos::VERB_DEFAULT)
274 
275 
276 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(CLASS_NAME,INARGS,OUTARGS) \
277  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel())
278 
279 
280 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END() \
281  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
282  *out \
283  << "\noutArgs on output =\n" << Teuchos::describe(blahblah_outArgs,localVerbLevel); \
284  \
285  totalTimer.stop(); \
286  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
287  *out \
288  << "\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<" sec\n" \
289  << "\nLeaving " << blahblah_classFuncNameStr << " ...\n"
290 
291 
292 // /////////////////////////////////
293 // Implementations
294 
295 
296 // Static class data members
297 
298 
299 template<class Scalar>
300 RCP<
303  >
304 >
306 
307 template<class Scalar>
308 const std::string
310 = "Local Verbosity Level";
311 
312 template<class Scalar>
316 
317 template<class Scalar>
318 const std::string
320 = getVerbosityLevelParameterValueName(
322  );
323 
324 
325 // Constructors/initializers
326 
327 
328 template<class Scalar>
330 {}
331 
332 
333 template<class Scalar>
335  const RCP<ModelEvaluator<Scalar> > &model
336  )
337 {
338  this->initialize(model);
339 }
340 
341 
342 template<class Scalar>
344  const RCP<const ModelEvaluator<Scalar> > &model
345  )
346 {
347  this->initialize(model);
348 }
349 
350 
351 template<class Scalar>
353  const RCP<ModelEvaluator<Scalar> > &model
354  )
355 {
356  model_.initialize(model);
357 }
358 
359 
360 template<class Scalar>
362  const RCP<const ModelEvaluator<Scalar> > &model
363  )
364 {
365  model_.initialize(model);
366 }
367 
368 
369 template<class Scalar>
371 {
372  model_.uninitialize();
373 }
374 
375 
376 // Virtual functions that can overridden
377 
378 
379 template<class Scalar>
381 {
382  return model_.isConst();
383 }
384 
385 
386 template<class Scalar>
389 {
390  return model_.getNonconstObj();
391 }
392 
393 
394 template<class Scalar>
397 {
398  return model_.getConstObj();
399 }
400 
401 
402 // Overridden from ModelEvaulator.
403 
404 
405 template<class Scalar>
408 {
409  return getUnderlyingModel()->get_x_space();
410 }
411 
412 
413 template<class Scalar>
416 {
417  return getUnderlyingModel()->get_f_space();
418 }
419 
420 
421 template<class Scalar>
424 {
425  return getUnderlyingModel()->get_f_multiplier_space();
426 }
427 
428 
429 template<class Scalar>
432 {
433  return getUnderlyingModel()->get_p_space(l);
434 }
435 
436 
437 template<class Scalar>
440 {
441  return getUnderlyingModel()->get_p_names(l);
442 }
443 
444 
445 template<class Scalar>
448 {
449  return getUnderlyingModel()->get_g_space(j);
450 }
451 
452 
453 template<class Scalar>
456 {
457  return getUnderlyingModel()->get_g_multiplier_space(j);
458 }
459 
460 
461 template<class Scalar>
464 {
465  return getUnderlyingModel()->get_g_names(j);
466 }
467 
468 
469 template<class Scalar>
472 {
473  return getUnderlyingModel()->getNominalValues();
474 }
475 
476 
477 template<class Scalar>
480 {
481  return getUnderlyingModel()->getLowerBounds();
482 }
483 
484 
485 template<class Scalar>
488 {
489  return getUnderlyingModel()->getUpperBounds();
490 }
491 
492 
493 template<class Scalar>
496 {
497  return getUnderlyingModel()->create_W();
498 }
499 
500 
501 template<class Scalar>
504 {
505  return getUnderlyingModel()->create_W_op();
506 }
507 
508 
509 template<class Scalar>
512 {
513  return getUnderlyingModel()->create_W_prec();
514 }
515 
516 
517 template<class Scalar>
520 {
521  return getUnderlyingModel()->get_W_factory();
522 }
523 
524 
525 #ifdef Thyra_BUILD_HESSIAN_SUPPORT
526 template<class Scalar>
528 ModelEvaluatorDelegatorBase<Scalar>::create_hess_g_pp( int j, int l1, int l2 ) const
529 {
530  return getUnderlyingModel()->create_hess_g_pp(j, l1, l2);
531 }
532 #endif // ifdef Thyra_BUILD_HESSIAN_SUPPORT
533 
534 
535 template<class Scalar>
536 ModelEvaluatorBase::InArgs<Scalar>
538 {
539  ModelEvaluatorBase::InArgsSetup<Scalar> inArgs = getUnderlyingModel()->createInArgs();
540  inArgs.setModelEvalDescription(this->description());
541  return std::move(inArgs);
542 }
543 
544 
545 template<class Scalar>
547  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint
548  ,const bool wasSolved
549  )
550 {
551  getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
552 }
553 
554 
555 // protected
556 
557 
558 // Producted utility functions to be called by subclasses
559 
560 
561 template<class Scalar>
563  ParameterList *paramList
564  ) const
565 {
566  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
567  if (is_null(LocalVerbosityLevel_validator_))
568  LocalVerbosityLevel_validator_ =
569  Teuchos::verbosityLevelParameterEntryValidator(
570  LocalVerbosityLevel_name_
571  );
572  paramList->set(
573  LocalVerbosityLevel_name_, LocalVerbosityLevel_default_,
574  "Overriding verbosity level for this model evaluator object.\n"
575  "This level will not propagate to nested model evaluator objects\n"
576  "The value of \"default\" result in the object verbosity level being\n"
577  "used instead.",
578  LocalVerbosityLevel_validator_
579  );
580 }
581 
582 
583 template<class Scalar>
586  ParameterList &paramList
587  ) const
588 {
589  return LocalVerbosityLevel_validator_->getIntegralValue(
590  paramList, LocalVerbosityLevel_name_, LocalVerbosityLevel_default_ );
591 }
592 
593 
594 // private
595 
596 
597 // Producted functions overridden from ModelEvaluatorDefaultBase
598 
599 
600 template<class Scalar>
603 {
604  return getUnderlyingModel()->create_DfDp_op(l);
605 }
606 
607 
608 template<class Scalar>
609 RCP<LinearOpBase<Scalar> >
610 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_dot_op_impl(
611  int j
612  ) const
613 {
614  return getUnderlyingModel()->create_DgDx_dot_op(j);
615 }
616 
617 
618 template<class Scalar>
619 RCP<LinearOpBase<Scalar> >
620 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_op_impl(
621  int j
622  ) const
623 {
624  return getUnderlyingModel()->create_DgDx_op(j);
625 }
626 
627 
628 template<class Scalar>
629 RCP<LinearOpBase<Scalar> >
630 ModelEvaluatorDelegatorBase<Scalar>::create_DgDp_op_impl(
631  int j, int l
632  ) const
633 {
634  return getUnderlyingModel()->create_DgDp_op(j,l);
635 }
636 
637 
638 template<class Scalar>
639 ModelEvaluatorBase::OutArgs<Scalar>
640 ModelEvaluatorDelegatorBase<Scalar>::createOutArgsImpl() const
641 {
642  ModelEvaluatorBase::OutArgsSetup<Scalar>
643  outArgs = getUnderlyingModel()->createOutArgs();
644  outArgs.setModelEvalDescription(this->description());
645  return std::move(outArgs);
646 }
647 
648 
649 } // namespace Thyra
650 
651 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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...