00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 };
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
00391
00392 bool initialized_;
00393 bool test_setup_;
00394 options_ptr_t options_;
00395
00396 factory_mat_ptr_t factory_Gc_full_;
00397 mat_fcty_ptr_t factory_Gc_;
00398
00399 mutable size_type Gc_nz_orig_;
00400 mutable size_type Gh_nz_orig_;
00401 mutable size_type Gc_nz_full_;
00402 mutable size_type Gh_nz_full_;
00403 mutable FirstOrderExplInfo::val_t Gc_val_orig_;
00404 mutable FirstOrderExplInfo::ivect_t Gc_ivect_orig_;
00405 mutable FirstOrderExplInfo::jvect_t Gc_jvect_orig_;
00406 mutable FirstOrderExplInfo::val_t Gh_val_orig_;
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_;
00411
00412
00413
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
00425 ,size_type n_full
00426 ,bool load_struct
00427 ,const index_type col_offset
00428 ,const value_type *val_full
00429 ,const value_type *val_full_end
00430 ,const index_type *ivect_full
00431 ,const index_type *jvect_full
00432 ,index_type *nz
00433 ,value_type *val_itr
00434 ,index_type *ivect_itr
00435 ,index_type *jvect_itr
00436 ) const;
00437
00438 };
00439
00440
00441
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 }
00461
00462 #endif // NLP_SERIAL_PREPROCESS_EXPL_JAC_H