// Copyright (C) 2005, 2006 International Business Machines and others. // All Rights Reserved. // This code is published under the Eclipse Public License. // // $Id: MittelmannDistCntrlNeumA.cpp 2005 2011-06-06 12:55:16Z stefan $ // // Authors: Carl Laird, Andreas Waechter IBM 2004-11-05 #include "MittelmannDistCntrlNeumA.hpp" #ifdef HAVE_CASSERT # include #else # ifdef HAVE_ASSERT_H # include # else # error "don't have header file for assert" # endif #endif using namespace Ipopt; /* Constructor. */ MittelmannDistCntrlNeumABase::MittelmannDistCntrlNeumABase() : y_d_(NULL) {} MittelmannDistCntrlNeumABase::~MittelmannDistCntrlNeumABase() { delete [] y_d_; } void MittelmannDistCntrlNeumABase::SetBaseParameters(Index N, Number lb_y, Number ub_y, Number lb_u, Number ub_u, Number b_0j, Number b_1j, Number b_i0, Number b_i1, Number u_init) { N_ = N; h_ = 1./(N+1); hh_ = h_*h_; lb_y_ = lb_y; ub_y_ = ub_y; lb_u_ = lb_u; ub_u_ = ub_u; b_0j_ = b_0j; b_1j_ = b_1j; b_i0_ = b_i0; b_i1_ = b_i1; u_init_ = u_init; // Initialize the target profile variables delete [] y_d_; y_d_ = new Number[(N_+2)*(N_+2)]; for (Index j=0; j<= N_+1; j++) { for (Index i=0; i<= N_+1; i++) { y_d_[y_index(i,j)] = y_d_cont(x1_grid(i),x2_grid(j)); } } } bool MittelmannDistCntrlNeumABase::get_nlp_info( Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_lag, IndexStyleEnum& index_style) { // We for each of the N_+2 times N_+2 mesh points we have the value // of the functions y, and for each N_ times N_ interior mesh points // we have values for u n = (N_+2)*(N_+2) + N_*N_; // For each of the N_ times N_ interior mesh points we have the // discretized PDE, and we have one constriant for each boundary // point (except for the corners) m = N_*N_ + 4*N_; // y(i,j), y(i-1,j), y(i+1,j), y(i,j-1), y(i,j+1), u(i,j) for each // of the N_*N_ discretized PDEs, and for the Neumann boundary // conditions nnz_jac_g = 6*N_*N_ + 8*N_; // diagonal entry for each dydy, dudu, dydu in the interior nnz_h_lag = 0; if (!fint_cont_dydy_alwayszero() || !d_cont_dydy_alwayszero()) { nnz_h_lag += N_*N_; } if (!fint_cont_dudu_alwayszero() || !d_cont_dudu_alwayszero()) { nnz_h_lag += N_*N_; } if (!fint_cont_dydu_alwayszero() || !d_cont_dydu_alwayszero()) { nnz_h_lag += N_*N_; } // We use the C indexing style for row/col entries (corresponding to // the C notation, starting at 0) index_style = C_STYLE; return true; } bool MittelmannDistCntrlNeumABase::get_bounds_info(Index n, Number* x_l, Number* x_u, Index m, Number* g_l, Number* g_u) { // Set overall bounds on the variables for (Index i=0; i<=N_+1; i++) { for (Index j=0; j<=N_+1; j++) { Index iy = y_index(i,j); x_l[iy] = lb_y_; x_u[iy] = ub_y_; } } for (Index i=1; i<=N_; i++) { for (Index j=1; j<=N_; j++) { Index iu = u_index(i,j); x_l[iu] = lb_u_; x_u[iu] = ub_u_; } } // There is no information for the y's at the corner points, so just // take those variables out x_l[y_index(0,0)] = x_u[y_index(0,0)] = 0.; x_l[y_index(0,N_+1)] = x_u[y_index(0,N_+1)] = 0.; x_l[y_index(N_+1,0)] = x_u[y_index(N_+1,0)] = 0.; x_l[y_index(N_+1,N_+1)] = x_u[y_index(N_+1,N_+1)] = 0.; // all discretized PDE constraints have right hand side zero for (Index i=0; i