NLPInterfacePack_NLPSerialPreprocessExplJac.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 NLP_SERIAL_PREPROCESS_EXPL_JAC_H
00030 #define NLP_SERIAL_PREPROCESS_EXPL_JAC_H
00031 
00032 #include <valarray>
00033 
00034 #include "NLPInterfacePack_NLPSerialPreprocess.hpp"
00035 #include "NLPInterfacePack_NLPFirstOrder.hpp"
00036 #include "AbstractLinAlgPack_BasisSystemFactoryStd.hpp"
00037 #include "DenseLinAlgPack_DVectorClass.hpp"
00038 #include "Teuchos_AbstractFactory.hpp"
00039 #include "Teuchos_StandardCompositionMacros.hpp"
00040 
00041 namespace NLPInterfacePack {
00042 
00080 class NLPSerialPreprocessExplJac
00081   : virtual public NLPSerialPreprocess
00082   , virtual public NLPFirstOrder
00083 {
00084 public:
00085 
00088   
00090   typedef Teuchos::RCP<
00091     const Teuchos::AbstractFactory<MatrixOp> >    factory_mat_ptr_t;
00092 
00094 
00097 
00099   STANDARD_COMPOSITION_MEMBERS( BasisSystemFactory, basis_sys_fcty );
00100 
00103   NLPSerialPreprocessExplJac(
00104     const basis_sys_fcty_ptr_t  &basis_sys_fcty  = Teuchos::rcp(new BasisSystemFactoryStd())
00105     ,const factory_mat_ptr_t    &factory_Gc_full = Teuchos::null
00106     );
00107 
00118   void set_factory_Gc_full( const factory_mat_ptr_t &factory_Gc_full );
00119 
00121 
00124 
00126   void set_options( const options_ptr_t& options );
00128   const options_ptr_t& get_options() const;
00130   void initialize(bool test_setup); 
00132   bool is_initialized() const;
00133 
00135 
00138   
00140   const mat_fcty_ptr_t factory_Gc() const;
00142   const basis_sys_ptr_t basis_sys() const;
00144   void set_Gc(MatrixOp* Gc);
00145 
00147 
00150 
00152   bool get_next_basis(
00153     Permutation*  P_var,   Range1D* var_dep
00154     ,Permutation* P_equ,   Range1D* equ_decomp
00155     );
00157   void set_basis(
00158     const Permutation   &P_var,   const Range1D  &var_dep
00159     ,const Permutation  *P_equ,   const Range1D  *equ_decomp
00160     );
00161 
00163 
00164 
00165 protected:
00166 
00169 
00171   void imp_calc_Gc(
00172     const Vector& x, bool newx
00173     ,const FirstOrderInfo& first_order_info
00174     ) const;
00175   
00177 
00180 
00214   struct FirstOrderExplInfo {
00216     typedef std::valarray<value_type>    val_t;
00218     typedef std::valarray<index_type>    ivect_t;
00219     //
00220     typedef std::valarray<index_type>    jvect_t;
00222     FirstOrderExplInfo()
00223       :Gc_val(NULL), Gc_ivect(NULL), Gc_jvect(NULL)
00224       ,Gh_val(NULL), Gh_ivect(NULL), Gh_jvect(NULL)
00225       ,f(NULL)
00226     {}
00228     FirstOrderExplInfo(
00229       index_type* Gc_nz_in, val_t* Gc_val_in, ivect_t* Gc_ivect_in, jvect_t* Gc_jvect_in
00230       ,index_type* Gh_nz_in, val_t* Gh_val_in, ivect_t* Gh_ivect_in, jvect_t* Gh_jvect_in
00231       ,const ObjGradInfoSerial& obj_grad
00232       )
00233       :Gc_nz(Gc_nz_in), Gc_val(Gc_val_in), Gc_ivect(Gc_ivect_in), Gc_jvect(Gc_jvect_in)
00234       ,Gh_nz(Gh_nz_in), Gh_val(Gh_val_in), Gh_ivect(Gh_ivect_in), Gh_jvect(Gh_jvect_in)
00235       ,Gf(obj_grad.Gf), f(obj_grad.f), c(obj_grad.c), h(obj_grad.h)
00236     {}
00238     size_type*    Gc_nz;
00240     val_t*        Gc_val;
00242     ivect_t*      Gc_ivect;
00244     jvect_t*      Gc_jvect;
00246     size_type*    Gh_nz;
00248     val_t*        Gh_val;
00250     ivect_t*      Gh_ivect;
00252     jvect_t*      Gh_jvect;
00254     DVector*       Gf;
00256     value_type*   f;
00258     DVector*       c;
00260     DVector*       h;
00261   }; // end struct FirstOrderExplInfo
00262 
00264 
00267 
00274   virtual size_type imp_Gc_nz_orig() const = 0;
00275 
00282   virtual size_type imp_Gh_nz_orig() const = 0;
00283 
00324   virtual void imp_calc_Gc_orig(
00325     const DVectorSlice& x_full, bool newx
00326     , const FirstOrderExplInfo& first_order_expl_info
00327     ) const = 0;
00328 
00369   virtual void imp_calc_Gh_orig(
00370     const DVectorSlice& x_full, bool newx
00371     , const FirstOrderExplInfo& first_order_expl_info
00372     ) const = 0;
00373 
00375 
00378 
00380   void assert_initialized() const;
00381 
00383   const FirstOrderExplInfo first_order_expl_info() const;
00384 
00386 
00387 private:
00388 
00389   // ////////////////////////////////////////
00390   // Private data members
00391   
00392   bool initialized_;              // Flag for if the NLP has has been properly initialized
00393   bool test_setup_;               // Flag for if to test the setup of things or not
00394   options_ptr_t options_;         // The options being used
00395 
00396   factory_mat_ptr_t   factory_Gc_full_;
00397   mat_fcty_ptr_t      factory_Gc_;
00398 
00399   mutable size_type   Gc_nz_orig_;    // Number of nonzeros in the original NLP Gc
00400   mutable size_type   Gh_nz_orig_;    // Number of nonzeros in the original NLP Gh
00401   mutable size_type   Gc_nz_full_;    // Number of nonzeros in the full NLP Gc
00402   mutable size_type   Gh_nz_full_;    // Number of nonzeros in the full NLP Gh
00403   mutable FirstOrderExplInfo::val_t    Gc_val_orig_;   // Storage for explicit nonzeros of full Gc
00404   mutable FirstOrderExplInfo::ivect_t  Gc_ivect_orig_;
00405   mutable FirstOrderExplInfo::jvect_t  Gc_jvect_orig_;
00406   mutable FirstOrderExplInfo::val_t    Gh_val_orig_;   // Storage for explicit nonzeros of orig Gh
00407   mutable FirstOrderExplInfo::ivect_t  Gh_ivect_orig_;
00408   mutable FirstOrderExplInfo::jvect_t  Gh_jvect_orig_;
00409 
00410   mutable bool                         Gc_perm_new_basis_updated_;  // Flag for if a new basis was set!
00411 
00412   // ////////////////////////////
00413   // Private member functions
00414 
00415   //
00416   void imp_calc_Gc_or_Gh(
00417     bool calc_Gc
00418     ,const Vector& x, bool newx
00419     ,const FirstOrderInfo& first_order_info
00420     ) const;
00421 
00422   //
00423   void imp_fill_jacobian_entries(
00424     size_type           n             // [in]
00425     ,size_type          n_full        // [in]
00426     ,bool               load_struct   // [in] If true, then the structure is loaded also
00427     ,const index_type   col_offset    // [in] Offset for filled column indexes
00428     ,const value_type   *val_full     // [in] Values (!=NULL)
00429     ,const value_type   *val_full_end // [in] Values end (!=NULL)
00430     ,const index_type   *ivect_full   // [in] Row indexes (!=NULL)
00431     ,const index_type   *jvect_full   // [in] Column indexes (!=NULL)
00432     ,index_type         *nz           // [in/out] Number of nonzeros added (!=NULL)            
00433     ,value_type         *val_itr      // [out] Values to fill (!=NULL)
00434     ,index_type         *ivect_itr    // [out] Row indexes (can be NULL if load_struct == false)
00435     ,index_type         *jvect_itr    // [out] Column indexes  (can be NULL if load_struct == false)
00436     ) const;
00437 
00438 };  // end class NLPSerialPreprocessExplJac
00439 
00440 // ///////////////////////////
00441 // inline members
00442 
00443 inline
00444 const NLPSerialPreprocessExplJac::FirstOrderExplInfo
00445 NLPSerialPreprocessExplJac::first_order_expl_info() const
00446 {
00447   return FirstOrderExplInfo(
00448     &Gc_nz_orig_
00449     ,&Gc_val_orig_
00450     ,&Gc_ivect_orig_
00451     ,&Gc_jvect_orig_
00452     ,&Gh_nz_orig_
00453     ,&Gh_val_orig_
00454     ,&Gh_ivect_orig_
00455     ,&Gh_jvect_orig_
00456     ,obj_grad_orig_info()
00457     );
00458 }
00459 
00460 } // end namespace NLPInterfacePack 
00461 
00462 #endif // NLP_SERIAL_PREPROCESS_EXPL_JAC_H

Generated on Tue Oct 20 12:51:48 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7