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 "Teuchos_Describable.hpp"
00034 #include "Teuchos_Polynomial.hpp"
00035 #include "Thyra_PolynomialVectorTraits.hpp"
00036 
00037 namespace Thyra {
00038 
00044 class ModelEvaluatorBase
00045   : virtual public Teuchos::Describable
00046   , virtual public Teuchos::VerboseObject<ModelEvaluatorBase>
00047 {
00048 public:
00049 
00052 
00054   enum EInArgsMembers {
00055     IN_ARG_x_dot 
00056     ,IN_ARG_x 
00057     ,IN_ARG_x_dot_poly 
00058     ,IN_ARG_x_poly 
00059     ,IN_ARG_t 
00060     ,IN_ARG_alpha 
00061     ,IN_ARG_beta 
00062   };
00064   static const int NUM_E_IN_ARGS_MEMBERS=7;
00065 
00067   template<class Scalar>
00068   class InArgs : public Teuchos::Describable {
00069   public:
00071     typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00073     InArgs();
00075     int Np() const;
00077     void set_x_dot( const Teuchos::RefCountPtr<const VectorBase<Scalar> > &x_dot );
00079     Teuchos::RefCountPtr<const VectorBase<Scalar> > get_x_dot() const;
00081     void set_x( const Teuchos::RefCountPtr<const VectorBase<Scalar> > &x );
00083     Teuchos::RefCountPtr<const VectorBase<Scalar> > get_x() const;
00085     void set_x_poly( const Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly );
00087     Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > get_x_poly() const;
00089     void set_x_dot_poly( const Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly );
00091     Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > get_x_dot_poly() const;
00093     void set_p( int l, const Teuchos::RefCountPtr<const VectorBase<Scalar> > &p_l );
00095     Teuchos::RefCountPtr<const VectorBase<Scalar> > get_p(int l) const;
00097     void set_t( ScalarMag t );
00099     ScalarMag get_t() const;
00101     void set_alpha( Scalar alpha );
00103     Scalar get_alpha() const;
00105     void set_beta( Scalar beta );
00107     Scalar get_beta() const;
00109     bool supports(EInArgsMembers arg) const;
00111     void setArgs( const InArgs<Scalar>& inArgs, bool ignoreUnsupported = false );
00113     std::string description() const;
00115     void describe( Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel ) const;
00116   protected:
00118     void _setModelEvalDescription( const std::string &modelEvalDescription );
00120     void _set_Np(int Np);
00122     void _setSupports( EInArgsMembers arg, bool supports );
00124     void _setSupports( const InArgs<Scalar>& inArgs );
00126     void _setUnsupportsAndRelated( EInArgsMembers arg );
00127   private:
00128     // types
00129     typedef std::vector<Teuchos::RefCountPtr<const VectorBase<Scalar> > > p_t;
00130     // data
00131     std::string                                      modelEvalDescription_;
00132     Teuchos::RefCountPtr<const VectorBase<Scalar> >  x_dot_;
00133     Teuchos::RefCountPtr<const VectorBase<Scalar> >  x_;
00134     Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > x_dot_poly_;
00135     Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > x_poly_;
00136     p_t                                              p_;
00137     ScalarMag                                        t_;
00138     Scalar                                           alpha_;
00139     Scalar                                           beta_;
00140     bool supports_[NUM_E_IN_ARGS_MEMBERS];
00141     // functions
00142     void assert_supports(EInArgsMembers arg) const;
00143     void assert_l(int l) const;
00144   };
00145 
00147   enum EDerivativeMultiVectorOrientation {
00148     DERIV_MV_BY_COL           
00149     ,DERIV_TRANS_MV_BY_ROW    
00150   };
00151 
00153   enum EDerivativeLinearOp { DERIV_LINEAR_OP };
00154 
00156   class DerivativeSupport {
00157   public:
00159     DerivativeSupport()
00160       :supportsLinearOp_(false), supportsMVByCol_(false), supportsTransMVByRow_(false)
00161       {}
00163     DerivativeSupport( EDerivativeLinearOp )
00164       :supportsLinearOp_(true), supportsMVByCol_(false), supportsTransMVByRow_(false)
00165       {}
00167     DerivativeSupport( EDerivativeMultiVectorOrientation mvOrientation )
00168       :supportsLinearOp_(false), supportsMVByCol_(mvOrientation==DERIV_MV_BY_COL)
00169       ,supportsTransMVByRow_(mvOrientation==DERIV_TRANS_MV_BY_ROW)
00170       {}
00172     DerivativeSupport& plus(EDerivativeLinearOp)
00173       { supportsLinearOp_ = true; return *this; }
00175     DerivativeSupport& plus(EDerivativeMultiVectorOrientation mvOrientation)
00176       {
00177         switch(mvOrientation) {
00178           case DERIV_MV_BY_COL: supportsMVByCol_ = true; break;
00179           case DERIV_TRANS_MV_BY_ROW: supportsTransMVByRow_ = true; break;
00180           default: TEST_FOR_EXCEPT(true);
00181         }
00182         return *this;
00183       }
00185     bool none() const
00186       { return ( !supportsLinearOp_ && !supportsMVByCol_ && !supportsTransMVByRow_ ); }
00188     bool supports(EDerivativeLinearOp) const
00189       { return supportsLinearOp_; }
00191     bool supports(EDerivativeMultiVectorOrientation mvOrientation) const
00192       {
00193         switch(mvOrientation) {
00194           case DERIV_MV_BY_COL: return supportsMVByCol_;
00195           case DERIV_TRANS_MV_BY_ROW: return supportsTransMVByRow_;
00196           default: TEST_FOR_EXCEPT(true);
00197         }
00198         return false; // Will never be called!
00199       }
00200   private:
00201     bool supportsLinearOp_;
00202     bool supportsMVByCol_;
00203     bool supportsTransMVByRow_;
00204   public:
00205   };
00206   
00208   enum EDerivativeLinearity {
00209     DERIV_LINEARITY_UNKNOWN      
00210     ,DERIV_LINEARITY_CONST       
00211     ,DERIV_LINEARITY_NONCONST    
00212   };
00213 
00215   enum ERankStatus {
00216     DERIV_RANK_UNKNOWN       
00217     ,DERIV_RANK_FULL         
00218     ,DERIV_RANK_DEFICIENT    
00219   };
00220 
00222   struct DerivativeProperties {
00224     EDerivativeLinearity     linearity;
00226     ERankStatus              rank;
00228     bool                     supportsAdjoint;
00230     DerivativeProperties()
00231       :linearity(DERIV_LINEARITY_UNKNOWN),rank(DERIV_RANK_UNKNOWN),supportsAdjoint(false) {}
00233     DerivativeProperties(
00234       EDerivativeLinearity in_linearity, ERankStatus in_rank, bool in_supportsAdjoint
00235       ):linearity(in_linearity),rank(in_rank),supportsAdjoint(in_supportsAdjoint) {}
00236   };
00237 
00241   template<class Scalar>
00242   class DerivativeMultiVector {
00243   public:
00245     DerivativeMultiVector() {}
00247     DerivativeMultiVector(
00248       const Teuchos::RefCountPtr<MultiVectorBase<Scalar> >  &mv
00249       ,const EDerivativeMultiVectorOrientation              orientation = DERIV_MV_BY_COL
00250       ) : mv_(mv.assert_not_null()), orientation_(orientation) {}
00252     void changeOrientation( const EDerivativeMultiVectorOrientation orientation )
00253       { orientation_ = orientation; };
00255     const DerivativeMultiVector<Scalar>& assert_not_null() const
00256       { mv_.assert_not_null(); return *this; }
00258     Teuchos::RefCountPtr<MultiVectorBase<Scalar> > getMultiVector() const
00259       { return mv_; }
00261     EDerivativeMultiVectorOrientation getOrientation() const
00262       { return orientation_; }
00263   private:
00264     Teuchos::RefCountPtr<MultiVectorBase<Scalar> >   mv_;
00265     EDerivativeMultiVectorOrientation                orientation_;
00266   };
00267 
00271   template<class Scalar>
00272   class Derivative {
00273   public:
00275     Derivative() {}
00277     Derivative( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &lo )
00278       : lo_(lo.assert_not_null()) {}
00280     Derivative( const DerivativeMultiVector<Scalar> &dmv )
00281       : dmv_(dmv) {}
00283     bool isEmpty() const
00284       { return ( lo_.get()==NULL && dmv_.getMultiVector().get()==NULL ); }
00286     const Derivative<Scalar>& assert_not_null() const
00287       { dmv_.assert_not_null(); lo_.assert_not_null(); return *this; }
00289     Teuchos::RefCountPtr<LinearOpBase<Scalar> > getLinearOp() const
00290       { return lo_; }
00292     DerivativeMultiVector<Scalar> getDerivativeMultiVector() const
00293       { return dmv_; }
00294   private:
00295     Teuchos::RefCountPtr<LinearOpBase<Scalar> >   lo_;
00296     DerivativeMultiVector<Scalar>                 dmv_;
00297   };
00298 
00300   enum EOutArgsMembers {
00301     OUT_ARG_f       
00302     ,OUT_ARG_W      
00303     ,OUT_ARG_W_op   
00304     ,OUT_ARG_f_poly 
00305   };
00307   static const int NUM_E_OUT_ARGS_MEMBERS=4;
00308 
00310   enum EOutArgsDfDp {
00311     OUT_ARG_DfDp   
00312   };
00313 
00315   enum EOutArgsDgDx {
00316     OUT_ARG_DgDx   
00317   };
00318 
00320   enum EOutArgsDgDp {
00321     OUT_ARG_DgDp   
00322   };
00323   
00325   template<class Scalar>
00326   class OutArgs : public Teuchos::Describable {
00327   public:
00329     OutArgs();
00331     int Np() const;
00333     int Ng() const;
00335     bool supports(EOutArgsMembers arg) const;
00337     const DerivativeSupport& supports(EOutArgsDfDp arg, int l) const;
00339     const DerivativeSupport& supports(EOutArgsDgDx arg, int j) const;
00341     const DerivativeSupport& supports(EOutArgsDgDp arg, int j, int l) const;
00343     void set_f( const Teuchos::RefCountPtr<VectorBase<Scalar> > &f );
00345     Teuchos::RefCountPtr<VectorBase<Scalar> > get_f() const;
00347     void set_g( int j, const Teuchos::RefCountPtr<VectorBase<Scalar> > &g_j );
00349     Teuchos::RefCountPtr<VectorBase<Scalar> > get_g(int j) const;
00351     void set_W( const Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> > &W );
00353     Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> > get_W() const;
00355     void set_W_op( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &W_op );
00357     Teuchos::RefCountPtr<LinearOpBase<Scalar> > get_W_op() const;
00359     DerivativeProperties get_W_properties() const;
00361     void set_DfDp(int l,  const Derivative<Scalar> &DfDp_l);
00363     Derivative<Scalar> get_DfDp(int l) const;
00365     DerivativeProperties get_DfDp_properties(int l) const;
00367     void set_DgDx(int j, const Derivative<Scalar> &DgDx_j);
00369     Derivative<Scalar> get_DgDx(int j) const;
00371     DerivativeProperties get_DgDx_properties(int j) const;
00373     void set_DgDp( int j, int l, const Derivative<Scalar> &DgDp_j_l );
00375     Derivative<Scalar> get_DgDp(int j, int l) const;
00377     DerivativeProperties get_DgDp_properties(int j, int l) const;
00379     void set_f_poly( const Teuchos::RefCountPtr<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly );
00381     Teuchos::RefCountPtr<Teuchos::Polynomial< VectorBase<Scalar> > > get_f_poly() const;
00383     void setArgs( const OutArgs<Scalar>& outArgs, bool ignoreUnsupported = false );
00385     void setFailed() const;
00387     bool isFailed() const;
00389     std::string description() const;
00391     void describe( Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel ) const;
00392   protected:
00394     void _setModelEvalDescription( const std::string &modelEvalDescription );
00396     void _set_Np_Ng(int Np, int Ng);
00398     void _setSupports( EOutArgsMembers arg, bool supports );
00400     void _setSupports( EOutArgsDfDp arg, int l, const DerivativeSupport& );
00402     void _setSupports( EOutArgsDgDx arg, int j, const DerivativeSupport& );
00404     void _setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& );
00406     void _set_W_properties( const DerivativeProperties &properties );
00408     void _set_DfDp_properties( int l, const DerivativeProperties &properties );
00410     void _set_DgDx_properties( int j, const DerivativeProperties &properties );
00412     void _set_DgDp_properties( int j, int l, const DerivativeProperties &properties );
00414     void _setSupports( const OutArgs<Scalar>& outArgs );
00416     void _setUnsupportsAndRelated( EInArgsMembers arg );
00418     void _setUnsupportsAndRelated( EOutArgsMembers arg );
00419   private:
00420     // types
00421     typedef std::vector<Teuchos::RefCountPtr<VectorBase<Scalar> > >     g_t;
00422     typedef std::vector<Derivative<Scalar> >                            deriv_t;
00423     typedef std::vector<DerivativeProperties>                           deriv_properties_t;
00424     typedef std::vector<DerivativeSupport>                              supports_t;
00425     // data
00426     std::string                                           modelEvalDescription_;
00427     bool                                                  supports_[NUM_E_OUT_ARGS_MEMBERS];
00428     supports_t                                            supports_DfDp_;   // Np
00429     supports_t                                            supports_DgDx_;   // Ng
00430     supports_t                                            supports_DgDp_;   // Ng x Np
00431     Teuchos::RefCountPtr<VectorBase<Scalar> >             f_;
00432     g_t                                                   g_;               // Ng
00433     Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> >  W_;
00434     Teuchos::RefCountPtr<LinearOpBase<Scalar> >           W_op_;
00435     DerivativeProperties                                  W_properties_;
00436     deriv_t                                               DfDp_;            // Np
00437     deriv_properties_t                                    DfDp_properties_; // Np
00438     deriv_t                                               DgDx_;            // Ng
00439     deriv_properties_t                                    DgDx_properties_; // Ng
00440     deriv_t                                               DgDp_;            // Ng x Np
00441     deriv_properties_t                                    DgDp_properties_; // Ng x Np
00442     Teuchos::RefCountPtr<Teuchos::Polynomial< VectorBase<Scalar> > > f_poly_;
00443     mutable bool                                          isFailed_;
00444     // functions
00445     void assert_supports(EOutArgsMembers arg) const;
00446     void assert_supports(EOutArgsDfDp arg, int l) const;
00447     void assert_supports(EOutArgsDgDx arg, int j) const;
00448     void assert_supports(EOutArgsDgDp arg, int j, int l) const;
00449     void assert_l(int l) const;
00450     void assert_j(int j) const;
00451   };
00452 
00454 
00455 #ifdef HAVE_PROTECTED_NESTED_TEMPLATE_CLASS_ACCESS // Added since at least gcc 3.3.4 does not do the right thing here!
00456 protected:
00457 #endif
00458 
00461 
00463   template<class Scalar>
00464   class InArgsSetup : public InArgs<Scalar> {
00465   public:
00467     InArgsSetup();
00469     InArgsSetup( const InArgs<Scalar>& );
00471     void setModelEvalDescription( const std::string &modelEvalDescription );
00473     void set_Np(int Np);
00475     void setSupports( EInArgsMembers arg, bool supports = true );
00477     void setSupports( const InArgs<Scalar>& inArgs );
00479     void setUnsupportsAndRelated( EInArgsMembers arg );
00480   };
00481 
00483   template<class Scalar>
00484   class OutArgsSetup : public OutArgs<Scalar> {
00485   public:
00487     OutArgsSetup();
00489     OutArgsSetup( const OutArgs<Scalar>& );
00491     void setModelEvalDescription( const std::string &modelEvalDescription );
00493     void set_Np_Ng(int Np, int Ng);
00495     void setSupports( EOutArgsMembers arg, bool supports = true );
00497     void setSupports(EOutArgsDfDp arg, int l, const DerivativeSupport& );
00499     void setSupports(EOutArgsDgDx arg, int j, const DerivativeSupport& );
00501     void setSupports(EOutArgsDgDp arg, int j, int l, const DerivativeSupport& );
00503     void set_W_properties( const DerivativeProperties &properties );
00505     void set_DfDp_properties( int l, const DerivativeProperties &properties );
00507     void set_DgDx_properties( int j, const DerivativeProperties &properties );
00509     void set_DgDp_properties( int j, int l, const DerivativeProperties &properties );
00511     void setSupports( const OutArgs<Scalar>& outArgs );
00513     void setUnsupportsAndRelated( EInArgsMembers arg );
00515     void setUnsupportsAndRelated( EOutArgsMembers arg );
00516    };
00517 
00519 
00520 };
00521 
00526 
00528 std::string toString(ModelEvaluatorBase::EInArgsMembers);
00529 
00531 std::string toString(ModelEvaluatorBase::EOutArgsMembers);
00532 
00534 std::string toString(ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation);
00535 
00537 
00538 } // namespace Thyra
00539 
00540 // //////////////////////////////////
00541 // Inline Defintions
00542 
00543 //
00544 // Thyra_MEB_helper_functions_grp
00545 //
00546 
00547 inline
00548 std::string Thyra::toString(ModelEvaluatorBase::EInArgsMembers arg)
00549 {
00550   switch(arg) {
00551     case ModelEvaluatorBase::IN_ARG_x_dot:
00552       return "IN_ARG_x_dot";
00553     case ModelEvaluatorBase::IN_ARG_x:
00554       return "IN_ARG_x";
00555     case ModelEvaluatorBase::IN_ARG_t:
00556       return "IN_ARG_t";
00557     case ModelEvaluatorBase::IN_ARG_alpha:
00558       return "IN_ARG_alpha";
00559     case ModelEvaluatorBase::IN_ARG_beta:
00560       return "IN_ARG_beta";
00561     default:
00562       TEST_FOR_EXCEPT(true);
00563   }
00564   return ""; // Will never be executed!
00565 }
00566 
00567 inline
00568 std::string Thyra::toString(ModelEvaluatorBase::EOutArgsMembers arg)
00569 {
00570   switch(arg) {
00571     case ModelEvaluatorBase::OUT_ARG_f:
00572       return "OUT_ARG_f";
00573     case ModelEvaluatorBase::OUT_ARG_W:
00574       return "OUT_ARG_W";
00575     default:
00576       TEST_FOR_EXCEPT(true);
00577   }
00578   return ""; // Will never be executed!
00579 }
00580 
00581 inline
00582 std::string Thyra::toString(ModelEvaluatorBase::EDerivativeMultiVectorOrientation orientation)
00583 {
00584   switch(orientation) {
00585     case ModelEvaluatorBase::DERIV_MV_BY_COL:
00586       return "DERIV_MV_BY_COL";
00587     case ModelEvaluatorBase::DERIV_TRANS_MV_BY_ROW:
00588       return "DERIV_TRANS_MV_BY_ROW";
00589     default:
00590       TEST_FOR_EXCEPT(true);
00591   }
00592   return ""; // Should never execute this!
00593 }
00594 
00595 // //////////////////////////////////
00596 // Definitions
00597 
00598 namespace Thyra {
00599 
00600 //
00601 // ModelEvaluatorBase::InArgs
00602 //
00603 
00604 template<class Scalar>
00605 ModelEvaluatorBase::InArgs<Scalar>::InArgs()
00606 {
00607   typedef Teuchos::ScalarTraits<Scalar> ST;
00608   typedef Teuchos::ScalarTraits<typename ST::magnitudeType> SMT;
00609   std::fill_n(&supports_[0],NUM_E_IN_ARGS_MEMBERS,false);
00610   t_     = SMT::zero();
00611   alpha_ = ST::zero();
00612   beta_  = ST::zero();
00613 }
00614 
00615 template<class Scalar>
00616 int ModelEvaluatorBase::InArgs<Scalar>::Np() const
00617 { return p_.size(); }
00618 
00619 template<class Scalar>
00620 void ModelEvaluatorBase::InArgs<Scalar>::set_x_dot( const Teuchos::RefCountPtr<const VectorBase<Scalar> > &x_dot )
00621 { assert_supports(IN_ARG_x_dot); x_dot_ = x_dot; }
00622 
00623 template<class Scalar>
00624 Teuchos::RefCountPtr<const VectorBase<Scalar> >
00625 ModelEvaluatorBase::InArgs<Scalar>::get_x_dot() const
00626 { assert_supports(IN_ARG_x_dot); return x_dot_; }
00627 
00628 template<class Scalar>
00629 void ModelEvaluatorBase::InArgs<Scalar>::set_x( const Teuchos::RefCountPtr<const VectorBase<Scalar> > &x )
00630 { assert_supports(IN_ARG_x); x_ = x; }
00631 
00632 template<class Scalar>
00633 Teuchos::RefCountPtr<const VectorBase<Scalar> >
00634 ModelEvaluatorBase::InArgs<Scalar>::get_x() const
00635 { assert_supports(IN_ARG_x); return x_; }
00636 
00637 template<class Scalar>
00638 void ModelEvaluatorBase::InArgs<Scalar>::set_x_dot_poly( const Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_dot_poly )
00639 { assert_supports(IN_ARG_x_dot_poly); x_dot_poly_ = x_dot_poly; }
00640 
00641 template<class Scalar>
00642 Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > >
00643 ModelEvaluatorBase::InArgs<Scalar>::get_x_dot_poly() const
00644 { assert_supports(IN_ARG_x_dot_poly); return x_dot_poly_; }
00645 
00646 template<class Scalar>
00647 void ModelEvaluatorBase::InArgs<Scalar>::set_x_poly( const Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > > &x_poly )
00648 { assert_supports(IN_ARG_x_poly); x_poly_ = x_poly; }
00649 
00650 template<class Scalar>
00651 Teuchos::RefCountPtr<const Teuchos::Polynomial< VectorBase<Scalar> > >
00652 ModelEvaluatorBase::InArgs<Scalar>::get_x_poly() const
00653 { assert_supports(IN_ARG_x_poly); return x_poly_; }
00654 
00655 template<class Scalar>
00656 void ModelEvaluatorBase::InArgs<Scalar>::set_p( int l, const Teuchos::RefCountPtr<const VectorBase<Scalar> > &p_l )
00657 { assert_l(l); p_[l] = p_l; }
00658 
00659 template<class Scalar>
00660 Teuchos::RefCountPtr<const VectorBase<Scalar> >
00661 ModelEvaluatorBase::InArgs<Scalar>::get_p(int l) const
00662 { assert_l(l); return p_[l]; }
00663 
00664 template<class Scalar>
00665 void ModelEvaluatorBase::InArgs<Scalar>::set_t( ScalarMag t )
00666 { assert_supports(IN_ARG_t); t_ = t; }
00667 
00668 template<class Scalar>
00669 typename ModelEvaluatorBase::InArgs<Scalar>::ScalarMag
00670 ModelEvaluatorBase::InArgs<Scalar>::get_t() const
00671 { assert_supports(IN_ARG_t); return t_; }
00672 
00673 template<class Scalar>
00674 void ModelEvaluatorBase::InArgs<Scalar>::set_alpha( Scalar alpha )
00675 { assert_supports(IN_ARG_alpha); alpha_ = alpha; }
00676 
00677 template<class Scalar>
00678 Scalar ModelEvaluatorBase::InArgs<Scalar>::get_alpha() const
00679 { assert_supports(IN_ARG_alpha); return alpha_; }
00680 
00681 template<class Scalar>
00682 void ModelEvaluatorBase::InArgs<Scalar>::set_beta( Scalar beta )
00683 { assert_supports(IN_ARG_beta); beta_ = beta; }
00684 
00685 template<class Scalar>
00686 Scalar ModelEvaluatorBase::InArgs<Scalar>::get_beta() const
00687 { assert_supports(IN_ARG_beta); return beta_; }
00688 
00689 template<class Scalar>
00690 bool ModelEvaluatorBase::InArgs<Scalar>::supports(EInArgsMembers arg) const
00691 {
00692   TEST_FOR_EXCEPTION(
00693     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00694     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
00695     );
00696   return supports_[arg];
00697 }
00698 
00699 template<class Scalar>
00700 void ModelEvaluatorBase::InArgs<Scalar>::setArgs( const InArgs<Scalar>& inArgs, bool ignoreUnsupported )
00701 {
00702   if( inArgs.supports(IN_ARG_x_dot) && inArgs.get_x_dot().get() ) {
00703     if(supports(IN_ARG_x_dot) || !ignoreUnsupported)
00704       set_x_dot(inArgs.get_x_dot());
00705   }
00706   if( inArgs.supports(IN_ARG_x) && inArgs.get_x().get() ) {
00707     if(supports(IN_ARG_x) || !ignoreUnsupported)
00708       set_x(inArgs.get_x());
00709   }
00710   if( inArgs.supports(IN_ARG_x_dot_poly) && inArgs.get_x_dot_poly().get() ) {
00711     if(supports(IN_ARG_x_dot_poly) || !ignoreUnsupported)
00712       set_x_dot_poly(inArgs.get_x_dot_poly());
00713   }
00714   if( inArgs.supports(IN_ARG_x_poly) && inArgs.get_x_poly().get() ) {
00715     if(supports(IN_ARG_x_poly) || !ignoreUnsupported)
00716       set_x_poly(inArgs.get_x_poly());
00717   }
00718   const int min_Np = TEUCHOS_MIN(this->Np(),inArgs.Np());
00719   for( int l = 0; l < min_Np; ++l ) {
00720     if(inArgs.get_p(l).get())
00721       set_p(l,inArgs.get_p(l));
00722   }
00723   if( inArgs.supports(IN_ARG_t) ) {
00724     if(supports(IN_ARG_t) || !ignoreUnsupported)
00725       set_t(inArgs.get_t());
00726   }
00727   if( inArgs.supports(IN_ARG_alpha) ) {
00728     if(supports(IN_ARG_alpha) || !ignoreUnsupported)
00729       set_alpha(inArgs.get_alpha());
00730   }
00731   if( inArgs.supports(IN_ARG_beta) ) {
00732     if(supports(IN_ARG_beta) || !ignoreUnsupported)
00733       set_beta(inArgs.get_beta());
00734   }
00735 }
00736 
00737 template<class Scalar>
00738 std::string ModelEvaluatorBase::InArgs<Scalar>::description() const
00739 {
00740   typedef Teuchos::ScalarTraits<Scalar> ST;
00741   std::ostringstream oss;
00742   oss
00743     << "Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">"
00744     << "{"
00745     << "model="<<modelEvalDescription_
00746     << ",Np="<<Np()
00747     << "}";
00748   return oss.str();
00749 }
00750 
00751 template<class Scalar>
00752 void ModelEvaluatorBase::InArgs<Scalar>::describe(
00753   Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
00754   ) const
00755 {
00756   typedef Teuchos::ScalarTraits<Scalar> ST;
00757   using Teuchos::OSTab;
00758   typedef Teuchos::RefCountPtr<const VectorBase<Scalar> > CV_ptr;
00759   if(verbLevel == Teuchos::VERB_NONE)
00760     return;
00761   Teuchos::RefCountPtr<Teuchos::FancyOStream>
00762     out = Teuchos::rcp(&out_arg,false);
00763   OSTab tab(out);
00764   *out <<"Thyra::ModelEvaluatorBase::InArgs<"<<ST::name()<<">:\n";
00765   tab.incrTab();
00766   *out <<"model = " << modelEvalDescription_ << "\n";
00767   *out <<"Np = " << Np() << "\n";
00768   switch(verbLevel) {
00769     case Teuchos::VERB_LOW:
00770     case Teuchos::VERB_MEDIUM:
00771     case Teuchos::VERB_HIGH:
00772     case Teuchos::VERB_EXTREME:
00773     {
00774       if(this->supports(IN_ARG_x_dot) ) {
00775         *out << "x_dot =";
00776         CV_ptr x_dot = this->get_x_dot();
00777         if(x_dot.get())
00778           *out << "\n" << Teuchos::describe(*x_dot,verbLevel);
00779         else
00780           *out << " NULL\n";
00781       }
00782       if(this->supports(IN_ARG_x) ) {
00783         *out << "x =";
00784         CV_ptr x = this->get_x();
00785         if(x.get())
00786           *out << "\n" << Teuchos::describe(*x,verbLevel);
00787         else
00788           *out << " NULL\n";
00789       }
00790       for( int l = 0; l < Np(); ++l ) {
00791         *out << "p("<<l<<") =";
00792         CV_ptr p_l = this->get_p(l);
00793         if(p_l.get())
00794           *out << "\n" << Teuchos::describe(*p_l,verbLevel);
00795         else
00796           *out << " NULL\n";
00797       }
00798       // ToDo: Add output for more objects!
00799       break;
00800     }
00801     default:
00802       TEST_FOR_EXCEPT(true);
00803   }
00804 }
00805 
00806 template<class Scalar>
00807 void ModelEvaluatorBase::InArgs<Scalar>::_setModelEvalDescription( const std::string &modelEvalDescription )
00808 { modelEvalDescription_ = modelEvalDescription; }
00809 
00810 template<class Scalar>
00811 void ModelEvaluatorBase::InArgs<Scalar>::_set_Np(int Np)
00812 {
00813   p_.resize(Np);
00814 }
00815 
00816 template<class Scalar>
00817 void ModelEvaluatorBase::InArgs<Scalar>::_setSupports( EInArgsMembers arg, bool supports )
00818 {
00819   TEST_FOR_EXCEPTION(
00820     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00821     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!");
00822   supports_[arg] = supports;
00823 }
00824 
00825 template<class Scalar>
00826 void ModelEvaluatorBase::InArgs<Scalar>::_setSupports( const InArgs<Scalar>& inArgs )
00827 {
00828   std::copy( &inArgs.supports_[0], &inArgs.supports_[0] + NUM_E_IN_ARGS_MEMBERS, &supports_[0] );
00829 }
00830 
00831 template<class Scalar>
00832 void ModelEvaluatorBase::InArgs<Scalar>::_setUnsupportsAndRelated( EInArgsMembers arg )
00833 {
00834   this->_setSupports(arg,false);
00835   switch(arg) {
00836     case IN_ARG_x: {
00837       this->_setSupports(IN_ARG_x_dot,false);
00838       this->_setSupports(IN_ARG_x_dot_poly,false);
00839       this->_setSupports(IN_ARG_alpha,false);
00840       this->_setSupports(IN_ARG_beta,false);
00841       break;
00842     }
00843     default:
00844       TEST_FOR_EXCEPTION(
00845         true ,std::logic_error
00846         ,"Error, can handle args other than IN_ARG_x yet!"
00847         );
00848   }
00849 }
00850 
00851 template<class Scalar>
00852 void ModelEvaluatorBase::InArgs<Scalar>::assert_supports(EInArgsMembers arg) const
00853 {
00854   TEST_FOR_EXCEPTION(
00855     !supports_[arg], std::logic_error
00856     ,"Thyra::ModelEvaluatorBase::InArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(arg): "
00857     "model = \'"<<modelEvalDescription_<<"\': Error, "
00858     "The argument arg = " << toString(arg) << " is not supported!"
00859     );
00860 }
00861 
00862 template<class Scalar>
00863 void ModelEvaluatorBase::InArgs<Scalar>::assert_l(int l) const
00864 {
00865   TEST_FOR_EXCEPTION(
00866     !( 0 <= l && l < Np() ), std::logic_error
00867     ,"Thyra::ModelEvaluatorBase::InArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_l(l): "
00868     " model = \'"<<modelEvalDescription_<<"\': Error, "
00869     "The parameter l = " << l << " is not in the range [0,"<<Np()-1<<"]!"
00870     );
00871 }
00872 
00873 //
00874 // ModelEvaluatorBase::OutArgs
00875 //
00876 
00877 template<class Scalar>
00878 ModelEvaluatorBase::OutArgs<Scalar>::OutArgs()
00879   :isFailed_(false)
00880 { std::fill_n(&supports_[0],NUM_E_OUT_ARGS_MEMBERS,false); }
00881 
00882 template<class Scalar>
00883 int ModelEvaluatorBase::OutArgs<Scalar>::Np() const
00884 { return DfDp_.size(); }
00885 
00886 template<class Scalar>
00887 int ModelEvaluatorBase::OutArgs<Scalar>::Ng() const
00888 { return g_.size(); }
00889 
00890 template<class Scalar>
00891 bool ModelEvaluatorBase::OutArgs<Scalar>::supports(EOutArgsMembers arg) const
00892 {
00893   TEST_FOR_EXCEPTION(
00894     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00895     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
00896     );
00897   return supports_[arg];
00898 }
00899 
00900 template<class Scalar>
00901 const ModelEvaluatorBase::DerivativeSupport&
00902 ModelEvaluatorBase::OutArgs<Scalar>::supports(EOutArgsDfDp arg, int l) const
00903 {
00904   assert_l(l);
00905   return supports_DfDp_[l];
00906 }
00907 
00908 template<class Scalar>
00909 const ModelEvaluatorBase::DerivativeSupport&
00910 ModelEvaluatorBase::OutArgs<Scalar>::supports(EOutArgsDgDx arg, int j) const
00911 {
00912   assert_j(j);
00913   return supports_DgDx_[j];
00914 }
00915 
00916 template<class Scalar>
00917 const ModelEvaluatorBase::DerivativeSupport&
00918 ModelEvaluatorBase::OutArgs<Scalar>::supports(EOutArgsDgDp arg, int j, int l) const
00919 {
00920   assert_j(j);
00921   assert_l(l);
00922   return supports_DgDp_[ j*Np() + l ];
00923 }
00924 
00925 template<class Scalar>
00926 void ModelEvaluatorBase::OutArgs<Scalar>::set_f( const Teuchos::RefCountPtr<VectorBase<Scalar> > &f )
00927 {
00928   assert_supports(OUT_ARG_f);
00929   f_ = f;
00930 }
00931 
00932 template<class Scalar>
00933 Teuchos::RefCountPtr<VectorBase<Scalar> >
00934 ModelEvaluatorBase::OutArgs<Scalar>::get_f() const
00935 {
00936   assert_supports(OUT_ARG_f);
00937   return f_;
00938 }
00939 
00940 template<class Scalar>
00941 void ModelEvaluatorBase::OutArgs<Scalar>::set_g( int j, const Teuchos::RefCountPtr<VectorBase<Scalar> > &g_j )
00942 {
00943   assert_j(j);
00944   g_[j] = g_j;
00945 }
00946 
00947 template<class Scalar>
00948 Teuchos::RefCountPtr<VectorBase<Scalar> >
00949 ModelEvaluatorBase::OutArgs<Scalar>::get_g(int j) const
00950 { 
00951   assert_j(j);
00952   return g_[j];
00953 }
00954 
00955 template<class Scalar>
00956 void ModelEvaluatorBase::OutArgs<Scalar>::set_W( const Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> > &W )
00957 {
00958   assert_supports(OUT_ARG_W);
00959   W_ = W;
00960 }
00961 
00962 template<class Scalar>
00963 Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> >
00964 ModelEvaluatorBase::OutArgs<Scalar>::get_W() const
00965 {
00966   assert_supports(OUT_ARG_W);
00967   return W_;
00968 }
00969 
00970 template<class Scalar>
00971 void ModelEvaluatorBase::OutArgs<Scalar>::set_W_op( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &W_op )
00972 {
00973   assert_supports(OUT_ARG_W_op);
00974   W_op_ = W_op;
00975 }
00976 
00977 template<class Scalar>
00978 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00979 ModelEvaluatorBase::OutArgs<Scalar>::get_W_op() const
00980 {
00981   assert_supports(OUT_ARG_W_op);
00982   return W_op_;
00983 }
00984 
00985 template<class Scalar>
00986 ModelEvaluatorBase::DerivativeProperties
00987 ModelEvaluatorBase::OutArgs<Scalar>::get_W_properties() const
00988 {
00989   return W_properties_;
00990 }
00991 
00992 template<class Scalar>
00993 void ModelEvaluatorBase::OutArgs<Scalar>::set_DfDp( int l, const Derivative<Scalar> &DfDp_l )
00994 {
00995   assert_supports(OUT_ARG_DfDp,l);
00996   DfDp_[l] = DfDp_l;
00997 }
00998 
00999 template<class Scalar>
01000 ModelEvaluatorBase::Derivative<Scalar>
01001 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp(int l) const
01002 {
01003   assert_supports(OUT_ARG_DfDp,l);
01004   return DfDp_[l];
01005 }
01006 
01007 template<class Scalar>
01008 ModelEvaluatorBase::DerivativeProperties
01009 ModelEvaluatorBase::OutArgs<Scalar>::get_DfDp_properties(int l) const
01010 {
01011   assert_supports(OUT_ARG_DfDp,l);
01012   return DfDp_properties_[l];
01013 }
01014 
01015 template<class Scalar>
01016 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDx( int j, const Derivative<Scalar> &DgDx_j )
01017 {
01018   assert_supports(OUT_ARG_DgDx,j);
01019   DgDx_[j] = DgDx_j;
01020 }
01021 
01022 template<class Scalar>
01023 ModelEvaluatorBase::Derivative<Scalar>
01024 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx(int j) const
01025 {
01026   assert_supports(OUT_ARG_DgDx,j);
01027   return DgDx_[j];
01028 }
01029 
01030 template<class Scalar>
01031 ModelEvaluatorBase::DerivativeProperties
01032 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDx_properties(int j) const
01033 {
01034   assert_supports(OUT_ARG_DgDx,j);
01035   return DgDx_properties_[j];
01036 }
01037 
01038 template<class Scalar>
01039 void ModelEvaluatorBase::OutArgs<Scalar>::set_DgDp( int j, int l, const Derivative<Scalar> &DgDp_j_l )
01040 {
01041   assert_supports(OUT_ARG_DgDp,j,l);
01042   DgDp_[ j*Np() + l ] = DgDp_j_l;
01043 }
01044 
01045 template<class Scalar>
01046 ModelEvaluatorBase::Derivative<Scalar>
01047 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp(int j, int l) const
01048 {
01049   assert_supports(OUT_ARG_DgDp,j,l);
01050   return DgDp_[ j*Np() + l ];
01051 }
01052 
01053 template<class Scalar>
01054 ModelEvaluatorBase::DerivativeProperties
01055 ModelEvaluatorBase::OutArgs<Scalar>::get_DgDp_properties(int j, int l) const
01056 {
01057   assert_supports(OUT_ARG_DgDp,j,l);
01058   return DgDp_properties_[ j*Np() + l ];
01059 }
01060 
01061 template<class Scalar>
01062 void ModelEvaluatorBase::OutArgs<Scalar>::set_f_poly( const Teuchos::RefCountPtr<Teuchos::Polynomial< VectorBase<Scalar> > > &f_poly )
01063 { f_poly_ = f_poly; }
01064 
01065 template<class Scalar>
01066 Teuchos::RefCountPtr<Teuchos::Polynomial< VectorBase<Scalar> > >
01067 ModelEvaluatorBase::OutArgs<Scalar>::get_f_poly() const
01068 { return f_poly_; }
01069 
01070 
01071 template<class Scalar>
01072 void ModelEvaluatorBase::OutArgs<Scalar>::setArgs( const OutArgs<Scalar>& outArgs, bool ignoreUnsupported )
01073 {
01074   const int min_Np = TEUCHOS_MIN(this->Np(),outArgs.Np());
01075   const int min_Ng = TEUCHOS_MIN(this->Ng(),outArgs.Ng());
01076   if( outArgs.supports(OUT_ARG_f) && outArgs.get_f().get() ) {
01077     if(supports(OUT_ARG_f) || !ignoreUnsupported)
01078       set_f(outArgs.get_f());
01079   }
01080   for( int j = 0; j < min_Ng; ++j ) {
01081     if(outArgs.get_g(j).get())
01082       set_g(j,outArgs.get_g(j));
01083   }
01084   if( outArgs.supports(OUT_ARG_W) && outArgs.get_W().get() ) {
01085     if(supports(OUT_ARG_W) || !ignoreUnsupported)
01086       set_W(outArgs.get_W());
01087   }
01088   for( int l = 0; l < min_Np; ++l ) {
01089     if( !outArgs.supports(OUT_ARG_DfDp,l).none() && !outArgs.get_DfDp(l).isEmpty() ) {
01090       if(!supports(OUT_ARG_DfDp,l).none() || !ignoreUnsupported)
01091         set_DfDp(l,outArgs.get_DfDp(l));
01092     }
01093   }
01094   for( int j = 0; j < min_Ng; ++j ) {
01095     if( !outArgs.supports(OUT_ARG_DgDx,j).none() && !outArgs.get_DgDx(j).isEmpty() ) {
01096       if(!supports(OUT_ARG_DgDx,j).none() || !ignoreUnsupported)
01097         set_DgDx(j,outArgs.get_DgDx(j));
01098     }
01099   }
01100   for( int l = 0; l < min_Np; ++l ) {
01101     for( int j = 0; j < min_Ng; ++j ) {
01102       if( !outArgs.supports(OUT_ARG_DgDp,j,l).none() && !outArgs.get_DgDp(j,l).isEmpty() ) {
01103         if(!supports(OUT_ARG_DgDp,j,l).none() || !ignoreUnsupported)
01104           set_DgDp(j,l,outArgs.get_DgDp(j,l));
01105       }
01106     }
01107   }
01108 }
01109 
01110 template<class Scalar>
01111 void ModelEvaluatorBase::OutArgs<Scalar>::setFailed() const
01112 {
01113   typedef Teuchos::ScalarTraits<Scalar> ST;
01114   isFailed_ = true;
01115   if( this->supports(OUT_ARG_f) && this->get_f().get() ) {
01116     assign(&*this->get_f(),ST::nan());
01117   }
01118   for( int j = 0; j < this->Ng(); ++j ) {
01119     if(this->get_g(j).get())
01120       assign(&*this->get_g(j),ST::nan());
01121   }
01122   // ToDo: Set other objects to NaN as well!
01123 }
01124 
01125 template<class Scalar>
01126 bool ModelEvaluatorBase::OutArgs<Scalar>::isFailed() const
01127 {
01128   return isFailed_;
01129 }
01130 
01131 template<class Scalar>
01132 std::string ModelEvaluatorBase::OutArgs<Scalar>::description() const
01133 {
01134   typedef Teuchos::ScalarTraits<Scalar> ST;
01135   std::ostringstream oss;
01136   oss
01137     << "Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">"
01138     << "{"
01139     << "model="<<modelEvalDescription_
01140     << ",Np="<<Np()
01141     << ",Ng="<<Ng()
01142     << "}";
01143   return oss.str();
01144 }
01145 
01146 template<class Scalar>
01147 void ModelEvaluatorBase::OutArgs<Scalar>::describe(
01148   Teuchos::FancyOStream &out_arg, const Teuchos::EVerbosityLevel verbLevel
01149   ) const
01150 {
01151   using Teuchos::OSTab;
01152   typedef Teuchos::ScalarTraits<Scalar> ST;
01153   typedef Teuchos::RefCountPtr<const VectorBase<Scalar> > CV_ptr;
01154   typedef Teuchos::RefCountPtr<const LinearOpWithSolveBase<Scalar> > CLOWS_ptr;
01155   typedef ModelEvaluatorBase MEB;
01156   if(verbLevel == Teuchos::VERB_NONE)
01157     return;
01158   Teuchos::RefCountPtr<Teuchos::FancyOStream>
01159     out = Teuchos::rcp(&out_arg,false);
01160   OSTab tab(out);
01161   *out <<"Thyra::ModelEvaluatorBase::OutArgs<"<<ST::name()<<">:\n";
01162   tab.incrTab();
01163   *out <<"model = " << modelEvalDescription_ << "\n";
01164   *out <<"Np = " << Np() << "\n";
01165   *out <<"Ng = " << Ng() << "\n";
01166   switch(verbLevel) {
01167     case Teuchos::VERB_LOW:
01168     case Teuchos::VERB_MEDIUM:
01169     case Teuchos::VERB_HIGH:
01170     case Teuchos::VERB_EXTREME:
01171     {
01172       if(this->supports(OUT_ARG_f) ) {
01173         *out << "f =";
01174         CV_ptr f = this->get_f();
01175         if(f.get())
01176           *out << "\n" << Teuchos::describe(*f,verbLevel);
01177         else
01178           *out << " NULL\n";
01179       }
01180       for( int j = 0; j < Ng(); ++j ) {
01181         *out << "g("<<j<<") =";
01182         CV_ptr g_j = this->get_g(j);
01183         if(g_j.get())
01184           *out << "\n" << Teuchos::describe(*g_j,verbLevel);
01185         else
01186           *out << " NULL\n";
01187       }
01188       if(this->supports(OUT_ARG_W) ) {
01189         *out << "W =";
01190         CLOWS_ptr W = this->get_W();
01191         if(W.get())
01192           *out << "\n" << Teuchos::describe(*W,verbLevel);
01193         else
01194           *out << " NULL\n";
01195       }
01196       for( int l = 0; l < Np(); ++l ) {
01197         if(!this->supports(OUT_ARG_DfDp,l).none()) {
01198           *out << "DfDp("<<l<<") =";
01199           const MEB::Derivative<Scalar> DfDp_l = this->get_DfDp(l);
01200           if(!DfDp_l.isEmpty()) {
01201             *out << "\n";
01202             if(DfDp_l.getLinearOp().get()) {
01203               *out << Teuchos::describe(*DfDp_l.getLinearOp(),verbLevel);
01204             }
01205             else {
01206               *OSTab(out).getOStream()
01207                 << "orientation="
01208                 << toString(DfDp_l.getDerivativeMultiVector().getOrientation()) << "\n";
01209               *out << Teuchos::describe(*DfDp_l.getDerivativeMultiVector().getMultiVector(),verbLevel);
01210             }
01211           }
01212           else {
01213             *out << " NULL\n";
01214           }
01215         }
01216       }
01217       // ToDo: Add output for more objects?
01218       break;
01219     }
01220     default:
01221       TEST_FOR_EXCEPT(true);
01222   }
01223 }
01224 
01225 // protected
01226 
01227 template<class Scalar>
01228 void ModelEvaluatorBase::OutArgs<Scalar>::_setModelEvalDescription( const std::string &modelEvalDescription )
01229 { modelEvalDescription_ = modelEvalDescription; }
01230 
01231 template<class Scalar>
01232 void ModelEvaluatorBase::OutArgs<Scalar>::_set_Np_Ng(int Np, int Ng)
01233 {
01234   if(Np) {
01235     supports_DfDp_.resize(Np);
01236     DfDp_.resize(Np);                 std::fill_n(DfDp_.begin(),Np,Derivative<Scalar>());
01237     DfDp_properties_.resize(Np);      std::fill_n(DfDp_properties_.begin(),Np,DerivativeProperties());
01238   }
01239   if(Ng) {
01240     g_.resize(Ng);                    std::fill_n(g_.begin(),Ng,Teuchos::null);
01241     supports_DgDx_.resize(Ng);
01242     DgDx_.resize(Ng);                 std::fill_n(DgDx_.begin(),Ng,Derivative<Scalar>());
01243     DgDx_properties_.resize(Ng);      std::fill_n(DgDx_properties_.begin(),Ng,DerivativeProperties());
01244   }
01245   if(Np && Ng) {
01246     const int NpNg = Np*Ng;
01247     supports_DgDp_.resize(NpNg);
01248     DgDp_.resize(NpNg);                 std::fill_n(DgDp_.begin(),NpNg,Derivative<Scalar>());
01249     DgDp_properties_.resize(NpNg);      std::fill_n(DgDp_properties_.begin(),NpNg,DerivativeProperties());
01250   }
01251 }
01252 
01253 template<class Scalar>
01254 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports( EOutArgsMembers arg, bool supports )
01255 {
01256   TEST_FOR_EXCEPTION(
01257     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
01258     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
01259     );
01260   supports_[arg] = supports;
01261 }
01262 
01263 template<class Scalar>
01264 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports( EOutArgsDfDp arg, int l, const DerivativeSupport& supports )
01265 {
01266   assert_l(l);
01267   supports_DfDp_[l] = supports;
01268 }
01269 
01270 template<class Scalar>
01271 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports( EOutArgsDgDx arg, int j, const DerivativeSupport& supports )
01272 {
01273   assert_j(j);
01274   supports_DgDx_[j] = supports;
01275 }
01276 
01277 template<class Scalar>
01278 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports )
01279 {
01280   assert_j(j);
01281   assert_l(l);
01282   supports_DgDp_[ j*Np()+ l ] = supports;
01283 }
01284 
01285 template<class Scalar>
01286 void ModelEvaluatorBase::OutArgs<Scalar>::_set_W_properties( const DerivativeProperties &properties )
01287 {
01288   W_properties_ = properties;
01289 }
01290 
01291 template<class Scalar>
01292 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DfDp_properties( int l, const DerivativeProperties &properties )
01293 {
01294   assert_supports(OUT_ARG_DfDp,l);
01295   DfDp_properties_[l] = properties;
01296 }
01297 
01298 template<class Scalar>
01299 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDx_properties( int j, const DerivativeProperties &properties )
01300 {
01301   assert_supports(OUT_ARG_DgDx,j);
01302   DgDx_properties_[j] = properties;
01303 }
01304 
01305 template<class Scalar>
01306 void ModelEvaluatorBase::OutArgs<Scalar>::_set_DgDp_properties( int j, int l, const DerivativeProperties &properties )
01307 {
01308   assert_supports(OUT_ARG_DgDp,j,l);
01309   DgDp_properties_[ j*Np()+ l ] = properties;
01310 }
01311 
01312 template<class Scalar>
01313 void ModelEvaluatorBase::OutArgs<Scalar>::_setSupports( const OutArgs<Scalar>& outArgs )
01314 {
01315   std::copy( &outArgs.supports_[0], &outArgs.supports_[0] + NUM_E_OUT_ARGS_MEMBERS, &supports_[0] );
01316   supports_DfDp_ = outArgs.supports_DfDp_;
01317   supports_DgDx_ = outArgs.supports_DgDx_;
01318   supports_DgDp_ = outArgs.supports_DgDp_;
01319   W_properties_ = outArgs.W_properties_;
01320   DfDp_properties_ = outArgs.DfDp_properties_;
01321   DgDx_properties_ = outArgs.DgDx_properties_;
01322   DgDp_properties_ = outArgs.DgDp_properties_;
01323 }
01324 
01325 template<class Scalar>
01326 void ModelEvaluatorBase::OutArgs<Scalar>::_setUnsupportsAndRelated( EInArgsMembers arg )
01327 {
01328   switch(arg) {
01329     case IN_ARG_x: {
01330       const int Ng = this->Ng();
01331       for( int j = 0; j < Ng; ++j )
01332         this->_setSupports(OUT_ARG_DgDx,j,DerivativeSupport());
01333       break;
01334     }
01335     default:
01336       TEST_FOR_EXCEPTION(
01337         true ,std::logic_error
01338         ,"Error, can handle args other than IN_ARG_x yet!"
01339         );
01340   }
01341 }
01342 
01343 template<class Scalar>
01344 void ModelEvaluatorBase::OutArgs<Scalar>::_setUnsupportsAndRelated( EOutArgsMembers arg )
01345 {
01346   this->_setSupports(arg,false);
01347   switch(arg) {
01348     case OUT_ARG_f: {
01349       this->_setSupports(OUT_ARG_W,false);
01350       this->_setSupports(OUT_ARG_W_op,false);
01351       this->_setSupports(OUT_ARG_f_poly,false);
01352       const int Np = this->Np();
01353       for( int l = 0; l < Np; ++l )
01354         this->_setSupports(OUT_ARG_DfDp,l,DerivativeSupport());
01355       break;
01356     }
01357     default:
01358       TEST_FOR_EXCEPTION(
01359         true ,std::logic_error
01360         ,"Error, can handle args other than OUT_ARG_f yet!"
01361         );
01362   }
01363 }
01364 
01365 // private
01366 
01367 template<class Scalar>
01368 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(EOutArgsMembers arg) const
01369 {
01370   TEST_FOR_EXCEPTION(
01371     !this->supports(arg), std::logic_error
01372     ,"Thyra::ModelEvaluatorBase::OutArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(arg): "
01373     "model = \'"<<modelEvalDescription_<<"\': Error,"
01374     "The argument arg = " << toString(arg) << " is not supported!"
01375     );
01376 }
01377 
01378 template<class Scalar>
01379 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(EOutArgsDfDp arg, int l) const
01380 {
01381   TEST_FOR_EXCEPTION(
01382     this->supports(arg,l).none(), std::logic_error
01383     ,"Thyra::ModelEvaluatorBase::OutArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(OUT_ARG_DfDp,l): "
01384     "model = \'"<<modelEvalDescription_<<"\': Error,"
01385     "The argument DfDp(l) with index l = " << l << " is not supported!"
01386     );
01387 }
01388 
01389 template<class Scalar>
01390 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(EOutArgsDgDx arg, int j) const
01391 {
01392   TEST_FOR_EXCEPTION(
01393     this->supports(arg,j).none(), std::logic_error
01394     ,"Thyra::ModelEvaluatorBase::OutArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(OUT_ARG_DgDx,j): "
01395     "model = \'"<<modelEvalDescription_<<"\': Error,"
01396     "The argument DgDx(j) with index j = " << j << " is not supported!"
01397     );
01398 }
01399 
01400 template<class Scalar>
01401 void ModelEvaluatorBase::OutArgs<Scalar>::assert_supports(EOutArgsDgDp arg, int j, int l) const
01402 {
01403   TEST_FOR_EXCEPTION(
01404     this->supports(arg,j,l).none(), std::logic_error
01405     ,"Thyra::ModelEvaluatorBase::OutArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_supports(OUT_ARG_DgDp,j,l): "
01406     "model = \'"<<modelEvalDescription_<<"\': Error,"
01407     "The argument DgDp(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
01408     );
01409 }
01410 
01411 template<class Scalar>
01412 void ModelEvaluatorBase::OutArgs<Scalar>::assert_l(int l) const
01413 {
01414   TEST_FOR_EXCEPTION(
01415     !( 0 <= l && l < Np() ), std::logic_error
01416     ,"Thyra::ModelEvaluatorBase::OutArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_l(l): "
01417     "model = \'"<<modelEvalDescription_<<"\': Error, "
01418     "The parameter subvector p(l) index l = " << l << " is not in the range [0,"<<Np()-1<<"]!"
01419     );
01420 }
01421 
01422 template<class Scalar>
01423 void ModelEvaluatorBase::OutArgs<Scalar>::assert_j(int j) const
01424 {
01425   TEST_FOR_EXCEPTION(
01426     !( 0 <= j && j < Ng() ), std::logic_error
01427     ,"Thyra::ModelEvaluatorBase::OutArgs<" << Teuchos::ScalarTraits<Scalar>::name() <<">::assert_j(j): "
01428     "model = \'"<<modelEvalDescription_<<"\': Error, "
01429     "The auxiliary function g(j) index j = " << j << " is not in the range [0,"<<Ng()-1<<"]!"
01430     );
01431 }
01432 
01433 //
01434 // ModelEvaluatorBase::InArgsSetup
01435 //
01436 
01437 template<class Scalar>
01438 ModelEvaluatorBase::InArgsSetup<Scalar>::InArgsSetup()
01439 {}
01440 
01441 template<class Scalar>
01442 ModelEvaluatorBase::InArgsSetup<Scalar>::InArgsSetup( const InArgs<Scalar>& inArgs )
01443   :InArgs<Scalar>(inArgs)
01444 {}
01445 
01446 template<class Scalar>
01447 void ModelEvaluatorBase::InArgsSetup<Scalar>::setModelEvalDescription( const std::string &modelEvalDescription )
01448 { this->_setModelEvalDescription(modelEvalDescription); }
01449 
01450 template<class Scalar>
01451 void ModelEvaluatorBase::InArgsSetup<Scalar>::set_Np(int Np)
01452 { this->_set_Np(Np); }
01453 
01454 template<class Scalar>
01455 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports( EInArgsMembers arg, bool supports )
01456 { this->_setSupports(arg,supports); }
01457 
01458 template<class Scalar>
01459 void ModelEvaluatorBase::InArgsSetup<Scalar>::setSupports( const InArgs<Scalar>& inArgs )
01460 { this->_setSupports(inArgs); }
01461 
01462 template<class Scalar>
01463 void ModelEvaluatorBase::InArgsSetup<Scalar>::setUnsupportsAndRelated( EInArgsMembers arg )
01464 { this->_setUnsupportsAndRelated(arg); }
01465 
01466 //
01467 // ModelEvaluatorBase::OutArgsSetup
01468 //
01469 
01470 template<class Scalar>
01471 ModelEvaluatorBase::OutArgsSetup<Scalar>::OutArgsSetup()
01472 {}
01473 
01474 template<class Scalar>
01475 ModelEvaluatorBase::OutArgsSetup<Scalar>::OutArgsSetup( const OutArgs<Scalar>& outArgs )
01476   :OutArgs<Scalar>(outArgs)
01477 {}
01478 
01479 template<class Scalar>
01480 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setModelEvalDescription( const std::string &modelEvalDescription )
01481 { this->_setModelEvalDescription(modelEvalDescription); }
01482 
01483 template<class Scalar>
01484 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_Np_Ng(int Np, int Ng)
01485 { this->_set_Np_Ng(Np,Ng); }
01486 
01487 template<class Scalar>
01488 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( EOutArgsMembers arg, bool supports )
01489 { this->_setSupports(arg,supports); }
01490 
01491 template<class Scalar>
01492 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( EOutArgsDfDp arg, int l, const DerivativeSupport& supports )
01493 { this->_setSupports(arg,l,supports); }
01494 
01495 template<class Scalar>
01496 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( EOutArgsDgDx arg, int j, const DerivativeSupport& supports )
01497 { this->_setSupports(arg,j,supports); }
01498 
01499 template<class Scalar>
01500 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports )
01501 { this->_setSupports(arg,j,l,supports); }
01502 
01503 template<class Scalar>
01504 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_W_properties( const DerivativeProperties &properties )
01505 { this->_set_W_properties(properties); }
01506 
01507 template<class Scalar>
01508 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DfDp_properties( int l, const DerivativeProperties &properties )
01509 { this->_set_DfDp_properties(l,properties); }
01510 
01511 template<class Scalar>
01512 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDx_properties( int j, const DerivativeProperties &properties )
01513 { this->_set_DgDx_properties(j,properties); }
01514 
01515 template<class Scalar>
01516 void ModelEvaluatorBase::OutArgsSetup<Scalar>::set_DgDp_properties( int j, int l, const DerivativeProperties &properties )
01517 { this->_set_DgDp_properties(j,l,properties); }
01518 
01519 template<class Scalar>
01520 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setSupports( const OutArgs<Scalar>& outArgs )
01521 { this->_setSupports(outArgs); }
01522 
01523 template<class Scalar>
01524 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setUnsupportsAndRelated( EInArgsMembers arg )
01525 { this->_setUnsupportsAndRelated(arg); }
01526 
01527 template<class Scalar>
01528 void ModelEvaluatorBase::OutArgsSetup<Scalar>::setUnsupportsAndRelated( EOutArgsMembers arg )
01529 { this->_setUnsupportsAndRelated(arg); }
01530 
01531 } // namespace Thyra
01532 
01533 #endif // THYRA_MODEL_EVALUATOR_BASE_HPP

Generated on Thu Sep 18 12:33:03 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1