Thyra Package Browser (Single Doxygen Collection) Version of the Day
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 
00033 #include "Thyra_ModelEvaluator.hpp"
00034 
00035 
00036 namespace Thyra {
00037 
00038 
00046 template<class Scalar>
00047 RCP<ModelEvaluatorBase::InArgs<Scalar> >
00048 clone( const ModelEvaluatorBase::InArgs<Scalar> &inArgs );
00049 
00050 
00052 template<class Scalar>
00053 ModelEvaluatorBase::Derivative<Scalar>
00054 derivativeGradient(
00055   const RCP<MultiVectorBase<Scalar> > &grad
00056   );
00057 
00058 
00060 template<class Scalar>
00061 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00062 create_DfDp_mv(
00063   const ModelEvaluator<Scalar>& model,
00064   int l,
00065   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00066   );
00067 
00068 
00070 template<class Scalar>
00071 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00072 create_DgDx_dot_mv(
00073   const ModelEvaluator<Scalar>& model,
00074   int j,
00075   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00076   );
00077 
00078 
00080 template<class Scalar>
00081 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00082 create_DgDx_mv(
00083   const ModelEvaluator<Scalar>& model,
00084   int j,
00085   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00086   );
00087 
00088 
00090 template<class Scalar>
00091 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00092 create_DgDp_mv(
00093   const ModelEvaluator<Scalar>& model,
00094   int j,
00095   int l,
00096   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00097   );
00098 
00099 
00101 template<class Scalar>
00102 ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00103 get_dmv(
00104   const ModelEvaluatorBase::Derivative<Scalar> &deriv
00105   ,const std::string &derivName
00106   );
00107 
00108 
00110 template<class Scalar>
00111 RCP<MultiVectorBase<Scalar> >
00112 get_mv(
00113   const ModelEvaluatorBase::Derivative<Scalar> &deriv
00114   ,const std::string &derivName
00115   ,ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00116   );
00117 
00118 
00124 template<class Scalar>
00125 void assertDerivSpaces(
00126   const std::string &modelEvalDescription,
00127   const ModelEvaluatorBase::Derivative<Scalar> &deriv,
00128   const std::string &deriv_name,
00129   const VectorSpaceBase<Scalar> &fnc_space,
00130   const std::string &fnc_space_name,
00131   const VectorSpaceBase<Scalar> &var_space,
00132   const std::string &var_space_name
00133   );
00134 
00135 
00140 template<class Scalar>
00141 void assertInArgsOutArgsSetup(
00142   const std::string &modelEvalDescription,
00143   const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00144   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00145   );
00146 
00147 
00152 template<class Scalar>
00153 void assertInArgsEvalObjects(
00154   const ModelEvaluator<Scalar> &model,
00155   const ModelEvaluatorBase::InArgs<Scalar> &inArgs
00156   );
00157 
00158 
00163 template<class Scalar>
00164 void assertOutArgsEvalObjects(
00165   const ModelEvaluator<Scalar> &model,
00166   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs,
00167   const ModelEvaluatorBase::InArgs<Scalar> *inArgs = 0
00168   );
00169 
00170 
00172 template<class Scalar>
00173 void eval_f(
00174   const ModelEvaluator<Scalar> &model
00175   ,const VectorBase<Scalar> &x
00176   ,VectorBase<Scalar> *f
00177   );
00178 
00179 
00181 template<class Scalar>
00182 void eval_f_W(
00183   const ModelEvaluator<Scalar> &model
00184   ,const VectorBase<Scalar> &x
00185   ,VectorBase<Scalar> *f
00186   ,LinearOpWithSolveBase<Scalar> *W
00187   );
00188 
00189 
00191 template<class Scalar>
00192 void eval_f(
00193   const ModelEvaluator<Scalar> &model
00194   ,const VectorBase<Scalar> &x
00195   ,const Scalar &t
00196   ,VectorBase<Scalar> *f
00197   );
00198 
00199 
00201 template<class Scalar>
00202 void eval_g(
00203   const ModelEvaluator<Scalar> &model,
00204   const int l,
00205   const VectorBase<Scalar> &p_l,
00206   const int j,
00207   const Ptr<VectorBase<Scalar> > &g_j
00208   );
00209 
00210 
00212 template<class Scalar>
00213 void eval_g(
00214   const ModelEvaluator<Scalar> &model,
00215   const int l,
00216   const VectorBase<Scalar> &p_l,
00217   const int j,
00218   VectorBase<Scalar> *g_j
00219   )
00220 {
00221   eval_g(model, l, p_l, j, Teuchos::ptr(g_j));
00222 }
00223 
00224 
00226 template<class Scalar>
00227 void eval_g(
00228   const ModelEvaluator<Scalar> &model,
00229   const int l,
00230   const VectorBase<Scalar> &p_l,
00231   const Scalar &t,
00232   const int j,
00233   VectorBase<Scalar> *g_j
00234   );
00235 
00236 
00238 template<class Scalar>
00239 void eval_g_DgDp(
00240   const ModelEvaluator<Scalar> &model,
00241   const int l,
00242   const VectorBase<Scalar> &p_l,
00243   const int j,
00244   const Ptr<VectorBase<Scalar> > &g_j,
00245   const ModelEvaluatorBase::Derivative<Scalar> &DgDp_j_l
00246   );
00247 
00248 
00250 template<class Scalar>
00251 void eval_f(
00252   const ModelEvaluator<Scalar> &model
00253   ,const VectorBase<Scalar> &x_dot
00254   ,const VectorBase<Scalar> &x
00255   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00256   ,VectorBase<Scalar> *f
00257   );
00258 
00259 
00262 template<class Scalar>
00263 void eval_f_W(
00264   const ModelEvaluator<Scalar> &model
00265   ,const VectorBase<Scalar> &x_dot
00266   ,const VectorBase<Scalar> &x
00267   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00268   ,const Scalar &alpha
00269   ,const Scalar &beta
00270   ,VectorBase<Scalar> *f
00271   ,LinearOpWithSolveBase<Scalar> *W
00272   );
00273 
00274 
00275 #ifdef HAVE_THYRA_ME_POLYNOMIAL
00276 
00277 
00279 template<class Scalar>
00280 void eval_f_poly(
00281   const ModelEvaluator<Scalar> &model
00282   ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_poly
00283   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00284   ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
00285   );
00286 
00287 
00289 template<class Scalar>
00290 void eval_f_poly(
00291   const ModelEvaluator<Scalar> &model
00292   ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_dot_poly
00293   ,const VectorBase<Scalar> &x_poly
00294   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00295   ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
00296   );
00297 
00298 
00299 #endif // HAVE_THYRA_ME_POLYNOMIAL
00300 
00301 
00302 } // namespace Thyra
00303 
00304 
00305 //
00306 // Implementations
00307 //
00308 
00309 
00310 #include "Thyra_AssertOp.hpp"
00311 #include "Teuchos_Utils.hpp"
00312 
00313 
00314 template<class Scalar>
00315 Teuchos::RCP<Thyra::ModelEvaluatorBase::InArgs<Scalar> >
00316 Thyra::clone( const ModelEvaluatorBase::InArgs<Scalar> &inArgs )
00317 {
00318   RCP<ModelEvaluatorBase::InArgs<Scalar> >
00319     newInArgs = Teuchos::rcp(new ModelEvaluatorBase::InArgs<Scalar>);
00320   *newInArgs = inArgs;
00321   return newInArgs;
00322 }
00323 
00324 
00325 template<class Scalar>
00326 Thyra::ModelEvaluatorBase::Derivative<Scalar>
00327 Thyra::derivativeGradient(
00328   const RCP<MultiVectorBase<Scalar> > &grad
00329   )
00330 {
00331   return ModelEvaluatorBase::Derivative<Scalar>(
00332     grad,
00333     ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM
00334     );
00335 }
00336 
00337 
00338 template<class Scalar>
00339 Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00340 Thyra::create_DfDp_mv(
00341   const ModelEvaluator<Scalar>& model,
00342   int l,
00343   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00344   )
00345 {
00346   TEST_FOR_EXCEPT(!(orientation==ModelEvaluatorBase::DERIV_MV_BY_COL));
00347   return createMembers( model.get_f_space(), model.get_p_space(l)->dim() );
00348 }
00349 
00350 
00351 template<class Scalar>
00352 Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00353 Thyra::create_DgDx_dot_mv(
00354   const ModelEvaluator<Scalar>& model,
00355   int j,
00356   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00357   )
00358 {
00359   typedef ModelEvaluatorBase MEB;
00360   switch(orientation) {
00361     case MEB::DERIV_MV_BY_COL:
00362       return
00363         MEB::DerivativeMultiVector<Scalar>(
00364           createMembers( model.get_g_space(j), model.get_x_space()->dim() )
00365           ,MEB::DERIV_MV_BY_COL
00366           );
00367     case MEB::DERIV_TRANS_MV_BY_ROW:
00368       return
00369         MEB::DerivativeMultiVector<Scalar>(
00370           createMembers( model.get_x_space(), model.get_g_space(j)->dim() )
00371           ,MEB::DERIV_TRANS_MV_BY_ROW
00372           );
00373     default:
00374       TEST_FOR_EXCEPT(true);
00375   }
00376   return MEB::DerivativeMultiVector<Scalar>(); // Never executed!
00377 }
00378 
00379 
00380 template<class Scalar>
00381 Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00382 Thyra::create_DgDx_mv(
00383   const ModelEvaluator<Scalar>& model,
00384   int j,
00385   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00386   )
00387 {
00388   return create_DgDx_dot_mv(model,j,orientation);
00389 }
00390 
00391 
00392 template<class Scalar>
00393 Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00394 Thyra::create_DgDp_mv(
00395   const ModelEvaluator<Scalar>& model,
00396   int j,
00397   int l,
00398   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00399   )
00400 {
00401   typedef ModelEvaluatorBase MEB;
00402   switch(orientation) {
00403     case MEB::DERIV_MV_BY_COL:
00404       return
00405         MEB::DerivativeMultiVector<Scalar>(
00406           createMembers( model.get_g_space(j), model.get_p_space(l)->dim() )
00407           ,MEB::DERIV_MV_BY_COL
00408           );
00409     case MEB::DERIV_TRANS_MV_BY_ROW:
00410       return
00411         MEB::DerivativeMultiVector<Scalar>(
00412           createMembers( model.get_p_space(l), model.get_g_space(j)->dim() )
00413           ,MEB::DERIV_TRANS_MV_BY_ROW
00414           );
00415     default:
00416       TEST_FOR_EXCEPT(true);
00417   }
00418   return MEB::DerivativeMultiVector<Scalar>(); // Never executed!
00419 }
00420 
00421 
00422 template<class Scalar>
00423 Thyra::ModelEvaluatorBase::DerivativeMultiVector<Scalar>
00424 Thyra::get_dmv(
00425   const ModelEvaluatorBase::Derivative<Scalar> &deriv
00426   ,const std::string &derivName
00427   )
00428 {
00429   TEST_FOR_EXCEPTION(
00430     deriv.getLinearOp().get()!=NULL, std::logic_error
00431     ,"Error, LinearOpBase type not expected for " << derivName <<"!"
00432     );
00433   return deriv.getDerivativeMultiVector();
00434 }
00435 
00436 
00437 template<class Scalar>
00438 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00439 Thyra::get_mv(
00440   const ModelEvaluatorBase::Derivative<Scalar> &deriv
00441   ,const std::string &derivName
00442   ,ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00443   )
00444 {
00445   typedef ModelEvaluatorBase MEB;
00446   TEST_FOR_EXCEPTION(
00447     deriv.getLinearOp().get()!=NULL, std::logic_error
00448     ,"Error, LinearOpBase type not expected for " << derivName <<"!"
00449     );
00450   MEB::DerivativeMultiVector<Scalar>
00451     dmv = deriv.getDerivativeMultiVector();
00452   RCP<MultiVectorBase<Scalar> >
00453     mv = dmv.getMultiVector();
00454   if( mv.get() ) {
00455     TEST_FOR_EXCEPTION(
00456       dmv.getOrientation() != orientation, std::logic_error
00457       ,"Error, the orientation " << toString(dmv.getOrientation()) << " is not the"
00458       " expected orientation of " << toString(orientation)
00459       << " for " << derivName << "!"
00460       );
00461   }
00462   return mv;
00463 }
00464 
00465 
00466 template<class Scalar>
00467 void Thyra::assertDerivSpaces(
00468   const std::string &modelEvalDescription,
00469   const ModelEvaluatorBase::Derivative<Scalar> &deriv,
00470   const std::string &deriv_name,
00471   const VectorSpaceBase<Scalar> &fnc_space,
00472   const std::string &fnc_space_name,
00473   const VectorSpaceBase<Scalar> &var_space,
00474   const std::string &var_space_name
00475   )
00476 {
00477   typedef ModelEvaluatorBase MEB;
00478   if (!is_null(deriv.getLinearOp())) {
00479     const RCP<const LinearOpBase<Scalar> > lo = deriv.getLinearOp();
00480     if (!is_null(lo->range())) {
00481       THYRA_ASSERT_VEC_SPACES_NAMES(
00482         modelEvalDescription,
00483         *lo->range(), deriv_name + ".range()",
00484         fnc_space, fnc_space_name
00485         );
00486       THYRA_ASSERT_VEC_SPACES_NAMES(
00487         modelEvalDescription,
00488         *lo->domain(), deriv_name + ".domain()",
00489         var_space, var_space_name
00490         );
00491     }
00492   }
00493   else if(!is_null(deriv.getMultiVector())) {
00494     const RCP<const LinearOpBase<Scalar> > mv = deriv.getMultiVector();
00495     switch(deriv.getMultiVectorOrientation()) {
00496       case MEB::DERIV_MV_BY_COL: {
00497         THYRA_ASSERT_VEC_SPACES_NAMES(
00498           modelEvalDescription,
00499           *mv->range(), deriv_name + ".range()",
00500           fnc_space, fnc_space_name
00501           );
00502         THYRA_ASSERT_VEC_SPACES_NAMES(
00503           modelEvalDescription,
00504           *mv->domain(), deriv_name + ".domain()",
00505           var_space, var_space_name
00506           );
00507         break;
00508       }
00509       case MEB::DERIV_TRANS_MV_BY_ROW: {
00510         THYRA_ASSERT_VEC_SPACES_NAMES(
00511           modelEvalDescription,
00512           *mv->range(), deriv_name + "^T.range()",
00513           var_space, var_space_name
00514           );
00515         THYRA_ASSERT_VEC_SPACES_NAMES(
00516           modelEvalDescription,
00517           *mv->domain(), deriv_name + "^T.domain()",
00518           fnc_space, fnc_space_name
00519           );
00520         break;
00521       }
00522 #ifdef TEUCHOS_DEBUG
00523       default:
00524         TEST_FOR_EXCEPT(true);
00525 #endif
00526     }
00527   }
00528 }
00529 
00530 
00531 template<class Scalar>
00532 void Thyra::assertInArgsOutArgsSetup(
00533   const std::string &modelEvalDescription,
00534   const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
00535   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
00536   )
00537 {
00538 
00539   typedef ModelEvaluatorBase MEB;
00540 
00541   const int Ng = outArgs.Ng();
00542   const int Np = outArgs.Np();
00543 
00544   // Description
00545   TEUCHOS_ASSERT_EQUALITY(inArgs.modelEvalDescription(), modelEvalDescription);
00546   TEUCHOS_ASSERT_EQUALITY(outArgs.modelEvalDescription(), modelEvalDescription);
00547 
00548   // Np
00549   TEST_FOR_EXCEPTION(
00550     inArgs.Np() != outArgs.Np(), std::logic_error,
00551     "Error: The underlying model " << modelEvalDescription << " incorrectly\n"
00552     "set inArgs.Np() = "<<inArgs.Np()<<" != outArgs.Np() = "
00553     <<outArgs.Np()<<"!"
00554     );
00555 
00556   // x_dot
00557   TEST_FOR_EXCEPTION(
00558     inArgs.supports(MEB::IN_ARG_x_dot) && !inArgs.supports(MEB::IN_ARG_x),
00559     std::logic_error,
00560     "Error: The underlying model " << modelEvalDescription << " supports\n"
00561     "x_dot but does not support x!"
00562     );
00563 
00564   // t
00565   TEST_FOR_EXCEPTION(
00566     inArgs.supports(MEB::IN_ARG_x_dot) && !inArgs.supports(MEB::IN_ARG_t),
00567     std::logic_error,
00568     "Error: The underlying model " << modelEvalDescription << " supports\n"
00569     "x_dot but does not support t!"
00570     );
00571 
00572   // W and W_op
00573   TEST_FOR_EXCEPTION(
00574     (
00575       ( outArgs.supports(MEB::OUT_ARG_W) || outArgs.supports(MEB::OUT_ARG_W_op) )
00576       &&
00577       !inArgs.supports(MEB::IN_ARG_x)
00578       ),
00579     std::logic_error,
00580     "Error: The underlying model " << modelEvalDescription << " says that\n"
00581     "it supports W and/or W_op but it does not support x!"
00582     );
00583   TEST_FOR_EXCEPTION(
00584     (
00585       ( outArgs.supports(MEB::OUT_ARG_W) || outArgs.supports(MEB::OUT_ARG_W_op) )
00586       &&
00587       inArgs.supports(MEB::IN_ARG_x_dot)
00588       &&
00589       !( inArgs.supports(MEB::IN_ARG_alpha) && inArgs.supports(MEB::IN_ARG_beta) )
00590       ),
00591     std::logic_error,
00592     "Error: The underlying model " << modelEvalDescription << " supports W and/or W_op\n"
00593     "and x_dot but it does not support alpha and beta as InArgs!"
00594     );
00595 
00596   for ( int l = 0; l < Np; ++l ) {
00597 
00598     // DfDp(l): OutArgs checks this automatically!
00599 
00600     for ( int j = 0; j < Ng; ++j ) {
00601 
00602       // DgDx_dot(j)
00603       TEST_FOR_EXCEPTION(
00604         ( !outArgs.supports(MEB::OUT_ARG_DgDx_dot,j).none()
00605           && !inArgs.supports(MEB::IN_ARG_x_dot) ),
00606         std::logic_error,
00607         "Error: The underlying model " << modelEvalDescription << " says that\n"
00608         "it supports DgDx_dot("<<j<<") but it does not support x_dot!"
00609         );
00610 
00611       // DgDx(j)
00612       TEST_FOR_EXCEPTION(
00613         ( !outArgs.supports(MEB::OUT_ARG_DgDx,j).none()
00614           && !inArgs.supports(MEB::IN_ARG_x) ),
00615         std::logic_error,
00616         "Error: The underlying model " << modelEvalDescription << " says that\n"
00617         "it supports DgDx("<<j<<") but it does not support x!"
00618         );
00619 
00620       // DgDp(j,l): OutArgs checks this automatically!
00621 
00622     }
00623 
00624   }
00625 
00626 }
00627 
00628 
00629 template<class Scalar>
00630 void Thyra::assertInArgsEvalObjects(
00631   const ModelEvaluator<Scalar> &model,
00632   const ModelEvaluatorBase::InArgs<Scalar> &inArgs
00633   )
00634 {
00635   
00636   typedef ModelEvaluatorBase MEB;
00637 
00638   const std::string description = model.description();
00639   const int Np = inArgs.Np();
00640 
00641   model.createInArgs().assertSameSupport(inArgs);
00642 
00643   // x_dot
00644   if ( inArgs.supports(MEB::IN_ARG_x_dot) && !is_null(inArgs.get_x_dot()) ) {
00645     THYRA_ASSERT_VEC_SPACES(
00646       description, *inArgs.get_x_dot()->space(), *model.get_x_space() );
00647   }
00648 
00649   // x
00650   if ( inArgs.supports(MEB::IN_ARG_x) && !is_null(inArgs.get_x()) ) {
00651     THYRA_ASSERT_VEC_SPACES(
00652       description, *inArgs.get_x()->space(), *model.get_x_space() );
00653   }
00654     
00655   // p(l)
00656   for ( int l = 0; l < Np; ++l ) {
00657     if (!is_null(inArgs.get_p(l))) {
00658       THYRA_ASSERT_VEC_SPACES(
00659         description, *inArgs.get_p(l)->space(), *model.get_p_space(l) );
00660     }
00661   }
00662 
00663 }
00664 
00665 
00666 template<class Scalar>
00667 void Thyra::assertOutArgsEvalObjects(
00668   const ModelEvaluator<Scalar> &model,
00669   const ModelEvaluatorBase::OutArgs<Scalar> &outArgs,
00670   const ModelEvaluatorBase::InArgs<Scalar> *inArgs
00671   )
00672 {
00673 
00674   typedef ScalarTraits<Scalar> ST;
00675   typedef Teuchos::Utils TU;
00676   typedef ModelEvaluatorBase MEB;
00677 
00678   const std::string description = model.description();
00679   const int Ng = outArgs.Ng();
00680   const int Np = outArgs.Np();
00681 
00682   if (inArgs) {
00683     TEUCHOS_ASSERT_EQUALITY(outArgs.Np(), inArgs->Np());
00684   }
00685 
00686   model.createOutArgs().assertSameSupport(outArgs);
00687 
00688   // f
00689   if ( outArgs.supports(MEB::OUT_ARG_f) && !is_null(outArgs.get_f()) ) {
00690     THYRA_ASSERT_VEC_SPACES(
00691       description, *outArgs.get_f()->space(), *model.get_f_space() );
00692   }
00693 
00694   // W
00695   if ( outArgs.supports(MEB::OUT_ARG_W) && !is_null(outArgs.get_W()) ) {
00696     if (!is_null(outArgs.get_W()->range())) {
00697       THYRA_ASSERT_VEC_SPACES(
00698         description, *outArgs.get_W()->range(), *model.get_f_space() );
00699       THYRA_ASSERT_VEC_SPACES(
00700         description, *outArgs.get_W()->domain(), *model.get_x_space() );
00701     }
00702   }
00703     
00704   // W_op
00705   if ( outArgs.supports(MEB::OUT_ARG_W_op) && !is_null(outArgs.get_W_op()) ) {
00706     if (!is_null(outArgs.get_W_op()->range())) {
00707       THYRA_ASSERT_VEC_SPACES(
00708         description, *outArgs.get_W_op()->range(), *model.get_f_space() );
00709       THYRA_ASSERT_VEC_SPACES(
00710         description, *outArgs.get_W_op()->domain(), *model.get_x_space() );
00711     }
00712   }
00713 
00714   // alpha and beta (not really in outArgs but can only be validated if W or
00715   // W_op is set)
00716   if (
00717     inArgs
00718     &&
00719     (
00720       ( outArgs.supports(MEB::OUT_ARG_W) && !is_null(outArgs.get_W()) )
00721       ||
00722       ( outArgs.supports(MEB::OUT_ARG_W_op) && !is_null(outArgs.get_W_op()) )
00723       )
00724     )
00725   {
00726     if ( inArgs->supports(MEB::IN_ARG_alpha) && inArgs->supports(MEB::IN_ARG_beta) ) {
00727       // 08/25/08 tscoffe:  In the block-composed linear operator case for
00728       // Rythmos::ImplicitRKModelEvaluator, I need to specify that a given
00729       // block is all zeros and I'm depending on the underlying model to
00730       // intelligently fill the block with zeros if both alpha and beta are
00731       // zero.  
00732       //TEST_FOR_EXCEPT( inArgs->get_alpha() == ST::zero() && inArgs->get_beta() == ST::zero() );
00733     }
00734     else if ( inArgs->supports(MEB::IN_ARG_beta) ) {
00735       TEST_FOR_EXCEPT( inArgs->get_beta() == ST::zero() );
00736     }
00737   }
00738 
00739   // DfDp(l)
00740   if (outArgs.supports(MEB::OUT_ARG_f)) {
00741     for ( int l = 0; l < Np; ++l ) {
00742       if (!outArgs.supports(MEB::OUT_ARG_DfDp,l).none()) {
00743         assertDerivSpaces(
00744           description,
00745           outArgs.get_DfDp(l), "DfDp("+TU::toString(l)+")",
00746           *model.get_f_space(), "f_space",
00747           *model.get_p_space(l), "p_space("+TU::toString(l)+")"
00748           );
00749       }
00750     }
00751   }
00752     
00753   // g(l)
00754   for ( int j = 0; j < Ng; ++j ) {
00755     if (!is_null(outArgs.get_g(j))) {
00756       THYRA_ASSERT_VEC_SPACES(
00757         description, *outArgs.get_g(j)->space(), *model.get_g_space(j) );
00758     }
00759   }
00760 
00761   // DgDx_dot(j)
00762   for ( int j = 0; j < Ng; ++j ) {
00763     if (!outArgs.supports(MEB::OUT_ARG_DgDx_dot,j).none()) {
00764       assertDerivSpaces(
00765         description,
00766         outArgs.get_DgDx_dot(j), "DgDx_dot("+TU::toString(j)+")",
00767         *model.get_g_space(j), "g_space("+TU::toString(j)+")",
00768         *model.get_x_space(), "x_space"
00769         );
00770     }
00771   }
00772 
00773   // DgDx(j)
00774   for ( int j = 0; j < Ng; ++j ) {
00775     if (!outArgs.supports(MEB::OUT_ARG_DgDx,j).none()) {
00776       assertDerivSpaces(
00777         description,
00778         outArgs.get_DgDx(j), "DgDx("+TU::toString(j)+")",
00779         *model.get_g_space(j), "g_space("+TU::toString(j)+")",
00780         *model.get_x_space(), "x_space"
00781         );
00782     }
00783   }
00784 
00785   // Assert DgDp(j,l)
00786   for ( int j = 0; j < Ng; ++j ) {
00787     for ( int l = 0; l < Np; ++l ) {
00788       if (!outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()) {
00789         const std::string j_str = TU::toString(j);
00790         const std::string l_str = TU::toString(l);
00791         assertDerivSpaces(
00792           description,
00793           outArgs.get_DgDp(j,l), "DgDp("+j_str+","+l_str+")",
00794           *model.get_g_space(j), "g_space("+j_str+")",
00795           *model.get_p_space(l), "p_space("+l_str+")"
00796           );
00797       }
00798     }
00799   }
00800 
00801 }
00802 
00803 
00804 template<class Scalar>
00805 void Thyra::eval_f(
00806   const ModelEvaluator<Scalar> &model
00807   ,const VectorBase<Scalar> &x
00808   ,VectorBase<Scalar> *f
00809   )
00810 {
00811   typedef ModelEvaluatorBase MEB;
00812   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00813   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
00814   inArgs.set_x(Teuchos::rcp(&x,false));
00815   outArgs.set_f(Teuchos::rcp(f,false));
00816   model.evalModel(inArgs,outArgs);
00817 }
00818 
00819 
00820 template<class Scalar>
00821 void Thyra::eval_f_W(
00822   const ModelEvaluator<Scalar> &model
00823   ,const VectorBase<Scalar> &x
00824   ,VectorBase<Scalar> *f
00825   ,LinearOpWithSolveBase<Scalar> *W
00826   )
00827 {
00828 
00829   typedef ModelEvaluatorBase MEB;
00830 
00831   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00832   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
00833 
00834   inArgs.set_x(Teuchos::rcp(&x,false));
00835 
00836   if (f) outArgs.set_f(Teuchos::rcp(f,false));
00837   if (W) outArgs.set_W(Teuchos::rcp(W,false));
00838 
00839   model.evalModel(inArgs,outArgs);
00840 
00841 }
00842 
00843 
00844 template<class Scalar>
00845 void Thyra::eval_f(
00846   const ModelEvaluator<Scalar> &model
00847   ,const VectorBase<Scalar> &x
00848   ,const Scalar &t
00849   ,VectorBase<Scalar> *f
00850   )
00851 {
00852   typedef ModelEvaluatorBase MEB;
00853   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00854   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
00855   inArgs.set_x(Teuchos::rcp(&x,false));
00856   if(inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(t);
00857   outArgs.set_f(Teuchos::rcp(f,false));
00858   model.evalModel(inArgs,outArgs);
00859 }
00860 
00861 
00862 template<class Scalar>
00863 void Thyra::eval_g(
00864   const ModelEvaluator<Scalar> &model,
00865   const int l,
00866   const VectorBase<Scalar> &p_l,
00867   const int j,
00868   const Ptr<VectorBase<Scalar> > &g_j
00869   )
00870 {
00871   typedef ModelEvaluatorBase MEB;
00872   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00873   MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
00874   inArgs.set_p(l, Teuchos::rcpFromRef(p_l));
00875   outArgs.set_g(j, Teuchos::rcpFromRef(*g_j));
00876   model.evalModel(inArgs,outArgs);
00877 }
00878 
00879 
00880 template<class Scalar>
00881 void Thyra::eval_g(
00882   const ModelEvaluator<Scalar> &model,
00883   const int l,
00884   const VectorBase<Scalar> &p_l,
00885   const Scalar &t,
00886   const int j,
00887   VectorBase<Scalar> *g_j
00888   )
00889 {
00890   typedef ModelEvaluatorBase MEB;
00891   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00892   MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
00893   inArgs.set_p(l,Teuchos::rcp(&p_l,false));
00894   inArgs.set_t(t);
00895   outArgs.set_g(j,Teuchos::rcp(g_j,false));
00896   model.evalModel(inArgs,outArgs);
00897 }
00898 
00899 
00900 template<class Scalar>
00901 void Thyra::eval_g_DgDp(
00902   const ModelEvaluator<Scalar> &model,
00903   const int l,
00904   const VectorBase<Scalar> &p_l,
00905   const int j,
00906   const Ptr<VectorBase<Scalar> > &g_j,
00907   const ModelEvaluatorBase::Derivative<Scalar> &DgDp_j_l
00908   )
00909 {
00910   typedef ModelEvaluatorBase MEB;
00911   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00912   MEB::OutArgs<Scalar> outArgs= model.createOutArgs();
00913   inArgs.set_p(l, Teuchos::rcpFromRef(p_l));
00914   if (!is_null(g_j)) {
00915     outArgs.set_g(j, Teuchos::rcpFromPtr(g_j));
00916   }
00917   if (!DgDp_j_l.isEmpty()) {
00918     outArgs.set_DgDp(j, l, DgDp_j_l);
00919   }
00920   model.evalModel(inArgs,outArgs);
00921 }
00922 
00923 
00924 template<class Scalar>
00925 void Thyra::eval_f(
00926   const ModelEvaluator<Scalar> &model
00927   ,const VectorBase<Scalar> &x_dot
00928   ,const VectorBase<Scalar> &x
00929   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00930   ,VectorBase<Scalar> *f
00931   )
00932 {
00933 
00934   typedef ModelEvaluatorBase MEB;
00935 
00936   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00937   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
00938 
00939   inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
00940   inArgs.set_x(Teuchos::rcp(&x,false));
00941   if(inArgs.supports(MEB::IN_ARG_t))
00942     inArgs.set_t(t);
00943 
00944   outArgs.set_f(Teuchos::rcp(f,false));
00945 
00946   model.evalModel(inArgs,outArgs);
00947 
00948 }
00949 
00950 
00951 template<class Scalar>
00952 void Thyra::eval_f_W(
00953   const ModelEvaluator<Scalar> &model
00954   ,const VectorBase<Scalar> &x_dot
00955   ,const VectorBase<Scalar> &x
00956   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00957   ,const Scalar &alpha
00958   ,const Scalar &beta
00959   ,VectorBase<Scalar> *f
00960   ,LinearOpWithSolveBase<Scalar> *W
00961   )
00962 {
00963 
00964   typedef ModelEvaluatorBase MEB;
00965 
00966   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00967   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
00968 
00969   inArgs.set_x_dot(Teuchos::rcp(&x_dot,false));
00970   inArgs.set_x(Teuchos::rcp(&x,false));
00971   if(inArgs.supports(MEB::IN_ARG_t))
00972     inArgs.set_t(t);
00973   inArgs.set_alpha(alpha);
00974   inArgs.set_beta(beta);
00975 
00976   if(f) outArgs.set_f(Teuchos::rcp(f,false));
00977   if(W) outArgs.set_W(Teuchos::rcp(W,false));
00978 
00979   model.evalModel(inArgs,outArgs);
00980 
00981 }
00982 
00983 
00984 #ifdef HAVE_THYRA_ME_POLYNOMIAL
00985 
00986 
00987 template<class Scalar>
00988 void Thyra::eval_f_poly(
00989   const ModelEvaluator<Scalar> &model
00990   ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_poly
00991   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
00992   ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
00993   )
00994 {
00995 
00996   typedef ModelEvaluatorBase MEB;
00997 
00998   MEB::InArgs<Scalar> inArgs = model.createInArgs();
00999   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
01000 
01001   inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
01002   if(inArgs.supports(MEB::IN_ARG_t))
01003     inArgs.set_t(t);
01004 
01005   outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
01006 
01007   model.evalModel(inArgs,outArgs);
01008 
01009 }
01010 
01011 
01012 template<class Scalar>
01013 void Thyra::eval_f_poly(
01014   const ModelEvaluator<Scalar> &model
01015   ,const Teuchos::Polynomial< VectorBase<Scalar> > &x_dot_poly
01016   ,const VectorBase<Scalar> &x_poly
01017   ,const typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t
01018   ,Teuchos::Polynomial< VectorBase<Scalar> > *f_poly
01019   )
01020 {
01021 
01022   typedef ModelEvaluatorBase MEB;
01023 
01024   MEB::InArgs<Scalar> inArgs = model.createInArgs();
01025   MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
01026 
01027   inArgs.set_x_dot_poly(Teuchos::rcp(&x_dot_poly,false));
01028   inArgs.set_x_poly(Teuchos::rcp(&x_poly,false));
01029   if(inArgs.supports(MEB::IN_ARG_t))
01030     inArgs.set_t(t);
01031 
01032   outArgs.set_f_poly(Teuchos::rcp(f_poly,false));
01033 
01034   model.evalModel(inArgs,outArgs);
01035 
01036 }
01037 
01038 
01039 #endif // HAVE_THYRA_ME_POLYNOMIAL
01040 
01041 
01042 #endif // THYRA_MODEL_EVALUATOR_HELPERS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines