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

Generated on Tue Jul 13 09:26:22 2010 for Thyra by  doxygen 1.4.7