MOOCHO (Single Doxygen Collection) Version of the Day
NLPInterfacePack_NLPThyraModelEvaluatorBase.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
00030 #define NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
00031 
00032 #include <vector>
00033 
00034 #include "NLPInterfacePack_NLPFirstOrder.hpp"
00035 #include "AbstractLinAlgPack_VectorSpace.hpp"
00036 #include "Thyra_ModelEvaluator.hpp"
00037 #include "Teuchos_TestForException.hpp"
00038 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00039 
00040 namespace AbstractLinAlgPack { class VectorSpaceThyra; }
00041 
00042 namespace NLPInterfacePack {
00043 
00079 class NLPThyraModelEvaluatorBase : virtual public NLPObjGrad {
00080 public:
00081 
00083   STANDARD_MEMBER_COMPOSITION_MEMBERS( bool, showModelEvaluatorTrace );
00084 
00087 
00089   void initialize(bool test_setup);
00091   bool is_initialized() const;
00093   vec_space_ptr_t space_x() const;
00095   vec_space_ptr_t space_c() const;
00097     size_type num_bounded_x() const;
00099   void force_xinit_in_bounds(bool force_xinit_in_bounds);
00101   bool force_xinit_in_bounds() const;
00103   const Vector& xinit() const;
00105   const Vector& xl() const;
00107   const Vector& xu() const;
00109   value_type max_var_bounds_viol() const;
00111   void set_f(value_type* f);
00113   void set_c(VectorMutable* c);
00115   void unset_quantities();
00117   void scale_f( value_type scale_f );
00119   value_type scale_f() const;
00121   void report_final_solution(
00122     const Vector&    x
00123     ,const Vector*   lambda
00124     ,const Vector*   nu
00125     ,bool            optimal
00126     );
00127 
00129 
00132 
00134   void set_Gf(VectorMutable* Gf);
00135 
00137 
00138 protected:
00139 
00142 
00144   void imp_calc_f(
00145     const Vector& x, bool newx
00146     ,const ZeroOrderInfo& zero_order_info) const;
00148   void imp_calc_c(
00149     const Vector& x, bool newx
00150     ,const ZeroOrderInfo& zero_order_info) const;
00151 
00153 
00156 
00158   void imp_calc_Gf(
00159     const Vector& x, bool newx
00160     ,const ObjGradInfo& obj_grad_info) const;
00161 
00163 
00164 protected:
00165 
00168 
00170   NLPThyraModelEvaluatorBase();
00171 
00192   void initializeBase(
00193     const Teuchos::RCP<Thyra::ModelEvaluator<value_type> >  &model
00194     ,const int                                                      p_idx
00195     ,const int                                                      g_idx
00196     );
00197 
00199   void updateInitialGuessAndBounds() const;
00200 
00202   void assert_is_initialized() const;
00204   void copy_from_model_x( const Thyra::VectorBase<value_type>* model_x, VectorMutable* x_D ) const;
00206   void copy_from_model_p( const Thyra::VectorBase<value_type> *model_p, VectorMutable* x_I ) const;
00208   void set_x(
00209     const Vector                                      &x
00210     ,Thyra::ModelEvaluatorBase::InArgs<value_type>    *model_inArgs_inout
00211     ) const;
00213   void preprocessBaseInOutArgs(
00214     const Vector                                      &x
00215     ,bool                                             newx
00216     ,const ZeroOrderInfo                              *zero_order_info
00217     ,const ObjGradInfo                                *obj_grad_info
00218     ,const NLPFirstOrder::FirstOrderInfo              *first_order_info
00219     ,Thyra::ModelEvaluatorBase::InArgs<value_type>    *model_inArgs_inout
00220     ,Thyra::ModelEvaluatorBase::OutArgs<value_type>   *model_outArgs_inout
00221     ,MatrixOp*                                        *Gc_out
00222     ,VectorMutable*                                   *Gf_out
00223     ,value_type*                                      *f_out
00224     ,VectorMutable*                                   *c_out
00225     ) const;
00227   void postprocessBaseOutArgs(
00228     Thyra::ModelEvaluatorBase::OutArgs<value_type>        *model_outArgs_inout
00229     ,VectorMutable                                        *Gf
00230     ,value_type                                           *f
00231     ,VectorMutable                                        *c
00232     ) const;
00233     
00235 
00236 //private: // ToDo: Make these private and refactor the other classes ...
00237 
00238   // /////////////////////////////////////////
00239   // Private types
00240 
00241   typedef Teuchos::RCP<const AbstractLinAlgPack::VectorSpaceThyra> VectorSpaceThyra_ptr_t;
00242 
00243   // /////////////////////////////////////////
00244   // Private data members
00245 
00246   bool                                initialized_;  // flag for if initialized has been called.
00247   value_type                          obj_scale_;    // default = 1.0;
00248   bool                                has_bounds_;   // True if has bounds
00249   bool                                force_xinit_in_bounds_; // default = true.
00250   index_type                          num_bounded_x_;
00251   Teuchos::RCP<Thyra::ModelEvaluator<value_type> >
00252                                       model_;
00253   int                                 p_idx_;
00254   int                                 g_idx_;
00255   bool                                DfDp_supports_op_;
00256   bool                                DfDp_supports_mv_;
00257   VectorSpace::space_ptr_t            space_x_;      // Space for the variables
00258   VectorSpaceThyra_ptr_t              space_c_;      // Space for the constraints
00259   NLPFirstOrder::mat_fcty_ptr_t       factory_Gc_;   // Factory for Gc
00260   NLPFirstOrder::basis_sys_ptr_t      basis_sys_;    // The basis system
00261   mutable bool                        x_guess_bounds_updated_;
00262   VectorSpace::vec_mut_ptr_t          xinit_;        // Initial guess.
00263   VectorSpace::vec_mut_ptr_t          xl_;           // lower bounds.
00264   VectorSpace::vec_mut_ptr_t          xu_;           // upper bounds.
00265 
00266   Teuchos::RCP<Thyra::VectorBase<value_type> >                     model_g_;
00267 
00268   mutable bool model_g_updated_;
00269   mutable bool model_Dg_updated_;
00270 
00271   mutable bool f_updated_;
00272   mutable bool c_updated_;
00273   mutable bool Gf_updated_;
00274   mutable bool Gc_updated_;
00275 
00276   // /////////////////////////////////////////
00277   // Private member functions
00278 
00280   void evalModel( 
00281     const Vector            &x
00282     ,bool                   newx
00283     ,const ZeroOrderInfo    *zero_order_info  // != NULL if only zero-order info
00284     ,const ObjGradInfo      *obj_grad_info    // != NULL if obj-grad and below info
00285     ) const;
00286 
00287 };  // end class NLPThyraModelEvaluatorBase
00288 
00289 } // end namespace NLPInterfacePack
00290 
00291 #endif  // NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines