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

Generated on Tue Oct 20 12:47:13 2009 for Thyra Nonlinear Model Evaluator Support by doxygen 1.4.7