Thyra_ModelEvaluatorBase_def.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_BASE_DEF_HPP
00030 #define THYRA_MODEL_EVALUATOR_BASE_DEF_HPP
00031 
00032 
00033 #include "Thyra_ModelEvaluatorBase_decl.hpp"
00034 
00035 
00036 namespace Thyra {
00037 
00038 
00039 namespace ModelEvaluatorHelperPack {
00040 
00041 
00042 template<class Scalar>
00043 inline
00044 RCP<const Thyra::VectorBase<Scalar> >
00045 condCloneVec(
00046   const RCP<const Thyra::VectorBase<Scalar> > &vec,
00047   bool cloneObject
00048   )
00049 {
00050   if(cloneObject)
00051     return vec->clone_v();
00052   return vec;
00053 }
00054 
00055 
00056 } // namespace ModelEvaluatorHelperPack
00057 
00058 
00059 //
00060 // ModelEvaluatorBase::InArgs
00061 //
00062 
00063 
00064 template<class Scalar>
00065 ModelEvaluatorBase::InArgs<Scalar>::InArgs()
00066   :modelEvalDescription_("WARNING!  THIS INARGS OBJECT IS UNINITALIZED!")
00067 {
00068   typedef Teuchos::ScalarTraits<Scalar> ST;
00069   typedef Teuchos::ScalarTraits<typename ST::magnitudeType> SMT;
00070   std::fill_n(&supports_[0],NUM_E_IN_ARGS_MEMBERS,false);
00071   t_     = SMT::zero();
00072   alpha_ = ST::zero();
00073   beta_  = ST::zero();
00074 }
00075 
00076 
00077 template<class Scalar>
00078 int ModelEvaluatorBase::InArgs<Scalar>::Np() const
00079 { return p_.size(); }
00080 
00081 template<class Scalar>
00082 bool ModelEvaluatorBase::InArgs<Scalar>::supports(EInArgsMembers arg) const
00083 {
00084   TEST_FOR_EXCEPTION(
00085     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00086     ,"model = \'"<<modelEvalDescription_
00087     <<"\': Error, arg="<<toString(arg)<<" is invalid!"
00088     );
00089   return supports_[arg];
00090 }
00091 
00092 
00093 template<class Scalar>
00094 void ModelEvaluatorBase::InArgs<Scalar>::set_x_dot(
00095   const RCP<const VectorBase<Scalar> > &x_dot
00096   )
00097 { assert_supports(IN_ARG_x_dot); x_dot_ = x_dot; }
00098 
00099 
00100 template<class Scalar>
00101 RCP<const VectorBase<Scalar> >
00102 ModelEvaluatorBase::InArgs<Scalar>::get_x_dot() const
00103 { assert_supports(IN_ARG_x_dot); return x_dot_; }
00104 
00105 
00106 template<class Scalar>
00107 void ModelEvaluatorBase::InArgs<Scalar>::set_x(
00108   const RCP<const VectorBase<Scalar> > &x
00109   )
00110 { assert_supports(IN_ARG_x); x_ = x; }
00111 
00112 
00113 template<class Scalar>
00114 RCP<const VectorBase<Scalar> >
00115 ModelEvaluatorBase::InArgs<Scalar>::get_x() const
00116 { assert_supports(IN_ARG_x); return x_; }
00117 
00118 
00119 template<class Scalar>
00120 void ModelEvaluatorBase::InArgs<Scalar>::set_x_dot_poly(
00121   const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly
00122   )
00123 { assert_supports(IN_ARG_x_dot_poly); x_dot_poly_ = x_dot_poly; }
00124 
00125 
00126 template<class Scalar>
00127 RCP<const Teuchos::Polynomial< VectorBase<Scalar> > >
00128 ModelEvaluatorBase::InArgs<Scalar>::get_x_dot_poly() const
00129 { assert_supports(IN_ARG_x_dot_poly); return x_dot_poly_; }
00130 
00131 
00132 template<class Scalar>
00133 void ModelEvaluatorBase::InArgs<Scalar>::set_x_poly(
00134   const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly
00135   )
00136 { assert_supports(IN_ARG_x_poly); x_poly_ = x_poly; }
00137 
00138 
00139 template<class Scalar>
00140 RCP<const Teuchos::Polynomial< VectorBase<Scalar> > >
00141 ModelEvaluatorBase::InArgs<Scalar>::get_x_poly() const
00142 { assert_supports(IN_ARG_x_poly); return x_poly_; }
00143 
00144 
00145 template<class Scalar>
00146 void ModelEvaluatorBase::InArgs<Scalar>::set_p(
00147   int l, const RCP<const VectorBase<Scalar> > &p_l
00148   )
00149 { assert_l(l); p_[l] = p_l; }
00150 
00151 
00152 template<class Scalar>
00153 RCP<const VectorBase<Scalar> >
00154 ModelEvaluatorBase::InArgs<Scalar>::get_p(int l) const
00155 { assert_l(l); return p_[l]; }
00156 
00157 
00158 template<class Scalar>
00159 void ModelEvaluatorBase::InArgs<Scalar>::set_t( ScalarMag t )
00160 { assert_supports(IN_ARG_t); t_ = t; }
00161 
00162 
00163 template<class Scalar>
00164 typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag
00165 ModelEvaluatorBase::InArgs<Scalar>::get_t() const
00166 { assert_supports(IN_ARG_t); return t_; }
00167 
00168 
00169 template<class Scalar>
00170 void ModelEvaluatorBase::InArgs<Scalar>::set_alpha( Scalar alpha )
00171 { assert_supports(IN_ARG_alpha); alpha_ = alpha; }
00172 
00173 
00174 template<class Scalar>
00175 Scalar ModelEvaluatorBase::InArgs<Scalar>::get_alpha() const
00176 { assert_supports(IN_ARG_alpha); return alpha_; }
00177 
00178 
00179 template<class Scalar>
00180 void ModelEvaluatorBase::InArgs<Scalar>::set_beta( Scalar beta )
00181 { assert_supports(IN_ARG_beta); beta_ = beta; }
00182 
00183 
00184 template<class Scalar>
00185 Scalar ModelEvaluatorBase::InArgs<Scalar>::get_beta() const
00186 { assert_supports(IN_ARG_beta); return beta_; }
00187 
00188 
00189 template<class Scalar>
00190 void ModelEvaluatorBase::InArgs<Scalar>::setArgs(
00191   const InArgs<Scalar>& inArgs, bool ignoreUnsupported, bool cloneObjects
00192   )
00193 {
00194   using ModelEvaluatorHelperPack::condCloneVec;
00195   if( inArgs.supports(IN_ARG_x_dot) && inArgs.get_x_dot().get() ) {
00196     if(supports(IN_ARG_x_dot) || !ignoreUnsupported)
00197       set_x_dot(condCloneVec(inArgs.get_x_dot(),cloneObjects));
00198   }
00199   if( inArgs.supports(IN_ARG_x) && inArgs.get_x().get() ) {
00200     if(supports(IN_ARG_x) || !ignoreUnsupported)
00201       set_x(condCloneVec(inArgs.get_x(),cloneObjects));
00202   }
00203   if( inArgs.supports(IN_ARG_x_dot_poly) && inArgs.get_x_dot_poly().get() ) {
00204     if(supports(IN_ARG_x_dot_poly) || !ignoreUnsupported) {
00205       TEST_FOR_EXCEPT(
00206         cloneObjects && "Have not implemented cloning for x_dot_poly yet!" );
00207       set_x_dot_poly(inArgs.get_x_dot_poly());
00208     }
00209   }
00210   if( inArgs.supports(IN_ARG_x_poly) && inArgs.get_x_poly().get() ) {
00211     if(supports(IN_ARG_x_poly) || !ignoreUnsupported) {
00212       TEST_FOR_EXCEPT(
00213         cloneObjects && "Have not implemented cloning for x_poly yet!" );
00214       set_x_poly(inArgs.get_x_poly());
00215     }
00216   }
00217   const int min_Np = TEUCHOS_MIN(this->Np(),inArgs.Np());
00218   for( int l = 0; l < min_Np; ++l ) {
00219     if(inArgs.get_p(l).get())
00220       set_p(l,condCloneVec(inArgs.get_p(l),cloneObjects));
00221   }
00222   if( inArgs.supports(IN_ARG_t) ) {
00223     if(supports(IN_ARG_t) || !ignoreUnsupported)
00224       set_t(inArgs.get_t());
00225   }
00226   if( inArgs.supports(IN_ARG_alpha) ) {
00227     if(supports(IN_ARG_alpha) || !ignoreUnsupported)
00228       set_alpha(inArgs.get_alpha());
00229   }
00230   if( inArgs.supports(IN_ARG_beta) ) {
00231     if(supports(IN_ARG_beta) || !ignoreUnsupported)
00232       set_beta(inArgs.get_beta());
00233   }
00234 }
00235 
00236 
00237 template<class Scalar>
00238 void ModelEvaluatorBase::InArgs<Scalar>::assertSameSupport(
00239   const InArgs<Scalar> &inArgs
00240   ) const
00241 {
00242   for ( int inArg_i = 0; inArg_i < NUM_E_IN_ARGS_MEMBERS; ++inArg_i ) {
00243     const EInArgsMembers inArg_arg = static_cast<EInArgsMembers>(inArg_i);
00244     const std::string inArg_name = toString(inArg_arg);
00245     TEST_FOR_EXCEPTION(
00246       supports(inArg_arg) != inArgs.supports(inArg_arg), std::logic_error,
00247       "Error, the input argument "<<inArg_name<<" with support "<<inArgs.supports(inArg_arg)<<"\n"
00248       "in the InArgs object for the model:\n\n"
00249       "  "<<inArgs.modelEvalDescription()<<"\n\n"
00250       "is not the same the argument "<<inArg_name<<" with support "<<supports(inArg_arg)<<"\n"
00251       "in the InArgs object for the model:\n\n"
00252       "  "<<modelEvalDescription()<<"\n\n"
00253       "and these two InArgs objects are not compatible!"
00254       );
00255   }
00256   TEUCHOS_ASSERT_EQUALITY( this->Np(), inArgs.Np() );
00257 }
00258 
00259 
00260 template<class Scalar>
00261 std::string ModelEvaluatorBase::InArgs<Scalar>::modelEvalDescription() const
00262 {
00263   return modelEvalDescription_;
00264 }
00265 
00266 
00267 template<class Scalar>
00268 std::string ModelEvaluatorBase::InArgs<Scalar>::description() const
00269 {
00270   typedef Teuchos::ScalarTraits<Scalar> ST;
00271   std::ostringstream oss;
00272   oss
00273     << "Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">"
00274     << "{"
00275     << "model="<<modelEvalDescription_
00276     << ",Np="<<Np()
00277     << "}";
00278   return oss.str();
00279 }
00280 
00281 
00282 template<class Scalar>
00283 void ModelEvaluatorBase::InArgs<Scalar>::describe(
00284   Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
00285   ) const
00286 {
00287   using std::endl;
00288   typedef Teuchos::ScalarTraits<Scalar> ST;
00289   using Teuchos::OSTab;
00290   using Teuchos::describe;
00291   using Teuchos::includesVerbLevel;
00292   typedef RCP<const VectorBase<Scalar> > CV_ptr;
00293 
00294   if(verbLevel == Teuchos::VERB_NONE)
00295     return;
00296 
00297   RCP<Teuchos::FancyOStream>
00298     out = Teuchos::rcp(&out_arg,false);
00299   const bool dump_x = includesVerbLevel(verbLevel,Teuchos::VERB_HIGH);
00300   const Teuchos::EVerbosityLevel x_verbLevel =
00301     dump_x?Teuchos::VERB_EXTREME:verbLevel;
00302   const bool print_x_nrm = includesVerbLevel(verbLevel,Teuchos::VERB_LOW);
00303   const bool dump_p = includesVerbLevel(verbLevel,Teuchos::VERB_MEDIUM);
00304   const Teuchos::EVerbosityLevel p_verbLevel =
00305     dump_p?Teuchos::VERB_EXTREME:verbLevel;
00306   const bool print_p_nrm = includesVerbLevel(verbLevel,Teuchos::VERB_LOW);
00307   OSTab tab(out);
00308 
00309   *out <<"Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">:\n";
00310   tab.incrTab();
00311 
00312   *out <<"model = " << modelEvalDescription_ << "\n";
00313   *out <<"Np = " << Np() << "\n";
00314 
00315   CV_ptr x_dot;
00316   if ( this->supports(IN_ARG_x_dot) && !is_null(x_dot=get_x_dot()) ) {
00317     *out << "x_dot = " << Teuchos::describe(*x_dot,x_verbLevel);
00318     if (print_x_nrm)
00319       *out << "||x_dot|| = " << norm(*x_dot) << endl;
00320   }
00321 
00322   CV_ptr x;
00323   if ( this->supports(IN_ARG_x) && !is_null(x=get_x()) ) {
00324     *out << "x = " << Teuchos::describe(*x,x_verbLevel);
00325     if (print_x_nrm)
00326       *out << "||x|| = " << norm(*x) << endl;
00327   }
00328   
00329   if (print_x_nrm) {
00330     for( int l = 0; l < Np(); ++l ) {
00331       CV_ptr p_l;
00332       if ( !is_null(p_l = this->get_p(l)) ) {
00333         *out << "p("<<l<<") = " << Teuchos::describe(*p_l,p_verbLevel);
00334         if (print_p_nrm)
00335           *out << "||p("<<l<<")|| = " << norm(*p_l) << endl;
00336       }
00337     }
00338   }
00339   
00340   if (includesVerbLevel(verbLevel,Teuchos::VERB_MEDIUM)) {
00341     if (this->supports(IN_ARG_t)) {
00342       *out << "t = " << t_ << endl;
00343     }
00344     if (this->supports(IN_ARG_alpha)) {
00345       *out << "alpha = " << alpha_ << endl;
00346     }
00347     if (this->supports(IN_ARG_beta)) {
00348       *out << "beta = " << beta_ << endl;
00349     }
00350   }
00351   
00352 }
00353 
00354 
00355 template<class Scalar>
00356 void ModelEvaluatorBase::InArgs<Scalar>::_setModelEvalDescription(
00357   const std::string &modelEvalDescription_in
00358   )
00359 {
00360   modelEvalDescription_ = modelEvalDescription_in;
00361 }
00362 
00363 
00364 template<class Scalar>
00365 void ModelEvaluatorBase::InArgs<Scalar>::_set_Np(int Np_in)
00366 {
00367   p_.resize(Np_in);
00368 }
00369 
00370 
00371 template<class Scalar>
00372 void ModelEvaluatorBase::InArgs<Scalar>::_setSupports(
00373   EInArgsMembers arg, bool supports_in
00374   )
00375 {
00376   TEST_FOR_EXCEPTION(
00377     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00378     ,"model = \'"<<modelEvalDescription_
00379     <<"\': Error, arg="<<toString(arg)<<" is invalid!");
00380   supports_[arg] = supports_in;
00381 }
00382 
00383 
00384 template<class Scalar>
00385 void ModelEvaluatorBase::InArgs<Scalar>::_setSupports(
00386   const InArgs<Scalar>& inArgs, const int Np_in
00387   )
00388 {
00389   std::copy(
00390     &inArgs.supports_[0],
00391     &inArgs.supports_[0] + NUM_E_IN_ARGS_MEMBERS, &supports_[0] );
00392   this->_set_Np( Np_in >= 0 ? Np_in : inArgs.Np() );
00393 }
00394 
00395 
00396 template<class Scalar>
00397 void ModelEvaluatorBase::InArgs<Scalar>::_setUnsupportsAndRelated(
00398   EInArgsMembers arg
00399   )
00400 {
00401   switch(arg) {
00402     case IN_ARG_x: {
00403       this->_setSupports(IN_ARG_x_dot,false);
00404       this->_setSupports(IN_ARG_x_dot_poly,false);
00405       this->_setSupports(IN_ARG_alpha,false);
00406       this->_setSupports(IN_ARG_beta,false);
00407       break;
00408     }
00409     default:
00410       TEST_FOR_EXCEPTION(
00411         true ,std::logic_error,
00412         "Error, can not handle args other than IN_ARG_x yet!"
00413         );
00414       break;
00415   }
00416   this->_setSupports(arg,false);
00417 }
00418 
00419 
00420 template<class Scalar>
00421 void ModelEvaluatorBase::InArgs<Scalar>::assert_supports(
00422   EInArgsMembers arg
00423   ) const
00424 {
00425   TEST_FOR_EXCEPTION(
00426     !supports_[arg], std::logic_error
00427     ,"Thyra::ModelEvaluatorBase::InArgs<"
00428     << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(arg): "
00429     "model = \'"<<modelEvalDescription_<<"\': Error, "
00430     "The argument arg = " << toString(arg) << " is not supported!"
00431     );
00432 }
00433 
00434 
00435 template<class Scalar>
00436 void ModelEvaluatorBase::InArgs<Scalar>::assert_l(int l) const
00437 {
00438   TEST_FOR_EXCEPTION(
00439     !( 0 <= l && l < Np() ), std::logic_error
00440     ,"Thyra::ModelEvaluatorBase::InArgs<Scalar>::assert_l(l):\n\n"
00441     " model = \'"<<modelEvalDescription_<<"\':\n\n"
00442     "Error, The parameter l = " << l << " is not in the range [0,"<<Np()<<")!"
00443     );
00444 }
00445 
00446 
00447 //
00448 // ModelEvaluatorBase::DerivativeMultiVector
00449 //
00450 
00451 
00452 template<class Scalar>
00453 std::string ModelEvaluatorBase::DerivativeMultiVector<Scalar>::description() const
00454 {
00455   using std::endl;
00456   std::ostringstream oss;
00457   oss << "DerivativeMultiVector{";
00458   if (is_null(getMultiVector())) {
00459     oss << "NULL";
00460   }
00461   else {
00462     oss
00463       << "multiVec=" << getMultiVector()->description()
00464       << ",orientation=" << toString(getOrientation());
00465   }
00466   oss << "}";
00467   return oss.str();
00468 }
00469 
00470 
00471 template<class Scalar>
00472 void ModelEvaluatorBase::DerivativeMultiVector<Scalar>::describe(
00473   Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
00474   ) const
00475 {
00476   using std::endl;
00477   using Teuchos::describe;
00478   Teuchos::OSTab tab1(out);
00479   out << "DerivativeMultiVector\n";
00480   Teuchos::OSTab tab2(out);
00481   out
00482     << "multiVec = "
00483     << describe(*getMultiVector(),verbLevel)
00484     << "orientation = "
00485     << toString(getOrientation()) << endl;
00486 }
00487 
00488 
00489 // 2007/06/12: rabartl: The above description() and describe(...) functions
00490 // have to be defined here and not in the class DerivativeMultiVector since it
00491 // relies on the non-member function
00492 // toString(ModelEvaluatorBase::EDerivativeMultiVectorOrientation) which is
00493 // defined after the class definition for ModelEvaluatorBase.  This was caught
00494 // by the intel compiler.  I am not sure why this worked with gcc.
00495 
00496 
00497 //
00498 // ModelEvaluatorBase::Derivative
00499 //
00500 
00501 
00502 template<class Scalar>
00503 std::string
00504 ModelEvaluatorBase::Derivative<Scalar>::description() const
00505 {
00506   using std::endl;
00507   std::ostringstream oss;
00508   oss << "Derivative{";
00509   if (isEmpty()) {
00510     oss << "NULL";
00511   }
00512   else if (!is_null(getLinearOp())) {
00513     oss << "linearOp=" << getLinearOp()->description();
00514   }
00515   else {
00516     oss << "derivMultiVec=" << getDerivativeMultiVector().description();
00517   }
00518   oss << "}";
00519   return oss.str();
00520 }
00521 
00522 
00523 template<class Scalar>
00524 void ModelEvaluatorBase::Derivative<Scalar>::describe( 
00525   Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
00526   ) const
00527 {
00528   using std::endl;
00529   using Teuchos::describe;
00530   Teuchos::OSTab tab1(out);
00531   out << "Derivative:";
00532   if (isEmpty()) {
00533     out << " NULL\n";
00534   }
00535   else if (!is_null(getLinearOp())) {
00536     out
00537       << endl
00538       << "linearOp = " << describe(*getLinearOp(),verbLevel);
00539   }
00540   else {
00541     out
00542       << endl
00543       << "derivMultiVec = ";
00544     getDerivativeMultiVector().describe(out,verbLevel);
00545   }
00546 }
00547 
00548 
00549 //
00550 // ModelEvaluatorBase::OutArgs
00551 //
00552 
00553 
00554 template<class Scalar>
00555 ModelEvaluatorBase::OutArgs<Scalar>::OutArgs()
00556   :modelEvalDescription_("WARNING!  THIS OUTARGS OBJECT IS UNINITALIZED!"),
00557    isFailed_(false)
00558 { std::fill_n(&supports_[0],NUM_E_OUT_ARGS_MEMBERS,false); }
00559 
00560 
00561 template<class Scalar>
00562 int ModelEvaluatorBase::OutArgs<Scalar>::Np() const
00563 { return DfDp_.size(); }
00564 
00565 
00566 template<class Scalar>
00567 int ModelEvaluatorBase::OutArgs<Scalar>::Ng() const
00568 { return g_.size(); }
00569 
00570 
00571 template<class Scalar>
00572 bool ModelEvaluatorBase::OutArgs<Scalar>::supports(
00573   EOutArgsMembers arg
00574   ) const
00575 {
00576   TEST_FOR_EXCEPTION(
00577     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00578     ,"model = \'"<<modelEvalDescription_
00579     <<"\': Error, arg="<<toString(arg)<<" is invalid!"
00580     );
00581   return supports_[arg];
00582 }
00583 
00584 
00585 template<class Scalar>
00586 const ModelEvaluatorBase::DerivativeSupport&
00587 ModelEvaluatorBase::OutArgs<Scalar>::supports(
00588   EOutArgsDfDp arg, int l
00589   ) const
00590 {
00591   assert_l(l);
00592   return supports_DfDp_[l];
00593 }
00594 
00595 
00596 template<class Scalar>
00597 const ModelEvaluatorBase::DerivativeSupport&
00598 ModelEvaluatorBase::OutArgs<Scalar>::supports(
00599   EOutArgsDgDx_dot arg, int j
00600   ) const
00601 {
00602   assert_j(j);
00603   return supports_DgDx_dot_[j];
00604 }
00605 
00606 
00607 template<class Scalar>
00608 const ModelEvaluatorBase::DerivativeSupport&
00609 ModelEvaluatorBase::OutArgs<Scalar>::supports(
00610   EOutArgsDgDx arg, int j
00611   ) const
00612 {
00613   assert_j(j);
00614   return supports_DgDx_[j];
00615 }
00616 
00617 
00618 template<class Scalar>
00619 const ModelEvaluatorBase::DerivativeSupport&
00620 ModelEvaluatorBase::OutArgs<Scalar>::supports(
00621   EOutArgsDgDp arg, int j, int l
00622   ) const
00623 {
00624   assert_j(j);
00625   assert_l(l);
00626   return supports_DgDp_[ j*Np() + l ];
00627 }
00628 
00629 
00630 template<class Scalar>
00631 void ModelEvaluatorBase::OutArgs<Scalar>::set_f( 
00632   const RCP<VectorBase<Scalar> > &f
00633   )
00634 {
00635   assert_supports(OUT_ARG_f);
00636   f_ = f;
00637 }
00638 
00639 
00640 template<class Scalar>
00641 RCP<VectorBase<Scalar> >
00642 ModelEvaluatorBase::OutArgs<Scalar>::get_f() const
00643 {
00644   assert_supports(OUT_ARG_f);
00645   return f_;
00646 }
00647 
00648 
00649 template<class Scalar>
00650 void ModelEvaluatorBase::OutArgs<Scalar>::set_g(
00651   int j, const RCP<VectorBase<Scalar> > &g_j
00652   )
00653 {
00654   assert_j(j);
00655   g_[j] = g_j;
00656 }
00657 
00658 
00659 template<class Scalar>
00660 RCP<VectorBase<Scalar> >
00661 ModelEvaluatorBase::OutArgs<Scalar>::get_g(int j) const
00662 { 
00663   assert_j(j);
00664   return g_[j];
00665 }
00666 
00667 
00668 template<class Scalar>
00669 void ModelEvaluatorBase::OutArgs<Scalar>::set_W(
00670   const RCP<LinearOpWithSolveBase<Scalar> > &W
00671   )
00672 {
00673   assert_supports(OUT_ARG_W);
00674   W_ = W;
00675 }
00676 
00677 
00678 template<class Scalar>
00679 RCP<LinearOpWithSolveBase<Scalar> >
00680 ModelEvaluatorBase::OutArgs<Scalar>::get_W() const
00681 {
00682   assert_supports(OUT_ARG_W);
00683   return W_;
00684 }
00685 
00686 
00687 template<class Scalar>
00688 void ModelEvaluatorBase::OutArgs<Scalar>::set_W_op(
00689   const RCP<LinearOpBase<Scalar> > &W_op
00690   )
00691 {
00692   assert_supports(OUT_ARG_W_op);
00693   W_op_ = W_op;
00694 }
00695 
00696 
00697 template<class Scalar>
00698 RCP<LinearOpBase<Scalar> >
00699 ModelEvaluatorBase::OutArgs<Scalar>::get_W_op() const
00700 {
00701   assert_supports(OUT_ARG_W_op);
00702   return W_op_;
00703 }
00704 
00705 
00706 template<class Scalar>
00707 ModelEvaluatorBase::DerivativeProperties
00708 ModelEvaluatorBase::OutArgs<Scalar>::get_W_properties() const
00709 {
00710   assert_supports(OUT_ARG_f);
00711   return W_properties_;
00712 }
00713 
00714 
00715 template<class Scalar>
00716 void ModelEvaluatorBase::OutArgs<Scalar>::set_DfDp(
00717   int l, const Derivative<Scalar> &DfDp_l
00718   )
00719 {
00720   assert_supports(OUT_ARG_DfDp,l,DfDp_l);
00721   DfDp_[l] = DfDp_l;
00722 }
00723 
00724 
00725 template<class Scalar>
00726 ModelEvaluatorBase::Derivative<Scalar>
00727 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp(int l) const
00728 {
00729   assert_supports(OUT_ARG_DfDp,l);
00730   return DfDp_[l];
00731 }
00732 
00733 
00734 template<class Scalar>
00735 ModelEvaluatorBase::DerivativeProperties
00736 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp_properties(int l) const
00737 {
00738   assert_supports(OUT_ARG_DfDp,l);
00739   return DfDp_properties_[l];
00740 }
00741 
00742 
00743 template<class Scalar>
00744 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDx_dot(
00745   int j, const Derivative<Scalar> &DgDx_dot_j
00746   )
00747 {
00748   assert_supports(OUT_ARG_DgDx_dot,j,DgDx_dot_j);
00749   DgDx_dot_[j] = DgDx_dot_j;
00750 }
00751 
00752 
00753 template<class Scalar>
00754 ModelEvaluatorBase::Derivative<Scalar>
00755 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_dot(int j) const
00756 {
00757   assert_supports(OUT_ARG_DgDx_dot,j);
00758   return DgDx_dot_[j];
00759 }
00760 
00761 
00762 template<class Scalar>
00763 ModelEvaluatorBase::DerivativeProperties
00764 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_dot_properties(int j) const
00765 {
00766   assert_supports(OUT_ARG_DgDx_dot,j);
00767   return DgDx_dot_properties_[j];
00768 }
00769 
00770 
00771 template<class Scalar>
00772 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDx(
00773   int j, const Derivative<Scalar> &DgDx_j
00774   )
00775 {
00776   assert_supports(OUT_ARG_DgDx,j,DgDx_j);
00777   DgDx_[j] = DgDx_j;
00778 }
00779 
00780 
00781 template<class Scalar>
00782 ModelEvaluatorBase::Derivative<Scalar>
00783 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx(int j) const
00784 {
00785   assert_supports(OUT_ARG_DgDx,j);
00786   return DgDx_[j];
00787 }
00788 
00789 
00790 template<class Scalar>
00791 ModelEvaluatorBase::DerivativeProperties
00792 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_properties(int j) const
00793 {
00794   assert_supports(OUT_ARG_DgDx,j);
00795   return DgDx_properties_[j];
00796 }
00797 
00798 
00799 template<class Scalar>
00800 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDp(
00801   int j, int l, const Derivative<Scalar> &DgDp_j_l
00802   )
00803 {
00804   assert_supports(OUT_ARG_DgDp,j,l,DgDp_j_l);
00805   DgDp_[ j*Np() + l ] = DgDp_j_l;
00806 }
00807 
00808 
00809 template<class Scalar>
00810 ModelEvaluatorBase::Derivative<Scalar>
00811 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp(int j, int l) const
00812 {
00813   assert_supports(OUT_ARG_DgDp,j,l);
00814   return DgDp_[ j*Np() + l ];
00815 }
00816 
00817 
00818 template<class Scalar>
00819 ModelEvaluatorBase::DerivativeProperties
00820 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp_properties(int j, int l) const
00821 {
00822   assert_supports(OUT_ARG_DgDp,j,l);
00823   return DgDp_properties_[ j*Np() + l ];
00824 }
00825 
00826 
00827 template<class Scalar>
00828 void ModelEvaluatorBase::OutArgs<Scalar>::set_f_poly(
00829   const RCP<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly
00830   )
00831 {
00832   f_poly_ = f_poly;
00833 }
00834 
00835 
00836 template<class Scalar>
00837 RCP<Teuchos::Polynomial< VectorBase<Scalar> > >
00838 ModelEvaluatorBase::OutArgs<Scalar>::get_f_poly() const
00839 {
00840   return f_poly_;
00841 }
00842 
00843 
00844 template<class Scalar>
00845 void ModelEvaluatorBase::OutArgs<Scalar>::setArgs(
00846   const OutArgs<Scalar>& inputOutArgs, bool ignoreUnsupported
00847   )
00848 {
00849   typedef ModelEvaluatorBase MEB;
00850   const int min_Np = TEUCHOS_MIN(this->Np(),inputOutArgs.Np());
00851   const int min_Ng = TEUCHOS_MIN(this->Ng(),inputOutArgs.Ng());
00852   // f
00853   if ( inputOutArgs.supports(OUT_ARG_f) && inputOutArgs.get_f().get() ) {
00854     if ( supports(OUT_ARG_f) || !ignoreUnsupported )
00855       set_f(inputOutArgs.get_f());
00856   }
00857   // f_poly
00858   if ( inputOutArgs.supports(OUT_ARG_f_poly) && inputOutArgs.get_f_poly().get() ) {
00859     if ( supports(OUT_ARG_f_poly) || !ignoreUnsupported )
00860       set_f_poly(inputOutArgs.get_f_poly());
00861   }
00862   // g(j)
00863   for ( int j = 0; j < min_Ng; ++j ) {
00864     if ( inputOutArgs.get_g(j).get() )
00865       set_g(j,inputOutArgs.get_g(j));
00866   }
00867   // W
00868   if( inputOutArgs.supports(OUT_ARG_W) && inputOutArgs.get_W().get() ) {
00869     if ( supports(OUT_ARG_W) || !ignoreUnsupported )
00870       set_W(inputOutArgs.get_W());
00871   }
00872   // W_op
00873   if( inputOutArgs.supports(OUT_ARG_W_op) && inputOutArgs.get_W_op().get() ) {
00874     if ( supports(OUT_ARG_W_op) || !ignoreUnsupported )
00875       set_W_op(inputOutArgs.get_W_op());
00876   }
00877   // DfDp(l)
00878   for ( int l = 0; l < min_Np; ++l ) {
00879     MEB::Derivative<Scalar> DfDp_l;
00880     if ( !inputOutArgs.supports(OUT_ARG_DfDp,l).none()
00881       && !(DfDp_l=inputOutArgs.get_DfDp(l)).isEmpty() )
00882     {
00883       if ( DfDp_l.isSupportedBy(supports(OUT_ARG_DfDp,l)) || !ignoreUnsupported )
00884         set_DfDp(l,DfDp_l);
00885     }
00886   }
00887   // DgDx_dot(j) and DgDx(j)
00888   for ( int j = 0; j < min_Ng; ++j ) {
00889     // DgDx_dot(j)
00890     MEB::Derivative<Scalar> DgDx_dot_j;
00891     if ( !inputOutArgs.supports(OUT_ARG_DgDx_dot,j).none()
00892       && !(DgDx_dot_j=inputOutArgs.get_DgDx_dot(j)).isEmpty() )
00893     {
00894       if( DgDx_dot_j.isSupportedBy(supports(OUT_ARG_DgDx_dot,j)) || !ignoreUnsupported )
00895         set_DgDx_dot(j,DgDx_dot_j);
00896     }
00897     // DgDx(j)
00898     MEB::Derivative<Scalar> DgDx_j;
00899     if ( !inputOutArgs.supports(OUT_ARG_DgDx,j).none()
00900       && !(DgDx_j=inputOutArgs.get_DgDx(j)).isEmpty() ) {
00901       if ( DgDx_j.isSupportedBy(supports(OUT_ARG_DgDx,j)) || !ignoreUnsupported )
00902         set_DgDx(j,DgDx_j);
00903     }
00904   }
00905   // DgDp(j,l)
00906   for ( int l = 0; l < min_Np; ++l ) {
00907     for ( int j = 0; j < min_Ng; ++j ) {
00908       MEB::Derivative<Scalar> DgDp_j_l;
00909       if ( !inputOutArgs.supports(OUT_ARG_DgDp,j,l).none() 
00910         && !(DgDp_j_l=inputOutArgs.get_DgDp(j,l)).isEmpty() )
00911       {
00912         if ( DgDp_j_l.isSupportedBy(supports(OUT_ARG_DgDp,j,l)) || !ignoreUnsupported )
00913           set_DgDp(j,l,DgDp_j_l);
00914       }
00915     }
00916   }
00917   // ToDo: Add more args as needed!
00918 }
00919 
00920 
00921 template<class Scalar>
00922 void ModelEvaluatorBase::OutArgs<Scalar>::setFailed() const
00923 {
00924   typedef Teuchos::ScalarTraits<Scalar> ST;
00925   isFailed_ = true;
00926   if( this->supports(OUT_ARG_f) && this->get_f().get() ) {
00927     assign(&*this->get_f(),ST::nan());
00928   }
00929   for( int j = 0; j < this->Ng(); ++j ) {
00930     if(this->get_g(j).get())
00931       assign(&*this->get_g(j),ST::nan());
00932   }
00933   // ToDo: Set other objects to NaN as well!
00934 }
00935 
00936 
00937 template<class Scalar>
00938 bool ModelEvaluatorBase::OutArgs<Scalar>::isFailed() const
00939 {
00940   return isFailed_;
00941 }
00942 
00943 
00944 template<class Scalar>
00945 bool ModelEvaluatorBase::OutArgs<Scalar>::isEmpty() const
00946 {
00947   if (!is_null(f_))
00948     return false;
00949   if (!is_null(W_))
00950     return false;
00951   if (!is_null(W_op_))
00952     return false;
00953   for ( int l = 0; l < Np(); ++l ) {
00954     if (!DfDp_[l].isEmpty())
00955       return false;
00956   }
00957   if (!is_null(f_poly_))
00958     return false;
00959   for ( int j = 0; j < Ng(); ++j ) {
00960     if (!is_null(g_[j]))
00961       return false;
00962     if (!DgDx_dot_[j].isEmpty())
00963       return false;
00964     if (!DgDx_[j].isEmpty())
00965       return false;
00966     for ( int l = 0; l < Np(); ++l ) {
00967       if (!DgDp_[j*Np()+l].isEmpty())
00968         return false;
00969     }
00970   }
00971   return true;
00972 }
00973 
00974 
00975 template<class Scalar>
00976 void ModelEvaluatorBase::OutArgs<Scalar>::assertSameSupport(
00977   const OutArgs<Scalar> &outArgs
00978   ) const
00979 {
00980 
00981   for ( int outArg_i = 0; outArg_i < NUM_E_OUT_ARGS_MEMBERS; ++outArg_i ) {
00982     const EOutArgsMembers outArg_arg = static_cast<EOutArgsMembers>(outArg_i);
00983     const std::string outArg_name = toString(outArg_arg);
00984     TEST_FOR_EXCEPTION(
00985       supports(outArg_arg) != outArgs.supports(outArg_arg), std::logic_error,
00986       "Error, the output argument "<<outArg_name<<" with support "<<outArgs.supports(outArg_arg)<<"\n"
00987       "in the OutArgs object for the model:\n\n"
00988       "  "<<outArgs.modelEvalDescription()<<"\n\n"
00989       "is not the same the argument "<<outArg_name<<" with support "<<supports(outArg_arg)<<"\n"
00990       "in the OutArgs object for the model:\n\n"
00991       "  "<<modelEvalDescription()<<"\n\n"
00992       "and these two OutArgs objects are not compatible!"
00993       );
00994   }
00995 
00996   const int l_Np = this->Np();
00997   const int l_Ng = this->Ng();
00998   TEUCHOS_ASSERT_EQUALITY( l_Np, outArgs.Np() );
00999   TEUCHOS_ASSERT_EQUALITY( l_Ng, outArgs.Ng() );
01000 
01001   if (supports(OUT_ARG_f)) {
01002     for ( int l = 0; l < l_Np; ++l ) {
01003       TEST_FOR_EXCEPTION(
01004         !supports(OUT_ARG_DfDp,l).isSameSupport(outArgs.supports(OUT_ARG_DfDp,l)),
01005         std::logic_error,
01006         "Error, the support for DfDp("<<l<<") is not the same for the models\n\n"
01007         "  "<<outArgs.modelEvalDescription()<<"\n\n"
01008         "and:\n\n"
01009         "  "<<modelEvalDescription()<<"\n\n"
01010         "and these two OutArgs objects are not compatible!"
01011         );
01012     }
01013   }
01014 
01015   for ( int j = 0; j < l_Ng; ++j ) {
01016     TEST_FOR_EXCEPTION(
01017       !supports(OUT_ARG_DgDx_dot,j).isSameSupport(outArgs.supports(OUT_ARG_DgDx_dot,j)),
01018       std::logic_error,
01019       "Error, the support for DgDx_dot("<<j<<") is not the same for the models\n\n"
01020       "  "<<outArgs.modelEvalDescription()<<"\n\n"
01021       "and:\n\n"
01022       "  "<<modelEvalDescription()<<"\n\n"
01023       "and these two OutArgs objects are not compatible!"
01024       );
01025     TEST_FOR_EXCEPTION(
01026       !supports(OUT_ARG_DgDx,j).isSameSupport(outArgs.supports(OUT_ARG_DgDx,j)),
01027       std::logic_error,
01028       "Error, the support for DgDx("<<j<<") is not the same for the models\n\n"
01029       "  "<<outArgs.modelEvalDescription()<<"\n\n"
01030       "and:\n\n"
01031       "  "<<modelEvalDescription()<<"\n\n"
01032       "and these two OutArgs objects are not compatible!"
01033       );
01034     for ( int l = 0; l < l_Np; ++l ) {
01035       TEST_FOR_EXCEPTION(
01036         !supports(OUT_ARG_DgDp,j,l).isSameSupport(outArgs.supports(OUT_ARG_DgDp,j,l)),
01037         std::logic_error,
01038         "Error, the support for DgDp("<<j<<","<<l<<") is not the same for the models\n\n"
01039         "  "<<outArgs.modelEvalDescription()<<"\n\n"
01040         "and:\n\n"
01041         "  "<<modelEvalDescription()<<"\n\n"
01042         "and these two OutArgs objects are not compatible!"
01043         );
01044     }
01045   }
01046 }
01047 
01048 
01049 template<class Scalar>
01050 std::string ModelEvaluatorBase::OutArgs<Scalar>::modelEvalDescription() const
01051 {
01052   return modelEvalDescription_;
01053 }
01054 
01055 
01056 template<class Scalar>
01057 std::string ModelEvaluatorBase::OutArgs<Scalar>::description() const
01058 {
01059   typedef Teuchos::ScalarTraits<Scalar> ST;
01060   std::ostringstream oss;
01061   oss
01062     << "Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">"
01063     << "{"
01064     << "model="<<modelEvalDescription_
01065     << ",Np="<<Np()
01066     << ",Ng="<<Ng()
01067     << "}";
01068   return oss.str();
01069 }
01070 
01071 
01072 template<class Scalar>
01073 void ModelEvaluatorBase::OutArgs<Scalar>::describe(
01074   Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
01075   ) const
01076 {
01077 
01078   using Teuchos::OSTab;
01079   using Teuchos::describe;
01080   typedef Teuchos::ScalarTraits<Scalar> ST;
01081   typedef RCP<const VectorBase<Scalar> > CV_ptr;
01082   typedef RCP<const LinearOpBase<Scalar> > CLO_ptr;
01083   typedef RCP<const LinearOpWithSolveBase<Scalar> > CLOWS_ptr;
01084   typedef ModelEvaluatorBase MEB;
01085   typedef MEB::Derivative<Scalar> Deriv;
01086 
01087   if( verbLevel == Teuchos::VERB_NONE && verbLevel == Teuchos::VERB_DEFAULT )
01088     return;
01089 
01090   RCP<Teuchos::FancyOStream>
01091     out = Teuchos::rcp(&out_arg,false);
01092   OSTab tab(out);
01093 
01094   *out <<"Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">:\n";
01095   tab.incrTab();
01096 
01097   *out <<"model = " << modelEvalDescription_ << "\n";
01098   *out <<"Np = " << Np() << "\n";
01099   *out <<"Ng = " << Ng() << "\n";
01100 
01101   CV_ptr f;
01102   if (this->supports(OUT_ARG_f) && !is_null(f=get_f()) ) {
01103     *out << "f = " << Teuchos::describe(*f,verbLevel);
01104   }
01105   
01106   for( int j = 0; j < Ng(); ++j ) {
01107     CV_ptr g_j;
01108     if (!is_null(g_j=this->get_g(j)))
01109       *out << "g("<<j<<") = " << Teuchos::describe(*g_j,verbLevel);
01110   }
01111   
01112   CLOWS_ptr W;
01113   if ( this->supports(OUT_ARG_W) && !is_null(W=get_W()) ) {
01114     *out << "W = " << Teuchos::describe(*W,verbLevel);
01115   }
01116   
01117   CLO_ptr W_op;
01118   if ( this->supports(OUT_ARG_W_op) && !is_null(W_op=get_W_op()) ) {
01119     *out << "W_op = " << Teuchos::describe(*W_op,verbLevel);
01120   }
01121   
01122   for( int l = 0; l < Np(); ++l ) {
01123     Deriv DfDp_l;
01124     if (
01125       !this->supports(OUT_ARG_DfDp,l).none()
01126       && !(DfDp_l=get_DfDp(l)).isEmpty()
01127       )
01128     {
01129       *out << "DfDp("<<l<<") = ";
01130       DfDp_l.describe(*out,verbLevel);
01131     }
01132   }
01133   
01134   for( int j = 0; j < Ng(); ++j ) {
01135     
01136     Deriv DgDx_dot_j;
01137     if (
01138       !this->supports(OUT_ARG_DgDx_dot,j).none()
01139       && !(DgDx_dot_j=get_DgDx_dot(j)).isEmpty()
01140       )
01141     {
01142       *out << "DgDx_dot("<<j<<") = ";
01143       DgDx_dot_j.describe(*out,verbLevel);
01144     }
01145     
01146     Deriv DgDx_j;
01147     if (
01148       !this->supports(OUT_ARG_DgDx,j).none()
01149       && !(DgDx_j=get_DgDx(j)).isEmpty()
01150       )
01151     {
01152       *out << "DgDx("<<j<<") = ";
01153       DgDx_j.describe(*out,verbLevel);
01154     }
01155     
01156     for( int l = 0; l < Np(); ++l ) {
01157       
01158       Deriv DgDp_j_l;
01159       if (
01160         !this->supports(OUT_ARG_DgDp,j,l).none()
01161         && !(DgDp_j_l=get_DgDp(j,l)).isEmpty()
01162         )
01163       {
01164         *out << "DgDp("<<j<<","<<l<<") = ";
01165         DgDp_j_l.describe(*out,verbLevel);
01166       }
01167     }
01168     
01169   }
01170   
01171   // ToDo: Add output for more objects?
01172 
01173 }
01174 
01175 
01176 // protected
01177 
01178 
01179 template<class Scalar>
01180 void ModelEvaluatorBase::OutArgs<Scalar>::_setModelEvalDescription(
01181   const std::string &modelEvalDescription_in
01182   )
01183 {
01184   modelEvalDescription_ = modelEvalDescription_in;
01185 }
01186 
01187 template<class Scalar>
01188 void ModelEvaluatorBase::OutArgs<Scalar>::_set_Np_Ng(int Np_in, int Ng_in)
01189 {
01190   if(Np_in) {
01191     supports_DfDp_.resize(Np_in);
01192     DfDp_.resize(Np_in); std::fill_n(DfDp_.begin(),Np_in,Derivative<Scalar>());
01193     DfDp_properties_.resize(Np_in); std::fill_n(DfDp_properties_.begin(),Np_in,DerivativeProperties());
01194   }
01195   if(Ng_in) {
01196     g_.resize(Ng_in); std::fill_n(g_.begin(),Ng_in,Teuchos::null);
01197     supports_DgDx_dot_.resize(Ng_in);
01198     DgDx_dot_.resize(Ng_in); std::fill_n(DgDx_dot_.begin(),Ng_in,Derivative<Scalar>());
01199     DgDx_dot_properties_.resize(Ng_in); std::fill_n(DgDx_dot_properties_.begin(),Ng_in,DerivativeProperties());
01200     supports_DgDx_.resize(Ng_in);
01201     DgDx_.resize(Ng_in); std::fill_n(DgDx_.begin(),Ng_in,Derivative<Scalar>());
01202     DgDx_properties_.resize(Ng_in); std::fill_n(DgDx_properties_.begin(),Ng_in,DerivativeProperties());
01203   }
01204   if(Np_in && Ng_in) {
01205     const int NpNg = Np_in*Ng_in;
01206     supports_DgDp_.resize(NpNg);
01207     DgDp_.resize(NpNg); std::fill_n(DgDp_.begin(),NpNg,Derivative<Scalar>());
01208     DgDp_properties_.resize(NpNg); std::fill_n(DgDp_properties_.begin(),NpNg,DerivativeProperties());
01209   }
01210 }
01211 
01212 
01213 template<class Scalar>
01214 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
01215   EOutArgsMembers arg, bool supports_in )
01216 {
01217   TEST_FOR_EXCEPTION(
01218     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
01219     ,"model = \'"<<modelEvalDescription_
01220     <<"\': Error, arg="<<toString(arg)<<" is invalid!"
01221     );
01222   supports_[arg] = supports_in;
01223 }
01224 
01225 
01226 template<class Scalar>
01227 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
01228   EOutArgsDfDp arg, int l, const DerivativeSupport& supports_in
01229   )
01230 {
01231   assert_supports(OUT_ARG_f);
01232   assert_l(l);
01233   supports_DfDp_[l] = supports_in;
01234 }
01235 
01236 
01237 template<class Scalar>
01238 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
01239   EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports_in
01240   )
01241 {
01242   assert_j(j);
01243   supports_DgDx_dot_[j] = supports_in;
01244 }
01245 
01246 
01247 template<class Scalar>
01248 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
01249   EOutArgsDgDx arg, int j, const DerivativeSupport& supports_in
01250   )
01251 {
01252   assert_j(j);
01253   supports_DgDx_[j] = supports_in;
01254 }
01255 
01256 
01257 template<class Scalar>
01258 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
01259   EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports_in
01260   )
01261 {
01262   assert_j(j);
01263   assert_l(l);
01264   supports_DgDp_[ j*Np()+ l ] = supports_in;
01265 }
01266 
01267 
01268 template<class Scalar>
01269 void ModelEvaluatorBase::OutArgs<Scalar>::_set_W_properties( 
01270   const DerivativeProperties &properties
01271   )
01272 {
01273   W_properties_ = properties;
01274 }
01275 
01276 
01277 template<class Scalar>
01278 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DfDp_properties(
01279   int l, const DerivativeProperties &properties
01280   )
01281 {
01282   assert_supports(OUT_ARG_DfDp,l);
01283   DfDp_properties_[l] = properties;
01284 }
01285 
01286 
01287 template<class Scalar>
01288 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDx_dot_properties(
01289   int j, const DerivativeProperties &properties
01290   )
01291 {
01292   assert_supports(OUT_ARG_DgDx_dot,j);
01293   DgDx_dot_properties_[j] = properties;
01294 }
01295 
01296 
01297 template<class Scalar>
01298 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDx_properties(
01299   int j, const DerivativeProperties &properties
01300   )
01301 {
01302   assert_supports(OUT_ARG_DgDx,j);
01303   DgDx_properties_[j] = properties;
01304 }
01305 
01306 
01307 template<class Scalar>
01308 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDp_properties(
01309   int j, int l, const DerivativeProperties &properties
01310   )
01311 {
01312   assert_supports(OUT_ARG_DgDp,j,l);
01313   DgDp_properties_[ j*Np()+ l ] = properties;
01314 }
01315 
01316 
01317 template<class Scalar>
01318 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
01319   const OutArgs<Scalar>& inputOutArgs
01320   )
01321 {
01322   typedef ModelEvaluatorBase MEB;
01323   const int l_Np = TEUCHOS_MIN(this->Np(),inputOutArgs.Np()); 
01324   const int l_Ng = TEUCHOS_MIN(this->Ng(),inputOutArgs.Ng()); 
01325   std::copy(
01326     &inputOutArgs.supports_[0],
01327     &inputOutArgs.supports_[0] + NUM_E_OUT_ARGS_MEMBERS, &supports_[0] );
01328   for( int l = 0; l < l_Np; ++l ) {
01329     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DfDp,l);
01330     if (!ds.none()) {
01331       this->_setSupports(MEB::OUT_ARG_DfDp,l,ds);
01332       this->_set_DfDp_properties(l,inputOutArgs.get_DfDp_properties(l));
01333     }
01334   }
01335   for( int j = 0; j < l_Ng; ++j ) {
01336     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx_dot,j);
01337     this->_setSupports(MEB::OUT_ARG_DgDx_dot,j,ds);
01338     if(!ds.none()) this->_set_DgDx_dot_properties(j,inputOutArgs.get_DgDx_dot_properties(j));
01339   }
01340   for( int j = 0; j < l_Ng; ++j ) {
01341     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx,j);
01342     this->_setSupports(MEB::OUT_ARG_DgDx,j,ds);
01343     if(!ds.none()) this->_set_DgDx_properties(j,inputOutArgs.get_DgDx_properties(j));
01344   }
01345   for( int j = 0; j < l_Ng; ++j ) for( int l = 0; l < l_Np; ++l ) {
01346     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDp,j,l);
01347     this->_setSupports(MEB::OUT_ARG_DgDp,j,l,ds);
01348     if(!ds.none()) this->_set_DgDp_properties(j,l,inputOutArgs.get_DgDp_properties(j,l));
01349   }
01350   if(this->supports(OUT_ARG_W) || this->supports(OUT_ARG_W_op))
01351     this->_set_W_properties(inputOutArgs.get_W_properties());
01352 }
01353 
01354 
01355 template<class Scalar>
01356 void ModelEvaluatorBase::OutArgs<Scalar>::_setUnsupportsAndRelated(
01357   EInArgsMembers arg
01358   )
01359 {
01360   switch(arg) {
01361     case IN_ARG_x: {
01362       const int l_Ng = this->Ng();
01363       for( int j = 0; j < l_Ng; ++j ) {
01364         this->_setSupports(OUT_ARG_DgDx_dot,j,DerivativeSupport());
01365         this->_setSupports(OUT_ARG_DgDx,j,DerivativeSupport());
01366       }
01367       break;
01368     }
01369     default:
01370       TEST_FOR_EXCEPTION(
01371         true ,std::logic_error,
01372         "Error, can not handle args other than IN_ARG_x yet!"
01373         );
01374       break;
01375   }
01376 }
01377 
01378 
01379 template<class Scalar>
01380 void ModelEvaluatorBase::OutArgs<Scalar>::_setUnsupportsAndRelated(
01381   EOutArgsMembers arg
01382   )
01383 {
01384   switch(arg) {
01385     case OUT_ARG_f: {
01386       this->_setSupports(OUT_ARG_W,false);
01387       this->_setSupports(OUT_ARG_W_op,false);
01388       this->_setSupports(OUT_ARG_f_poly,false);
01389       const int l_Np = this->Np();
01390       for( int l = 0; l < l_Np; ++l )
01391         this->_setSupports(OUT_ARG_DfDp,l,DerivativeSupport());
01392       break;
01393     }
01394     default:
01395       TEST_FOR_EXCEPTION(
01396         true ,std::logic_error,
01397         "Error, can not handle args other than OUT_ARG_f yet!"
01398         );
01399       break;
01400   }
01401   this->_setSupports(arg,false);
01402 }
01403 
01404 
01405 // private
01406 
01407 
01408 template<class Scalar>
01409 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(EOutArgsMembers arg) const
01410 {
01411   TEST_FOR_EXCEPTION(
01412     !this->supports(arg), std::logic_error
01413     ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(arg):\n\n"
01414     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01415     "Error, The argument arg = " << toString(arg) << " is not supported!"
01416     );
01417 }
01418 
01419 
01420 template<class Scalar>
01421 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
01422   EOutArgsDfDp arg, int l, const Derivative<Scalar> &deriv
01423   ) const
01424 {
01425   const DerivativeSupport derivSupport = this->supports(arg,l);
01426   TEST_FOR_EXCEPTION(
01427     !deriv.isSupportedBy(derivSupport), std::logic_error,
01428     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DfDp,l):\n\n"
01429     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01430     "Error, The argument DfDp("<<l<<") = " << deriv.description() << "\n"
01431     "is not supported!\n\n"
01432     "The supported types include " << derivSupport.description() << "!"
01433     );
01434 }
01435 
01436 
01437 template<class Scalar>
01438 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
01439   EOutArgsDgDx_dot arg, int j, const Derivative<Scalar> &deriv
01440   ) const
01441 {
01442   const DerivativeSupport derivSupport = this->supports(arg,j);
01443   TEST_FOR_EXCEPTION(
01444     !deriv.isSupportedBy(derivSupport), std::logic_error,
01445     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx_dot,j):\n\n"
01446     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01447     "Error, The argument DgDx_dot("<<j<<") = " << deriv.description() << "\n"
01448     "is not supported!\n\n"
01449     "The supported types include " << derivSupport.description() << "!"
01450     );
01451 }
01452 
01453 
01454 template<class Scalar>
01455 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
01456   EOutArgsDgDx arg, int j, const Derivative<Scalar> &deriv
01457   ) const
01458 {
01459   const DerivativeSupport derivSupport = this->supports(arg,j);
01460   TEST_FOR_EXCEPTION(
01461     !deriv.isSupportedBy(derivSupport), std::logic_error,
01462     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx,j):\n\n"
01463     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01464     "Error, The argument DgDx("<<j<<") = " << deriv.description() << "\n"
01465     "is not supported!\n\n"
01466     "The supported types include " << derivSupport.description() << "!"
01467     );
01468 }
01469 
01470 
01471 template<class Scalar>
01472 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
01473   EOutArgsDgDp arg, int j, int l, const Derivative<Scalar> &deriv
01474   ) const
01475 {
01476   const DerivativeSupport derivSupport = this->supports(arg,j,l);
01477   TEST_FOR_EXCEPTION(
01478     !deriv.isSupportedBy(derivSupport), std::logic_error,
01479     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDp,j,l):\n\n"
01480     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01481     "Error, The argument DgDp("<<j<<","<<l<<") = " << deriv.description() << "\n"
01482     "is not supported!\n\n"
01483     "The supported types include " << derivSupport.description() << "!"
01484     );
01485 }
01486 
01487 
01488 template<class Scalar>
01489 void ModelEvaluatorBase::OutArgs<Scalar>::assert_l(int l) const
01490 {
01491   TEST_FOR_EXCEPTION(
01492     !( 0 <= l && l < Np() ), std::logic_error
01493     ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_l(l):\n\n"
01494     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01495     "Error,  The parameter subvector p("<<l<<")"
01496     " is not in the range [0,"<<Np()<<")!"
01497     );
01498 }
01499 
01500 
01501 template<class Scalar>
01502 void ModelEvaluatorBase::OutArgs<Scalar>::assert_j(int j) const
01503 {
01504   TEST_FOR_EXCEPTION(
01505     !( 0 <= j && j < Ng() ), std::logic_error
01506     ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_j(j):\n\n"
01507     "model = \'"<<modelEvalDescription_<<"\':\n\n"
01508     "Error, The auxiliary function g("<<j<<")"
01509     " is not in the range [0,"<<Ng()<<")!"
01510     );
01511 }
01512 
01513 
01514 //
01515 // ModelEvaluatorBase::InArgsSetup
01516 //
01517 
01518 
01519 template<class Scalar>
01520 ModelEvaluatorBase::InArgsSetup<Scalar>::InArgsSetup()
01521 {}
01522 
01523 
01524 template<class Scalar>
01525 ModelEvaluatorBase::InArgsSetup<Scalar>::InArgsSetup( const InArgs<Scalar>& inArgs )
01526   :InArgs<Scalar>(inArgs)
01527 {}
01528 
01529 
01530 template<class Scalar>
01531 void ModelEvaluatorBase::InArgsSetup<Scalar>::setModelEvalDescription(
01532   const std::string &modelEvalDescription_in )
01533 {
01534   this->_setModelEvalDescription(modelEvalDescription_in);
01535 }
01536 
01537 
01538 template<class Scalar>
01539 void ModelEvaluatorBase::InArgsSetup<Scalar>::set_Np(int Np_in)
01540 { this->_set_Np(Np_in); }
01541 
01542 
01543 template<class Scalar>
01544 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports( EInArgsMembers arg, bool supports_in )
01545 { this->_setSupports(arg,supports_in); }
01546 
01547 
01548 template<class Scalar>
01549 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports(
01550   const InArgs<Scalar>& inArgs, const int Np_in
01551   )
01552 {
01553   this->_setSupports(inArgs, Np_in);
01554 }
01555 
01556 
01557 template<class Scalar>
01558 void ModelEvaluatorBase::InArgsSetup<Scalar>::setUnsupportsAndRelated(
01559   EInArgsMembers arg
01560   )
01561 {
01562   this->_setUnsupportsAndRelated(arg);
01563 }
01564 
01565 
01566 //
01567 // ModelEvaluatorBase::OutArgsSetup
01568 //
01569 
01570 
01571 template<class Scalar>
01572 ModelEvaluatorBase::OutArgsSetup<Scalar>::OutArgsSetup()
01573 {}
01574 
01575 
01576 template<class Scalar>
01577 ModelEvaluatorBase::OutArgsSetup<Scalar>::OutArgsSetup(
01578   const OutArgs<Scalar>& inputOutArgs
01579   )
01580   :OutArgs<Scalar>(inputOutArgs)
01581 {}
01582 
01583 
01584 template<class Scalar>
01585 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setModelEvalDescription(
01586   const std::string &modelEvalDescription_in
01587   )
01588 { this->_setModelEvalDescription(modelEvalDescription_in); }
01589 
01590 
01591 template<class Scalar>
01592 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_Np_Ng(int Np_in, int Ng_in)
01593 { this->_set_Np_Ng(Np_in, Ng_in); }
01594 
01595 
01596 template<class Scalar>
01597 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
01598   EOutArgsMembers arg, bool supports_in
01599   )
01600 { this->_setSupports(arg,supports_in); }
01601 
01602 
01603 template<class Scalar>
01604 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
01605   EOutArgsDfDp arg, int l, const DerivativeSupport& supports_in
01606   )
01607 { this->_setSupports(arg,l,supports_in); }
01608 
01609 
01610 template<class Scalar>
01611 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( 
01612   EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports_in
01613   )
01614 { this->_setSupports(arg,j,supports_in); }
01615 
01616 
01617 template<class Scalar>
01618 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
01619   EOutArgsDgDx arg, int j, const DerivativeSupport& supports_in
01620   )
01621 { this->_setSupports(arg,j,supports_in); }
01622 
01623 
01624 template<class Scalar>
01625 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
01626   EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports_in
01627   )
01628 { this->_setSupports(arg,j,l,supports_in); }
01629 
01630 
01631 template<class Scalar>
01632 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_W_properties(
01633   const DerivativeProperties &properties
01634   )
01635 { this->_set_W_properties(properties); }
01636 
01637 
01638 template<class Scalar>
01639 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DfDp_properties(
01640   int l, const DerivativeProperties &properties
01641   )
01642 { this->_set_DfDp_properties(l,properties); }
01643 
01644 
01645 template<class Scalar>
01646 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDx_dot_properties(
01647   int j, const DerivativeProperties &properties
01648   )
01649 { this->_set_DgDx_dot_properties(j,properties); }
01650 
01651 
01652 template<class Scalar>
01653 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDx_properties(
01654   int j, const DerivativeProperties &properties
01655   )
01656 { this->_set_DgDx_properties(j,properties); }
01657 
01658 
01659 template<class Scalar>
01660 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDp_properties(
01661   int j, int l, const DerivativeProperties &properties
01662   )
01663 { this->_set_DgDp_properties(j,l,properties); }
01664 
01665 
01666 template<class Scalar>
01667 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
01668   const OutArgs<Scalar>& inputOutArgs
01669   )
01670 { this->_setSupports(inputOutArgs); }
01671 
01672 
01673 template<class Scalar>
01674 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setUnsupportsAndRelated(
01675   EInArgsMembers arg
01676   )
01677 { this->_setUnsupportsAndRelated(arg); }
01678 
01679 
01680 template<class Scalar>
01681 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setUnsupportsAndRelated(
01682   EOutArgsMembers arg
01683   )
01684 { this->_setUnsupportsAndRelated(arg); }
01685 
01686 
01687 } // namespace Thyra
01688 
01689 
01690 
01691 //
01692 // Explicit instantiation macro
01693 //
01694 // Must be expanded from within the Thyra namespace!
01695 //
01696 
01697 
01698 #define THYRA_MODEL_EVALUATOR_BASE_INSTANT(SCALAR) \
01699   \
01700   template class ModelEvaluatorBase::InArgs<SCALAR >; \
01701   \
01702   template std::string \
01703   ModelEvaluatorBase::Derivative<SCALAR >::description() const; \
01704   \
01705   template \
01706   void ModelEvaluatorBase::Derivative<SCALAR >::describe( \
01707     Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel \
01708     ) const; \
01709   \
01710   template class ModelEvaluatorBase::OutArgs<SCALAR >; \
01711   \
01712   template class ModelEvaluatorBase::InArgsSetup<SCALAR >; \
01713   \
01714   template class ModelEvaluatorBase::OutArgsSetup<SCALAR >;
01715 
01716 
01717 #endif // THYRA_MODEL_EVALUATOR_BASE_DEF_HPP

Generated on Wed May 12 21:26:47 2010 for Thyra ANA Nonlinear Model Evaluator Interfaces by  doxygen 1.4.7