Rythmos - Transient Integration for Differential Equations Version of the Day
Rythmos_StateAndForwardSensitivityModelEvaluator.hpp
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //                           Rythmos Package
00005 //                 Copyright (2006) 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 Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 #ifndef RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
00030 #define RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
00031 
00032 
00033 #include "Rythmos_ForwardSensitivityModelEvaluatorBase.hpp"
00034 #include "Thyra_ModelEvaluator.hpp" // Interface
00035 #include "Thyra_StateFuncModelEvaluatorBase.hpp" // Implementation
00036 #include "Thyra_DefaultProductVectorSpace.hpp"
00037 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
00038 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
00039 #include "Thyra_DefaultMultiVectorProductVector.hpp"
00040 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
00041 #include "Teuchos_implicit_cast.hpp"
00042 
00043 
00044 namespace Rythmos {
00045 
00046 
00183 template<class Scalar>
00184 class StateAndForwardSensitivityModelEvaluator
00185   : virtual public Thyra::StateFuncModelEvaluatorBase<Scalar>
00186 {
00187 public:
00188 
00191 
00193   StateAndForwardSensitivityModelEvaluator();
00194 
00202   void initializeStructure(
00203     const Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > &sensModel
00204     );
00205 
00206   // 2007/05/30: rabartl: ToDo: Add function to set the nominal values etc.
00207 
00213   Teuchos::RCP<const Thyra::DefaultProductVector<Scalar> >
00214   create_x_bar_vec(
00215     const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_vec,
00216     const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &s_bar_vec
00217     ) const;
00218 
00220 
00223 
00225   int Np() const;
00227   Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
00229   Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
00231   Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
00233   Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
00235   Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
00237   Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
00239   Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
00240 
00242 
00243 private:
00244 
00247 
00249   Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
00251   void evalModelImpl(
00252     const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00253     const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00254     ) const;
00255 
00257 
00258 private:
00259 
00260   // /////////////////////////
00261   // Private data members
00262 
00263   Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > sensModel_;
00264 
00265   int Np_;
00266   Teuchos::RCP<const Thyra::DefaultProductVectorSpace<Scalar> > x_bar_space_;
00267   Teuchos::RCP<const Thyra::DefaultProductVectorSpace<Scalar> > f_bar_space_;
00268   
00269 };
00270 
00271 
00272 // /////////////////////////////////
00273 // Implementations
00274 
00275 
00276 // Constructors/Intializers/Accessors
00277 
00278 
00279 template<class Scalar>
00280 StateAndForwardSensitivityModelEvaluator<Scalar>::StateAndForwardSensitivityModelEvaluator()
00281   :Np_(0)
00282 {}
00283 
00284 
00285 template<class Scalar>
00286 void StateAndForwardSensitivityModelEvaluator<Scalar>::initializeStructure(
00287   const Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > &sensModel
00288   )
00289 {
00290 
00291   using Teuchos::tuple; using Teuchos::RCP;
00292   typedef Thyra::ModelEvaluatorBase MEB;
00293 
00294   TEST_FOR_EXCEPT( is_null(sensModel) );
00295   
00296   sensModel_ = sensModel;
00297 
00298   const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
00299     stateModel = sensModel_->getStateModel();
00300   
00301   x_bar_space_ = Thyra::productVectorSpace<Scalar>(
00302     tuple<RCP<const Thyra::VectorSpaceBase<Scalar> > >(
00303       stateModel->get_x_space(), sensModel_->get_x_space()
00304       )
00305     );
00306 
00307   f_bar_space_ = Thyra::productVectorSpace<Scalar>(
00308     tuple<RCP<const Thyra::VectorSpaceBase<Scalar> > >(
00309       stateModel->get_f_space(), sensModel_->get_f_space()
00310       )
00311     );
00312 
00313   Np_ = stateModel->Np();
00314 
00315 }
00316 
00317 
00318 template<class Scalar> 
00319 Teuchos::RCP<const Thyra::DefaultProductVector<Scalar> >
00320 StateAndForwardSensitivityModelEvaluator<Scalar>::create_x_bar_vec(
00321   const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_vec,
00322   const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &s_bar_vec
00323   ) const
00324 {
00325 
00326   using Teuchos::tuple;
00327   using Teuchos::RCP;
00328   typedef RCP<const Thyra::VectorBase<Scalar> > RCPCV;
00329 
00330   return Thyra::defaultProductVector<Scalar>(
00331     x_bar_space_, tuple<RCPCV>(x_vec,s_bar_vec)
00332     );
00333 
00334 }
00335 
00336 
00337 // Public functions overridden from ModelEvaulator
00338 
00339 
00340 template<class Scalar>
00341 int StateAndForwardSensitivityModelEvaluator<Scalar>::Np() const
00342 {
00343   return Np_;
00344 }
00345 
00346 
00347 template<class Scalar>
00348 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00349 StateAndForwardSensitivityModelEvaluator<Scalar>::get_p_space(int l) const
00350 {
00351   return sensModel_->getStateModel()->get_p_space(l);
00352 }
00353 
00354 
00355 template<class Scalar>
00356 Teuchos::RCP<const Teuchos::Array<std::string> >
00357 StateAndForwardSensitivityModelEvaluator<Scalar>::get_p_names(int l) const
00358 {
00359   return sensModel_->getStateModel()->get_p_names(l);
00360 }
00361 
00362 
00363 template<class Scalar>
00364 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00365 StateAndForwardSensitivityModelEvaluator<Scalar>::get_x_space() const
00366 {
00367   return x_bar_space_;
00368 }
00369 
00370 
00371 template<class Scalar>
00372 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00373 StateAndForwardSensitivityModelEvaluator<Scalar>::get_f_space() const
00374 {
00375   return f_bar_space_;
00376 }
00377 
00378 
00379 template<class Scalar>
00380 Thyra::ModelEvaluatorBase::InArgs<Scalar>
00381 StateAndForwardSensitivityModelEvaluator<Scalar>::getNominalValues() const
00382 {
00383   return this->createInArgs();
00384 }
00385 
00386 
00387 template<class Scalar>
00388 Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> >
00389 StateAndForwardSensitivityModelEvaluator<Scalar>::create_W() const
00390 {
00391   TEST_FOR_EXCEPT("ToDo: Implement create_W() when needed!");
00392   return Teuchos::null;
00393 }
00394 
00395 
00396 template<class Scalar>
00397 Thyra::ModelEvaluatorBase::InArgs<Scalar>
00398 StateAndForwardSensitivityModelEvaluator<Scalar>::createInArgs() const
00399 {
00400   typedef Thyra::ModelEvaluatorBase MEB;
00401   MEB::InArgs<Scalar>
00402     stateModelInArgs = sensModel_->getStateModel()->createInArgs();
00403   MEB::InArgsSetup<Scalar> inArgs;
00404   inArgs.setModelEvalDescription(this->description());
00405   inArgs.set_Np(Np_);
00406   inArgs.setSupports( MEB::IN_ARG_x_dot,
00407     stateModelInArgs.supports(MEB::IN_ARG_x_dot) );
00408   inArgs.setSupports( MEB::IN_ARG_x );
00409   inArgs.setSupports( MEB::IN_ARG_t );
00410   inArgs.setSupports( MEB::IN_ARG_alpha,
00411     stateModelInArgs.supports(MEB::IN_ARG_alpha) );
00412   inArgs.setSupports( MEB::IN_ARG_beta,
00413     stateModelInArgs.supports(MEB::IN_ARG_beta) );
00414   return inArgs;
00415 }
00416 
00417 
00418 // Private functions overridden from ModelEvaulatorDefaultBase
00419 
00420 
00421 template<class Scalar>
00422 Thyra::ModelEvaluatorBase::OutArgs<Scalar>
00423 StateAndForwardSensitivityModelEvaluator<Scalar>::createOutArgsImpl() const
00424 {
00425   typedef Thyra::ModelEvaluatorBase MEB;
00426   MEB::OutArgs<Scalar>
00427     stateModelOutArgs = sensModel_->getStateModel()->createOutArgs();
00428   MEB::OutArgsSetup<Scalar> outArgs;
00429   outArgs.setModelEvalDescription(this->description());
00430   outArgs.set_Np_Ng(Np_,0);
00431   outArgs.setSupports(MEB::OUT_ARG_f);
00432   if (stateModelOutArgs.supports(MEB::OUT_ARG_W) ) {
00433     outArgs.setSupports(MEB::OUT_ARG_W);
00434     outArgs.set_W_properties(stateModelOutArgs.get_W_properties());
00435   }
00436   return outArgs;
00437 }
00438 
00439 
00440 template<class Scalar>
00441 void StateAndForwardSensitivityModelEvaluator<Scalar>::evalModelImpl(
00442   const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00443   const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00444   ) const
00445 {
00446   TEST_FOR_EXCEPT("ToDo: Implement evalModel(...) when needed!");
00447 }
00448 
00449 
00450 } // namespace Rythmos
00451 
00452 
00453 #endif // RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
 All Classes Functions Variables Typedefs Friends