58 #include "Thyra_DetachedVectorView.hpp"
59 #include "Thyra_VectorStdOps.hpp"
64 namespace NLPInterfacePack {
173 typedef Thyra::ModelEvaluatorBase MEB;
175 MEB::InArgs<value_type> model_finalPoint =
model_->createInArgs();
180 RCP<const Vector> xD = x.
sub_view(var_dep), xI;
182 model_finalPoint.set_x(dyn_cast<const VectorMutableThyra>(*xD).thyra_vec().assert_not_null());
184 model_finalPoint.set_p(
p_idx_,dyn_cast<const VectorMutableThyra>(*xI).thyra_vec().assert_not_null());
185 else if( model_finalPoint.Np() >= 1 )
186 model_finalPoint.set_p(0,
model_->getNominalValues().get_p(0));
190 model_finalPoint.set_p(
p_idx_,dyn_cast<const VectorMutableThyra>(x).thyra_vec().assert_not_null());
192 model_->reportFinalPoint(model_finalPoint,optimal);
206 const Vector& x,
bool newx
214 const Vector& x,
bool newx
224 const Vector& x,
bool newx
234 :showModelEvaluatorTrace_(false),initialized_(false)
235 ,obj_scale_(1.0),has_bounds_(false)
236 ,force_xinit_in_bounds_(true),num_bounded_x_(0)
237 ,x_guess_bounds_updated_(false)
241 const Teuchos::RCP<Thyra::ModelEvaluator<value_type> > &model,
251 typedef ::Thyra::ModelEvaluatorBase MEB;
257 const char msg_err[] =
"NLPThyraModelEvaluatorBase::initialize(...): Errror!";
258 Thyra::ModelEvaluatorBase::OutArgs<value_type> model_outArgs = model->createOutArgs();
261 TEUCHOS_TEST_FOR_EXCEPTION( g_idx >= 0 && ( g_idx > model_outArgs.Ng()-1 ), std::invalid_argument, msg_err );
264 const bool no_model_x = (model_space_x.get() == NULL);
266 const bool no_model_f = (model_space_f.get() == NULL);
269 TEUCHOS_TEST_FOR_EXCEPTION( !model_outArgs.supports(MEB::OUT_ARG_W), std::invalid_argument, msg_err );
270 MEB::DerivativeProperties model_W_properties = model_outArgs.get_W_properties();
271 TEUCHOS_TEST_FOR_EXCEPTION( model_W_properties.supportsAdjoint==
false, std::invalid_argument, msg_err );
272 TEUCHOS_TEST_FOR_EXCEPTION( model_W_properties.rank==MEB::DERIV_RANK_DEFICIENT, std::invalid_argument, msg_err );
291 DfDp_supports_op_ = model_outArgs.supports(MEB::OUT_ARG_DfDp,p_idx).supports(MEB::DERIV_LINEAR_OP);
292 DfDp_supports_mv_ = model_outArgs.supports(MEB::OUT_ARG_DfDp,p_idx).supports(MEB::DERIV_MV_BY_COL);
299 VectorSpace::space_ptr_t space_xI;
302 VectorSpace::space_ptr_t space_xD;
305 space_xD =
Teuchos::rcp(
new VectorSpaceThyra(model_space_x));
307 VectorSpace::space_ptr_t spaces_xD_xI[] = { space_xD, space_xI };
333 new BasisSystemComposite(
364 typedef ::Thyra::ModelEvaluatorBase MEB;
369 Thyra::ModelEvaluatorBase::OutArgs<value_type>
370 model_outArgs =
model_->createOutArgs();
372 model_space_x =
model_->get_x_space();
374 no_model_x = (model_space_x.
get() == NULL);
376 model_space_f =
model_->get_f_space();
378 no_model_f = (model_space_f.
get() == NULL);
380 Thyra::ModelEvaluatorBase::InArgs<value_type>
381 model_initialGuess =
model_->getNominalValues(),
382 model_lowerBounds =
model_->getLowerBounds(),
383 model_upperBounds =
model_->getUpperBounds();
386 VectorSpace::vec_mut_ptr_t xinit_D =
xinit_->sub_view(
basis_sys_->var_dep());
388 VectorSpace::vec_mut_ptr_t xl_D =
xl_->sub_view(
basis_sys_->var_dep());
390 VectorSpace::vec_mut_ptr_t xu_D =
xu_->sub_view(
basis_sys_->var_dep());
396 VectorSpace::vec_mut_ptr_t xinit_I =
xinit_->sub_view(var_indep);
398 VectorSpace::vec_mut_ptr_t xl_I =
xl_->sub_view(var_indep);
400 VectorSpace::vec_mut_ptr_t xu_I =
xu_->sub_view(var_indep);
412 ,
"NLPThyraModelEvaluatorBase::assert_is_initialized() : Error, "
413 "NLPThyraModelEvaluatorBase::initialize() has not been called yet."
431 ,Thyra::ModelEvaluatorBase::InArgs<value_type> *model_inArgs_inout
436 using Teuchos::rcp_const_cast;
437 using Teuchos::rcp_dynamic_cast;
439 typedef Thyra::ModelEvaluatorBase MEB;
443 MEB::InArgs<value_type> &model_inArgs = *model_inArgs_inout;
448 RCP<const Vector> xD = x.
sub_view(var_dep), xI;
450 model_inArgs.set_x(dyn_cast<const VectorMutableThyra>(*xD).thyra_vec().assert_not_null());
452 model_inArgs.set_p(
p_idx_,dyn_cast<const VectorMutableThyra>(*xI).thyra_vec().assert_not_null());
456 model_inArgs.set_p(
p_idx_,dyn_cast<const VectorMutableThyra>(x).thyra_vec().assert_not_null());
466 ,Thyra::ModelEvaluatorBase::InArgs<value_type> *model_inArgs_inout
467 ,Thyra::ModelEvaluatorBase::OutArgs<value_type> *model_outArgs_inout
476 using Teuchos::rcp_const_cast;
477 using Teuchos::rcp_dynamic_cast;
481 typedef Thyra::ModelEvaluatorBase MEB;
482 typedef MEB::DerivativeMultiVector<value_type> DerivMV;
483 typedef MEB::Derivative<value_type> Deriv;
489 MEB::InArgs<value_type> &model_inArgs = *model_inArgs_inout;
490 set_x(x,&model_inArgs);
499 if(zero_order_info) {
500 f = zero_order_info->
f;
501 c = zero_order_info->
c;
503 else if(obj_grad_info) {
504 Gf = obj_grad_info->
Gf;
505 f = obj_grad_info->
f;
506 c = obj_grad_info->
c;
508 else if(first_order_info) {
509 Gc = first_order_info->
Gc;
510 Gf = first_order_info->
Gf;
511 f = first_order_info->
f;
512 c = first_order_info->
c;
518 MEB::OutArgs<value_type> &model_outArgs = *model_outArgs_inout;
533 if( var_dep.size() ) {
534 model_outArgs.set_DgDx(
537 rcp_const_cast<Thyra::VectorBase<value_type> >(
538 dyn_cast<VectorMutableThyra>(*Gf->
sub_view(var_dep)).thyra_vec()
540 ,MEB::DERIV_TRANS_MV_BY_ROW
544 model_outArgs.set_DgDp(
547 rcp_const_cast<Thyra::VectorBase<value_type> >(
548 dyn_cast<VectorMutableThyra>(*Gf->
sub_view(var_indep)).thyra_vec()
550 ,MEB::DERIV_TRANS_MV_BY_ROW
556 if(Gc_out) *Gc_out = Gc;
557 if(Gf_out) *Gf_out =
Gf;
558 if(f_out) *f_out =
f;
559 if(c_out) *c_out =
c;
563 Thyra::ModelEvaluatorBase::OutArgs<value_type> *model_outArgs_inout
569 typedef Thyra::ModelEvaluatorBase MEB;
570 MEB::OutArgs<value_type> &model_outArgs = *model_outArgs_inout;
582 thyra_c = model_outArgs.get_f();
615 typedef Thyra::ModelEvaluatorBase MEB;
620 out = this->getOStream();
625 VOTSME modelOutputTempState(
model_,out,verbLevel);
627 *out <<
"\nEntering MoochoPack::NLPThyraModelEvaluatorBase::evalModel(...) ...\n";
631 MEB::InArgs<value_type> model_inArgs =
model_->createInArgs();
632 MEB::OutArgs<value_type> model_outArgs =
model_->createOutArgs();
637 x,newx,zero_order_info,obj_grad_info,NULL
638 ,&model_inArgs,&model_outArgs,NULL,&Gf,&f,&c
643 model_->evalModel(model_inArgs,model_outArgs);
650 *out <<
"\nLeaving MoochoPack::NLPThyraModelEvaluatorBase::evalModel(...) ...\n";
void initialize(bool test_setup)
Initialize the NLP for its first use.
virtual value_type & f()
Returns non-const *this->get_f().
VectorSpace::vec_mut_ptr_t xl_
Teuchos::RCP< Thyra::VectorBase< value_type > > model_g_
virtual vec_ptr_t sub_view(const Range1D &rng) const
Create an abstract view of a vector object .
AbstractLinAlgPack::size_type size_type
VectorMutable * Gf
Pointer to gradient of objective function Gf (may be NULL if not set)
virtual vec_mut_ptr_t sub_view(const Range1D &rng)
Create a mutable abstract view of a vector object.
VectorMutable * c
Pointer to constraints residual c (Will be NULL if not set)
vec_space_ptr_t space_c() const
Struct for gradient (objective), objective and constriants (pointers)
value_type max_var_bounds_viol() const
index_type num_bounded_x_
MatrixOp * Gc
Pointer to Jacobian of equality constraints Gc (may be NULL if not set)
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
VectorMutable * c
Pointer to constraints residual c (may be NULL if not set)
void postprocessBaseOutArgs(Thyra::ModelEvaluatorBase::OutArgs< value_type > *model_outArgs_inout, VectorMutable *Gf, value_type *f, VectorMutable *c) const
VectorSpace::vec_mut_ptr_t xinit_
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
const Vector & xinit() const
VectorMutable * Gf
Pointer to gradient of objective function Gf (may be NULL if not set)
VectorSpace adapter subclass for Thyra::VectorSpaceBase<value_type> .
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initializeBase(const Teuchos::RCP< Thyra::ModelEvaluator< value_type > > &model, const int p_idx, const int g_idx)
Initialize given a Thyra::ModelEvaluator and a description of how to interpret it.
void initialize(bool test_setup)
value_type scale_f() const
void report_final_solution(const Vector &x, const Vector *lambda, const Vector *nu, bool optimal)
value_type * f
Pointer to objective function f (may be NULL if not set)
bool is_initialized() const
void get_thyra_vector(const VectorSpaceThyra &thyra_vec_spc, const Vector &vec, Teuchos::RCP< const Thyra::VectorBase< value_type > > *thyra_vec)
bool force_xinit_in_bounds_
virtual void unset_quantities()
Call to unset all storage quantities (both in this class and all subclasses).
void imp_calc_f(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
void commit_thyra_vector(const VectorSpaceThyra &thyra_vec_spc, VectorMutable *vec, Teuchos::RCP< Thyra::VectorBase< value_type > > *thyra_vec)
const Vector & xu() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void imp_calc_Gf(const Vector &x, bool newx, const ObjGradInfo &obj_grad_info) const
const Vector & xl() const
virtual void has_changed() const
Must be called by any vector subclass that modifies this vector object!
void copy_from_model_p(const Thyra::VectorBase< value_type > *model_p, VectorMutable *x_I) const
void copy_from_model_x(const Thyra::VectorBase< value_type > *model_x, VectorMutable *x_D) const
T_To & dyn_cast(T_From &from)
VectorMutable adapter subclass for Thyra::VectorBase.
Struct for zero and first order quantities (pointers)
virtual void set_c(VectorMutable *c)
Set a pointer to a vector to be updated when this->calc_c() is called.
void preprocessBaseInOutArgs(const Vector &x, bool newx, const ZeroOrderInfo *zero_order_info, const ObjGradInfo *obj_grad_info, const NLPFirstOrder::FirstOrderInfo *first_order_info, Thyra::ModelEvaluatorBase::InArgs< value_type > *model_inArgs_inout, Thyra::ModelEvaluatorBase::OutArgs< value_type > *model_outArgs_inout, MatrixOp **Gc_out, VectorMutable **Gf_out, value_type **f_out, VectorMutable **c_out) const
VectorSpace::vec_mut_ptr_t xu_
VectorSpace::space_ptr_t space_x_
NLPFirstOrder::mat_fcty_ptr_t factory_Gc_
size_type num_bounded(const Vector &xl, const Vector &xu, value_type inf_bound)
Count the number of finitly bounded elements in xl <= x <= xu.
void set_f(value_type *f)
Struct for objective and constriants (pointer).
const RCP< T > & assert_not_null() const
VectorMutable * c
Pointer to equality constraints residule c (may be NULL if not set)
MatrixOp adapter subclass for Thyra::LinearOpBase.
MatrixOpNonsing adapter subclass for Thyra::Nonlin::LinearOpWithSolve.
NLPThyraModelEvaluatorBase()
Thrown if any member functions are called before initialize() has been called.
vec_space_ptr_t space_x() const
Teuchos::RCP< Thyra::ModelEvaluator< value_type > > model_
AbstractLinAlgPack::value_type value_type
void set_x(const Vector &x, Thyra::ModelEvaluatorBase::InArgs< value_type > *model_inArgs_inout) const
void set_c(VectorMutable *c)
Abstract interface for mutable coordinate vectors {abstract}.
NLPFirstOrder::basis_sys_ptr_t basis_sys_
value_type * f
Pointer to objective function f (Will be NULL if not set)
void assert_is_initialized() const
void updateInitialGuessAndBounds() const
Update the initial guess and bounds .
void set_Gf(VectorMutable *Gf)
virtual VectorMutable & Gf()
Returns non-const *this->get_Gf().
void imp_calc_c(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
value_type * f
Pointer to objective function f (may be NULL if not set)
void evalModel(const Vector &x, bool newx, const ZeroOrderInfo *zero_order_info, const ObjGradInfo *obj_grad_info) const
static value_type infinite_bound()
Value for an infinite bound.
bool x_guess_bounds_updated_
virtual EVerbosityLevel getVerbLevel() const
size_type num_bounded_x() const
virtual void set_Gf(VectorMutable *Gf)
Set a pointer to a vector to be updated when this->calc_Gf() is called.
RangePack::Range1D Range1D
virtual void set_f(value_type *f)
Set a pointer to an value to be updated when this->calc_f() is called.
bool force_xinit_in_bounds() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
VectorSpaceThyra_ptr_t space_c_
virtual VectorMutable & c()
Returns non-const *this->get_c().