Thyra_ModelEvaluatorBase.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_MODEL_EVALUATOR_BASE_HPP
00030 #define THYRA_MODEL_EVALUATOR_BASE_HPP
00031 
00032 #include "Thyra_LinearOpWithSolveBase.hpp"
00033 #include "Thyra_PolynomialVectorTraits.hpp"
00034 #include "Teuchos_Describable.hpp"
00035 #include "Teuchos_Polynomial.hpp"
00036 #include "Teuchos_Assert.hpp"
00037 
00038 
00039 namespace Thyra {
00040 
00041 
00059 class ModelEvaluatorBase
00060   : virtual public Teuchos::Describable
00061   , virtual public Teuchos::VerboseObject<ModelEvaluatorBase>
00062 {
00063 public:
00064 
00067 
00069   enum EInArgsMembers {
00070     IN_ARG_x_dot 
00071     ,IN_ARG_x 
00072     ,IN_ARG_x_dot_poly 
00073     ,IN_ARG_x_poly 
00074     ,IN_ARG_t 
00075     ,IN_ARG_alpha 
00076     ,IN_ARG_beta 
00077   };
00079   static const int NUM_E_IN_ARGS_MEMBERS=7;
00080 
00091   template<class Scalar>
00092   class InArgs : public Teuchos::Describable {
00093   public:
00095     typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00097     InArgs();
00100     int Np() const;
00102     bool supports(EInArgsMembers arg) const;
00104     void set_x_dot( const RCP<const VectorBase<Scalar> > &x_dot );
00106     RCP<const VectorBase<Scalar> > get_x_dot() const;
00108     void set_x( const RCP<const VectorBase<Scalar> > &x );
00110     RCP<const VectorBase<Scalar> > get_x() const;
00112     void set_x_poly( 
00113       const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly );
00115     RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > get_x_poly() const;
00117     void set_x_dot_poly(
00118       const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly );
00120     RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > get_x_dot_poly() const;
00122     void set_p( int l, const RCP<const VectorBase<Scalar> > &p_l );
00124     RCP<const VectorBase<Scalar> > get_p(int l) const;
00126     void set_t( ScalarMag t );
00128     ScalarMag get_t() const;
00130     void set_alpha( Scalar alpha );
00132     Scalar get_alpha() const;
00134     void set_beta( Scalar beta );
00136     Scalar get_beta() const;
00139     void setArgs(
00140       const InArgs<Scalar>& inArgs, bool ignoreUnsupported = false,
00141       bool cloneObjects = false
00142       );
00144     void assertSameSupport( const InArgs<Scalar> &inArgs ) const;
00146     std::string modelEvalDescription() const;
00148     std::string description() const;
00151     void describe(
00152       Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
00153       ) const;
00154   protected:
00156     void _setModelEvalDescription( const std::string &modelEvalDescription );
00158     void _set_Np(int Np);
00160     void _setSupports( EInArgsMembers arg, bool supports );
00162     void _setSupports( const InArgs<Scalar>& inputInArgs, const int Np );
00164     void _setUnsupportsAndRelated( EInArgsMembers arg );
00165   private:
00166     // types
00167     typedef Teuchos::Array<RCP<const VectorBase<Scalar> > > p_t;
00168     // data
00169     std::string modelEvalDescription_;
00170     RCP<const VectorBase<Scalar> > x_dot_;
00171     RCP<const VectorBase<Scalar> > x_;
00172     RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > x_dot_poly_;
00173     RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > x_poly_;
00174     p_t p_;
00175     ScalarMag t_;
00176     Scalar alpha_;
00177     Scalar beta_;
00178     bool supports_[NUM_E_IN_ARGS_MEMBERS];
00179     // functions
00180     void assert_supports(EInArgsMembers arg) const;
00181     void assert_l(int l) const;
00182   };
00183 
00185   enum EDerivativeMultiVectorOrientation {
00186     DERIV_MV_BY_COL           
00187     ,DERIV_TRANS_MV_BY_ROW    
00188   };
00189 
00191   enum EDerivativeLinearOp {
00192     DERIV_LINEAR_OP 
00193   };
00194 
00197   class DerivativeSupport {
00198   public:
00200     DerivativeSupport()
00201       :supportsLinearOp_(false), supportsMVByCol_(false), supportsTransMVByRow_(false)
00202       {}
00204     DerivativeSupport( EDerivativeLinearOp )
00205       :supportsLinearOp_(true), supportsMVByCol_(false), supportsTransMVByRow_(false)
00206       {}
00208     DerivativeSupport( EDerivativeMultiVectorOrientation mvOrientation )
00209       :supportsLinearOp_(false), supportsMVByCol_(mvOrientation==DERIV_MV_BY_COL)
00210       ,supportsTransMVByRow_(mvOrientation==DERIV_TRANS_MV_BY_ROW)
00211       {}
00213     DerivativeSupport& plus(EDerivativeLinearOp)
00214       { supportsLinearOp_ = true; return *this; }
00216     DerivativeSupport& plus(EDerivativeMultiVectorOrientation mvOrientation)
00217       {
00218         switch(mvOrientation) {
00219           case DERIV_MV_BY_COL: supportsMVByCol_ = true; break;
00220           case DERIV_TRANS_MV_BY_ROW: supportsTransMVByRow_ = true; break;
00221           default: TEST_FOR_EXCEPT(true);
00222         }
00223         return *this;
00224       }
00226     bool none() const
00227       { return ( !supportsLinearOp_ && !supportsMVByCol_ && !supportsTransMVByRow_ ); }
00229     bool supports(EDerivativeLinearOp) const
00230       { return supportsLinearOp_; }
00232     bool supports(EDerivativeMultiVectorOrientation mvOrientation) const
00233       {
00234         switch(mvOrientation) {
00235           case DERIV_MV_BY_COL: return supportsMVByCol_;
00236           case DERIV_TRANS_MV_BY_ROW: return supportsTransMVByRow_;
00237           default: TEST_FOR_EXCEPT(true);
00238         }
00239         return false; // Will never be called!
00240       }
00242     bool isSameSupport(const DerivativeSupport &derivSupport) const
00243       {
00244         return (
00245           supportsLinearOp_ == derivSupport.supportsLinearOp_
00246           && supportsMVByCol_ == derivSupport.supportsMVByCol_
00247           && supportsTransMVByRow_ == derivSupport.supportsTransMVByRow_
00248           );
00249       } 
00251     std::string description() const;
00252   private:
00253     bool supportsLinearOp_;
00254     bool supportsMVByCol_;
00255     bool supportsTransMVByRow_;
00256   public:
00257   };
00258   
00260   enum EDerivativeLinearity {
00261     DERIV_LINEARITY_UNKNOWN      
00262     ,DERIV_LINEARITY_CONST       
00263     ,DERIV_LINEARITY_NONCONST    
00264   };
00265 
00267   enum ERankStatus {
00268     DERIV_RANK_UNKNOWN       
00269     ,DERIV_RANK_FULL         
00270     ,DERIV_RANK_DEFICIENT    
00271   };
00272 
00275   struct DerivativeProperties {
00277     EDerivativeLinearity     linearity;
00279     ERankStatus              rank;
00281     bool                     supportsAdjoint;
00283     DerivativeProperties()
00284       :linearity(DERIV_LINEARITY_UNKNOWN),
00285        rank(DERIV_RANK_UNKNOWN),supportsAdjoint(false)
00286       {}
00288     DerivativeProperties(
00289       EDerivativeLinearity in_linearity, ERankStatus in_rank,
00290       bool in_supportsAdjoint
00291       )
00292       :linearity(in_linearity),rank(in_rank),
00293        supportsAdjoint(in_supportsAdjoint)
00294       {}
00295   };
00296 
00300   template<class Scalar>
00301   class DerivativeMultiVector {
00302   public:
00304     DerivativeMultiVector()
00305       :orientation_(DERIV_MV_BY_COL)
00306       {}
00308     DerivativeMultiVector(
00309       const RCP<MultiVectorBase<Scalar> > &mv
00310       ,const EDerivativeMultiVectorOrientation orientation = DERIV_MV_BY_COL
00311       ) : mv_(mv.assert_not_null()), orientation_(orientation) {}
00313     void changeOrientation( const EDerivativeMultiVectorOrientation orientation )
00314       { orientation_ = orientation; };
00316     const DerivativeMultiVector<Scalar>& assert_not_null() const
00317       { mv_.assert_not_null(); return *this; }
00319     RCP<MultiVectorBase<Scalar> > getMultiVector() const
00320       { return mv_; }
00322     EDerivativeMultiVectorOrientation getOrientation() const
00323       { return orientation_; }
00325     std::string description() const;
00327     void describe( 
00328       Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
00329       ) const;
00330   private:
00331     RCP<MultiVectorBase<Scalar> > mv_;
00332     EDerivativeMultiVectorOrientation orientation_;
00333   };
00334 
00338   template<class Scalar>
00339   class Derivative {
00340   public:
00342     Derivative() {}
00344     Derivative( const RCP<LinearOpBase<Scalar> > &lo )
00345       : lo_(lo.assert_not_null()) {}
00347     Derivative(
00348       const RCP<MultiVectorBase<Scalar> > &mv,
00349       const EDerivativeMultiVectorOrientation orientation = DERIV_MV_BY_COL
00350       ) : dmv_(mv,orientation) {}
00352     Derivative( const DerivativeMultiVector<Scalar> &dmv )
00353       : dmv_(dmv) {}
00355     bool isEmpty() const
00356       { return ( lo_.get()==NULL && dmv_.getMultiVector().get()==NULL ); }
00358     const Derivative<Scalar>& assert_not_null() const
00359       { dmv_.assert_not_null(); lo_.assert_not_null(); return *this; }
00361     RCP<LinearOpBase<Scalar> > getLinearOp() const
00362       { return lo_; }
00364     RCP<MultiVectorBase<Scalar> > getMultiVector() const
00365       { return dmv_.getMultiVector(); }
00367     EDerivativeMultiVectorOrientation getMultiVectorOrientation() const
00368       { return dmv_.getOrientation(); }
00370     DerivativeMultiVector<Scalar> getDerivativeMultiVector() const
00371       { return dmv_; }
00375     bool isSupportedBy( const DerivativeSupport &derivSupport ) const
00376       {
00377         // If there is not derivative support then we will return false!
00378         if (derivSupport.none())
00379           return false;
00380         if (!is_null(getMultiVector())) {
00381           return derivSupport.supports(getMultiVectorOrientation());
00382         }
00383         else if(!is_null(getLinearOp())) {
00384           return derivSupport.supports(DERIV_LINEAR_OP);
00385         }
00386         // If nothing is set then of course we support that!
00387         return true;
00388       }
00390     std::string description() const;
00392     void describe( 
00393       Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
00394       ) const;
00395   private:
00396     RCP<LinearOpBase<Scalar> > lo_;
00397     DerivativeMultiVector<Scalar> dmv_;
00398   };
00399 
00401   enum EOutArgsMembers {
00402     OUT_ARG_f       
00403     ,OUT_ARG_W      
00404     ,OUT_ARG_W_op   
00405     ,OUT_ARG_f_poly 
00406   };
00408   static const int NUM_E_OUT_ARGS_MEMBERS=4;
00409 
00411   enum EOutArgsDfDp {
00412     OUT_ARG_DfDp   
00413   };
00414 
00416   enum EOutArgsDgDx_dot {
00417     OUT_ARG_DgDx_dot   
00418   };
00419 
00421   enum EOutArgsDgDx {
00422     OUT_ARG_DgDx   
00423   };
00424 
00426   enum EOutArgsDgDp {
00427     OUT_ARG_DgDp   
00428   };
00429   
00450   template<class Scalar>
00451   class OutArgs : public Teuchos::Describable {
00452   public:
00454     OutArgs();
00457     int Np() const;
00460     int Ng() const;
00462     bool supports(EOutArgsMembers arg) const;
00465     const DerivativeSupport& supports(EOutArgsDfDp arg, int l) const;
00468     const DerivativeSupport& supports(EOutArgsDgDx_dot arg, int j) const;
00471     const DerivativeSupport& supports(EOutArgsDgDx arg, int j) const;
00474     const DerivativeSupport& supports(EOutArgsDgDp arg, int j, int l) const;
00476     void set_f( const RCP<VectorBase<Scalar> > &f );
00478     RCP<VectorBase<Scalar> > get_f() const;
00480     void set_g( int j, const RCP<VectorBase<Scalar> > &g_j );
00482     RCP<VectorBase<Scalar> > get_g(int j) const;
00484     void set_W( const RCP<LinearOpWithSolveBase<Scalar> > &W );
00486     RCP<LinearOpWithSolveBase<Scalar> > get_W() const;
00488     void set_W_op( const RCP<LinearOpBase<Scalar> > &W_op );
00490     RCP<LinearOpBase<Scalar> > get_W_op() const;
00493     DerivativeProperties get_W_properties() const;
00495     void set_DfDp(int l,  const Derivative<Scalar> &DfDp_l);
00497     Derivative<Scalar> get_DfDp(int l) const;
00500     DerivativeProperties get_DfDp_properties(int l) const;
00502     void set_DgDx_dot(int j, const Derivative<Scalar> &DgDx_dot_j);
00504     Derivative<Scalar> get_DgDx_dot(int j) const;
00507     DerivativeProperties get_DgDx_dot_properties(int j) const;
00509     void set_DgDx(int j, const Derivative<Scalar> &DgDx_j);
00511     Derivative<Scalar> get_DgDx(int j) const;
00514     DerivativeProperties get_DgDx_properties(int j) const;
00516     void set_DgDp( int j, int l, const Derivative<Scalar> &DgDp_j_l );
00518     Derivative<Scalar> get_DgDp(int j, int l) const;
00521     DerivativeProperties get_DgDp_properties(int j, int l) const;
00523     void set_f_poly( const RCP<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly );
00525     RCP<Teuchos::Polynomial< VectorBase<Scalar> > > get_f_poly() const;
00531     void setArgs( const OutArgs<Scalar>& outArgs, bool ignoreUnsupported = false );
00543     void setFailed() const;
00549     bool isFailed() const;
00551     bool isEmpty() const;
00553     void assertSameSupport( const OutArgs<Scalar> &outArgs ) const;
00555     std::string modelEvalDescription() const;
00557     std::string description() const;
00560     void describe(
00561       Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
00562       ) const;
00563   protected:
00565     void _setModelEvalDescription( const std::string &modelEvalDescription );
00567     void _set_Np_Ng(int Np, int Ng);
00569     void _setSupports( EOutArgsMembers arg, bool supports );
00571     void _setSupports( EOutArgsDfDp arg, int l, const DerivativeSupport& );
00573     void _setSupports( EOutArgsDgDx_dot arg, int j, const DerivativeSupport& );
00575     void _setSupports( EOutArgsDgDx arg, int j, const DerivativeSupport& );
00577     void _setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& );
00579     void _set_W_properties( const DerivativeProperties &properties );
00581     void _set_DfDp_properties( int l, const DerivativeProperties &properties );
00583     void _set_DgDx_dot_properties( int j, const DerivativeProperties &properties );
00585     void _set_DgDx_properties( int j, const DerivativeProperties &properties );
00587     void _set_DgDp_properties( int j, int l, const DerivativeProperties &properties );
00589     void _setSupports( const OutArgs<Scalar>& inputOutArgs );
00591     void _setUnsupportsAndRelated( EInArgsMembers arg );
00593     void _setUnsupportsAndRelated( EOutArgsMembers arg );
00594   private:
00595     // types
00596     typedef Teuchos::Array<RCP<VectorBase<Scalar> > > g_t;
00597     typedef Teuchos::Array<Derivative<Scalar> > deriv_t;
00598     typedef Teuchos::Array<DerivativeProperties> deriv_properties_t;
00599     typedef Teuchos::Array<DerivativeSupport> supports_t;
00600     // data
00601     std::string modelEvalDescription_;
00602     bool supports_[NUM_E_OUT_ARGS_MEMBERS];
00603     supports_t supports_DfDp_; // Np
00604     supports_t supports_DgDx_dot_; // Ng
00605     supports_t supports_DgDx_; // Ng
00606     supports_t supports_DgDp_; // Ng x Np
00607     RCP<VectorBase<Scalar> > f_;
00608     g_t g_; // Ng
00609     RCP<LinearOpWithSolveBase<Scalar> > W_;
00610     RCP<LinearOpBase<Scalar> > W_op_;
00611     DerivativeProperties W_properties_;
00612     deriv_t DfDp_; // Np
00613     deriv_properties_t DfDp_properties_; // Np
00614     deriv_t DgDx_dot_; // Ng
00615     deriv_t DgDx_; // Ng
00616     deriv_properties_t DgDx_dot_properties_; // Ng
00617     deriv_properties_t DgDx_properties_; // Ng
00618     deriv_t DgDp_; // Ng x Np
00619     deriv_properties_t DgDp_properties_; // Ng x Np
00620     RCP<Teuchos::Polynomial< VectorBase<Scalar> > > f_poly_;
00621     mutable bool isFailed_;
00622     // functions
00623     void assert_supports(EOutArgsMembers arg) const;
00624     void assert_supports(
00625       EOutArgsDfDp arg, int l,
00626       const Derivative<Scalar> &deriv = Derivative<Scalar>()
00627       ) const;
00628     void assert_supports(
00629       EOutArgsDgDx_dot arg, int j,
00630       const Derivative<Scalar> &deriv = Derivative<Scalar>()
00631       ) const;
00632     void assert_supports(
00633       EOutArgsDgDx arg, int j,
00634       const Derivative<Scalar> &deriv = Derivative<Scalar>()
00635       ) const;
00636     void assert_supports(
00637       EOutArgsDgDp arg, int j, int l,
00638       const Derivative<Scalar> &deriv = Derivative<Scalar>()
00639       ) const;
00640     void assert_l(int l) const;
00641     void assert_j(int j) const;
00642   };
00643 
00645 
00646 // Added since at least gcc 3.3.4 does not do the right thing here!
00647 #ifdef HAVE_PROTECTED_NESTED_TEMPLATE_CLASS_ACCESS
00648 protected:
00649 #endif
00650 
00653 
00661   template<class Scalar>
00662   class InArgsSetup : public InArgs<Scalar> {
00663   public:
00665     InArgsSetup();
00667     InArgsSetup( const InArgs<Scalar>& );
00669     void setModelEvalDescription( const std::string &modelEvalDescription );
00671     void set_Np(int Np);
00673     void setSupports( EInArgsMembers arg, bool supports = true );
00675     void setSupports( const InArgs<Scalar>& inputInArgs, const int Np = -1 );
00677     void setUnsupportsAndRelated( EInArgsMembers arg );
00678   };
00679 
00687   template<class Scalar>
00688   class OutArgsSetup : public OutArgs<Scalar> {
00689   public:
00691     OutArgsSetup();
00693     OutArgsSetup( const OutArgs<Scalar>& );
00695     void setModelEvalDescription( const std::string &modelEvalDescription );
00697     void set_Np_Ng(int Np, int Ng);
00699     void setSupports( EOutArgsMembers arg, bool supports = true );
00701     void setSupports(EOutArgsDfDp arg, int l, const DerivativeSupport& );
00703     void setSupports(EOutArgsDgDx_dot arg, int j, const DerivativeSupport& );
00705     void setSupports(EOutArgsDgDx arg, int j, const DerivativeSupport& );
00707     void setSupports(EOutArgsDgDp arg, int j, int l, const DerivativeSupport& );
00709     void set_W_properties( const DerivativeProperties &properties );
00711     void set_DfDp_properties( int l, const DerivativeProperties &properties );
00713     void set_DgDx_dot_properties( int j, const DerivativeProperties &properties );
00715     void set_DgDx_properties( int j, const DerivativeProperties &properties );
00717     void set_DgDp_properties( int j, int l, const DerivativeProperties &properties );
00719     void setSupports( const OutArgs<Scalar>& inputOutArgs );
00721     void setUnsupportsAndRelated( EInArgsMembers arg );
00723     void setUnsupportsAndRelated( EOutArgsMembers arg );
00724    };
00725 
00727 
00728 };
00729 
00730 
00735 
00736 
00738 std::string toString(ModelEvaluatorBase::EInArgsMembers);
00739 
00740 
00742 std::string toString(ModelEvaluatorBase::EOutArgsMembers);
00743 
00744 
00746 std::string toString(
00747   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00748   );
00749 
00750 
00752 ModelEvaluatorBase::EDerivativeMultiVectorOrientation
00753 getOtherDerivativeMultiVectorOrientation(
00754   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00755   );
00756 
00757 
00759 
00760 
00761 } // namespace Thyra
00762 
00763 
00764 // //////////////////////////////////
00765 // Inline Defintions
00766 
00767 
00768 //
00769 // Thyra_MEB_helper_functions_grp
00770 //
00771 
00772 
00773 inline
00774 std::string Thyra::toString(ModelEvaluatorBase::EInArgsMembers arg)
00775 {
00776   switch(arg) {
00777     case ModelEvaluatorBase::IN_ARG_x_dot:
00778       return "IN_ARG_x_dot";
00779     case ModelEvaluatorBase::IN_ARG_x:
00780       return "IN_ARG_x";
00781     case ModelEvaluatorBase::IN_ARG_x_dot_poly:
00782       return "IN_ARG_x_dot_poly";
00783     case ModelEvaluatorBase::IN_ARG_x_poly:
00784       return "IN_ARG_xt_poly";
00785     case ModelEvaluatorBase::IN_ARG_t:
00786       return "IN_ARG_t";
00787     case ModelEvaluatorBase::IN_ARG_alpha:
00788       return "IN_ARG_alpha";
00789     case ModelEvaluatorBase::IN_ARG_beta:
00790       return "IN_ARG_beta";
00791 #ifdef TEUCHOS_DEBUG
00792     default:
00793       TEST_FOR_EXCEPT(true);
00794 #endif
00795   }
00796   return ""; // Will never be executed!
00797 }
00798 
00799 
00800 inline
00801 std::string Thyra::toString(ModelEvaluatorBase::EOutArgsMembers arg)
00802 {
00803   switch(arg) {
00804     case ModelEvaluatorBase::OUT_ARG_f:
00805       return "OUT_ARG_f";
00806     case ModelEvaluatorBase::OUT_ARG_W:
00807       return "OUT_ARG_W";
00808     case ModelEvaluatorBase::OUT_ARG_W_op:
00809       return "OUT_ARG_W_op";
00810     case ModelEvaluatorBase::OUT_ARG_f_poly:
00811       return "OUT_ARG_f_poly";
00812 #ifdef TEUCHOS_DEBUG
00813     default:
00814       TEST_FOR_EXCEPT(true);
00815 #endif
00816   }
00817   return ""; // Will never be executed!
00818 }
00819 
00820 
00821 inline
00822 std::string Thyra::toString(
00823   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00824   )
00825 {
00826   switch(orientation) {
00827     case ModelEvaluatorBase::DERIV_MV_BY_COL:
00828       return "DERIV_MV_BY_COL";
00829     case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW:
00830       return "DERIV_TRANS_MV_BY_ROW";
00831 #ifdef TEUCHOS_DEBUG
00832     default:
00833       TEST_FOR_EXCEPT(true);
00834 #endif
00835   }
00836   return ""; // Should never execute this!
00837 }
00838 
00839 
00840 inline
00841 Thyra::ModelEvaluatorBase::EDerivativeMultiVectorOrientation
00842 Thyra::getOtherDerivativeMultiVectorOrientation(
00843   ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation
00844   )
00845 {
00846   switch(orientation) {
00847     case ModelEvaluatorBase::DERIV_MV_BY_COL:
00848       return ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW;
00849     case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW:
00850       return ModelEvaluatorBase::DERIV_MV_BY_COL;
00851 #ifdef TEUCHOS_DEBUG
00852     default:
00853       TEST_FOR_EXCEPT(true);
00854 #endif
00855   }
00856   return ModelEvaluatorBase::DERIV_MV_BY_COL; // Should never execute this!
00857 }
00858 
00859 
00860 // //////////////////////////////////
00861 // Definitions
00862 
00863 
00864 namespace Thyra {
00865 
00866 
00867 namespace ModelEvaluatorHelperPack {
00868 
00869 
00870 template<class Scalar>
00871 inline
00872 RCP<const Thyra::VectorBase<Scalar> >
00873 condCloneVec(
00874   const RCP<const Thyra::VectorBase<Scalar> > &vec,
00875   bool cloneObject
00876   )
00877 {
00878   if(cloneObject)
00879     return vec->clone_v();
00880   return vec;
00881 }
00882 
00883 
00884 } // namespace ModelEvaluatorHelperPack
00885 
00886 
00887 //
00888 // ModelEvaluatorBase::DerivativeSupport
00889 //
00890 
00891 
00892 inline
00893 std::string
00894 ModelEvaluatorBase::DerivativeSupport::description() const
00895 {
00896   std::ostringstream oss;
00897   oss << "DerivativeSupport{";
00898   if (none()) {
00899     oss << "none";
00900   }
00901   else {
00902     bool wroteOutput = false;
00903     if (supportsLinearOp_) {
00904       oss << "DERIV_LINEAR_OP";
00905       wroteOutput = true;
00906     }
00907     if (supportsMVByCol_) {
00908       oss << (wroteOutput?",":"") << toString(DERIV_MV_BY_COL);
00909       wroteOutput = true;
00910     }
00911     if (supportsTransMVByRow_) {
00912       oss << (wroteOutput?",":"") << toString(DERIV_TRANS_MV_BY_ROW);
00913       wroteOutput = true;
00914     }
00915   }
00916   oss << "}";
00917   return oss.str();
00918 }
00919 // 2007/09/08: rabartl: ToDo: Above: I really should move this function
00920 // definition into a *.cpp file since it is not templated and it is too long
00921 // to be inlined.  I am just making it inline so I can avoid this for now.
00922 
00923 
00924 //
00925 // ModelEvaluatorBase::InArgs
00926 //
00927 
00928 
00929 template<class Scalar>
00930 ModelEvaluatorBase::InArgs<Scalar>::InArgs()
00931   :modelEvalDescription_("WARNING!  THIS INARGS OBJECT IS UNINITALIZED!")
00932 {
00933   typedef Teuchos::ScalarTraits<Scalar> ST;
00934   typedef Teuchos::ScalarTraits<typename ST::magnitudeType> SMT;
00935   std::fill_n(&supports_[0],NUM_E_IN_ARGS_MEMBERS,false);
00936   t_     = SMT::zero();
00937   alpha_ = ST::zero();
00938   beta_  = ST::zero();
00939 }
00940 
00941 
00942 template<class Scalar>
00943 int ModelEvaluatorBase::InArgs<Scalar>::Np() const
00944 { return p_.size(); }
00945 
00946 template<class Scalar>
00947 bool ModelEvaluatorBase::InArgs<Scalar>::supports(EInArgsMembers arg) const
00948 {
00949   TEST_FOR_EXCEPTION(
00950     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00951     ,"model = \'"<<modelEvalDescription_
00952     <<"\': Error, arg="<<toString(arg)<<" is invalid!"
00953     );
00954   return supports_[arg];
00955 }
00956 
00957 
00958 template<class Scalar>
00959 void ModelEvaluatorBase::InArgs<Scalar>::set_x_dot(
00960   const RCP<const VectorBase<Scalar> > &x_dot
00961   )
00962 { assert_supports(IN_ARG_x_dot); x_dot_ = x_dot; }
00963 
00964 
00965 template<class Scalar>
00966 RCP<const VectorBase<Scalar> >
00967 ModelEvaluatorBase::InArgs<Scalar>::get_x_dot() const
00968 { assert_supports(IN_ARG_x_dot); return x_dot_; }
00969 
00970 
00971 template<class Scalar>
00972 void ModelEvaluatorBase::InArgs<Scalar>::set_x(
00973   const RCP<const VectorBase<Scalar> > &x
00974   )
00975 { assert_supports(IN_ARG_x); x_ = x; }
00976 
00977 
00978 template<class Scalar>
00979 RCP<const VectorBase<Scalar> >
00980 ModelEvaluatorBase::InArgs<Scalar>::get_x() const
00981 { assert_supports(IN_ARG_x); return x_; }
00982 
00983 
00984 template<class Scalar>
00985 void ModelEvaluatorBase::InArgs<Scalar>::set_x_dot_poly(
00986   const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly
00987   )
00988 { assert_supports(IN_ARG_x_dot_poly); x_dot_poly_ = x_dot_poly; }
00989 
00990 
00991 template<class Scalar>
00992 RCP<const Teuchos::Polynomial< VectorBase<Scalar> > >
00993 ModelEvaluatorBase::InArgs<Scalar>::get_x_dot_poly() const
00994 { assert_supports(IN_ARG_x_dot_poly); return x_dot_poly_; }
00995 
00996 
00997 template<class Scalar>
00998 void ModelEvaluatorBase::InArgs<Scalar>::set_x_poly(
00999   const RCP<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly
01000   )
01001 { assert_supports(IN_ARG_x_poly); x_poly_ = x_poly; }
01002 
01003 
01004 template<class Scalar>
01005 RCP<const Teuchos::Polynomial< VectorBase<Scalar> > >
01006 ModelEvaluatorBase::InArgs<Scalar>::get_x_poly() const
01007 { assert_supports(IN_ARG_x_poly); return x_poly_; }
01008 
01009 
01010 template<class Scalar>
01011 void ModelEvaluatorBase::InArgs<Scalar>::set_p(
01012   int l, const RCP<const VectorBase<Scalar> > &p_l
01013   )
01014 { assert_l(l); p_[l] = p_l; }
01015 
01016 
01017 template<class Scalar>
01018 RCP<const VectorBase<Scalar> >
01019 ModelEvaluatorBase::InArgs<Scalar>::get_p(int l) const
01020 { assert_l(l); return p_[l]; }
01021 
01022 
01023 template<class Scalar>
01024 void ModelEvaluatorBase::InArgs<Scalar>::set_t( ScalarMag t )
01025 { assert_supports(IN_ARG_t); t_ = t; }
01026 
01027 
01028 template<class Scalar>
01029 typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag
01030 ModelEvaluatorBase::InArgs<Scalar>::get_t() const
01031 { assert_supports(IN_ARG_t); return t_; }
01032 
01033 
01034 template<class Scalar>
01035 void ModelEvaluatorBase::InArgs<Scalar>::set_alpha( Scalar alpha )
01036 { assert_supports(IN_ARG_alpha); alpha_ = alpha; }
01037 
01038 
01039 template<class Scalar>
01040 Scalar ModelEvaluatorBase::InArgs<Scalar>::get_alpha() const
01041 { assert_supports(IN_ARG_alpha); return alpha_; }
01042 
01043 
01044 template<class Scalar>
01045 void ModelEvaluatorBase::InArgs<Scalar>::set_beta( Scalar beta )
01046 { assert_supports(IN_ARG_beta); beta_ = beta; }
01047 
01048 
01049 template<class Scalar>
01050 Scalar ModelEvaluatorBase::InArgs<Scalar>::get_beta() const
01051 { assert_supports(IN_ARG_beta); return beta_; }
01052 
01053 
01054 template<class Scalar>
01055 void ModelEvaluatorBase::InArgs<Scalar>::setArgs(
01056   const InArgs<Scalar>& inArgs, bool ignoreUnsupported, bool cloneObjects
01057   )
01058 {
01059   using ModelEvaluatorHelperPack::condCloneVec;
01060   if( inArgs.supports(IN_ARG_x_dot) && inArgs.get_x_dot().get() ) {
01061     if(supports(IN_ARG_x_dot) || !ignoreUnsupported)
01062       set_x_dot(condCloneVec(inArgs.get_x_dot(),cloneObjects));
01063   }
01064   if( inArgs.supports(IN_ARG_x) && inArgs.get_x().get() ) {
01065     if(supports(IN_ARG_x) || !ignoreUnsupported)
01066       set_x(condCloneVec(inArgs.get_x(),cloneObjects));
01067   }
01068   if( inArgs.supports(IN_ARG_x_dot_poly) && inArgs.get_x_dot_poly().get() ) {
01069     if(supports(IN_ARG_x_dot_poly) || !ignoreUnsupported) {
01070       TEST_FOR_EXCEPT(
01071         cloneObjects && "Have not implemented cloning for x_dot_poly yet!" );
01072       set_x_dot_poly(inArgs.get_x_dot_poly());
01073     }
01074   }
01075   if( inArgs.supports(IN_ARG_x_poly) && inArgs.get_x_poly().get() ) {
01076     if(supports(IN_ARG_x_poly) || !ignoreUnsupported) {
01077       TEST_FOR_EXCEPT(
01078         cloneObjects && "Have not implemented cloning for x_poly yet!" );
01079       set_x_poly(inArgs.get_x_poly());
01080     }
01081   }
01082   const int min_Np = TEUCHOS_MIN(this->Np(),inArgs.Np());
01083   for( int l = 0; l < min_Np; ++l ) {
01084     if(inArgs.get_p(l).get())
01085       set_p(l,condCloneVec(inArgs.get_p(l),cloneObjects));
01086   }
01087   if( inArgs.supports(IN_ARG_t) ) {
01088     if(supports(IN_ARG_t) || !ignoreUnsupported)
01089       set_t(inArgs.get_t());
01090   }
01091   if( inArgs.supports(IN_ARG_alpha) ) {
01092     if(supports(IN_ARG_alpha) || !ignoreUnsupported)
01093       set_alpha(inArgs.get_alpha());
01094   }
01095   if( inArgs.supports(IN_ARG_beta) ) {
01096     if(supports(IN_ARG_beta) || !ignoreUnsupported)
01097       set_beta(inArgs.get_beta());
01098   }
01099 }
01100 
01101 
01102 template<class Scalar>
01103 void ModelEvaluatorBase::InArgs<Scalar>::assertSameSupport(
01104   const InArgs<Scalar> &inArgs
01105   ) const
01106 {
01107   for ( int inArg_i = 0; inArg_i < NUM_E_IN_ARGS_MEMBERS; ++inArg_i ) {
01108     const EInArgsMembers inArg_arg = static_cast<EInArgsMembers>(inArg_i);
01109     const std::string inArg_name = toString(inArg_arg);
01110     TEST_FOR_EXCEPTION(
01111       supports(inArg_arg) != inArgs.supports(inArg_arg), std::logic_error,
01112       "Error, the input argument "<<inArg_name<<" with support "<<inArgs.supports(inArg_arg)<<"\n"
01113       "in the InArgs object for the model:\n\n"
01114       "  "<<inArgs.modelEvalDescription()<<"\n\n"
01115       "is not the same the argument "<<inArg_name<<" with support "<<supports(inArg_arg)<<"\n"
01116       "in the InArgs object for the model:\n\n"
01117       "  "<<modelEvalDescription()<<"\n\n"
01118       "and these two InArgs objects are not compatible!"
01119       );
01120   }
01121   TEUCHOS_ASSERT_EQUALITY( this->Np(), inArgs.Np() );
01122 }
01123 
01124 
01125 template<class Scalar>
01126 std::string ModelEvaluatorBase::InArgs<Scalar>::modelEvalDescription() const
01127 {
01128   return modelEvalDescription_;
01129 }
01130 
01131 
01132 template<class Scalar>
01133 std::string ModelEvaluatorBase::InArgs<Scalar>::description() const
01134 {
01135   typedef Teuchos::ScalarTraits<Scalar> ST;
01136   std::ostringstream oss;
01137   oss
01138     << "Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">"
01139     << "{"
01140     << "model="<<modelEvalDescription_
01141     << ",Np="<<Np()
01142     << "}";
01143   return oss.str();
01144 }
01145 
01146 
01147 template<class Scalar>
01148 void ModelEvaluatorBase::InArgs<Scalar>::describe(
01149   Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
01150   ) const
01151 {
01152   using std::endl;
01153   typedef Teuchos::ScalarTraits<Scalar> ST;
01154   using Teuchos::OSTab;
01155   using Teuchos::describe;
01156   using Teuchos::includesVerbLevel;
01157   typedef RCP<const VectorBase<Scalar> > CV_ptr;
01158 
01159   if(verbLevel == Teuchos::VERB_NONE)
01160     return;
01161 
01162   RCP<Teuchos::FancyOStream>
01163     out = Teuchos::rcp(&out_arg,false);
01164   const bool dump_x = includesVerbLevel(verbLevel,Teuchos::VERB_HIGH);
01165   const Teuchos::EVerbosityLevel x_verbLevel =
01166     dump_x?Teuchos::VERB_EXTREME:verbLevel;
01167   const bool print_x_nrm = includesVerbLevel(verbLevel,Teuchos::VERB_LOW);
01168   const bool dump_p = includesVerbLevel(verbLevel,Teuchos::VERB_MEDIUM);
01169   const Teuchos::EVerbosityLevel p_verbLevel =
01170     dump_p?Teuchos::VERB_EXTREME:verbLevel;
01171   const bool print_p_nrm = includesVerbLevel(verbLevel,Teuchos::VERB_LOW);
01172   OSTab tab(out);
01173 
01174   *out <<"Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">:\n";
01175   tab.incrTab();
01176 
01177   *out <<"model = " << modelEvalDescription_ << "\n";
01178   *out <<"Np = " << Np() << "\n";
01179 
01180   CV_ptr x_dot;
01181   if ( this->supports(IN_ARG_x_dot) && !is_null(x_dot=get_x_dot()) ) {
01182     *out << "x_dot = " << Teuchos::describe(*x_dot,x_verbLevel);
01183     if (print_x_nrm)
01184       *out << "||x_dot|| = " << norm(*x_dot) << endl;
01185   }
01186 
01187   CV_ptr x;
01188   if ( this->supports(IN_ARG_x) && !is_null(x=get_x()) ) {
01189     *out << "x = " << Teuchos::describe(*x,x_verbLevel);
01190     if (print_x_nrm)
01191       *out << "||x|| = " << norm(*x) << endl;
01192   }
01193   
01194   if (print_x_nrm) {
01195     for( int l = 0; l < Np(); ++l ) {
01196       CV_ptr p_l;
01197       if ( !is_null(p_l = this->get_p(l)) ) {
01198         *out << "p("<<l<<") = " << Teuchos::describe(*p_l,p_verbLevel);
01199         if (print_p_nrm)
01200           *out << "||p("<<l<<")|| = " << norm(*p_l) << endl;
01201       }
01202     }
01203   }
01204   
01205   if (includesVerbLevel(verbLevel,Teuchos::VERB_MEDIUM)) {
01206     if (this->supports(IN_ARG_t)) {
01207       *out << "t = " << t_ << endl;
01208     }
01209     if (this->supports(IN_ARG_alpha)) {
01210       *out << "alpha = " << alpha_ << endl;
01211     }
01212     if (this->supports(IN_ARG_beta)) {
01213       *out << "beta = " << beta_ << endl;
01214     }
01215   }
01216   
01217 }
01218 
01219 
01220 template<class Scalar>
01221 void ModelEvaluatorBase::InArgs<Scalar>::_setModelEvalDescription(
01222   const std::string &modelEvalDescription
01223   )
01224 {
01225   modelEvalDescription_ = modelEvalDescription;
01226 }
01227 
01228 
01229 template<class Scalar>
01230 void ModelEvaluatorBase::InArgs<Scalar>::_set_Np(int Np)
01231 {
01232   p_.resize(Np);
01233 }
01234 
01235 
01236 template<class Scalar>
01237 void ModelEvaluatorBase::InArgs<Scalar>::_setSupports(
01238   EInArgsMembers arg, bool supports
01239   )
01240 {
01241   TEST_FOR_EXCEPTION(
01242     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
01243     ,"model = \'"<<modelEvalDescription_
01244     <<"\': Error, arg="<<toString(arg)<<" is invalid!");
01245   supports_[arg] = supports;
01246 }
01247 
01248 
01249 template<class Scalar>
01250 void ModelEvaluatorBase::InArgs<Scalar>::_setSupports(
01251   const InArgs<Scalar>& inArgs, const int Np
01252   )
01253 {
01254   std::copy(
01255     &inArgs.supports_[0],
01256     &inArgs.supports_[0] + NUM_E_IN_ARGS_MEMBERS, &supports_[0] );
01257   this->_set_Np( Np >= 0 ? Np : inArgs.Np() );
01258 }
01259 
01260 
01261 template<class Scalar>
01262 void ModelEvaluatorBase::InArgs<Scalar>::_setUnsupportsAndRelated(
01263   EInArgsMembers arg
01264   )
01265 {
01266   switch(arg) {
01267     case IN_ARG_x: {
01268       this->_setSupports(IN_ARG_x_dot,false);
01269       this->_setSupports(IN_ARG_x_dot_poly,false);
01270       this->_setSupports(IN_ARG_alpha,false);
01271       this->_setSupports(IN_ARG_beta,false);
01272       break;
01273     }
01274 #ifdef TEUCHOS_DEBUG
01275     default:
01276       TEST_FOR_EXCEPTION(
01277         true ,std::logic_error
01278         ,"Error, can handle args other than IN_ARG_x yet!"
01279         );
01280 #endif
01281   }
01282   this->_setSupports(arg,false);
01283 }
01284 
01285 
01286 template<class Scalar>
01287 void ModelEvaluatorBase::InArgs<Scalar>::assert_supports(
01288   EInArgsMembers arg
01289   ) const
01290 {
01291   TEST_FOR_EXCEPTION(
01292     !supports_[arg], std::logic_error
01293     ,"Thyra::ModelEvaluatorBase::InArgs<"
01294     << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(arg): "
01295     "model = \'"<<modelEvalDescription_<<"\': Error, "
01296     "The argument arg = " << toString(arg) << " is not supported!"
01297     );
01298 }
01299 
01300 
01301 template<class Scalar>
01302 void ModelEvaluatorBase::InArgs<Scalar>::assert_l(int l) const
01303 {
01304   TEST_FOR_EXCEPTION(
01305     !( 0 <= l && l < Np() ), std::logic_error
01306     ,"Thyra::ModelEvaluatorBase::InArgs<Scalar>::assert_l(l):\n\n"
01307     " model = \'"<<modelEvalDescription_<<"\':\n\n"
01308     "Error, The parameter l = " << l << " is not in the range [0,"<<Np()<<")!"
01309     );
01310 }
01311 
01312 
01313 //
01314 // ModelEvaluatorBase::DerivativeMultiVector
01315 //
01316 
01317 
01318 template<class Scalar>
01319 std::string ModelEvaluatorBase::DerivativeMultiVector<Scalar>::description() const
01320 {
01321   using std::endl;
01322   std::ostringstream oss;
01323   oss << "DerivativeMultiVector{";
01324   if (is_null(getMultiVector())) {
01325     oss << "NULL";
01326   }
01327   else {
01328     oss
01329       << "multiVec=" << getMultiVector()->description()
01330       << ",orientation=" << toString(getOrientation());
01331   }
01332   oss << "}";
01333   return oss.str();
01334 }
01335 
01336 
01337 template<class Scalar>
01338 void ModelEvaluatorBase::DerivativeMultiVector<Scalar>::describe(
01339   Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
01340   ) const
01341 {
01342   using std::endl;
01343   using Teuchos::describe;
01344   Teuchos::OSTab tab1(out);
01345   out << "DerivativeMultiVector\n";
01346   Teuchos::OSTab tab2(out);
01347   out
01348     << "multiVec = "
01349     << describe(*getMultiVector(),verbLevel)
01350     << "orientation = "
01351     << toString(getOrientation()) << endl;
01352 }
01353 
01354 
01355 // 2007/06/12: rabartl: The above description() and describe(...) functions
01356 // have to be defined here and not in the class DerivativeMultiVector since it
01357 // relies on the non-member function
01358 // toString(ModelEvaluatorBase::EDerivativeMultiVectorOrientation) which is
01359 // defined after the class definition for ModelEvaluatorBase.  This was caught
01360 // by the intel compiler.  I am not sure why this worked with gcc.
01361 
01362 
01363 //
01364 // ModelEvaluatorBase::Derivative
01365 //
01366 
01367 
01368 template<class Scalar>
01369 std::string
01370 ModelEvaluatorBase::Derivative<Scalar>::description() const
01371 {
01372   using std::endl;
01373   std::ostringstream oss;
01374   oss << "Derivative{";
01375   if (isEmpty()) {
01376     oss << "NULL";
01377   }
01378   else if (!is_null(getLinearOp())) {
01379     oss << "linearOp=" << getLinearOp()->description();
01380   }
01381   else {
01382     oss << "derivMultiVec=" << getDerivativeMultiVector().description();
01383   }
01384   oss << "}";
01385   return oss.str();
01386 }
01387 
01388 
01389 template<class Scalar>
01390 void ModelEvaluatorBase::Derivative<Scalar>::describe( 
01391   Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel
01392   ) const
01393 {
01394   using std::endl;
01395   using Teuchos::describe;
01396   Teuchos::OSTab tab1(out);
01397   out << "Derivative:";
01398   if (isEmpty()) {
01399     out << " NULL\n";
01400   }
01401   else if (!is_null(getLinearOp())) {
01402     out
01403       << endl
01404       << "linearOp = " << describe(*getLinearOp(),verbLevel);
01405   }
01406   else {
01407     out
01408       << endl
01409       << "derivMultiVec = ";
01410     getDerivativeMultiVector().describe(out,verbLevel);
01411   }
01412 }
01413 
01414 
01415 //
01416 // ModelEvaluatorBase::OutArgs
01417 //
01418 
01419 
01420 template<class Scalar>
01421 ModelEvaluatorBase::OutArgs<Scalar>::OutArgs()
01422   :modelEvalDescription_("WARNING!  THIS OUTARGS OBJECT IS UNINITALIZED!"),
01423    isFailed_(false)
01424 { std::fill_n(&supports_[0],NUM_E_OUT_ARGS_MEMBERS,false); }
01425 
01426 
01427 template<class Scalar>
01428 int ModelEvaluatorBase::OutArgs<Scalar>::Np() const
01429 { return DfDp_.size(); }
01430 
01431 
01432 template<class Scalar>
01433 int ModelEvaluatorBase::OutArgs<Scalar>::Ng() const
01434 { return g_.size(); }
01435 
01436 
01437 template<class Scalar>
01438 bool ModelEvaluatorBase::OutArgs<Scalar>::supports(
01439   EOutArgsMembers arg
01440   ) const
01441 {
01442   TEST_FOR_EXCEPTION(
01443     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
01444     ,"model = \'"<<modelEvalDescription_
01445     <<"\': Error, arg="<<toString(arg)<<" is invalid!"
01446     );
01447   return supports_[arg];
01448 }
01449 
01450 
01451 template<class Scalar>
01452 const ModelEvaluatorBase::DerivativeSupport&
01453 ModelEvaluatorBase::OutArgs<Scalar>::supports(
01454   EOutArgsDfDp arg, int l
01455   ) const
01456 {
01457   assert_l(l);
01458   return supports_DfDp_[l];
01459 }
01460 
01461 
01462 template<class Scalar>
01463 const ModelEvaluatorBase::DerivativeSupport&
01464 ModelEvaluatorBase::OutArgs<Scalar>::supports(
01465   EOutArgsDgDx_dot arg, int j
01466   ) const
01467 {
01468   assert_j(j);
01469   return supports_DgDx_dot_[j];
01470 }
01471 
01472 
01473 template<class Scalar>
01474 const ModelEvaluatorBase::DerivativeSupport&
01475 ModelEvaluatorBase::OutArgs<Scalar>::supports(
01476   EOutArgsDgDx arg, int j
01477   ) const
01478 {
01479   assert_j(j);
01480   return supports_DgDx_[j];
01481 }
01482 
01483 
01484 template<class Scalar>
01485 const ModelEvaluatorBase::DerivativeSupport&
01486 ModelEvaluatorBase::OutArgs<Scalar>::supports(
01487   EOutArgsDgDp arg, int j, int l
01488   ) const
01489 {
01490   assert_j(j);
01491   assert_l(l);
01492   return supports_DgDp_[ j*Np() + l ];
01493 }
01494 
01495 
01496 template<class Scalar>
01497 void ModelEvaluatorBase::OutArgs<Scalar>::set_f( 
01498   const RCP<VectorBase<Scalar> > &f
01499   )
01500 {
01501   assert_supports(OUT_ARG_f);
01502   f_ = f;
01503 }
01504 
01505 
01506 template<class Scalar>
01507 RCP<VectorBase<Scalar> >
01508 ModelEvaluatorBase::OutArgs<Scalar>::get_f() const
01509 {
01510   assert_supports(OUT_ARG_f);
01511   return f_;
01512 }
01513 
01514 
01515 template<class Scalar>
01516 void ModelEvaluatorBase::OutArgs<Scalar>::set_g(
01517   int j, const RCP<VectorBase<Scalar> > &g_j
01518   )
01519 {
01520   assert_j(j);
01521   g_[j] = g_j;
01522 }
01523 
01524 
01525 template<class Scalar>
01526 RCP<VectorBase<Scalar> >
01527 ModelEvaluatorBase::OutArgs<Scalar>::get_g(int j) const
01528 { 
01529   assert_j(j);
01530   return g_[j];
01531 }
01532 
01533 
01534 template<class Scalar>
01535 void ModelEvaluatorBase::OutArgs<Scalar>::set_W(
01536   const RCP<LinearOpWithSolveBase<Scalar> > &W
01537   )
01538 {
01539   assert_supports(OUT_ARG_W);
01540   W_ = W;
01541 }
01542 
01543 
01544 template<class Scalar>
01545 RCP<LinearOpWithSolveBase<Scalar> >
01546 ModelEvaluatorBase::OutArgs<Scalar>::get_W() const
01547 {
01548   assert_supports(OUT_ARG_W);
01549   return W_;
01550 }
01551 
01552 
01553 template<class Scalar>
01554 void ModelEvaluatorBase::OutArgs<Scalar>::set_W_op(
01555   const RCP<LinearOpBase<Scalar> > &W_op
01556   )
01557 {
01558   assert_supports(OUT_ARG_W_op);
01559   W_op_ = W_op;
01560 }
01561 
01562 
01563 template<class Scalar>
01564 RCP<LinearOpBase<Scalar> >
01565 ModelEvaluatorBase::OutArgs<Scalar>::get_W_op() const
01566 {
01567   assert_supports(OUT_ARG_W_op);
01568   return W_op_;
01569 }
01570 
01571 
01572 template<class Scalar>
01573 ModelEvaluatorBase::DerivativeProperties
01574 ModelEvaluatorBase::OutArgs<Scalar>::get_W_properties() const
01575 {
01576   return W_properties_;
01577 }
01578 
01579 
01580 template<class Scalar>
01581 void ModelEvaluatorBase::OutArgs<Scalar>::set_DfDp(
01582   int l, const Derivative<Scalar> &DfDp_l
01583   )
01584 {
01585   assert_supports(OUT_ARG_DfDp,l,DfDp_l);
01586   DfDp_[l] = DfDp_l;
01587 }
01588 
01589 
01590 template<class Scalar>
01591 ModelEvaluatorBase::Derivative<Scalar>
01592 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp(int l) const
01593 {
01594   assert_supports(OUT_ARG_DfDp,l);
01595   return DfDp_[l];
01596 }
01597 
01598 
01599 template<class Scalar>
01600 ModelEvaluatorBase::DerivativeProperties
01601 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp_properties(int l) const
01602 {
01603   assert_supports(OUT_ARG_DfDp,l);
01604   return DfDp_properties_[l];
01605 }
01606 
01607 
01608 template<class Scalar>
01609 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDx_dot(
01610   int j, const Derivative<Scalar> &DgDx_dot_j
01611   )
01612 {
01613   assert_supports(OUT_ARG_DgDx_dot,j,DgDx_dot_j);
01614   DgDx_dot_[j] = DgDx_dot_j;
01615 }
01616 
01617 
01618 template<class Scalar>
01619 ModelEvaluatorBase::Derivative<Scalar>
01620 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_dot(int j) const
01621 {
01622   assert_supports(OUT_ARG_DgDx_dot,j);
01623   return DgDx_dot_[j];
01624 }
01625 
01626 
01627 template<class Scalar>
01628 ModelEvaluatorBase::DerivativeProperties
01629 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_dot_properties(int j) const
01630 {
01631   assert_supports(OUT_ARG_DgDx_dot,j);
01632   return DgDx_dot_properties_[j];
01633 }
01634 
01635 
01636 template<class Scalar>
01637 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDx(
01638   int j, const Derivative<Scalar> &DgDx_j
01639   )
01640 {
01641   assert_supports(OUT_ARG_DgDx,j,DgDx_j);
01642   DgDx_[j] = DgDx_j;
01643 }
01644 
01645 
01646 template<class Scalar>
01647 ModelEvaluatorBase::Derivative<Scalar>
01648 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx(int j) const
01649 {
01650   assert_supports(OUT_ARG_DgDx,j);
01651   return DgDx_[j];
01652 }
01653 
01654 
01655 template<class Scalar>
01656 ModelEvaluatorBase::DerivativeProperties
01657 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_properties(int j) const
01658 {
01659   assert_supports(OUT_ARG_DgDx,j);
01660   return DgDx_properties_[j];
01661 }
01662 
01663 
01664 template<class Scalar>
01665 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDp(
01666   int j, int l, const Derivative<Scalar> &DgDp_j_l
01667   )
01668 {
01669   assert_supports(OUT_ARG_DgDp,j,l,DgDp_j_l);
01670   DgDp_[ j*Np() + l ] = DgDp_j_l;
01671 }
01672 
01673 
01674 template<class Scalar>
01675 ModelEvaluatorBase::Derivative<Scalar>
01676 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp(int j, int l) const
01677 {
01678   assert_supports(OUT_ARG_DgDp,j,l);
01679   return DgDp_[ j*Np() + l ];
01680 }
01681 
01682 
01683 template<class Scalar>
01684 ModelEvaluatorBase::DerivativeProperties
01685 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp_properties(int j, int l) const
01686 {
01687   assert_supports(OUT_ARG_DgDp,j,l);
01688   return DgDp_properties_[ j*Np() + l ];
01689 }
01690 
01691 
01692 template<class Scalar>
01693 void ModelEvaluatorBase::OutArgs<Scalar>::set_f_poly(
01694   const RCP<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly
01695   )
01696 {
01697   f_poly_ = f_poly;
01698 }
01699 
01700 
01701 template<class Scalar>
01702 RCP<Teuchos::Polynomial< VectorBase<Scalar> > >
01703 ModelEvaluatorBase::OutArgs<Scalar>::get_f_poly() const
01704 {
01705   return f_poly_;
01706 }
01707 
01708 
01709 template<class Scalar>
01710 void ModelEvaluatorBase::OutArgs<Scalar>::setArgs(
01711   const OutArgs<Scalar>& inputOutArgs, bool ignoreUnsupported
01712   )
01713 {
01714   typedef ModelEvaluatorBase MEB;
01715   const int min_Np = TEUCHOS_MIN(this->Np(),inputOutArgs.Np());
01716   const int min_Ng = TEUCHOS_MIN(this->Ng(),inputOutArgs.Ng());
01717   // f
01718   if ( inputOutArgs.supports(OUT_ARG_f) && inputOutArgs.get_f().get() ) {
01719     if ( supports(OUT_ARG_f) || !ignoreUnsupported )
01720       set_f(inputOutArgs.get_f());
01721   }
01722   // f_poly
01723   if ( inputOutArgs.supports(OUT_ARG_f_poly) && inputOutArgs.get_f_poly().get() ) {
01724     if ( supports(OUT_ARG_f_poly) || !ignoreUnsupported )
01725       set_f_poly(inputOutArgs.get_f_poly());
01726   }
01727   // g(j)
01728   for ( int j = 0; j < min_Ng; ++j ) {
01729     if ( inputOutArgs.get_g(j).get() )
01730       set_g(j,inputOutArgs.get_g(j));
01731   }
01732   // W
01733   if( inputOutArgs.supports(OUT_ARG_W) && inputOutArgs.get_W().get() ) {
01734     if ( supports(OUT_ARG_W) || !ignoreUnsupported )
01735       set_W(inputOutArgs.get_W());
01736   }
01737   // W_op
01738   if( inputOutArgs.supports(OUT_ARG_W_op) && inputOutArgs.get_W_op().get() ) {
01739     if ( supports(OUT_ARG_W_op) || !ignoreUnsupported )
01740       set_W_op(inputOutArgs.get_W_op());
01741   }
01742   // DfDp(l)
01743   for ( int l = 0; l < min_Np; ++l ) {
01744     MEB::Derivative<Scalar> DfDp_l;
01745     if ( !inputOutArgs.supports(OUT_ARG_DfDp,l).none()
01746       && !(DfDp_l=inputOutArgs.get_DfDp(l)).isEmpty() )
01747     {
01748       if ( DfDp_l.isSupportedBy(supports(OUT_ARG_DfDp,l)) || !ignoreUnsupported )
01749         set_DfDp(l,DfDp_l);
01750     }
01751   }
01752   // DgDx_dot(j) and DgDx(j)
01753   for ( int j = 0; j < min_Ng; ++j ) {
01754     // DgDx_dot(j)
01755     MEB::Derivative<Scalar> DgDx_dot_j;
01756     if ( !inputOutArgs.supports(OUT_ARG_DgDx_dot,j).none()
01757       && !(DgDx_dot_j=inputOutArgs.get_DgDx_dot(j)).isEmpty() )
01758     {
01759       if( DgDx_dot_j.isSupportedBy(supports(OUT_ARG_DgDx_dot,j)) || !ignoreUnsupported )
01760         set_DgDx_dot(j,DgDx_dot_j);
01761     }
01762     // DgDx(j)
01763     MEB::Derivative<Scalar> DgDx_j;
01764     if ( !inputOutArgs.supports(OUT_ARG_DgDx,j).none()
01765       && !(DgDx_j=inputOutArgs.get_DgDx(j)).isEmpty() ) {
01766       if ( DgDx_j.isSupportedBy(supports(OUT_ARG_DgDx,j)) || !ignoreUnsupported )
01767         set_DgDx(j,DgDx_j);
01768     }
01769   }
01770   // DgDp(j,l)
01771   for ( int l = 0; l < min_Np; ++l ) {
01772     for ( int j = 0; j < min_Ng; ++j ) {
01773       MEB::Derivative<Scalar> DgDp_j_l;
01774       if ( !inputOutArgs.supports(OUT_ARG_DgDp,j,l).none() 
01775         && !(DgDp_j_l=inputOutArgs.get_DgDp(j,l)).isEmpty() )
01776       {
01777         if ( DgDp_j_l.isSupportedBy(supports(OUT_ARG_DgDp,j,l)) || !ignoreUnsupported )
01778           set_DgDp(j,l,DgDp_j_l);
01779       }
01780     }
01781   }
01782   // ToDo: Add more args as needed!
01783 }
01784 
01785 
01786 template<class Scalar>
01787 void ModelEvaluatorBase::OutArgs<Scalar>::setFailed() const
01788 {
01789   typedef Teuchos::ScalarTraits<Scalar> ST;
01790   isFailed_ = true;
01791   if( this->supports(OUT_ARG_f) && this->get_f().get() ) {
01792     assign(&*this->get_f(),ST::nan());
01793   }
01794   for( int j = 0; j < this->Ng(); ++j ) {
01795     if(this->get_g(j).get())
01796       assign(&*this->get_g(j),ST::nan());
01797   }
01798   // ToDo: Set other objects to NaN as well!
01799 }
01800 
01801 
01802 template<class Scalar>
01803 bool ModelEvaluatorBase::OutArgs<Scalar>::isFailed() const
01804 {
01805   return isFailed_;
01806 }
01807 
01808 
01809 template<class Scalar>
01810 bool ModelEvaluatorBase::OutArgs<Scalar>::isEmpty() const
01811 {
01812   if (!is_null(f_))
01813     return false;
01814   if (!is_null(W_))
01815     return false;
01816   if (!is_null(W_op_))
01817     return false;
01818   for ( int l = 0; l < Np(); ++l ) {
01819     if (!DfDp_[l].isEmpty())
01820       return false;
01821   }
01822   if (!is_null(f_poly_))
01823     return false;
01824   for ( int j = 0; j < Ng(); ++j ) {
01825     if (!is_null(g_[j]))
01826       return false;
01827     if (!DgDx_dot_[j].isEmpty())
01828       return false;
01829     if (!DgDx_[j].isEmpty())
01830       return false;
01831     for ( int l = 0; l < Np(); ++l ) {
01832       if (!DgDp_[j*Np()+l].isEmpty())
01833         return false;
01834     }
01835   }
01836   return true;
01837 }
01838 
01839 
01840 template<class Scalar>
01841 void ModelEvaluatorBase::OutArgs<Scalar>::assertSameSupport(
01842   const OutArgs<Scalar> &outArgs
01843   ) const
01844 {
01845 
01846   for ( int outArg_i = 0; outArg_i < NUM_E_OUT_ARGS_MEMBERS; ++outArg_i ) {
01847     const EOutArgsMembers outArg_arg = static_cast<EOutArgsMembers>(outArg_i);
01848     const std::string outArg_name = toString(outArg_arg);
01849     TEST_FOR_EXCEPTION(
01850       supports(outArg_arg) != outArgs.supports(outArg_arg), std::logic_error,
01851       "Error, the output argument "<<outArg_name<<" with support "<<outArgs.supports(outArg_arg)<<"\n"
01852       "in the OutArgs object for the model:\n\n"
01853       "  "<<outArgs.modelEvalDescription()<<"\n\n"
01854       "is not the same the argument "<<outArg_name<<" with support "<<supports(outArg_arg)<<"\n"
01855       "in the OutArgs object for the model:\n\n"
01856       "  "<<modelEvalDescription()<<"\n\n"
01857       "and these two OutArgs objects are not compatible!"
01858       );
01859   }
01860 
01861   const int Np = this->Np();
01862   const int Ng = this->Ng();
01863   TEUCHOS_ASSERT_EQUALITY( Np, outArgs.Np() );
01864   TEUCHOS_ASSERT_EQUALITY( Ng, outArgs.Ng() );
01865 
01866   if (supports(OUT_ARG_f)) {
01867     for ( int l = 0; l < Np; ++l ) {
01868       TEST_FOR_EXCEPTION(
01869         !supports(OUT_ARG_DfDp,l).isSameSupport(outArgs.supports(OUT_ARG_DfDp,l)),
01870         std::logic_error,
01871         "Error, the support for DfDp("<<l<<") is not the same for the models\n\n"
01872         "  "<<outArgs.modelEvalDescription()<<"\n\n"
01873         "and:\n\n"
01874         "  "<<modelEvalDescription()<<"\n\n"
01875         "and these two OutArgs objects are not compatible!"
01876         );
01877     }
01878   }
01879 
01880   for ( int j = 0; j < Ng; ++j ) {
01881     TEST_FOR_EXCEPTION(
01882       !supports(OUT_ARG_DgDx_dot,j).isSameSupport(outArgs.supports(OUT_ARG_DgDx_dot,j)),
01883       std::logic_error,
01884       "Error, the support for DgDx_dot("<<j<<") is not the same for the models\n\n"
01885       "  "<<outArgs.modelEvalDescription()<<"\n\n"
01886       "and:\n\n"
01887       "  "<<modelEvalDescription()<<"\n\n"
01888       "and these two OutArgs objects are not compatible!"
01889       );
01890     TEST_FOR_EXCEPTION(
01891       !supports(OUT_ARG_DgDx,j).isSameSupport(outArgs.supports(OUT_ARG_DgDx,j)),
01892       std::logic_error,
01893       "Error, the support for DgDx("<<j<<") is not the same for the models\n\n"
01894       "  "<<outArgs.modelEvalDescription()<<"\n\n"
01895       "and:\n\n"
01896       "  "<<modelEvalDescription()<<"\n\n"
01897       "and these two OutArgs objects are not compatible!"
01898       );
01899     for ( int l = 0; l < Np; ++l ) {
01900       TEST_FOR_EXCEPTION(
01901         !supports(OUT_ARG_DgDp,j,l).isSameSupport(outArgs.supports(OUT_ARG_DgDp,j,l)),
01902         std::logic_error,
01903         "Error, the support for DgDp("<<j<<","<<l<<") is not the same for the models\n\n"
01904         "  "<<outArgs.modelEvalDescription()<<"\n\n"
01905         "and:\n\n"
01906         "  "<<modelEvalDescription()<<"\n\n"
01907         "and these two OutArgs objects are not compatible!"
01908         );
01909     }
01910   }
01911 }
01912 
01913 
01914 template<class Scalar>
01915 std::string ModelEvaluatorBase::OutArgs<Scalar>::modelEvalDescription() const
01916 {
01917   return modelEvalDescription_;
01918 }
01919 
01920 
01921 template<class Scalar>
01922 std::string ModelEvaluatorBase::OutArgs<Scalar>::description() const
01923 {
01924   typedef Teuchos::ScalarTraits<Scalar> ST;
01925   std::ostringstream oss;
01926   oss
01927     << "Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">"
01928     << "{"
01929     << "model="<<modelEvalDescription_
01930     << ",Np="<<Np()
01931     << ",Ng="<<Ng()
01932     << "}";
01933   return oss.str();
01934 }
01935 
01936 
01937 template<class Scalar>
01938 void ModelEvaluatorBase::OutArgs<Scalar>::describe(
01939   Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
01940   ) const
01941 {
01942 
01943   using Teuchos::OSTab;
01944   using Teuchos::describe;
01945   typedef Teuchos::ScalarTraits<Scalar> ST;
01946   typedef RCP<const VectorBase<Scalar> > CV_ptr;
01947   typedef RCP<const LinearOpWithSolveBase<Scalar> > CLOWS_ptr;
01948   typedef ModelEvaluatorBase MEB;
01949   typedef MEB::Derivative<Scalar> Deriv;
01950 
01951   if( verbLevel == Teuchos::VERB_NONE && verbLevel == Teuchos::VERB_DEFAULT )
01952     return;
01953 
01954   RCP<Teuchos::FancyOStream>
01955     out = Teuchos::rcp(&out_arg,false);
01956   OSTab tab(out);
01957 
01958   *out <<"Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">:\n";
01959   tab.incrTab();
01960 
01961   *out <<"model = " << modelEvalDescription_ << "\n";
01962   *out <<"Np = " << Np() << "\n";
01963   *out <<"Ng = " << Ng() << "\n";
01964 
01965   CV_ptr f;
01966   if (this->supports(OUT_ARG_f) && !is_null(f=get_f()) ) {
01967     *out << "f = " << Teuchos::describe(*f,verbLevel);
01968   }
01969   
01970   for( int j = 0; j < Ng(); ++j ) {
01971     CV_ptr g_j;
01972     if (!is_null(g_j=this->get_g(j)))
01973       *out << "g("<<j<<") = " << Teuchos::describe(*g_j,verbLevel);
01974   }
01975   
01976   CLOWS_ptr W;
01977   if ( this->supports(OUT_ARG_W) && !is_null(W=get_W()) ) {
01978     *out << "W = " << Teuchos::describe(*W,verbLevel);
01979   }
01980   
01981   for( int l = 0; l < Np(); ++l ) {
01982     Deriv DfDp_l;
01983     if (
01984       !this->supports(OUT_ARG_DfDp,l).none()
01985       && !(DfDp_l=get_DfDp(l)).isEmpty()
01986       )
01987     {
01988       *out << "DfDp("<<l<<") = ";
01989       DfDp_l.describe(*out,verbLevel);
01990     }
01991   }
01992   
01993   for( int j = 0; j < Ng(); ++j ) {
01994     
01995     Deriv DgDx_dot_j;
01996     if (
01997       !this->supports(OUT_ARG_DgDx_dot,j).none()
01998       && !(DgDx_dot_j=get_DgDx_dot(j)).isEmpty()
01999       )
02000     {
02001       *out << "DgDx_dot("<<j<<") = ";
02002       DgDx_dot_j.describe(*out,verbLevel);
02003     }
02004     
02005     Deriv DgDx_j;
02006     if (
02007       !this->supports(OUT_ARG_DgDx,j).none()
02008       && !(DgDx_j=get_DgDx(j)).isEmpty()
02009       )
02010     {
02011       *out << "DgDx("<<j<<") = ";
02012       DgDx_j.describe(*out,verbLevel);
02013     }
02014     
02015     for( int l = 0; l < Np(); ++l ) {
02016       
02017       Deriv DgDp_j_l;
02018       if (
02019         !this->supports(OUT_ARG_DgDp,j,l).none()
02020         && !(DgDp_j_l=get_DgDp(j,l)).isEmpty()
02021         )
02022       {
02023         *out << "DgDp("<<j<<","<<l<<") = ";
02024         DgDp_j_l.describe(*out,verbLevel);
02025       }
02026     }
02027     
02028   }
02029   
02030   // ToDo: Add output for more objects?
02031 
02032 }
02033 
02034 
02035 // protected
02036 
02037 
02038 template<class Scalar>
02039 void ModelEvaluatorBase::OutArgs<Scalar>::_setModelEvalDescription(
02040   const std::string &modelEvalDescription
02041   )
02042 { modelEvalDescription_ = modelEvalDescription; }
02043 
02044 template<class Scalar>
02045 void ModelEvaluatorBase::OutArgs<Scalar>::_set_Np_Ng(int Np, int Ng)
02046 {
02047   if(Np) {
02048     supports_DfDp_.resize(Np);
02049     DfDp_.resize(Np); std::fill_n(DfDp_.begin(),Np,Derivative<Scalar>());
02050     DfDp_properties_.resize(Np); std::fill_n(DfDp_properties_.begin(),Np,DerivativeProperties());
02051   }
02052   if(Ng) {
02053     g_.resize(Ng); std::fill_n(g_.begin(),Ng,Teuchos::null);
02054     supports_DgDx_dot_.resize(Ng);
02055     DgDx_dot_.resize(Ng); std::fill_n(DgDx_dot_.begin(),Ng,Derivative<Scalar>());
02056     DgDx_dot_properties_.resize(Ng); std::fill_n(DgDx_dot_properties_.begin(),Ng,DerivativeProperties());
02057     supports_DgDx_.resize(Ng);
02058     DgDx_.resize(Ng); std::fill_n(DgDx_.begin(),Ng,Derivative<Scalar>());
02059     DgDx_properties_.resize(Ng); std::fill_n(DgDx_properties_.begin(),Ng,DerivativeProperties());
02060   }
02061   if(Np && Ng) {
02062     const int NpNg = Np*Ng;
02063     supports_DgDp_.resize(NpNg);
02064     DgDp_.resize(NpNg); std::fill_n(DgDp_.begin(),NpNg,Derivative<Scalar>());
02065     DgDp_properties_.resize(NpNg); std::fill_n(DgDp_properties_.begin(),NpNg,DerivativeProperties());
02066   }
02067 }
02068 
02069 
02070 template<class Scalar>
02071 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
02072   EOutArgsMembers arg, bool supports )
02073 {
02074   TEST_FOR_EXCEPTION(
02075     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
02076     ,"model = \'"<<modelEvalDescription_
02077     <<"\': Error, arg="<<toString(arg)<<" is invalid!"
02078     );
02079   supports_[arg] = supports;
02080 }
02081 
02082 
02083 template<class Scalar>
02084 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
02085   EOutArgsDfDp arg, int l, const DerivativeSupport& supports
02086   )
02087 {
02088   assert_supports(OUT_ARG_f);
02089   assert_l(l);
02090   supports_DfDp_[l] = supports;
02091 }
02092 
02093 
02094 template<class Scalar>
02095 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
02096   EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports
02097   )
02098 {
02099   assert_j(j);
02100   supports_DgDx_dot_[j] = supports;
02101 }
02102 
02103 
02104 template<class Scalar>
02105 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
02106   EOutArgsDgDx arg, int j, const DerivativeSupport& supports
02107   )
02108 {
02109   assert_j(j);
02110   supports_DgDx_[j] = supports;
02111 }
02112 
02113 
02114 template<class Scalar>
02115 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
02116   EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports
02117   )
02118 {
02119   assert_j(j);
02120   assert_l(l);
02121   supports_DgDp_[ j*Np()+ l ] = supports;
02122 }
02123 
02124 
02125 template<class Scalar>
02126 void ModelEvaluatorBase::OutArgs<Scalar>::_set_W_properties( 
02127   const DerivativeProperties &properties
02128   )
02129 {
02130   W_properties_ = properties;
02131 }
02132 
02133 
02134 template<class Scalar>
02135 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DfDp_properties(
02136   int l, const DerivativeProperties &properties
02137   )
02138 {
02139   assert_supports(OUT_ARG_DfDp,l);
02140   DfDp_properties_[l] = properties;
02141 }
02142 
02143 
02144 template<class Scalar>
02145 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDx_dot_properties(
02146   int j, const DerivativeProperties &properties
02147   )
02148 {
02149   assert_supports(OUT_ARG_DgDx_dot,j);
02150   DgDx_dot_properties_[j] = properties;
02151 }
02152 
02153 
02154 template<class Scalar>
02155 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDx_properties(
02156   int j, const DerivativeProperties &properties
02157   )
02158 {
02159   assert_supports(OUT_ARG_DgDx,j);
02160   DgDx_properties_[j] = properties;
02161 }
02162 
02163 
02164 template<class Scalar>
02165 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDp_properties(
02166   int j, int l, const DerivativeProperties &properties
02167   )
02168 {
02169   assert_supports(OUT_ARG_DgDp,j,l);
02170   DgDp_properties_[ j*Np()+ l ] = properties;
02171 }
02172 
02173 
02174 template<class Scalar>
02175 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports(
02176   const OutArgs<Scalar>& inputOutArgs
02177   )
02178 {
02179   typedef ModelEvaluatorBase MEB;
02180   const int Np = TEUCHOS_MIN(this->Np(),inputOutArgs.Np()); 
02181   const int Ng = TEUCHOS_MIN(this->Ng(),inputOutArgs.Ng()); 
02182   std::copy(
02183     &inputOutArgs.supports_[0],
02184     &inputOutArgs.supports_[0] + NUM_E_OUT_ARGS_MEMBERS, &supports_[0] );
02185   for( int l = 0; l < Np; ++l ) {
02186     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DfDp,l);
02187     if (!ds.none()) {
02188       this->_setSupports(MEB::OUT_ARG_DfDp,l,ds);
02189       this->_set_DfDp_properties(l,inputOutArgs.get_DfDp_properties(l));
02190     }
02191   }
02192   for( int j = 0; j < Ng; ++j ) {
02193     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx_dot,j);
02194     this->_setSupports(MEB::OUT_ARG_DgDx_dot,j,ds);
02195     if(!ds.none()) this->_set_DgDx_dot_properties(j,inputOutArgs.get_DgDx_dot_properties(j));
02196   }
02197   for( int j = 0; j < Ng; ++j ) {
02198     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDx,j);
02199     this->_setSupports(MEB::OUT_ARG_DgDx,j,ds);
02200     if(!ds.none()) this->_set_DgDx_properties(j,inputOutArgs.get_DgDx_properties(j));
02201   }
02202   for( int j = 0; j < Ng; ++j ) for( int l = 0; l < Np; ++l ) {
02203     DerivativeSupport ds = inputOutArgs.supports(MEB::OUT_ARG_DgDp,j,l);
02204     this->_setSupports(MEB::OUT_ARG_DgDp,j,l,ds);
02205     if(!ds.none()) this->_set_DgDp_properties(j,l,inputOutArgs.get_DgDp_properties(j,l));
02206   }
02207   if(this->supports(OUT_ARG_W) || this->supports(OUT_ARG_W_op))
02208     this->_set_W_properties(inputOutArgs.get_W_properties());
02209 }
02210 
02211 
02212 template<class Scalar>
02213 void ModelEvaluatorBase::OutArgs<Scalar>::_setUnsupportsAndRelated(
02214   EInArgsMembers arg
02215   )
02216 {
02217   switch(arg) {
02218     case IN_ARG_x: {
02219       const int Ng = this->Ng();
02220       for( int j = 0; j < Ng; ++j ) {
02221         this->_setSupports(OUT_ARG_DgDx_dot,j,DerivativeSupport());
02222         this->_setSupports(OUT_ARG_DgDx,j,DerivativeSupport());
02223       }
02224       break;
02225     }
02226 #ifdef TEUCHOS_DEBUG
02227     default:
02228       TEST_FOR_EXCEPTION(
02229         true ,std::logic_error
02230         ,"Error, can handle args other than IN_ARG_x yet!"
02231         );
02232 #endif
02233   }
02234 }
02235 
02236 
02237 template<class Scalar>
02238 void ModelEvaluatorBase::OutArgs<Scalar>::_setUnsupportsAndRelated(
02239   EOutArgsMembers arg
02240   )
02241 {
02242   switch(arg) {
02243     case OUT_ARG_f: {
02244       this->_setSupports(OUT_ARG_W,false);
02245       this->_setSupports(OUT_ARG_W_op,false);
02246       this->_setSupports(OUT_ARG_f_poly,false);
02247       const int Np = this->Np();
02248       for( int l = 0; l < Np; ++l )
02249         this->_setSupports(OUT_ARG_DfDp,l,DerivativeSupport());
02250       break;
02251     }
02252 #ifdef TEUCHOS_DEBUG
02253     default:
02254       TEST_FOR_EXCEPTION(
02255         true ,std::logic_error
02256         ,"Error, can handle args other than OUT_ARG_f yet!"
02257         );
02258 #endif
02259   }
02260   this->_setSupports(arg,false);
02261 }
02262 
02263 
02264 // private
02265 
02266 
02267 template<class Scalar>
02268 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(EOutArgsMembers arg) const
02269 {
02270   TEST_FOR_EXCEPTION(
02271     !this->supports(arg), std::logic_error
02272     ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(arg):\n\n"
02273     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02274     "Error, The argument arg = " << toString(arg) << " is not supported!"
02275     );
02276 }
02277 
02278 
02279 template<class Scalar>
02280 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
02281   EOutArgsDfDp arg, int l, const Derivative<Scalar> &deriv
02282   ) const
02283 {
02284   const DerivativeSupport derivSupport = this->supports(arg,l);
02285   TEST_FOR_EXCEPTION(
02286     !deriv.isSupportedBy(derivSupport), std::logic_error,
02287     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DfDp,l):\n\n"
02288     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02289     "Error, The argument DfDp("<<l<<") = " << deriv.description() << "\n"
02290     "is not supported!\n\n"
02291     "The supported types include " << derivSupport.description() << "!"
02292     );
02293 }
02294 
02295 
02296 template<class Scalar>
02297 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
02298   EOutArgsDgDx_dot arg, int j, const Derivative<Scalar> &deriv
02299   ) const
02300 {
02301   const DerivativeSupport derivSupport = this->supports(arg,j);
02302   TEST_FOR_EXCEPTION(
02303     !deriv.isSupportedBy(derivSupport), std::logic_error,
02304     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx_dot,j):\n\n"
02305     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02306     "Error, The argument DgDx_dot("<<j<<") = " << deriv.description() << "\n"
02307     "is not supported!\n\n"
02308     "The supported types include " << derivSupport.description() << "!"
02309     );
02310 }
02311 
02312 
02313 template<class Scalar>
02314 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
02315   EOutArgsDgDx arg, int j, const Derivative<Scalar> &deriv
02316   ) const
02317 {
02318   const DerivativeSupport derivSupport = this->supports(arg,j);
02319   TEST_FOR_EXCEPTION(
02320     !deriv.isSupportedBy(derivSupport), std::logic_error,
02321     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDx,j):\n\n"
02322     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02323     "Error, The argument DgDx("<<j<<") = " << deriv.description() << "\n"
02324     "is not supported!\n\n"
02325     "The supported types include " << derivSupport.description() << "!"
02326     );
02327 }
02328 
02329 
02330 template<class Scalar>
02331 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(
02332   EOutArgsDgDp arg, int j, int l, const Derivative<Scalar> &deriv
02333   ) const
02334 {
02335   const DerivativeSupport derivSupport = this->supports(arg,j,l);
02336   TEST_FOR_EXCEPTION(
02337     !deriv.isSupportedBy(derivSupport), std::logic_error,
02338     "Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(OUT_ARG_DgDp,j,l):\n\n"
02339     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02340     "Error, The argument DgDp("<<j<<","<<l<<") = " << deriv.description() << "\n"
02341     "is not supported!\n\n"
02342     "The supported types include " << derivSupport.description() << "!"
02343     );
02344 }
02345 
02346 
02347 template<class Scalar>
02348 void ModelEvaluatorBase::OutArgs<Scalar>::assert_l(int l) const
02349 {
02350   TEST_FOR_EXCEPTION(
02351     !( 0 <= l && l < Np() ), std::logic_error
02352     ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_l(l):\n\n"
02353     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02354     "Error,  The parameter subvector p("<<l<<")"
02355     " is not in the range [0,"<<Np()<<")!"
02356     );
02357 }
02358 
02359 
02360 template<class Scalar>
02361 void ModelEvaluatorBase::OutArgs<Scalar>::assert_j(int j) const
02362 {
02363   TEST_FOR_EXCEPTION(
02364     !( 0 <= j && j < Ng() ), std::logic_error
02365     ,"Thyra::ModelEvaluatorBase::OutArgs<Scalar>::assert_j(j):\n\n"
02366     "model = \'"<<modelEvalDescription_<<"\':\n\n"
02367     "Error, The auxiliary function g("<<j<<")"
02368     " is not in the range [0,"<<Ng()<<")!"
02369     );
02370 }
02371 
02372 
02373 //
02374 // ModelEvaluatorBase::InArgsSetup
02375 //
02376 
02377 
02378 template<class Scalar>
02379 ModelEvaluatorBase::InArgsSetup<Scalar>::InArgsSetup()
02380 {}
02381 
02382 
02383 template<class Scalar>
02384 ModelEvaluatorBase::InArgsSetup<Scalar>::InArgsSetup( const InArgs<Scalar>& inArgs )
02385   :InArgs<Scalar>(inArgs)
02386 {}
02387 
02388 
02389 template<class Scalar>
02390 void ModelEvaluatorBase::InArgsSetup<Scalar>::setModelEvalDescription( const std::string &modelEvalDescription )
02391 { this->_setModelEvalDescription(modelEvalDescription); }
02392 
02393 
02394 template<class Scalar>
02395 void ModelEvaluatorBase::InArgsSetup<Scalar>::set_Np(int Np)
02396 { this->_set_Np(Np); }
02397 
02398 
02399 template<class Scalar>
02400 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports( EInArgsMembers arg, bool supports )
02401 { this->_setSupports(arg,supports); }
02402 
02403 
02404 template<class Scalar>
02405 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports(
02406   const InArgs<Scalar>& inArgs, const int Np
02407   )
02408 { this->_setSupports(inArgs,Np); }
02409 
02410 
02411 template<class Scalar>
02412 void ModelEvaluatorBase::InArgsSetup<Scalar>::setUnsupportsAndRelated(
02413   EInArgsMembers arg
02414   )
02415 { this->_setUnsupportsAndRelated(arg); }
02416 
02417 
02418 //
02419 // ModelEvaluatorBase::OutArgsSetup
02420 //
02421 
02422 
02423 template<class Scalar>
02424 ModelEvaluatorBase::OutArgsSetup<Scalar>::OutArgsSetup()
02425 {}
02426 
02427 
02428 template<class Scalar>
02429 ModelEvaluatorBase::OutArgsSetup<Scalar>::OutArgsSetup(
02430   const OutArgs<Scalar>& inputOutArgs
02431   )
02432   :OutArgs<Scalar>(inputOutArgs)
02433 {}
02434 
02435 
02436 template<class Scalar>
02437 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setModelEvalDescription(
02438   const std::string &modelEvalDescription
02439   )
02440 { this->_setModelEvalDescription(modelEvalDescription); }
02441 
02442 
02443 template<class Scalar>
02444 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_Np_Ng(int Np, int Ng)
02445 { this->_set_Np_Ng(Np,Ng); }
02446 
02447 
02448 template<class Scalar>
02449 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
02450   EOutArgsMembers arg, bool supports
02451   )
02452 { this->_setSupports(arg,supports); }
02453 
02454 
02455 template<class Scalar>
02456 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
02457   EOutArgsDfDp arg, int l, const DerivativeSupport& supports
02458   )
02459 { this->_setSupports(arg,l,supports); }
02460 
02461 
02462 template<class Scalar>
02463 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( 
02464   EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports
02465   )
02466 { this->_setSupports(arg,j,supports); }
02467 
02468 
02469 template<class Scalar>
02470 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
02471   EOutArgsDgDx arg, int j, const DerivativeSupport& supports
02472   )
02473 { this->_setSupports(arg,j,supports); }
02474 
02475 
02476 template<class Scalar>
02477 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
02478   EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports
02479   )
02480 { this->_setSupports(arg,j,l,supports); }
02481 
02482 
02483 template<class Scalar>
02484 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_W_properties(
02485   const DerivativeProperties &properties
02486   )
02487 { this->_set_W_properties(properties); }
02488 
02489 
02490 template<class Scalar>
02491 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DfDp_properties(
02492   int l, const DerivativeProperties &properties
02493   )
02494 { this->_set_DfDp_properties(l,properties); }
02495 
02496 
02497 template<class Scalar>
02498 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDx_dot_properties(
02499   int j, const DerivativeProperties &properties
02500   )
02501 { this->_set_DgDx_dot_properties(j,properties); }
02502 
02503 
02504 template<class Scalar>
02505 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDx_properties(
02506   int j, const DerivativeProperties &properties
02507   )
02508 { this->_set_DgDx_properties(j,properties); }
02509 
02510 
02511 template<class Scalar>
02512 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDp_properties(
02513   int j, int l, const DerivativeProperties &properties
02514   )
02515 { this->_set_DgDp_properties(j,l,properties); }
02516 
02517 
02518 template<class Scalar>
02519 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports(
02520   const OutArgs<Scalar>& inputOutArgs
02521   )
02522 { this->_setSupports(inputOutArgs); }
02523 
02524 
02525 template<class Scalar>
02526 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setUnsupportsAndRelated(
02527   EInArgsMembers arg
02528   )
02529 { this->_setUnsupportsAndRelated(arg); }
02530 
02531 
02532 template<class Scalar>
02533 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setUnsupportsAndRelated(
02534   EOutArgsMembers arg
02535   )
02536 { this->_setUnsupportsAndRelated(arg); }
02537 
02538 
02539 } // namespace Thyra
02540 
02541 
02542 #endif // THYRA_MODEL_EVALUATOR_BASE_HPP

Generated on Tue Oct 20 12:47:26 2009 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.4.7