Thyra_ModelEvaluatorHelpers.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_MODEL_EVALUATOR_HELPERS_HPP
00030 #define THYRA_MODEL_EVALUATOR_HELPERS_HPP
00031 
00032 #include "Thyra_ModelEvaluator.hpp"
00033 
00034 namespace Thyra {
00035 
00037 template<class Scalar>
00038 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00039 create_DfDp_mv( const ModelEvaluator<Scalar>& model, int l, ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation )
00040 {
00041   TEST_FOR_EXCEPT(!(orientation==ModelEvaluatorBase::DERIV_MV_BY_COL));
00042   return createMembers( model.get_f_space(), model.get_p_space(l)->dim() );
00043 }
00044 
00046 template<class Scalar>
00047 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00048 create_DgDx_mv( const ModelEvaluator<Scalar>& model, int j, ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation )
00049 {
00050   typedef ModelEvaluatorBase MEB;
00051   switch(orientation) {
00052     case MEB::DERIV_MV_BY_COL:
00053       return createMembers( model.get_g_space(j), model.get_x_space()->dim() );
00054     case MEB::DERIV_TRANS_MV_BY_ROW:
00055       return createMembers( model.get_x_space(j), model.get_g_space()->dim() );
00056     default:
00057       TEST_FOR_EXCEPT(true);
00058   }
00059   return ModelEvaluatorBase::DerivativeMultiVector<Scalar>(); // Never be executed!
00060 }
00061 
00063 template<class Scalar>
00064 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00065 create_DgDp_mv( const ModelEvaluator<Scalar>& model, int j, int l, ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation )
00066 {
00067   typedef ModelEvaluatorBase MEB;
00068   switch(orientation) {
00069     case MEB::DERIV_MV_BY_COL:
00070       return createMembers( model.get_g_space(j), model.get_p_space(l)->dim() );
00071     case MEB::DERIV_TRANS_MV_BY_ROW:
00072       return createMembers( model.get_p_space(l), model.get_g_space(j)->dim() );
00073     default:
00074       TEST_FOR_EXCEPT(true);
00075   }
00076   return ModelEvaluatorBase::DerivativeMultiVector<Scalar>(); // Never be executed!
00077 }
00078 
00080 template<class Scalar>
00081 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00082 get_dmv(
00083   const ModelEvaluatorBase::Derivative<Scalar>             &deriv
00084   ,const std::string                                       &derivName
00085   )
00086 {
00087   TEST_FOR_EXCEPTION(
00088     deriv.getLinearOp().get()!=NULL, std::logic_error
00089     ,"Error, LinearOpBase type not expected for " << derivName <<"!"
00090     );
00091   return deriv.getDerivativeMultiVector();
00092 }
00093 
00095 template<class Scalar>
00096 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00097 get_mv(
00098   const ModelEvaluatorBase::Derivative<Scalar>             &deriv
00099   ,const std::string                                       &derivName
00100   ,ModelEvaluatorBase::EDerivativeMultiVectorOrientation   orientation
00101   )
00102 {
00103   typedef ModelEvaluatorBase MEB;
00104   TEST_FOR_EXCEPTION(
00105     deriv.getLinearOp().get()!=NULL, std::logic_error
00106     ,"Error, LinearOpBase type not expected for " << derivName <<"!"
00107     );
00108   MEB::DerivativeMultiVector<Scalar>
00109     dmv = deriv.getDerivativeMultiVector();
00110   Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00111     mv = dmv.getMultiVector();
00112   if( mv.get() ) {
00113     TEST_FOR_EXCEPTION(
00114       dmv.getOrientation() != orientation, std::logic_error
00115       ,"Error, the orientation " << toString(dmv.getOrientation()) << " is not the"
00116       " expected orientation of " << toString(orientation)
00117       << " for " << derivName << "!"
00118       );
00119   }
00120   return mv;
00121 }
00122 
00124 template<class Scalar>
00125 void eval_f(
00126   const ModelEvaluator<Scalar>                                    &model
00127   ,const VectorBase<Scalar>                                       &x
00128   ,VectorBase<Scalar>                                             *f
00129   )
00130 {
00131   typedef ModelEvaluatorBase MEB;
00132   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00133   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00134   inArgs.set_x(Teuchos::rcp(&x,false));
00135   outArgs.set_f(Teuchos::rcp(f,false));
00136   model.evalModel(inArgs,outArgs);
00137 }
00138 
00140 template<class Scalar>
00141 void eval_f_W(
00142   const ModelEvaluator<Scalar>                                    &model
00143   ,const VectorBase<Scalar>                                       &x
00144   ,VectorBase<Scalar>                                             *f
00145   ,LinearOpWithSolveBase<Scalar>                                  *W
00146   )
00147 {
00148 
00149   typedef ModelEvaluatorBase MEB;
00150 
00151   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00152   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00153 
00154   inArgs.set_x(Teuchos::rcp(&x,false));
00155 
00156   outArgs.set_f(Teuchos::rcp(f,false));
00157   if(W) outArgs.set_W(Teuchos::rcp(W,false));
00158 
00159   model.evalModel(inArgs,outArgs);
00160 
00161 }
00162 
00164 template<class Scalar>
00165 void eval_f_W(
00166   const ModelEvaluator<Scalar>                                    &model
00167   ,const VectorBase<Scalar>                                       &x
00168   ,const Scalar                                                   &beta
00169   ,VectorBase<Scalar>                                             *f
00170   ,LinearOpWithSolveBase<Scalar>                                  *W
00171   )
00172 {
00173 
00174   typedef ModelEvaluatorBase MEB;
00175 
00176   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00177   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00178 
00179   inArgs.set_x(Teuchos::rcp(&x,false));
00180   inArgs.set_beta(beta);
00181 
00182   outArgs.set_f(Teuchos::rcp(f,false));
00183   if(W) outArgs.set_W(Teuchos::rcp(W,false));
00184 
00185   model.evalModel(inArgs,outArgs);
00186 
00187 }
00188 
00190 template<class Scalar>
00191 void eval_f(
00192   const ModelEvaluator<Scalar>                                    &model
00193   ,const VectorBase<Scalar>                                       &x
00194   ,const Scalar                                                   &t
00195   ,VectorBase<Scalar>                                             *f
00196   )
00197 {
00198   typedef ModelEvaluatorBase MEB;
00199   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00200   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00201   inArgs.set_x(Teuchos::rcp(&x,false));
00202   if(inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(t);
00203   outArgs.set_f(Teuchos::rcp(f,false));
00204   model.evalModel(inArgs,outArgs);
00205 }
00206 
00207 
00209 template<class Scalar>
00210 void eval_f(
00211   const ModelEvaluator<Scalar>                                    &model
00212   ,const VectorBase<Scalar>                                       &x_dot
00213   ,const VectorBase<Scalar>                                       &x
00214   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag   &t
00215   ,VectorBase<Scalar>                                             *f
00216   )
00217 {
00218 
00219   typedef ModelEvaluatorBase MEB;
00220 
00221   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00222   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00223 
00224   inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
00225   inArgs.set_x(Teuchos::rcp(&x,false));
00226   if(inArgs.supports(MEB::IN_ARG_t))
00227     inArgs.set_t(t);
00228 
00229   outArgs.set_f(Teuchos::rcp(f,false));
00230 
00231   model.evalModel(inArgs,outArgs);
00232 
00233 }
00234 
00237 template<class Scalar>
00238 void eval_f_W(
00239   const ModelEvaluator<Scalar>                                    &model
00240   ,const VectorBase<Scalar>                                       &x_dot
00241   ,const VectorBase<Scalar>                                       &x
00242   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag   &t
00243   ,const Scalar                                                   &alpha
00244   ,const Scalar                                                   &beta
00245   ,VectorBase<Scalar>                                             *f
00246   ,LinearOpWithSolveBase<Scalar>                                  *W
00247   )
00248 {
00249 
00250   typedef ModelEvaluatorBase MEB;
00251 
00252   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00253   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00254 
00255   inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
00256   inArgs.set_x(Teuchos::rcp(&x,false));
00257   if(inArgs.supports(MEB::IN_ARG_t))
00258     inArgs.set_t(t);
00259   inArgs.set_alpha(alpha);
00260   inArgs.set_beta(beta);
00261 
00262   if(f) outArgs.set_f(Teuchos::rcp(f,false));
00263   if(W) outArgs.set_W(Teuchos::rcp(W,false));
00264 
00265   model.evalModel(inArgs,outArgs);
00266 
00267 }
00268 
00270 template<class Scalar>
00271 void eval_f_poly(
00272   const ModelEvaluator<Scalar>                                    &model
00273   ,const Teuchos::Polynomial< VectorBase<Scalar> >                &x_poly
00274   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag   &t
00275   ,Teuchos::Polynomial< VectorBase<Scalar> >                      *f_poly
00276   )
00277 {
00278 
00279   typedef ModelEvaluatorBase MEB;
00280 
00281   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00282   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00283 
00284   inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
00285   if(inArgs.supports(MEB::IN_ARG_t))
00286     inArgs.set_t(t);
00287 
00288   outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
00289 
00290   model.evalModel(inArgs,outArgs);
00291 
00292 }
00293 
00295 template<class Scalar>
00296 void eval_f_poly(
00297   const ModelEvaluator<Scalar>                                    &model
00298   ,const Teuchos::Polynomial< VectorBase<Scalar> >                &x_dot_poly
00299   ,const VectorBase<Scalar>                                       &x_poly
00300   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag   &t
00301   ,Teuchos::Polynomial< VectorBase<Scalar> >                      *f_poly
00302   )
00303 {
00304 
00305   typedef ModelEvaluatorBase MEB;
00306 
00307   MEB::InArgs<Scalar>   inArgs  = model.createInArgs();
00308   MEB::OutArgs<Scalar>  outArgs = model.createOutArgs();
00309 
00310   inArgs.set_x_dot_poly(Teuchos::rcp(&x_dot_poly,false));
00311   inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
00312   if(inArgs.supports(MEB::IN_ARG_t))
00313     inArgs.set_t(t);
00314 
00315   outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
00316 
00317   model.evalModel(inArgs,outArgs);
00318 
00319 }
00320 
00321 } // namespace Thyra
00322 
00323 
00324 #endif // THYRA_MODEL_EVALUATOR_HELPERS_HPP

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