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 
164  void reportFinalPoint(
165  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
166  const bool wasSolved
167  );
168 
170 
171 protected:
172 
175 
178  ParameterList *paramList
179  ) const;
180 
183  ParameterList &paramList
184  ) const;
185 
187 
188 private:
189 
192 
194  RCP<LinearOpBase<Scalar> > create_DfDp_op_impl(int l) const;
196  RCP<LinearOpBase<Scalar> > create_DgDx_dot_op_impl(int j) const;
198  RCP<LinearOpBase<Scalar> > create_DgDx_op_impl(int j) const;
200  RCP<LinearOpBase<Scalar> > create_DgDp_op_impl( int j, int l ) const;
202  ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
203 
205 
206 private: // Data members
207 
209 
210  static
211  RCP<
214  >
215  > LocalVerbosityLevel_validator_;
216  static const std::string LocalVerbosityLevel_name_;
217  static const Teuchos::EVerbosityLevel LocalVerbosityLevel_enum_default_;
218  static const std::string LocalVerbosityLevel_default_;
219 
220 };
221 
222 
223 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,LOCALVERBLEVEL) \
224  \
225  using Teuchos::includesVerbLevel; \
226  using Teuchos::RCP; \
227  using Teuchos::EVerbosityLevel; \
228  const std::string blahblah_classNameStr \
229  = std::string(CLASS_NAME)+"<"+Teuchos::ScalarTraits<Scalar>::name()+">"; \
230  const std::string blahblah_classFuncNameStr \
231  = blahblah_classNameStr+"::evalModel(...)"; \
232  THYRA_FUNC_TIME_MONITOR(blahblah_classFuncNameStr); \
233  \
234  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &blahblah_outArgs = (OUTARGS); \
235  \
236  Teuchos::Time totalTimer(""); \
237  totalTimer.start(true); \
238  \
239  const RCP<Teuchos::FancyOStream> out = this->getOStream(); \
240  const EVerbosityLevel verbLevel = this->getVerbLevel(); \
241  const EVerbosityLevel localVerbLevelInput = (LOCALVERBLEVEL); \
242  const EVerbosityLevel localVerbLevel = \
243  ( localVerbLevelInput==Teuchos::VERB_DEFAULT ? verbLevel : localVerbLevelInput ); \
244  Teuchos::OSTab tab(out); \
245  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
246  *out << "\nEntering " << blahblah_classFuncNameStr << " ...\n"; \
247  \
248  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
249  *out \
250  << "\ninArgs =\n" << Teuchos::describe((INARGS),localVerbLevel) \
251  << "\noutArgs on input =\n" << Teuchos::describe((OUTARGS),Teuchos::VERB_LOW); \
252  \
253  const RCP<const Thyra::ModelEvaluator<Scalar> > \
254  thyraModel = (UNDERLYINGMODEL); \
255  \
256  typedef Teuchos::VerboseObjectTempState<Thyra::ModelEvaluatorBase> VOTSME; \
257  VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel)
258 
259 
260 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,LOCALVERBLEVEL) \
261  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel(),LOCALVERBLEVEL)
262 
263 
264 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL) \
265  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,Teuchos::VERB_DEFAULT)
266 
267 
268 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(CLASS_NAME,INARGS,OUTARGS) \
269  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel())
270 
271 
272 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END() \
273  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
274  *out \
275  << "\noutArgs on output =\n" << Teuchos::describe(blahblah_outArgs,localVerbLevel); \
276  \
277  totalTimer.stop(); \
278  if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
279  *out \
280  << "\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<" sec\n" \
281  << "\nLeaving " << blahblah_classFuncNameStr << " ...\n"
282 
283 
284 // /////////////////////////////////
285 // Implementations
286 
287 
288 // Static class data members
289 
290 
291 template<class Scalar>
292 RCP<
295  >
296 >
298 
299 template<class Scalar>
300 const std::string
302 = "Local Verbosity Level";
303 
304 template<class Scalar>
308 
309 template<class Scalar>
310 const std::string
312 = getVerbosityLevelParameterValueName(
314  );
315 
316 
317 // Constructors/initializers
318 
319 
320 template<class Scalar>
322 {}
323 
324 
325 template<class Scalar>
327  const RCP<ModelEvaluator<Scalar> > &model
328  )
329 {
330  this->initialize(model);
331 }
332 
333 
334 template<class Scalar>
336  const RCP<const ModelEvaluator<Scalar> > &model
337  )
338 {
339  this->initialize(model);
340 }
341 
342 
343 template<class Scalar>
345  const RCP<ModelEvaluator<Scalar> > &model
346  )
347 {
348  model_.initialize(model);
349 }
350 
351 
352 template<class Scalar>
354  const RCP<const ModelEvaluator<Scalar> > &model
355  )
356 {
357  model_.initialize(model);
358 }
359 
360 
361 template<class Scalar>
363 {
364  model_.uninitialize();
365 }
366 
367 
368 // Virtual functions that can overridden
369 
370 
371 template<class Scalar>
373 {
374  return model_.isConst();
375 }
376 
377 
378 template<class Scalar>
381 {
382  return model_.getNonconstObj();
383 }
384 
385 
386 template<class Scalar>
389 {
390  return model_.getConstObj();
391 }
392 
393 
394 // Overridden from ModelEvaulator.
395 
396 
397 template<class Scalar>
400 {
401  return getUnderlyingModel()->get_x_space();
402 }
403 
404 
405 template<class Scalar>
408 {
409  return getUnderlyingModel()->get_f_space();
410 }
411 
412 
413 template<class Scalar>
416 {
417  return getUnderlyingModel()->get_p_space(l);
418 }
419 
420 
421 template<class Scalar>
424 {
425  return getUnderlyingModel()->get_p_names(l);
426 }
427 
428 
429 template<class Scalar>
432 {
433  return getUnderlyingModel()->get_g_space(j);
434 }
435 
436 
437 template<class Scalar>
440 {
441  return getUnderlyingModel()->get_g_names(j);
442 }
443 
444 
445 template<class Scalar>
448 {
449  return getUnderlyingModel()->getNominalValues();
450 }
451 
452 
453 template<class Scalar>
456 {
457  return getUnderlyingModel()->getLowerBounds();
458 }
459 
460 
461 template<class Scalar>
464 {
465  return getUnderlyingModel()->getUpperBounds();
466 }
467 
468 
469 template<class Scalar>
472 {
473  return getUnderlyingModel()->create_W();
474 }
475 
476 
477 template<class Scalar>
480 {
481  return getUnderlyingModel()->create_W_op();
482 }
483 
484 
485 template<class Scalar>
488 {
489  return getUnderlyingModel()->create_W_prec();
490 }
491 
492 
493 template<class Scalar>
496 {
497  return getUnderlyingModel()->get_W_factory();
498 }
499 
500 
501 template<class Scalar>
504 {
505  ModelEvaluatorBase::InArgsSetup<Scalar> inArgs = getUnderlyingModel()->createInArgs();
506  inArgs.setModelEvalDescription(this->description());
507  return inArgs;
508 }
509 
510 
511 template<class Scalar>
513  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint
514  ,const bool wasSolved
515  )
516 {
517  getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
518 }
519 
520 
521 // protected
522 
523 
524 // Producted utility functions to be called by subclasses
525 
526 
527 template<class Scalar>
529  ParameterList *paramList
530  ) const
531 {
532  TEUCHOS_TEST_FOR_EXCEPT(0==paramList);
533  if (is_null(LocalVerbosityLevel_validator_))
534  LocalVerbosityLevel_validator_ =
535  Teuchos::verbosityLevelParameterEntryValidator(
536  LocalVerbosityLevel_name_
537  );
538  paramList->set(
539  LocalVerbosityLevel_name_, LocalVerbosityLevel_default_,
540  "Overriding verbosity level for this model evaluator object.\n"
541  "This level will not propagate to nested model evaluator objects\n"
542  "The value of \"default\" result in the object verbosity level being\n"
543  "used instead.",
544  LocalVerbosityLevel_validator_
545  );
546 }
547 
548 
549 template<class Scalar>
552  ParameterList &paramList
553  ) const
554 {
555  return LocalVerbosityLevel_validator_->getIntegralValue(
556  paramList, LocalVerbosityLevel_name_, LocalVerbosityLevel_default_ );
557 }
558 
559 
560 // private
561 
562 
563 // Producted functions overridden from ModelEvaluatorDefaultBase
564 
565 
566 template<class Scalar>
569 {
570  return getUnderlyingModel()->create_DfDp_op(l);
571 }
572 
573 
574 template<class Scalar>
575 RCP<LinearOpBase<Scalar> >
576 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_dot_op_impl(
577  int j
578  ) const
579 {
580  return getUnderlyingModel()->create_DgDx_dot_op(j);
581 }
582 
583 
584 template<class Scalar>
585 RCP<LinearOpBase<Scalar> >
586 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_op_impl(
587  int j
588  ) const
589 {
590  return getUnderlyingModel()->create_DgDx_op(j);
591 }
592 
593 
594 template<class Scalar>
595 RCP<LinearOpBase<Scalar> >
596 ModelEvaluatorDelegatorBase<Scalar>::create_DgDp_op_impl(
597  int j, int l
598  ) const
599 {
600  return getUnderlyingModel()->create_DgDp_op(j,l);
601 }
602 
603 
604 template<class Scalar>
605 ModelEvaluatorBase::OutArgs<Scalar>
606 ModelEvaluatorDelegatorBase<Scalar>::createOutArgsImpl() const
607 {
608  ModelEvaluatorBase::OutArgsSetup<Scalar>
609  outArgs = getUnderlyingModel()->createOutArgs();
610  outArgs.setModelEvalDescription(this->description());
611  return outArgs;
612 }
613 
614 
615 } // namespace Thyra
616 
617 #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_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
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...