Thyra Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
00043 #define THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
00044 
00045 
00046 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
00047 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00048 #include "Teuchos_Time.hpp"
00049 
00050 
00051 namespace Thyra {
00052 
00053 
00100 template<class Scalar>
00101 class DefaultNominalBoundsOverrideModelEvaluator
00102   : virtual public ModelEvaluatorDelegatorBase<Scalar>
00103 {
00104 public:
00105 
00107   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00108 
00111 
00113   DefaultNominalBoundsOverrideModelEvaluator();
00114 
00116   DefaultNominalBoundsOverrideModelEvaluator(
00117     const RCP<ModelEvaluator<Scalar> > &thyraModel,
00118     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00119     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
00120     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
00121     );
00122 
00147   void initialize(
00148     const RCP<ModelEvaluator<Scalar> > &thyraModel,
00149     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00150     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
00151     const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
00152     );
00153   
00155   void setNominalValues(
00156     const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00157     );
00158   
00160   void setLowerBounds(
00161     const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds
00162     );
00163   
00165   void setUpperBounds(
00166     const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds
00167     );
00168   
00169   // ToDo: Add functions to reset lower and upper bounds when needed!
00170 
00172 
00175 
00177   std::string description() const;
00178 
00180 
00183 
00185   ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
00187   ModelEvaluatorBase::InArgs<Scalar> getLowerBounds() const;
00189   ModelEvaluatorBase::InArgs<Scalar> getUpperBounds() const;
00190 
00192 
00193 private:
00194 
00197 
00199   void evalModelImpl(
00200     const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00201     const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00202     ) const;
00203 
00205 
00206 private:
00207 
00208   RCP<const ModelEvaluatorBase::InArgs<Scalar> >  nominalValues_;
00209   RCP<const ModelEvaluatorBase::InArgs<Scalar> >  lowerBounds_;
00210   RCP<const ModelEvaluatorBase::InArgs<Scalar> >  upperBounds_;
00211   
00212 };
00213 
00214 
00215 // /////////////////////////////////
00216 // Implementations
00217 
00218 
00219 // Constructors/initializers/accessors/utilities
00220 
00221 
00222 template<class Scalar>
00223 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::DefaultNominalBoundsOverrideModelEvaluator()
00224 {}
00225 
00226 
00227 template<class Scalar>
00228 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::DefaultNominalBoundsOverrideModelEvaluator(
00229   const RCP<ModelEvaluator<Scalar> > &thyraModel,
00230   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00231   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
00232   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
00233   )
00234 {
00235   initialize(thyraModel,nominalValues,lowerBounds,upperBounds);
00236 }
00237 
00238 
00239 template<class Scalar>
00240 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::initialize(
00241   const RCP<ModelEvaluator<Scalar> > &thyraModel,
00242   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
00243   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
00244   const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
00245   )
00246 {
00247   this->ModelEvaluatorDelegatorBase<Scalar>::initialize(thyraModel);
00248   nominalValues_ = nominalValues;
00249   lowerBounds_ = lowerBounds;
00250   upperBounds_ = upperBounds;
00251 }
00252 
00253 
00254 template<class Scalar>
00255 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setNominalValues(
00256   const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &nominalValues
00257   )
00258 {
00259   nominalValues_ = nominalValues;
00260 }
00261 
00262 
00263 template<class Scalar>
00264 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setLowerBounds(
00265   const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &lowerBounds
00266   )
00267 {
00268   lowerBounds_ = lowerBounds;
00269 }
00270 
00271 
00272 template<class Scalar>
00273 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::setUpperBounds(
00274   const RCP<const ModelEvaluatorBase::InArgs<Scalar> >  &upperBounds
00275   )
00276 {
00277   upperBounds_ = upperBounds;
00278 }
00279 
00280 
00281 // Public functions overridden from Teuchos::Describable
00282 
00283 
00284 template<class Scalar>
00285 std::string DefaultNominalBoundsOverrideModelEvaluator<Scalar>::description() const
00286 {
00287   const RCP<const ModelEvaluator<Scalar> >
00288     thyraModel = this->getUnderlyingModel();
00289   std::ostringstream oss;
00290   oss << "Thyra::DefaultNominalBoundsOverrideModelEvaluator{";
00291   oss << "thyraModel=";
00292   if(thyraModel.get())
00293     oss << "\'"<<thyraModel->description()<<"\'";
00294   else
00295     oss << "NULL";
00296   oss << "}";
00297   return oss.str();
00298 }
00299 
00300 
00301 // Overridden from ModelEvaulator.
00302 
00303 
00304 template<class Scalar>
00305 ModelEvaluatorBase::InArgs<Scalar>
00306 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getNominalValues() const
00307 {
00308   if(nominalValues_.get())
00309     return *nominalValues_;
00310   return this->getUnderlyingModel()->getNominalValues();
00311 }
00312 
00313 
00314 template<class Scalar>
00315 ModelEvaluatorBase::InArgs<Scalar>
00316 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getLowerBounds() const
00317 {
00318   if(lowerBounds_.get())
00319     return *lowerBounds_;
00320   return this->getUnderlyingModel()->getLowerBounds();
00321 }
00322 
00323 
00324 template<class Scalar>
00325 ModelEvaluatorBase::InArgs<Scalar>
00326 DefaultNominalBoundsOverrideModelEvaluator<Scalar>::getUpperBounds() const
00327 {
00328   if(upperBounds_.get())
00329     return *upperBounds_;
00330   return this->getUnderlyingModel()->getUpperBounds();
00331 }
00332 
00333 
00334 // Private functions overridden from ModelEvaulatorDefaultBase
00335 
00336 
00337 template<class Scalar>
00338 void DefaultNominalBoundsOverrideModelEvaluator<Scalar>::evalModelImpl(
00339   const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00340   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00341   ) const
00342 {
00343 
00344   using Teuchos::rcp;
00345   using Teuchos::rcp_const_cast;
00346   using Teuchos::rcp_dynamic_cast;
00347   using Teuchos::OSTab;
00348   typedef ModelEvaluatorBase MEB;
00349 
00350   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
00351     "Thyra::DefaultNominalBoundsOverrideModelEvaluator",inArgs,outArgs
00352     );
00353 
00354   // First set the inArgs to what was overridden
00355   MEB::InArgs<Scalar>
00356     wrappedInArgs = ( !is_null(nominalValues_) ? *nominalValues_ : this->createInArgs() );
00357 
00358   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00359     *out
00360       << "\nwrappedInArgs after assigning to nominalValues =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
00361 
00362   // Reset those not at their nominal values
00363   wrappedInArgs.setArgs(inArgs);
00364 
00365   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
00366     *out
00367       << "\nwrappedInArgs after setting input values =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
00368 
00369   thyraModel->evalModel(wrappedInArgs,outArgs);
00370 
00371   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
00372   
00373 }
00374 
00375 
00376 } // namespace Thyra
00377 
00378 
00379 #endif // THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines