Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_ModelEvaluatorDelegatorBase.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
00030 #define THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
00031 
00032 
00033 #include "Thyra_ModelEvaluatorDefaultBase.hpp"
00034 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00035 #include "Teuchos_TimeMonitor.hpp"
00036 #include "Teuchos_StandardParameterEntryValidators.hpp"
00037 
00038 
00039 namespace Thyra {
00040 
00041 
00068 template<class Scalar>
00069 class ModelEvaluatorDelegatorBase
00070   : virtual public ModelEvaluatorDefaultBase<Scalar>
00071 {
00072 public:
00073 
00076 
00078   ModelEvaluatorDelegatorBase();
00079 
00081   ModelEvaluatorDelegatorBase(
00082     const RCP<ModelEvaluator<Scalar> > &model
00083     );
00084 
00086   ModelEvaluatorDelegatorBase(
00087     const RCP<const ModelEvaluator<Scalar> > &model
00088     );
00089 
00091   void initialize(
00092     const RCP<ModelEvaluator<Scalar> > &model
00093     );
00094 
00096   void initialize(
00097     const RCP<const ModelEvaluator<Scalar> > &model
00098     );
00099 
00101   void uninitialize();
00102 
00104 
00107 
00109   virtual bool isUnderlyingModelConst() const;
00110 
00112   virtual RCP<ModelEvaluator<Scalar> > getNonconstUnderlyingModel();
00113 
00115   virtual RCP<const ModelEvaluator<Scalar> > getUnderlyingModel() const;
00116 
00118 
00121 
00123   RCP<const VectorSpaceBase<Scalar> > get_x_space() const;
00125   RCP<const VectorSpaceBase<Scalar> > get_f_space() const;
00127   RCP<const VectorSpaceBase<Scalar> > get_p_space(int l) const;
00129   RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
00131   RCP<const VectorSpaceBase<Scalar> > get_g_space(int j) const;
00133   ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
00135   ModelEvaluatorBase::InArgs<Scalar> getLowerBounds() const;
00137   ModelEvaluatorBase::InArgs<Scalar> getUpperBounds() const;
00139   RCP<LinearOpWithSolveBase<Scalar> > create_W() const;
00141   RCP<LinearOpBase<Scalar> > create_W_op() const;
00143   RCP<const LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
00145   ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
00147   void reportFinalPoint(
00148     const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
00149     const bool wasSolved
00150     );
00151 
00153 
00154 protected:
00155 
00158 
00160   void setLocalVerbosityLevelValidatedParameter(
00161     ParameterList *paramList
00162     ) const;
00163 
00165   Teuchos::EVerbosityLevel readLocalVerbosityLevelValidatedParameter(
00166     ParameterList &paramList 
00167     ) const;
00168 
00170 
00171 private:
00172 
00175 
00177   RCP<LinearOpBase<Scalar> > create_DfDp_op_impl(int l) const;
00179   RCP<LinearOpBase<Scalar> > create_DgDx_dot_op_impl(int j) const;
00181   RCP<LinearOpBase<Scalar> > create_DgDx_op_impl(int j) const;
00183   RCP<LinearOpBase<Scalar> > create_DgDp_op_impl( int j, int l ) const;
00185   ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
00186 
00188 
00189 private: // Data members
00190 
00191   Teuchos::ConstNonconstObjectContainer<ModelEvaluator<Scalar> > model_;
00192 
00193   static
00194   RCP<
00195     Teuchos::StringToIntegralParameterEntryValidator<
00196       Teuchos::EVerbosityLevel
00197       >
00198     > LocalVerbosityLevel_validator_;
00199   static const std::string LocalVerbosityLevel_name_;
00200   static const Teuchos::EVerbosityLevel LocalVerbosityLevel_enum_default_;
00201   static const std::string LocalVerbosityLevel_default_;
00202   
00203 };
00204 
00205 
00206 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,LOCALVERBLEVEL) \
00207   \
00208   using Teuchos::includesVerbLevel; \
00209   using Teuchos::RCP; \
00210   using Teuchos::EVerbosityLevel; \
00211   const std::string blahblah_classNameStr \
00212     = std::string(CLASS_NAME)+"<"+Teuchos::ScalarTraits<Scalar>::name()+">"; \
00213   const std::string blahblah_classFuncNameStr \
00214     = blahblah_classNameStr+"::evalModel(...)"; \
00215   TEUCHOS_FUNC_TIME_MONITOR(blahblah_classFuncNameStr); \
00216   \
00217   const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &blahblah_outArgs = (OUTARGS); \
00218   \
00219   Teuchos::Time totalTimer(""); \
00220   totalTimer.start(true); \
00221   \
00222   const RCP<Teuchos::FancyOStream> out = this->getOStream(); \
00223   const EVerbosityLevel verbLevel = this->getVerbLevel(); \
00224   const EVerbosityLevel localVerbLevelInput = (LOCALVERBLEVEL); \
00225   const EVerbosityLevel localVerbLevel = \
00226     ( localVerbLevelInput==Teuchos::VERB_DEFAULT ? verbLevel : localVerbLevelInput ); \
00227   Teuchos::OSTab tab(out); \
00228   if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
00229     *out << "\nEntering " << blahblah_classFuncNameStr << " ...\n"; \
00230   \
00231   if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
00232     *out \
00233       << "\ninArgs =\n" << Teuchos::describe((INARGS),localVerbLevel) \
00234       << "\noutArgs on input =\n" << Teuchos::describe((OUTARGS),Teuchos::VERB_LOW); \
00235   \
00236   const RCP<const Thyra::ModelEvaluator<Scalar> > \
00237     thyraModel = (UNDERLYINGMODEL); \
00238   \
00239   typedef Teuchos::VerboseObjectTempState<Thyra::ModelEvaluatorBase> VOTSME; \
00240   VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel)
00241 
00242 
00243 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,LOCALVERBLEVEL) \
00244   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel(),LOCALVERBLEVEL)
00245 
00246 
00247 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL) \
00248   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_LOCALVERBLEVEL_BEGIN(CLASS_NAME,INARGS,OUTARGS,UNDERLYINGMODEL,Teuchos::VERB_DEFAULT)
00249 
00250 
00251 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(CLASS_NAME,INARGS,OUTARGS) \
00252   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(CLASS_NAME,INARGS,OUTARGS,this->getUnderlyingModel())
00253 
00254 
00255 #define THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END() \
00256   if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_MEDIUM)) \
00257     *out \
00258       << "\noutArgs on output =\n" << Teuchos::describe(blahblah_outArgs,localVerbLevel); \
00259   \
00260   totalTimer.stop(); \
00261   if(out.get() && includesVerbLevel(localVerbLevel,Teuchos::VERB_LOW)) \
00262     *out \
00263       << "\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<" sec\n" \
00264       << "\nLeaving " << blahblah_classFuncNameStr << " ...\n"
00265 
00266 
00267 // /////////////////////////////////
00268 // Implementations
00269 
00270 
00271 // Static class data members
00272 
00273 
00274 template<class Scalar>
00275 RCP<
00276   Teuchos::StringToIntegralParameterEntryValidator<
00277   Teuchos::EVerbosityLevel
00278   >
00279 >
00280 ModelEvaluatorDelegatorBase<Scalar>::LocalVerbosityLevel_validator_;
00281 
00282 template<class Scalar>
00283 const std::string
00284 ModelEvaluatorDelegatorBase<Scalar>::LocalVerbosityLevel_name_
00285 = "Local Verbosity Level";
00286 
00287 template<class Scalar>
00288 const Teuchos::EVerbosityLevel
00289 ModelEvaluatorDelegatorBase<Scalar>::LocalVerbosityLevel_enum_default_
00290 = Teuchos::VERB_DEFAULT;
00291 
00292 template<class Scalar>
00293 const std::string
00294 ModelEvaluatorDelegatorBase<Scalar>::LocalVerbosityLevel_default_
00295 = getVerbosityLevelParameterValueName(
00296   ModelEvaluatorDelegatorBase<Scalar>::LocalVerbosityLevel_enum_default_
00297   );
00298 
00299 
00300 // Constructors/initializers
00301 
00302 
00303 template<class Scalar>
00304 ModelEvaluatorDelegatorBase<Scalar>::ModelEvaluatorDelegatorBase()
00305 {}
00306 
00307 
00308 template<class Scalar>
00309 ModelEvaluatorDelegatorBase<Scalar>::ModelEvaluatorDelegatorBase(
00310   const RCP<ModelEvaluator<Scalar> >   &model
00311   )
00312 {
00313   this->initialize(model);
00314 }
00315 
00316 
00317 template<class Scalar>
00318 ModelEvaluatorDelegatorBase<Scalar>::ModelEvaluatorDelegatorBase(
00319   const RCP<const ModelEvaluator<Scalar> >   &model
00320   )
00321 {
00322   this->initialize(model);
00323 }
00324 
00325 
00326 template<class Scalar>
00327 void ModelEvaluatorDelegatorBase<Scalar>::initialize(
00328   const RCP<ModelEvaluator<Scalar> >   &model
00329   )
00330 {
00331   model_.initialize(model);
00332 }
00333 
00334 
00335 template<class Scalar>
00336 void ModelEvaluatorDelegatorBase<Scalar>::initialize(
00337   const RCP<const ModelEvaluator<Scalar> >   &model
00338   )
00339 {
00340   model_.initialize(model);
00341 }
00342 
00343 
00344 template<class Scalar>
00345 void ModelEvaluatorDelegatorBase<Scalar>::uninitialize()
00346 {
00347   model_.uninitialize();
00348 }
00349 
00350 
00351 // Virtual functions that can overriden
00352 
00353 
00354 template<class Scalar>
00355 bool ModelEvaluatorDelegatorBase<Scalar>::isUnderlyingModelConst() const
00356 {
00357   return model_.isConst();
00358 }
00359 
00360 
00361 template<class Scalar>
00362 RCP<ModelEvaluator<Scalar> >
00363 ModelEvaluatorDelegatorBase<Scalar>::getNonconstUnderlyingModel()
00364 {
00365   return model_.getNonconstObj();
00366 }
00367 
00368 
00369 template<class Scalar>
00370 RCP<const ModelEvaluator<Scalar> >
00371 ModelEvaluatorDelegatorBase<Scalar>::getUnderlyingModel() const
00372 {
00373   return model_.getConstObj();
00374 }
00375 
00376 
00377 // Overridden from ModelEvaulator.
00378 
00379 
00380 template<class Scalar>
00381 RCP<const VectorSpaceBase<Scalar> >
00382 ModelEvaluatorDelegatorBase<Scalar>::get_x_space() const
00383 {
00384   return getUnderlyingModel()->get_x_space();
00385 }
00386 
00387 
00388 template<class Scalar>
00389 RCP<const VectorSpaceBase<Scalar> >
00390 ModelEvaluatorDelegatorBase<Scalar>::get_f_space() const
00391 {
00392   return getUnderlyingModel()->get_f_space();
00393 }
00394 
00395 
00396 template<class Scalar>
00397 RCP<const VectorSpaceBase<Scalar> >
00398 ModelEvaluatorDelegatorBase<Scalar>::get_p_space(int l) const
00399 {
00400   return getUnderlyingModel()->get_p_space(l);
00401 }
00402 
00403 
00404 template<class Scalar>
00405 RCP<const Teuchos::Array<std::string> >
00406 ModelEvaluatorDelegatorBase<Scalar>::get_p_names(int l) const
00407 {
00408   return getUnderlyingModel()->get_p_names(l);
00409 }
00410 
00411 
00412 template<class Scalar>
00413 RCP<const VectorSpaceBase<Scalar> >
00414 ModelEvaluatorDelegatorBase<Scalar>::get_g_space(int j) const
00415 {
00416   return getUnderlyingModel()->get_g_space(j);
00417 }
00418 
00419 
00420 template<class Scalar>
00421 ModelEvaluatorBase::InArgs<Scalar>
00422 ModelEvaluatorDelegatorBase<Scalar>::getNominalValues() const
00423 {
00424   return getUnderlyingModel()->getNominalValues();
00425 }
00426 
00427 
00428 template<class Scalar>
00429 ModelEvaluatorBase::InArgs<Scalar>
00430 ModelEvaluatorDelegatorBase<Scalar>::getLowerBounds() const
00431 {
00432   return getUnderlyingModel()->getLowerBounds();
00433 }
00434 
00435 
00436 template<class Scalar>
00437 ModelEvaluatorBase::InArgs<Scalar>
00438 ModelEvaluatorDelegatorBase<Scalar>::getUpperBounds() const
00439 {
00440   return getUnderlyingModel()->getUpperBounds();
00441 }
00442 
00443 
00444 template<class Scalar>
00445 RCP<LinearOpWithSolveBase<Scalar> >
00446 ModelEvaluatorDelegatorBase<Scalar>::create_W() const
00447 {
00448   return getUnderlyingModel()->create_W();
00449 }
00450 
00451 
00452 template<class Scalar>
00453 RCP<LinearOpBase<Scalar> >
00454 ModelEvaluatorDelegatorBase<Scalar>::create_W_op() const
00455 {
00456   return getUnderlyingModel()->create_W_op();
00457 }
00458 
00459 
00460 template<class Scalar>
00461 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
00462 ModelEvaluatorDelegatorBase<Scalar>::get_W_factory() const
00463 {
00464   return getUnderlyingModel()->get_W_factory();
00465 }
00466 
00467 
00468 template<class Scalar>
00469 ModelEvaluatorBase::InArgs<Scalar>
00470 ModelEvaluatorDelegatorBase<Scalar>::createInArgs() const
00471 {
00472   ModelEvaluatorBase::InArgsSetup<Scalar> inArgs = getUnderlyingModel()->createInArgs();
00473   inArgs.setModelEvalDescription(this->description());
00474   return inArgs;
00475 }
00476 
00477 
00478 template<class Scalar>
00479 void ModelEvaluatorDelegatorBase<Scalar>::reportFinalPoint(
00480   const ModelEvaluatorBase::InArgs<Scalar>      &finalPoint
00481   ,const bool                                   wasSolved
00482   )
00483 {
00484   getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
00485 }
00486 
00487 
00488 // protected
00489 
00490 
00491 // Producted utility functions to be called by subclasses
00492 
00493 
00494 template<class Scalar>
00495 void ModelEvaluatorDelegatorBase<Scalar>::setLocalVerbosityLevelValidatedParameter(
00496     ParameterList *paramList
00497     ) const
00498 {
00499   TEST_FOR_EXCEPT(0==paramList);
00500   if (is_null(LocalVerbosityLevel_validator_))
00501     LocalVerbosityLevel_validator_ =
00502       Teuchos::verbosityLevelParameterEntryValidator(
00503         LocalVerbosityLevel_name_
00504         );
00505   paramList->set(
00506     LocalVerbosityLevel_name_, LocalVerbosityLevel_default_,
00507     "Overriding verbosity level for this model evaluator object.\n"
00508     "This level will not propagate to nested model evaluator objects\n"
00509     "The value of \"default\" result in the object verbosity level being\n"
00510     "used instead.",
00511     LocalVerbosityLevel_validator_
00512     );
00513 }
00514 
00515 
00516 template<class Scalar>
00517 Teuchos::EVerbosityLevel
00518 ModelEvaluatorDelegatorBase<Scalar>::readLocalVerbosityLevelValidatedParameter(
00519   ParameterList &paramList 
00520   ) const
00521 {
00522   return LocalVerbosityLevel_validator_->getIntegralValue(
00523     paramList, LocalVerbosityLevel_name_, LocalVerbosityLevel_default_ );
00524 }
00525 
00526 
00527 // private
00528 
00529 
00530 // Producted functions overridden from ModelEvaluatorDefaultBase
00531 
00532 
00533 template<class Scalar>
00534 RCP<LinearOpBase<Scalar> >
00535 ModelEvaluatorDelegatorBase<Scalar>::create_DfDp_op_impl(int l) const
00536 {
00537   return getUnderlyingModel()->create_DfDp_op(l);
00538 }
00539 
00540 
00541 template<class Scalar>
00542 RCP<LinearOpBase<Scalar> >
00543 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_dot_op_impl(
00544   int j
00545   ) const
00546 {
00547   return getUnderlyingModel()->create_DgDx_dot_op(j);
00548 }
00549 
00550 
00551 template<class Scalar>
00552 RCP<LinearOpBase<Scalar> >
00553 ModelEvaluatorDelegatorBase<Scalar>::create_DgDx_op_impl(
00554   int j
00555   ) const
00556 {
00557   return getUnderlyingModel()->create_DgDx_op(j);
00558 }
00559 
00560 
00561 template<class Scalar>
00562 RCP<LinearOpBase<Scalar> >
00563 ModelEvaluatorDelegatorBase<Scalar>::create_DgDp_op_impl(
00564   int j, int l
00565   ) const
00566 {
00567   return getUnderlyingModel()->create_DgDp_op(j,l);
00568 }
00569 
00570 
00571 template<class Scalar>
00572 ModelEvaluatorBase::OutArgs<Scalar>
00573 ModelEvaluatorDelegatorBase<Scalar>::createOutArgsImpl() const
00574 {
00575   ModelEvaluatorBase::OutArgsSetup<Scalar>
00576     outArgs = getUnderlyingModel()->createOutArgs();
00577   outArgs.setModelEvalDescription(this->description());
00578   return outArgs;
00579 }
00580 
00581 
00582 } // namespace Thyra
00583 
00584 #endif // THYRA_DEFAULT_MODEL_EVALUATOR_DELEGETOR_BASE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines