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 
168  void reportFinalPoint(
169  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
170  const bool wasSolved
171  );
172 
174 
175 protected:
176 
179 
182  ParameterList *paramList
183  ) const;
184 
187  ParameterList &paramList
188  ) const;
189 
191 
192 private:
193 
196 
198  RCP<LinearOpBase<Scalar> > create_DfDp_op_impl(int l) const;
200  RCP<LinearOpBase<Scalar> > create_DgDx_dot_op_impl(int j) const;
202  RCP<LinearOpBase<Scalar> > create_DgDx_op_impl(int j) const;
204  RCP<LinearOpBase<Scalar> > create_DgDp_op_impl( int j, int l ) const;
206  ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
207 
209 
210 private: // Data members
211 
213 
214  static
215  RCP<
218  >
219  > LocalVerbosityLevel_validator_;
220  static const std::string LocalVerbosityLevel_name_;
221  static const Teuchos::EVerbosityLevel LocalVerbosityLevel_enum_default_;
222  static const std::string LocalVerbosityLevel_default_;
223 
224 };
225 
226 
227 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,LOCALVERBLEVEL) \
228  \
229  using Teuchos::includesVerbLevel; \
230  using Teuchos::RCP; \
231  using Teuchos::EVerbosityLevel; \
232  const std::string blahblah_classNameStr \
233  = std::string(CLASS_NAME)+"<"+Teuchos::ScalarTraits<Scalar>::name()+">"; \
234  const std::string blahblah_classFuncNameStr \
235  = blahblah_classNameStr+"::evalModel(...)"; \
236  THYRA_FUNC_TIME_MONITOR(blahblah_classFuncNameStr); \
237  \
238  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &blahblah_outArgs = (OUTARGS); \
239  \
240  Teuchos::Time totalTimer(""); \
241  totalTimer.start(true); \
242  \
243  const RCP<Teuchos::FancyOStream> out = this->getOStream(); \
244  const EVerbosityLevel verbLevel = this->getVerbLevel(); \
245  const EVerbosityLevel localVerbLevelInput = (LOCALVERBLEVEL); \
246  const EVerbosityLevel localVerbLevel = \
247  ( localVerbLevelInput==Teuchos::VERB_DEFAULT ? verbLevel : localVerbLevelInput ); \
248  Teuchos::OSTab tab(out); \
249  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
250  *out << "\nEntering " << blahblah_classFuncNameStr << " ...\n"; \
251  \
252  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
253  *out \
254  << "\ninArgs =\n" << Teuchos::describe((INARGS),localVerbLevel) \
255  << "\noutArgs on input =\n" << Teuchos::describe((OUTARGS),Teuchos::VERB_LOW); \
256  \
257  const RCP<const Thyra::ModelEvaluator<Scalar> > \
258  thyraModel = (UNDERLYINGMODEL); \
259  \
260  typedef Teuchos::VerboseObjectTempState<Thyra::ModelEvaluatorBase> VOTSME; \
261  VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel)
262 
263 
264 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,LOCALVERBLEVEL) \
265  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel(),LOCALVERBLEVEL)
266 
267 
268 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL) \
269  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,Teuchos::VERB_DEFAULT)
270 
271 
272 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(CLASS_NAME,INARGS,OUTARGS) \
273  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel())
274 
275 
276 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END() \
277  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
278  *out \
279  << "\noutArgs on output =\n" << Teuchos::describe(blahblah_outArgs,localVerbLevel); \
280  \
281  totalTimer.stop(); \
282  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
283  *out \
284  << "\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<" sec\n" \
285  << "\nLeaving " << blahblah_classFuncNameStr << " ...\n"
286 
287 
288 // /////////////////////////////////
289 // Implementations
290 
291 
292 // Static class data members
293 
294 
295 template<class Scalar>
296 RCP<
299  >
300 >
302 
303 template<class Scalar>
304 const std::string
306 = "Local Verbosity Level";
307 
308 template<class Scalar>
312 
313 template<class Scalar>
314 const std::string
316 = getVerbosityLevelParameterValueName(
318  );
319 
320 
321 // Constructors/initializers
322 
323 
324 template<class Scalar>
326 {}
327 
328 
329 template<class Scalar>
331  const RCP<ModelEvaluator<Scalar> > &model
332  )
333 {
334  this->initialize(model);
335 }
336 
337 
338 template<class Scalar>
340  const RCP<const ModelEvaluator<Scalar> > &model
341  )
342 {
343  this->initialize(model);
344 }
345 
346 
347 template<class Scalar>
349  const RCP<ModelEvaluator<Scalar> > &model
350  )
351 {
352  model_.initialize(model);
353 }
354 
355 
356 template<class Scalar>
358  const RCP<const ModelEvaluator<Scalar> > &model
359  )
360 {
361  model_.initialize(model);
362 }
363 
364 
365 template<class Scalar>
367 {
368  model_.uninitialize();
369 }
370 
371 
372 // Virtual functions that can overridden
373 
374 
375 template<class Scalar>
377 {
378  return model_.isConst();
379 }
380 
381 
382 template<class Scalar>
385 {
386  return model_.getNonconstObj();
387 }
388 
389 
390 template<class Scalar>
393 {
394  return model_.getConstObj();
395 }
396 
397 
398 // Overridden from ModelEvaulator.
399 
400 
401 template<class Scalar>
404 {
405  return getUnderlyingModel()->get_x_space();
406 }
407 
408 
409 template<class Scalar>
412 {
413  return getUnderlyingModel()->get_f_space();
414 }
415 
416 
417 template<class Scalar>
420 {
421  return getUnderlyingModel()->get_f_multiplier_space();
422 }
423 
424 
425 template<class Scalar>
428 {
429  return getUnderlyingModel()->get_p_space(l);
430 }
431 
432 
433 template<class Scalar>
436 {
437  return getUnderlyingModel()->get_p_names(l);
438 }
439 
440 
441 template<class Scalar>
444 {
445  return getUnderlyingModel()->get_g_space(j);
446 }
447 
448 
449 template<class Scalar>
452 {
453  return getUnderlyingModel()->get_g_multiplier_space(j);
454 }
455 
456 
457 template<class Scalar>
460 {
461  return getUnderlyingModel()->get_g_names(j);
462 }
463 
464 
465 template<class Scalar>
468 {
469  return getUnderlyingModel()->getNominalValues();
470 }
471 
472 
473 template<class Scalar>
476 {
477  return getUnderlyingModel()->getLowerBounds();
478 }
479 
480 
481 template<class Scalar>
484 {
485  return getUnderlyingModel()->getUpperBounds();
486 }
487 
488 
489 template<class Scalar>
492 {
493  return getUnderlyingModel()->create_W();
494 }
495 
496 
497 template<class Scalar>
500 {
501  return getUnderlyingModel()->create_W_op();
502 }
503 
504 
505 template<class Scalar>
508 {
509  return getUnderlyingModel()->create_W_prec();
510 }
511 
512 
513 template<class Scalar>
516 {
517  return getUnderlyingModel()->get_W_factory();
518 }
519 
520 
521 template<class Scalar>
524 {
525  ModelEvaluatorBase::InArgsSetup<Scalar> inArgs = getUnderlyingModel()->createInArgs();
526  inArgs.setModelEvalDescription(this->description());
527  return std::move(inArgs);
528 }
529 
530 
531 template<class Scalar>
533  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint
534  ,const bool wasSolved
535  )
536 {
537  getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
538 }
539 
540 
541 // protected
542 
543 
544 // Producted utility functions to be called by subclasses
545 
546 
547 template<class Scalar>
549  ParameterList *paramList
550  ) const
551 {
552  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
553  if (is_null(LocalVerbosityLevel_validator_))
554  LocalVerbosityLevel_validator_ =
555  Teuchos::verbosityLevelParameterEntryValidator(
556  LocalVerbosityLevel_name_
557  );
558  paramList->set(
559  LocalVerbosityLevel_name_, LocalVerbosityLevel_default_,
560  "Overriding verbosity level for this model evaluator object.\n"
561  "This level will not propagate to nested model evaluator objects\n"
562  "The value of \"default\" result in the object verbosity level being\n"
563  "used instead.",
564  LocalVerbosityLevel_validator_
565  );
566 }
567 
568 
569 template<class Scalar>
572  ParameterList &paramList
573  ) const
574 {
575  return LocalVerbosityLevel_validator_->getIntegralValue(
576  paramList, LocalVerbosityLevel_name_, LocalVerbosityLevel_default_ );
577 }
578 
579 
580 // private
581 
582 
583 // Producted functions overridden from ModelEvaluatorDefaultBase
584 
585 
586 template<class Scalar>
589 {
590  return getUnderlyingModel()->create_DfDp_op(l);
591 }
592 
593 
594 template<class Scalar>
595 RCP<LinearOpBase<Scalar> >
596 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_dot_op_impl(
597  int j
598  ) const
599 {
600  return getUnderlyingModel()->create_DgDx_dot_op(j);
601 }
602 
603 
604 template<class Scalar>
605 RCP<LinearOpBase<Scalar> >
606 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_op_impl(
607  int j
608  ) const
609 {
610  return getUnderlyingModel()->create_DgDx_op(j);
611 }
612 
613 
614 template<class Scalar>
615 RCP<LinearOpBase<Scalar> >
616 ModelEvaluatorDelegatorBase<Scalar>::create_DgDp_op_impl(
617  int j, int l
618  ) const
619 {
620  return getUnderlyingModel()->create_DgDp_op(j,l);
621 }
622 
623 
624 template<class Scalar>
625 ModelEvaluatorBase::OutArgs<Scalar>
626 ModelEvaluatorDelegatorBase<Scalar>::createOutArgsImpl() const
627 {
628  ModelEvaluatorBase::OutArgsSetup<Scalar>
629  outArgs = getUnderlyingModel()->createOutArgs();
630  outArgs.setModelEvalDescription(this->description());
631  return std::move(outArgs);
632 }
633 
634 
635 } // namespace Thyra
636 
637 #endif // THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
Protected subclass of InArgs that only ModelEvaluator subclasses can access to set up the selection o...
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...