Thyra Version of the Day
Thyra_DefaultFinalPointCaptureModelEvaluator.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_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
00043 #define THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
00044 
00045 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
00046 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00047 #include "Teuchos_Time.hpp"
00048 
00049 
00050 //#define THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
00051 
00052 
00053 namespace Thyra {
00054 
00055 
00063 template<class Scalar>
00064 class DefaultFinalPointCaptureModelEvaluator
00065   : virtual public ModelEvaluatorDelegatorBase<Scalar>
00066 {
00067 public:
00068 
00070   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00071 
00074 
00076   DefaultFinalPointCaptureModelEvaluator();
00077 
00079   DefaultFinalPointCaptureModelEvaluator(
00080     const Teuchos::RCP<ModelEvaluator<Scalar> >  &thyraModel
00081     );
00082 
00084   const ModelEvaluatorBase::InArgs<Scalar>& getFinalPoint() const;
00085 
00087   bool finalPointWasSolved() const;
00088 
00090 
00093 
00095   std::string description() const;
00096 
00098 
00101 
00103   void reportFinalPoint(
00104     const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
00105     const bool wasSolved
00106     );
00107 
00109 
00110 private:
00111 
00114 
00116   void evalModelImpl(
00117     const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00118     const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00119     ) const;
00120 
00122 
00123 private:
00124 
00125   ModelEvaluatorBase::InArgs<Scalar> finalPoint_;
00126   bool finalPointWasSolved_;
00127   
00128 };
00129 
00130 
00131 // /////////////////////////////////
00132 // Implementations
00133 
00134 
00135 // Constructors/initializers/accessors/utilities
00136 
00137 
00138 template<class Scalar>
00139 DefaultFinalPointCaptureModelEvaluator<Scalar>::DefaultFinalPointCaptureModelEvaluator()
00140   :finalPointWasSolved_(false)
00141 {}
00142 
00143 
00144 template<class Scalar>
00145 DefaultFinalPointCaptureModelEvaluator<Scalar>::DefaultFinalPointCaptureModelEvaluator(
00146   const Teuchos::RCP<ModelEvaluator<Scalar> >                     &thyraModel
00147   )
00148 {
00149   this->ModelEvaluatorDelegatorBase<Scalar>::initialize(thyraModel);
00150   finalPoint_ = thyraModel->createInArgs();
00151   finalPoint_.setArgs(thyraModel->getNominalValues());
00152   finalPointWasSolved_ = false;
00153 }
00154 
00155 
00156 template<class Scalar>
00157 const ModelEvaluatorBase::InArgs<Scalar>&
00158 DefaultFinalPointCaptureModelEvaluator<Scalar>::getFinalPoint() const
00159 {
00160 #ifdef THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
00161   *Teuchos::VerboseObjectBase::getDefaultOStream()
00162     << "\nDefaultFinalPointCaptureModelEvaluator<Scalar>::getFinalPoint():"
00163     << " finalPoint =\n" << Teuchos::describe(finalPoint_,Teuchos::VERB_EXTREME);
00164 #endif  
00165   return finalPoint_;
00166 }
00167 
00168 
00169 template<class Scalar>
00170 bool DefaultFinalPointCaptureModelEvaluator<Scalar>::finalPointWasSolved() const
00171 {
00172   return finalPointWasSolved_;
00173 }
00174 
00175 
00176 // Public functions overridden from Teuchos::Describable
00177 
00178 
00179 template<class Scalar>
00180 std::string DefaultFinalPointCaptureModelEvaluator<Scalar>::description() const
00181 {
00182   const Teuchos::RCP<const ModelEvaluator<Scalar> >
00183     thyraModel = this->getUnderlyingModel();
00184   std::ostringstream oss;
00185   oss << "Thyra::DefaultFinalPointCaptureModelEvaluator{";
00186   oss << "thyraModel=";
00187   if(thyraModel.get())
00188     oss << "\'"<<thyraModel->description()<<"\'";
00189   else
00190     oss << "NULL";
00191   oss << "}";
00192   return oss.str();
00193 }
00194 
00195 
00196 // Overridden from ModelEvaulator.
00197 
00198 
00199 template<class Scalar>
00200 void DefaultFinalPointCaptureModelEvaluator<Scalar>::reportFinalPoint(
00201   const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
00202   const bool wasSolved
00203   )
00204 {
00205   finalPoint_.setArgs(finalPoint);
00206   finalPointWasSolved_ = wasSolved;
00207   if(!this->isUnderlyingModelConst())
00208     this->getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
00209 #ifdef THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
00210   *Teuchos::VerboseObjectBase::getDefaultOStream()
00211     << "\nDefaultFinalPointCaptureModelEvaluator<Scalar>::reportFinalPoint(...):"
00212     << " finalPoint =\n" << Teuchos::describe(finalPoint_,Teuchos::VERB_EXTREME);
00213 #endif  
00214 }
00215 
00216 
00217 // Private functions overridden from ModelEvaulatorDefaultBase
00218 
00219 
00220 template<class Scalar>
00221 void DefaultFinalPointCaptureModelEvaluator<Scalar>::evalModelImpl(
00222   const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00223   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00224   ) const
00225 {
00226 
00227   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
00228     "Thyra::DefaultFinalPointCaptureModelEvaluator",inArgs,outArgs
00229     );
00230 
00231   thyraModel->evalModel(inArgs,outArgs);
00232 
00233   THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
00234 
00235 }
00236 
00237 
00238 } // namespace Thyra
00239 
00240 
00241 #endif // THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines