Thyra_DefaultFinalPointCaptureModelEvaluator.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_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
00030 #define THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
00031 
00032 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
00033 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00034 #include "Teuchos_Time.hpp"
00035 
00036 //#define THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
00037 
00038 namespace Thyra {
00039 
00046 template<class Scalar>
00047 class DefaultFinalPointCaptureModelEvaluator
00048   : virtual public ModelEvaluatorDelegatorBase<Scalar>
00049 {
00050 public:
00051 
00053   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00054 
00057 
00059   DefaultFinalPointCaptureModelEvaluator();
00060 
00062   DefaultFinalPointCaptureModelEvaluator(
00063     const Teuchos::RefCountPtr<ModelEvaluator<Scalar> >  &thyraModel
00064     );
00065 
00067   const ModelEvaluatorBase::InArgs<Scalar>& getFinalPoint() const;
00068 
00070   bool finalPointWasSolved() const;
00071 
00073 
00076 
00078   void evalModel(
00079     const ModelEvaluatorBase::InArgs<Scalar>    &inArgs
00080     ,const ModelEvaluatorBase::OutArgs<Scalar>  &outArgs
00081     ) const;
00083   void reportFinalPoint(
00084     const ModelEvaluatorBase::InArgs<Scalar>      &finalPoint
00085     ,const bool                                   wasSolved
00086     );
00087 
00089 
00092 
00094   std::string description() const;
00095 
00097 
00098 private:
00099 
00100   ModelEvaluatorBase::InArgs<Scalar>  finalPoint_;
00101   bool                                finalPointWasSolved_;
00102   
00103 };
00104 
00105 // /////////////////////////////////
00106 // Implementations
00107 
00108 // Constructors/initializers/accessors/utilities
00109 
00110 template<class Scalar>
00111 DefaultFinalPointCaptureModelEvaluator<Scalar>::DefaultFinalPointCaptureModelEvaluator()
00112   :finalPointWasSolved_(false)
00113 {}
00114 
00115 template<class Scalar>
00116 DefaultFinalPointCaptureModelEvaluator<Scalar>::DefaultFinalPointCaptureModelEvaluator(
00117   const Teuchos::RefCountPtr<ModelEvaluator<Scalar> >                     &thyraModel
00118   )
00119 {
00120   this->ModelEvaluatorDelegatorBase<Scalar>::initialize(thyraModel);
00121   finalPoint_ = thyraModel->createInArgs();
00122   finalPoint_.setArgs(thyraModel->getNominalValues());
00123   finalPointWasSolved_ = false;
00124 }
00125 
00126 template<class Scalar>
00127 const ModelEvaluatorBase::InArgs<Scalar>&
00128 DefaultFinalPointCaptureModelEvaluator<Scalar>::getFinalPoint() const
00129 {
00130 #ifdef THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
00131   *Teuchos::VerboseObjectBase::getDefaultOStream()
00132     << "\nDefaultFinalPointCaptureModelEvaluator<Scalar>::getFinalPoint():"
00133     << " finalPoint =\n" << Teuchos::describe(finalPoint_,Teuchos::VERB_EXTREME);
00134 #endif  
00135   return finalPoint_;
00136 }
00137 
00138 template<class Scalar>
00139 bool DefaultFinalPointCaptureModelEvaluator<Scalar>::finalPointWasSolved() const
00140 {
00141   return finalPointWasSolved_;
00142 }
00143 
00144 // Overridden from ModelEvaulator.
00145 
00146 template<class Scalar>
00147 void DefaultFinalPointCaptureModelEvaluator<Scalar>::evalModel(
00148   const ModelEvaluatorBase::InArgs<Scalar>     &inArgs
00149   ,const ModelEvaluatorBase::OutArgs<Scalar>   &outArgs
00150   ) const
00151 {
00152 
00153   const Teuchos::RefCountPtr<Teuchos::FancyOStream> out       = this->getOStream();
00154   const Teuchos::EVerbosityLevel                    verbLevel = this->getVerbLevel();
00155   Teuchos::OSTab tab(out);
00156   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_LOW))
00157     *out << "\nEntering Thyra::DefaultFinalPointCapture<Scalar>::evalModel(...) ...\n";
00158 
00159   const Teuchos::RefCountPtr<const ModelEvaluator<Scalar> >
00160     thyraModel = this->getUnderlyingModel();
00161 
00162   typedef Teuchos::VerboseObjectTempState<ModelEvaluatorBase> VOTSME;
00163   VOTSME thyraModel_outputTempState(thyraModel,out,verbLevel);
00164 
00165   thyraModel->evalModel(inArgs,outArgs);
00166 
00167   if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_LOW))
00168     *out
00169       << "\nLeaving Thyra::DefaultFinalPointCapture<Scalar>::evalModel(...) ...\n";
00170 }
00171 
00172 template<class Scalar>
00173 void DefaultFinalPointCaptureModelEvaluator<Scalar>::reportFinalPoint(
00174   const ModelEvaluatorBase::InArgs<Scalar>      &finalPoint
00175   ,const bool                                   wasSolved
00176   )
00177 {
00178   finalPoint_.setArgs(finalPoint);
00179   finalPointWasSolved_ = wasSolved;
00180   if(!this->isUnderlyingModelConst())
00181     this->getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
00182 #ifdef THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
00183   *Teuchos::VerboseObjectBase::getDefaultOStream()
00184     << "\nDefaultFinalPointCaptureModelEvaluator<Scalar>::reportFinalPoint(...):"
00185     << " finalPoint =\n" << Teuchos::describe(finalPoint_,Teuchos::VERB_EXTREME);
00186 #endif  
00187 }
00188 
00189 // Public functions overridden from Teuchos::Describable
00190 
00191 template<class Scalar>
00192 std::string DefaultFinalPointCaptureModelEvaluator<Scalar>::description() const
00193 {
00194   const Teuchos::RefCountPtr<const ModelEvaluator<Scalar> >
00195     thyraModel = this->getUnderlyingModel();
00196   std::ostringstream oss;
00197   oss << "Thyra::DefaultFinalPointCaptureModelEvaluator{";
00198   oss << "thyraModel=";
00199   if(thyraModel.get())
00200     oss << "\'"<<thyraModel->description()<<"\'";
00201   else
00202     oss << "NULL";
00203   oss << "}";
00204   return oss.str();
00205 }
00206 
00207 } // namespace Thyra
00208 
00209 #endif // THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP

Generated on Thu Sep 18 12:33:02 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1