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 
00033 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
00034 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00035 #include "Teuchos_Time.hpp"
00036 
00037 
00038 namespace Thyra {
00039 
00040 
00087 template<class Scalar>
00088 class DefaultNominalBoundsOverrideModelEvaluator
00089   : virtual public ModelEvaluatorDelegatorBase<Scalar>
00090 {
00091 public:
00092 
00094   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00095 
00098 
00100   DefaultNominalBoundsOverrideModelEvaluator();
00101 
00103   DefaultNominalBoundsOverrideModelEvaluator(
00104     const RCP<ModelEvaluator<Scalar> > &thyraModel,
00105     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00106     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
00107     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
00108     );
00109 
00134   void initialize(
00135     const RCP<ModelEvaluator<Scalar> > &thyraModel,
00136     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00137     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
00138     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
00139     );
00140   
00142   void setNominalValues(
00143     const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00144     );
00145   
00147   void setLowerBounds(
00148     const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds
00149     );
00150   
00152   void setUpperBounds(
00153     const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds
00154     );
00155   
00156   // ToDo: Add functions to reset lower and upper bounds when needed!
00157 
00159 
00162 
00164   std::string description() const;
00165 
00167 
00170 
00172   ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
00174   ModelEvaluatorBase::InArgs<Scalar> getLowerBounds() const;
00176   ModelEvaluatorBase::InArgs<Scalar> getUpperBounds() const;
00177 
00179 
00180 private:
00181 
00184 
00186   void evalModelImpl(
00187     const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00188     const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00189     ) const;
00190 
00192 
00193 private:
00194 
00195   RCP<const ModelEvaluatorBase::InArgs<Scalar> >  nominalValues_;
00196   RCP<const ModelEvaluatorBase::InArgs<Scalar> >  lowerBounds_;
00197   RCP<const ModelEvaluatorBase::InArgs<Scalar> >  upperBounds_;
00198   
00199 };
00200 
00201 
00202 // /////////////////////////////////
00203 // Implementations
00204 
00205 
00206 // Constructors/initializers/accessors/utilities
00207 
00208 
00209 template<class Scalar>
00210 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::DefaultNominalBoundsOverrideModelEvaluator()
00211 {}
00212 
00213 
00214 template<class Scalar>
00215 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::DefaultNominalBoundsOverrideModelEvaluator(
00216   const RCP<ModelEvaluator<Scalar> > &thyraModel,
00217   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00218   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
00219   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
00220   )
00221 {
00222   initialize(thyraModel,nominalValues,lowerBounds,upperBounds);
00223 }
00224 
00225 
00226 template<class Scalar>
00227 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::initialize(
00228   const RCP<ModelEvaluator<Scalar> > &thyraModel,
00229   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00230   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
00231   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
00232   )
00233 {
00234   this->ModelEvaluatorDelegatorBase<Scalar>::initialize(thyraModel);
00235   nominalValues_ = nominalValues;
00236   lowerBounds_ = lowerBounds;
00237   upperBounds_ = upperBounds;
00238 }
00239 
00240 
00241 template<class Scalar>
00242 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setNominalValues(
00243   const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00244   )
00245 {
00246   nominalValues_ = nominalValues;
00247 }
00248 
00249 
00250 template<class Scalar>
00251 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setLowerBounds(
00252   const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds
00253   )
00254 {
00255   lowerBounds_ = lowerBounds;
00256 }
00257 
00258 
00259 template<class Scalar>
00260 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setUpperBounds(
00261   const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds
00262   )
00263 {
00264   upperBounds_ = upperBounds;
00265 }
00266 
00267 
00268 // Public functions overridden from Teuchos::Describable
00269 
00270 
00271 template<class Scalar>
00272 std::string DefaultNominalBoundsOverrideModelEvaluator<Scalar>::description() const
00273 {
00274   const RCP<const ModelEvaluator<Scalar> >
00275     thyraModel = this->getUnderlyingModel();
00276   std::ostringstream oss;
00277   oss << "Thyra::DefaultNominalBoundsOverrideModelEvaluator{";
00278   oss << "thyraModel=";
00279   if(thyraModel.get())
00280     oss << "\'"<<thyraModel->description()<<"\'";
00281   else
00282     oss << "NULL";
00283   oss << "}";
00284   return oss.str();
00285 }
00286 
00287 
00288 // Overridden from ModelEvaulator.
00289 
00290 
00291 template<class Scalar>
00292 ModelEvaluatorBase::InArgs<Scalar>
00293 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getNominalValues() const
00294 {
00295   if(nominalValues_.get())
00296     return *nominalValues_;
00297   return this->getUnderlyingModel()->getNominalValues();
00298 }
00299 
00300 
00301 template<class Scalar>
00302 ModelEvaluatorBase::InArgs<Scalar>
00303 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getLowerBounds() const
00304 {
00305   if(lowerBounds_.get())
00306     return *lowerBounds_;
00307   return this->getUnderlyingModel()->getLowerBounds();
00308 }
00309 
00310 
00311 template<class Scalar>
00312 ModelEvaluatorBase::InArgs<Scalar>
00313 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getUpperBounds() const
00314 {
00315   if(upperBounds_.get())
00316     return *upperBounds_;
00317   return this->getUnderlyingModel()->getUpperBounds();
00318 }
00319 
00320 
00321 // Private functions overridden from ModelEvaulatorDefaultBase
00322 
00323 
00324 template<class Scalar>
00325 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::evalModelImpl(
00326   const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00327   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00328   ) const
00329 {
00330 
00331   using Teuchos::rcp;
00332   using Teuchos::rcp_const_cast;
00333   using Teuchos::rcp_dynamic_cast;
00334   using Teuchos::OSTab;
00335   typedef ModelEvaluatorBase MEB;
00336 
00337   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
00338     "Thyra::DefaultNominalBoundsOverrideModelEvaluator",inArgs,outArgs
00339     );
00340 
00341   // First set the inArgs to what was overridden
00342   MEB::InArgs<Scalar>
00343     wrappedInArgs = ( !is_null(nominalValues_) ? *nominalValues_ : this->createInArgs() );
00344 
00345   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00346     *out
00347       << "\nwrappedInArgs after assigning to nominalValues =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
00348 
00349   // Reset those not at their nominal values
00350   wrappedInArgs.setArgs(inArgs);
00351 
00352   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00353     *out
00354       << "\nwrappedInArgs after setting input values =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
00355 
00356   thyraModel->evalModel(wrappedInArgs,outArgs);
00357 
00358   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
00359   
00360 }
00361 
00362 
00363 } // namespace Thyra
00364 
00365 
00366 #endif // THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP

Generated on Tue Jul 13 09:26:21 2010 for Thyra by  doxygen 1.4.7