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