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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
00043 #define NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
00044 
00045 #include <vector>
00046 
00047 #include "NLPInterfacePack_NLPFirstOrder.hpp"
00048 #include "AbstractLinAlgPack_VectorSpace.hpp"
00049 #include "Thyra_ModelEvaluator.hpp"
00050 #include "Teuchos_Assert.hpp"
00051 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00052 
00053 namespace AbstractLinAlgPack { class VectorSpaceThyra; }
00054 
00055 namespace NLPInterfacePack {
00056 
00092 class NLPThyraModelEvaluatorBase : virtual public NLPObjGrad {
00093 public:
00094 
00096   STANDARD_MEMBER_COMPOSITION_MEMBERS( bool, showModelEvaluatorTrace );
00097 
00100 
00102   void initialize(bool test_setup);
00104   bool is_initialized() const;
00106   vec_space_ptr_t space_x() const;
00108   vec_space_ptr_t space_c() const;
00110     size_type num_bounded_x() const;
00112   void force_xinit_in_bounds(bool force_xinit_in_bounds);
00114   bool force_xinit_in_bounds() const;
00116   const Vector& xinit() const;
00118   const Vector& xl() const;
00120   const Vector& xu() const;
00122   value_type max_var_bounds_viol() const;
00124   void set_f(value_type* f);
00126   void set_c(VectorMutable* c);
00128   void unset_quantities();
00130   void scale_f( value_type scale_f );
00132   value_type scale_f() const;
00134   void report_final_solution(
00135     const Vector&    x
00136     ,const Vector*   lambda
00137     ,const Vector*   nu
00138     ,bool            optimal
00139     );
00140 
00142 
00145 
00147   void set_Gf(VectorMutable* Gf);
00148 
00150 
00151 protected:
00152 
00155 
00157   void imp_calc_f(
00158     const Vector& x, bool newx
00159     ,const ZeroOrderInfo& zero_order_info) const;
00161   void imp_calc_c(
00162     const Vector& x, bool newx
00163     ,const ZeroOrderInfo& zero_order_info) const;
00164 
00166 
00169 
00171   void imp_calc_Gf(
00172     const Vector& x, bool newx
00173     ,const ObjGradInfo& obj_grad_info) const;
00174 
00176 
00177 protected:
00178 
00181 
00183   NLPThyraModelEvaluatorBase();
00184 
00205   void initializeBase(
00206     const Teuchos::RCP<Thyra::ModelEvaluator<value_type> >  &model
00207     ,const int                                                      p_idx
00208     ,const int                                                      g_idx
00209     );
00210 
00212   void updateInitialGuessAndBounds() const;
00213 
00215   void assert_is_initialized() const;
00217   void copy_from_model_x( const Thyra::VectorBase<value_type>* model_x, VectorMutable* x_D ) const;
00219   void copy_from_model_p( const Thyra::VectorBase<value_type> *model_p, VectorMutable* x_I ) const;
00221   void set_x(
00222     const Vector                                      &x
00223     ,Thyra::ModelEvaluatorBase::InArgs<value_type>    *model_inArgs_inout
00224     ) const;
00226   void preprocessBaseInOutArgs(
00227     const Vector                                      &x
00228     ,bool                                             newx
00229     ,const ZeroOrderInfo                              *zero_order_info
00230     ,const ObjGradInfo                                *obj_grad_info
00231     ,const NLPFirstOrder::FirstOrderInfo              *first_order_info
00232     ,Thyra::ModelEvaluatorBase::InArgs<value_type>    *model_inArgs_inout
00233     ,Thyra::ModelEvaluatorBase::OutArgs<value_type>   *model_outArgs_inout
00234     ,MatrixOp*                                        *Gc_out
00235     ,VectorMutable*                                   *Gf_out
00236     ,value_type*                                      *f_out
00237     ,VectorMutable*                                   *c_out
00238     ) const;
00240   void postprocessBaseOutArgs(
00241     Thyra::ModelEvaluatorBase::OutArgs<value_type>        *model_outArgs_inout
00242     ,VectorMutable                                        *Gf
00243     ,value_type                                           *f
00244     ,VectorMutable                                        *c
00245     ) const;
00246     
00248 
00249 //private: // ToDo: Make these private and refactor the other classes ...
00250 
00251   // /////////////////////////////////////////
00252   // Private types
00253 
00254   typedef Teuchos::RCP<const AbstractLinAlgPack::VectorSpaceThyra> VectorSpaceThyra_ptr_t;
00255 
00256   // /////////////////////////////////////////
00257   // Private data members
00258 
00259   bool                                initialized_;  // flag for if initialized has been called.
00260   value_type                          obj_scale_;    // default = 1.0;
00261   bool                                has_bounds_;   // True if has bounds
00262   bool                                force_xinit_in_bounds_; // default = true.
00263   index_type                          num_bounded_x_;
00264   Teuchos::RCP<Thyra::ModelEvaluator<value_type> >
00265                                       model_;
00266   int                                 p_idx_;
00267   int                                 g_idx_;
00268   bool                                DfDp_supports_op_;
00269   bool                                DfDp_supports_mv_;
00270   VectorSpace::space_ptr_t            space_x_;      // Space for the variables
00271   VectorSpaceThyra_ptr_t              space_c_;      // Space for the constraints
00272   NLPFirstOrder::mat_fcty_ptr_t       factory_Gc_;   // Factory for Gc
00273   NLPFirstOrder::basis_sys_ptr_t      basis_sys_;    // The basis system
00274   mutable bool                        x_guess_bounds_updated_;
00275   VectorSpace::vec_mut_ptr_t          xinit_;        // Initial guess.
00276   VectorSpace::vec_mut_ptr_t          xl_;           // lower bounds.
00277   VectorSpace::vec_mut_ptr_t          xu_;           // upper bounds.
00278 
00279   Teuchos::RCP<Thyra::VectorBase<value_type> >                     model_g_;
00280 
00281   mutable bool model_g_updated_;
00282   mutable bool model_Dg_updated_;
00283 
00284   mutable bool f_updated_;
00285   mutable bool c_updated_;
00286   mutable bool Gf_updated_;
00287   mutable bool Gc_updated_;
00288 
00289   // /////////////////////////////////////////
00290   // Private member functions
00291 
00293   void evalModel( 
00294     const Vector            &x
00295     ,bool                   newx
00296     ,const ZeroOrderInfo    *zero_order_info  // != NULL if only zero-order info
00297     ,const ObjGradInfo      *obj_grad_info    // != NULL if obj-grad and below info
00298     ) const;
00299 
00300 };  // end class NLPThyraModelEvaluatorBase
00301 
00302 } // end namespace NLPInterfacePack
00303 
00304 #endif  // NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines