Thyra_DefaultNominalBoundsOverrideModelEvaluator.hpp

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_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
00030 #define THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
00031 
00032 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
00033 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00034 #include "Teuchos_Time.hpp"
00035 
00036 namespace Thyra {
00037 
00073 template<class Scalar>
00074 class DefaultNominalBoundsOverrideModelEvaluator
00075   : virtual public ModelEvaluatorDelegatorBase<Scalar>
00076 {
00077 public:
00078 
00080   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00081 
00084 
00086   DefaultNominalBoundsOverrideModelEvaluator();
00087 
00089   DefaultNominalBoundsOverrideModelEvaluator(
00090     const Teuchos::RefCountPtr<ModelEvaluator<Scalar> >                     &thyraModel
00091     ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00092     ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds = Teuchos::null
00093     ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds = Teuchos::null
00094     );
00095 
00114   void initialize(
00115     const Teuchos::RefCountPtr<ModelEvaluator<Scalar> >                     &thyraModel
00116     ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00117     ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds = Teuchos::null
00118     ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds = Teuchos::null
00119     );
00120   
00122   void setNominalValues(
00123     const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00124     );
00125   
00126   // ToDo: Add functions to reset lower and upper bounds when needed!
00127 
00129 
00132 
00134   ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
00136   ModelEvaluatorBase::InArgs<Scalar> getLowerBounds() const;
00138   ModelEvaluatorBase::InArgs<Scalar> getUpperBounds() const;
00140   void evalModel(
00141     const ModelEvaluatorBase::InArgs<Scalar>    &inArgs
00142     ,const ModelEvaluatorBase::OutArgs<Scalar>  &outArgs
00143     ) const;
00144 
00146 
00149 
00151   std::string description() const;
00152 
00154 
00155 private:
00156 
00157   Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  nominalValues_;
00158   Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  lowerBounds_;
00159   Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  upperBounds_;
00160   
00161 };
00162 
00163 // /////////////////////////////////
00164 // Implementations
00165 
00166 // Constructors/initializers/accessors/utilities
00167 
00168 template<class Scalar>
00169 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::DefaultNominalBoundsOverrideModelEvaluator()
00170 {}
00171 
00172 template<class Scalar>
00173 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::DefaultNominalBoundsOverrideModelEvaluator(
00174   const Teuchos::RefCountPtr<ModelEvaluator<Scalar> >                     &thyraModel
00175   ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00176   ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds
00177   ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds
00178   )
00179 {
00180   initialize(thyraModel,nominalValues,lowerBounds,upperBounds);
00181 }
00182 
00183 template<class Scalar>
00184 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::initialize(
00185   const Teuchos::RefCountPtr<ModelEvaluator<Scalar> >                     &thyraModel
00186   ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00187   ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds
00188   ,const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds
00189   )
00190 {
00191   this->ModelEvaluatorDelegatorBase<Scalar>::initialize(thyraModel);
00192   nominalValues_ = nominalValues;
00193   lowerBounds_ = lowerBounds;
00194   upperBounds_ = upperBounds;
00195 }
00196 
00197 template<class Scalar>
00198 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setNominalValues(
00199   const Teuchos::RefCountPtr<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00200   )
00201 {
00202   nominalValues_ = nominalValues;
00203 }
00204 
00205 // Overridden from ModelEvaulator.
00206 
00207 template<class Scalar>
00208 ModelEvaluatorBase::InArgs<Scalar>
00209 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getNominalValues() const
00210 {
00211   if(nominalValues_.get()) return *nominalValues_;
00212   return this->getUnderlyingModel()->getNominalValues();
00213 }
00214 
00215 template<class Scalar>
00216 ModelEvaluatorBase::InArgs<Scalar>
00217 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getLowerBounds() const
00218 {
00219   if(lowerBounds_.get()) return *lowerBounds_;
00220   return this->getUnderlyingModel()->getLowerBounds();
00221 }
00222 
00223 template<class Scalar>
00224 ModelEvaluatorBase::InArgs<Scalar>
00225 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getUpperBounds() const
00226 {
00227   if(upperBounds_.get()) return *upperBounds_;
00228   return this->getUnderlyingModel()->getUpperBounds();
00229 }
00230 
00231 template<class Scalar>
00232 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::evalModel(
00233   const ModelEvaluatorBase::InArgs<Scalar>     &inArgs
00234   ,const ModelEvaluatorBase::OutArgs<Scalar>   &outArgs
00235   ) const
00236 {
00237   typedef ModelEvaluatorBase MEB;
00238   using Teuchos::RefCountPtr;
00239   using Teuchos::rcp;
00240   using Teuchos::rcp_const_cast;
00241   using Teuchos::rcp_dynamic_cast;
00242   using Teuchos::OSTab;
00243 
00244   Teuchos::Time totalTimer(""), timer("");
00245   totalTimer.start(true);
00246 
00247   const Teuchos::RefCountPtr<Teuchos::FancyOStream> out       = this->getOStream();
00248   const Teuchos::EVerbosityLevel                    verbLevel = this->getVerbLevel();
00249   Teuchos::OSTab tab(out);
00250   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_LOW))
00251     *out << "\nEntering Thyra::DefaultNominalBoundsOverrideModelEvaluator<Scalar>::evalModel(...) ...\n";
00252 
00253   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00254     *out
00255       << "\ninArgs =\n" << Teuchos::describe(inArgs,verbLevel)
00256       << "\noutArgs on input =\n" << Teuchos::describe(outArgs,Teuchos::VERB_LOW);
00257 
00258   const Teuchos::RefCountPtr<const ModelEvaluator<Scalar> >
00259     thyraModel = this->getUnderlyingModel();
00260 
00261   typedef Teuchos::VerboseObjectTempState<ModelEvaluatorBase> VOTSME;
00262   VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel);
00263 
00264   // First set the inArgs to what was overridden
00265   MEB::InArgs<Scalar> wrappedInArgs = *nominalValues_;
00266 
00267   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00268     *out
00269       << "\nwrappedInArgs after assigning to nominalValues =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
00270 
00271   // Reset those not at their nominal values
00272   wrappedInArgs.setArgs(inArgs);
00273 
00274   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00275     *out
00276       << "\nwrappedInArgs after setting input values =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
00277 
00278   thyraModel->evalModel(wrappedInArgs,outArgs);
00279 
00280   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00281     *out
00282       << "\noutArgs on output =\n" << Teuchos::describe(outArgs,verbLevel);
00283 
00284   totalTimer.stop();
00285   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_LOW))
00286     *out
00287       << "\nLeaving Thyra::DefaultNominalBoundsOverrideModelEvaluator<Scalar>::evalModel(...) ...\n";
00288   
00289 }
00290 
00291 // Public functions overridden from Teuchos::Describable
00292 
00293 template<class Scalar>
00294 std::string DefaultNominalBoundsOverrideModelEvaluator<Scalar>::description() const
00295 {
00296   const Teuchos::RefCountPtr<const ModelEvaluator<Scalar> >
00297     thyraModel = this->getUnderlyingModel();
00298   std::ostringstream oss;
00299   oss << "Thyra::DefaultNominalBoundsOverrideModelEvaluator{";
00300   oss << "thyraModel=";
00301   if(thyraModel.get())
00302     oss << "\'"<<thyraModel->description()<<"\'";
00303   else
00304     oss << "NULL";
00305   oss << "}";
00306   return oss.str();
00307 }
00308 
00309 } // namespace Thyra
00310 
00311 #endif // THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP

Generated on Thu Sep 18 12:32:48 2008 for Thyra Nonlinear Model Evaluator Support by doxygen 1.3.9.1