void MatrixZero::initialize( const VectorSpace::space_ptr_t& space_cols ,const VectorSpace::space_ptr_t& space_rows ) { TEUCHOS_TEST_FOR_EXCEPTION( (space_cols.get() == NULL && space_rows.get() != NULL) || (space_cols.get() != NULL && space_rows.get() == NULL) , std::invalid_argument ,"MatrixZero::initialize(...) : Error, the space_cols.get() and " "space_rows.get() must both be != NULL or == NULL" ); space_cols_ = space_cols; space_rows_ = space_rows; }
ExampleNLPObjGrad::ExampleNLPObjGrad( const VectorSpace::space_ptr_t& vec_space ,value_type xo ,bool has_bounds ,bool dep_bounded ) :vec_space_(vec_space), vec_space_comp_(Teuchos::null) ,initialized_(false), obj_scale_(1.0) ,has_bounds_(has_bounds), force_xinit_in_bounds_(true), n_(2*vec_space->dim()) { namespace rcp = MemMngPack; // Assert the size of the NLP TEUCHOS_TEST_FOR_EXCEPTION( vec_space->dim() <= 0, std::logic_error ,"ExampleNLPObjGrad::ExampleNLPObjGrad(...) Error!" ); // Setup the aggregate vector space object BasisSystemComposite::initialize_space_x( vec_space, vec_space, &var_dep_, &var_indep_, &vec_space_comp_ ); // Set the initial starting point. xinit_ = vec_space_comp_->create_member(); *xinit_ = xo; /* Setup the sparse bounds xl(i) = 0.01 \ } for i <: bounded_rng xu(i) = 20 / */ xl_ = vec_space_comp_->create_member(); xu_ = vec_space_comp_->create_member(); if(has_bounds) { const Range1D bounded_rng = ( dep_bounded ? var_dep_ : var_indep_ ), unbounded_rng = ( dep_bounded ? var_indep_ : var_dep_ ); *xl_->sub_view(bounded_rng) = 0.01; *xl_->sub_view(unbounded_rng) = -NLP::infinite_bound(); *xu_->sub_view(bounded_rng) = 20.0; *xu_->sub_view(unbounded_rng) = +NLP::infinite_bound(); } else { *xl_ = -NLP::infinite_bound(); *xu_ = +NLP::infinite_bound(); } }
void ExampleBasisSystem::initialize( const VectorSpace::space_ptr_t &space_x ,const Range1D &var_dep ,const Range1D &var_indep ) { namespace mmp = MemMngPack; TEUCHOS_TEST_FOR_EXCEPTION( space_x.get() == NULL, std::invalid_argument ,"ExampleBasisSystem::initialize(...) : Error, space_x must be specified!" ); BasisSystemComposite::initialize( space_x ,var_dep ,var_indep ,space_x->sub_space(var_dep) ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOpNonsing,MatrixSymDiagStd>()) // C ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixSymOp,MatrixSymDiagStd>()) // D'*D ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixSymOpNonsing,MatrixSymDiagStd>()) // S ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymDiagStd>()) // D ); }
ExampleBasisSystem::ExampleBasisSystem( const VectorSpace::space_ptr_t &space_x ,const Range1D &var_dep ,const Range1D &var_indep ) :BasisSystemComposite( space_x ,var_dep ,var_indep ,space_x->sub_space(var_dep) ,Teuchos::rcp( new Teuchos::AbstractFactoryStd<MatrixOpNonsing,MatrixSymDiagStd>()) // C ,Teuchos::rcp( new Teuchos::AbstractFactoryStd<MatrixSymOp,MatrixSymDiagStd>()) // D'*D ,Teuchos::rcp( new Teuchos::AbstractFactoryStd<MatrixSymOpNonsing,MatrixSymDiagStd>()) // S ,Teuchos::rcp( new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymDiagStd>()) // D ) {}
void ExampleNLPFirstOrder::imp_calc_Gc( const Vector& x, bool newx, const FirstOrderInfo& first_order_info) const { namespace rcp = MemMngPack; using Teuchos::dyn_cast; using AbstractLinAlgPack::Vp_S; // Should not have to do this! const index_type n = this->n(), m = this->m(); const Range1D var_dep = this->var_dep(), var_indep = this->var_indep(); // Get references to aggregate C and N matrices (if allocated) MatrixOpNonsing *C_aggr = NULL; MatrixOp *N_aggr = NULL; BasisSystemComposite::get_C_N( first_order_info.Gc, &C_aggr, &N_aggr ); // Will return NULLs if Gc is not initialized // Allocate C and N matrix objects if not done yet! Teuchos::RCP<MatrixOpNonsing> C_ptr = Teuchos::null; Teuchos::RCP<MatrixOp> N_ptr = Teuchos::null; if( C_aggr == NULL ) { const VectorSpace::space_ptr_t space_x = this->space_x(), space_xD = space_x->sub_space(var_dep); C_ptr = Teuchos::rcp(new MatrixSymDiagStd(space_xD->create_member())); N_ptr = Teuchos::rcp(new MatrixSymDiagStd(space_xD->create_member())); C_aggr = C_ptr.get(); N_aggr = N_ptr.get(); } // Get references to concreate C and N matrices MatrixSymDiagStd &C = dyn_cast<MatrixSymDiagStd>(*C_aggr); MatrixSymDiagStd &N = dyn_cast<MatrixSymDiagStd>(*N_aggr); // Get x = [ x_D' x_I ] Vector::vec_ptr_t x_D = x.sub_view(var_dep), x_I = x.sub_view(var_indep); // Set the diagonals of C and N (this is the only computation going on here) C.diag() = *x_I; // C.diag = x_I - 1.0 Vp_S( &C.diag(), -1.0 ); // ... N.diag() = *x_D; // N.diag = x_D - 10.0 Vp_S( &N.diag(), -10.0 ); // ... // Initialize the matrix object Gc if not done so yet if( C_ptr.get() != NULL ) { BasisSystemComposite::initialize_Gc( this->space_x(), var_dep, var_indep ,this->space_c() ,C_ptr, N_ptr ,first_order_info.Gc ); } }
void MeritFuncNLPModL1::set_space_c( const VectorSpace::space_ptr_t& space_c ) { mu_ = space_c->create_member(); *mu_ = 0.0; }