46 #include "NLPInterfacePack_ExampleNLPDirect.hpp"
47 #include "ExampleNLPDirectRTOps.h"
48 #include "AbstractLinAlgPack_BasisSystemComposite.hpp"
49 #include "AbstractLinAlgPack_VectorMutable.hpp"
50 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp"
51 #include "AbstractLinAlgPack_VectorStdOps.hpp"
52 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
53 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
54 #include "RTOpPack_RTOpC.hpp"
55 #include "Teuchos_dyn_cast.hpp"
56 #include "Teuchos_Assert.hpp"
57 #include "Teuchos_AbstractFactoryStd.hpp"
63 class init_rtop_server_t {
65 init_rtop_server_t() {
69 init_rtop_server_t init_rtop_server;
73 namespace NLPInterfacePack {
76 const VectorSpace::space_ptr_t& vec_space
83 namespace rcp = MemMngPack;
149 using LinAlgOpPack::Vp_MtV;
151 assert_is_initialized();
160 x.dim() !=
n, std::invalid_argument
161 ,
"ExampleNLPDirect::calc_point(...), Error x.dim() = " << x.dim()
162 <<
" != n = " <<
n );
164 c && !this->
space_c()->is_compatible(c->space()), std::invalid_argument
165 ,
"ExampleNLPDirect::calc_point(...), Error c is not compatible" );
166 TEUCHOS_TEST_FOR_EXCEPTION(
167 Gf && !this->
space_x()->is_compatible(Gf->space()), std::invalid_argument
168 ,
"ExampleNLPDirect::calc_point(...), Error, Gf is not compatible" );
169 TEUCHOS_TEST_FOR_EXCEPTION(
170 py && !this->
space_x()->sub_space(this->
var_dep())->is_compatible(py->space()), std::invalid_argument
171 ,
"ExampleNLPDirect::calc_point(...), Error, py is not compatible" );
172 TEUCHOS_TEST_FOR_EXCEPTION(
173 rGf && !this->
space_x()->sub_space(this->
var_dep())->is_compatible(rGf->space()), std::invalid_argument
174 ,
"ExampleNLPDirect::calc_point(...), Error, py is not compatible" );
175 TEUCHOS_TEST_FOR_EXCEPTION(
176 GcU, std::invalid_argument
177 ,
"ExampleNLPDirect::calc_point(...), Error, there are no undecomposed equalities" );
178 TEUCHOS_TEST_FOR_EXCEPTION(
179 D && !dynamic_cast<MatrixSymDiagStd*>(D), std::invalid_argument
180 ,
"ExampleNLPDirect::calc_point(...), Error, D is not compatible" );
181 TEUCHOS_TEST_FOR_EXCEPTION(
182 py!=NULL && c==NULL, std::invalid_argument
183 ,
"ExampleNLPDirect::calc_point(...) : "
184 "Error, if py!=NULL then c!=NULL must also be true" );
193 VectorSpace::vec_mut_ptr_t Gf_ptr;
195 Gf_ptr = this->
space_x()->create_member();
200 mat_fcty_ptr_t::element_type::obj_ptr_t D_ptr;
207 value_type *f_saved =
const_cast<this_t*
>(
this)->
get_f();
208 VectorMutable *c_saved =
const_cast<this_t*
>(
this)->
get_c();
209 VectorMutable *Gf_saved =
const_cast<this_t*
>(
this)->
get_Gf();
211 const_cast<this_t*
>(
this)->
set_f(f);
212 const_cast<this_t*
>(
this)->
set_c(c);
213 const_cast<this_t*
>(
this)->
set_Gf(Gf);
221 const_cast<this_t*
>(
this)->
set_f(f_saved);
222 const_cast<this_t*
>(
this)->
set_c(c_saved);
223 const_cast<this_t*
>(
this)->
set_Gf(Gf_saved);
242 *D_diag =
dynamic_cast<MatrixSymDiagStd*
>(D);
245 xD= x.sub_view(this->
var_dep()),
249 if ( py && !D ) task = 0;
250 else if( !py && D ) task = 1;
251 else if( py && D ) task = 2;
255 const int num_vecs = task < 2 ? 2 : 3;
256 const Vector* vecs[3] = { NULL, NULL, NULL };
257 const int num_targ_vecs = task < 2 ? 1 : 2;
258 VectorMutable* targ_vecs[2] = { NULL, NULL };
262 D_diag->init_identity( *this->
space_c(), 0.0 );
263 targ_vecs[0]= &D_diag->diag();
275 vecs[k] = xD.get(); ++k;
276 if(D) { vecs[k] = xI.get(); ++k; }
277 if(py) { vecs[k] =
c; ++k; }
279 AbstractLinAlgPack::apply_op(
280 explnlp2_calc_py_D_op, num_vecs, vecs, num_targ_vecs, num_targ_vecs?targ_vecs:NULL
300 calc_point(x,NULL,c,recalc_c,NULL,py,NULL,NULL,NULL,NULL);
void initialize(bool test_setup)
virtual void calc_c(const Vector &x, bool newx=true) const
void initialize(bool test_setup)
void calc_semi_newton_step(const Vector &x, VectorMutable *c, bool recalc_c, VectorMutable *py) const
const mat_fcty_ptr_t factory_D() const
void set_factories(const mat_sym_fcty_ptr_t &factory_transDtD, const mat_sym_nonsing_fcty_ptr_t &factory_S)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int RTOp_TOp_explnlp2_calc_py_D_set_task(int task, struct RTOp_RTOp *op)
T_To & dyn_cast(T_From &from)
virtual Range1D var_dep() const
virtual VectorMutable * get_Gf()
ExampleNLPDirect(const VectorSpace::space_ptr_t &vec_space, value_type xo, bool has_bounds, bool dep_bounded)
Constructor.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int RTOp_TOp_explnlp2_calc_py_D_construct(int task, struct RTOp_RTOp *op)
virtual void calc_f(const Vector &x, bool newx=true) const
virtual void set_c(VectorMutable *c)
Simple example NLP subclass to illustrate how to implement the NLPObjGrad interface for a specialized...
bool is_initialized() const
virtual value_type * get_f()
virtual Range1D var_indep() const
vec_space_ptr_t space_x() const
void initialize(bool test_setup)
vec_space_ptr_t space_c() const
Simple example NLP subclass to illustrate how to implement the NLPDirect interface for a specialized ...
virtual VectorMutable * get_c()
virtual void set_Gf(VectorMutable *Gf)
virtual void set_f(value_type *f)
virtual void calc_Gf(const Vector &x, bool newx=true) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void calc_point(const Vector &x, value_type *f, VectorMutable *c, bool recalc_c, VectorMutable *Gf, VectorMutable *py, VectorMutable *rGf, MatrixOp *GcU, MatrixOp *D, MatrixOp *Uz) const
virtual VectorMutable & c()
Range1D var_indep() const