Ipopt  3.11.9
MittelmannDistCntrlDiri.hpp
Go to the documentation of this file.
1 // Copyright (C) 2005, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: MittelmannDistCntrlDiri.hpp 2005 2011-06-06 12:55:16Z stefan $
6 //
7 // Authors: Andreas Waechter IBM 2005-10-18
8 // based on MyNLP.hpp
9 
10 #ifndef __MITTELMANNDISTRCNTRLDIRI_HPP__
11 #define __MITTELMANNDISTRCNTRLDIRI_HPP__
12 
13 #include "IpTNLP.hpp"
14 #include "RegisteredTNLP.hpp"
15 
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #else
19 #include "configall_system.h"
20 #endif
21 
22 #ifdef HAVE_CMATH
23 # include <cmath>
24 #else
25 # ifdef HAVE_MATH_H
26 # include <math.h>
27 # else
28 # error "don't have header file for math"
29 # endif
30 #endif
31 
32 #ifdef HAVE_CSTDIO
33 # include <cstdio>
34 #else
35 # ifdef HAVE_STDIO_H
36 # include <stdio.h>
37 # else
38 # error "don't have header file for stdio"
39 # endif
40 #endif
41 
42 using namespace Ipopt;
43 
51 {
52 public:
56 
58  virtual ~MittelmannDistCntrlDiriBase();
59 
63  virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
64  Index& nnz_h_lag, IndexStyleEnum& index_style);
65 
67  virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
68  Index m, Number* g_l, Number* g_u);
69 
71  virtual bool get_starting_point(Index n, bool init_x, Number* x,
72  bool init_z, Number* z_L, Number* z_U,
73  Index m, bool init_lambda,
74  Number* lambda);
75 
77  virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
78 
80  virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
81 
83  virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
84 
89  virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
90  Index m, Index nele_jac, Index* iRow, Index *jCol,
91  Number* values);
92 
97  virtual bool eval_h(Index n, const Number* x, bool new_x,
98  Number obj_factor, Index m, const Number* lambda,
99  bool new_lambda, Index nele_hess, Index* iRow,
100  Index* jCol, Number* values);
101 
103 
105  virtual bool get_scaling_parameters(Number& obj_scaling,
106  bool& use_x_scaling, Index n,
107  Number* x_scaling,
108  bool& use_g_scaling, Index m,
109  Number* g_scaling);
110 
115  virtual void finalize_solution(SolverReturn status,
116  Index n, const Number* x, const Number* z_L, const Number* z_U,
117  Index m, const Number* g, const Number* lambda,
118  Number obj_value,
119  const IpoptData* ip_data,
122 
123 protected:
127  void SetBaseParameters(Index N, Number alpha, Number lb_y,
128  Number ub_y, Number lb_u, Number ub_u,
129  Number u_init);
130 
134  virtual Number y_d_cont(Number x1, Number x2) const =0;
136  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const =0;
138  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const =0;
140  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const =0;
142  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const =0;
144 
145 private:
160 
185 
190  inline Index y_index(Index i, Index j) const
191  {
192  return j + (N_+2)*i;
193  }
196  inline Index u_index(Index i, Index j) const
197  {
198  return (N_+2)*(N_+2) + (j-1) + (N_)*(i-1);
199  }
202  inline Index pde_index(Index i, Index j) const
203  {
204  return (j-1) + N_*(i-1);
205  }
207  inline Number x1_grid(Index i) const
208  {
209  return h_*(Number)i;
210  }
212  inline Number x2_grid(Index i) const
213  {
214  return h_*(Number)i;
215  }
217 };
218 
221 {
222 public:
224  {}
225 
227  {}
228 
229  virtual bool InitializeProblem(Index N)
230  {
231  if (N<1) {
232  printf("N has to be at least 1.");
233  return false;
234  }
235  Number alpha = 0.001;
236  Number lb_y = -1e20;
237  Number ub_y = 0.185;
238  Number lb_u = 1.5;
239  Number ub_u = 4.5;
240  Number u_init = (ub_u+lb_u)/2.;
241 
242  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
243  return true;
244  }
245 protected:
247  virtual Number y_d_cont(Number x1, Number x2) const
248  {
249  return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
250  }
252  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
253  {
254  return pow(y,3) - y - u;
255  }
257  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
258  {
259  return 3.*y*y - 1.;
260  }
262  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
263  {
264  return -1.;
265  }
267  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
268  {
269  return 6.*y;
270  }
271 private:
277 };
278 
281 {
282 public:
284  {}
286  {}
287  virtual bool InitializeProblem(Index N)
288  {
289  if (N<1) {
290  printf("N has to be at least 1.");
291  return false;
292  }
293  Number alpha = 0.;
294  Number lb_y = -1e20;
295  Number ub_y = 0.185;
296  Number lb_u = 1.5;
297  Number ub_u = 4.5;
298  Number u_init = (ub_u+lb_u)/2.;
299 
300  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
301  return true;
302  }
303 protected:
305  virtual Number y_d_cont(Number x1, Number x2) const
306  {
307  return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
308  }
310  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
311  {
312  return pow(y,3) - y - u;
313  }
315  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
316  {
317  return 3.*y*y - 1.;
318  }
320  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
321  {
322  return -1.;
323  }
325  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
326  {
327  return 6.*y;
328  }
329 private:
335 };
336 
339 {
340 public:
342  :
343  pi_(4.*atan(1.))
344  {}
346  {}
347  virtual bool InitializeProblem(Index N)
348  {
349  if (N<1) {
350  printf("N has to be at least 1.");
351  return false;
352  }
353  Number alpha = 0.001;
354  Number lb_y = -1e20;
355  Number ub_y = 0.11;
356  Number lb_u = -5;
357  Number ub_u = 5.;
358  Number u_init = (ub_u+lb_u)/2.;
359 
360  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
361  return true;
362  }
363 protected:
365  virtual Number y_d_cont(Number x1, Number x2) const
366  {
367  return sin(2.*pi_*x1)*sin(2.*pi_*x2);
368  }
370  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
371  {
372  return -exp(y) - u;
373  }
375  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
376  {
377  return -exp(y);
378  }
380  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
381  {
382  return -1.;
383  }
385  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
386  {
387  return -exp(y);
388  }
389 private:
395 
396  const Number pi_;
397 };
398 
400 {
401 public:
403  :
404  pi_(4.*atan(1.))
405  {}
407  {}
408  virtual bool InitializeProblem(Index N)
409  {
410  if (N<1) {
411  printf("N has to be at least 1.");
412  return false;
413  }
414  Number alpha = 0.;
415  Number lb_y = -1e20;
416  Number ub_y = 0.11;
417  Number lb_u = -5;
418  Number ub_u = 5.;
419  Number u_init = (ub_u+lb_u)/2.;
420 
421  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
422  return true;
423  }
424 protected:
426  virtual Number y_d_cont(Number x1, Number x2) const
427  {
428  return sin(2.*pi_*x1)*sin(2.*pi_*x2);
429  }
431  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
432  {
433  return -exp(y) - u;
434  }
436  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
437  {
438  return -exp(y);
439  }
441  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
442  {
443  return -1.;
444  }
446  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
447  {
448  return -exp(y);
449  }
450 private:
456 
457  const Number pi_;
458 };
459 
460 #endif
MittelmannDistCntrlDiri2::d_cont_dydy
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
Definition: MittelmannDistCntrlDiri.hpp:325
MittelmannDistCntrlDiri1::d_cont
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
Definition: MittelmannDistCntrlDiri.hpp:252
MittelmannDistCntrlDiriBase::x2_grid
Number x2_grid(Index i) const
Compute the grid coordinate for given index in x2 direction.
Definition: MittelmannDistCntrlDiri.hpp:212
MittelmannDistCntrlDiri3a::d_cont_du
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:441
MittelmannDistCntrlDiri1::InitializeProblem
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Definition: MittelmannDistCntrlDiri.hpp:229
MittelmannDistCntrlDiriBase::alpha_
Number alpha_
Weighting parameter for the control target deviation functional in the objective.
Definition: MittelmannDistCntrlDiri.hpp:181
MittelmannDistCntrlDiri3a::d_cont_dy
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:436
Ipopt::IpoptData
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:83
MittelmannDistCntrlDiri3::d_cont_du
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:380
MittelmannDistCntrlDiri1::MittelmannDistCntrlDiri1
MittelmannDistCntrlDiri1()
Definition: MittelmannDistCntrlDiri.hpp:223
MittelmannDistCntrlDiri3::pi_
const Number pi_
Value of pi (made available for convenience)
Definition: MittelmannDistCntrlDiri.hpp:396
MittelmannDistCntrlDiriBase::h_
Number h_
Step size.
Definition: MittelmannDistCntrlDiri.hpp:166
MittelmannDistCntrlDiri1::d_cont_dy
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:257
RegisteredTNLP
Class implemented the NLP discretization of.
Definition: RegisteredTNLP.hpp:20
MittelmannDistCntrlDiriBase
Base class for distributed control problems with Dirichlet boundary conditions, as formulated by Hans...
Definition: MittelmannDistCntrlDiri.hpp:50
Ipopt::IpoptCalculatedQuantities
Class for all IPOPT specific calculated quantities.
Definition: IpIpoptCalculatedQuantities.hpp:81
MittelmannDistCntrlDiri3::InitializeProblem
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Definition: MittelmannDistCntrlDiri.hpp:347
Ipopt
Definition: matlabjournal.hpp:14
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
eval_g
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB eval_g
Callback function for evaluating constraint functions.
Definition: IpStdCInterface.h:172
MittelmannDistCntrlDiri3a::pi_
const Number pi_
Value of pi (made available for convenience)
Definition: MittelmannDistCntrlDiri.hpp:457
MittelmannDistCntrlDiri3a::d_cont_dydy
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
Definition: MittelmannDistCntrlDiri.hpp:446
MittelmannDistCntrlDiri2::d_cont
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
Definition: MittelmannDistCntrlDiri.hpp:310
MittelmannDistCntrlDiri2::InitializeProblem
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Definition: MittelmannDistCntrlDiri.hpp:287
MittelmannDistCntrlDiri3a::d_cont
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
Definition: MittelmannDistCntrlDiri.hpp:431
MittelmannDistCntrlDiriBase::pde_index
Index pde_index(Index i, Index j) const
Translation of interior mesh point indices to the corresponding PDE constraint number.
Definition: MittelmannDistCntrlDiri.hpp:202
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
nele_hess
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Definition: IpStdCInterface.h:166
eval_jac_g
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB Eval_Grad_F_CB Eval_Jac_G_CB eval_jac_g
Callback function for evaluating Jacobian of constraint functions.
Definition: IpStdCInterface.h:178
MittelmannDistCntrlDiri1::~MittelmannDistCntrlDiri1
virtual ~MittelmannDistCntrlDiri1()
Definition: MittelmannDistCntrlDiri.hpp:226
nele_jac
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
Definition: IpStdCInterface.h:164
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
MittelmannDistCntrlDiriBase::ub_u_
Number ub_u_
overall upper bound on u
Definition: MittelmannDistCntrlDiri.hpp:176
MittelmannDistCntrlDiriBase::ub_y_
Number ub_y_
overall upper bound on y
Definition: MittelmannDistCntrlDiri.hpp:172
MittelmannDistCntrlDiriBase::hh_
Number hh_
h_ squaredd
Definition: MittelmannDistCntrlDiri.hpp:168
MittelmannDistCntrlDiri2::y_d_cont
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Definition: MittelmannDistCntrlDiri.hpp:305
IpTNLP.hpp
eval_f
Number Number Index Number Number Index Index Index Eval_F_CB eval_f
Callback function for evaluating objective function.
Definition: IpStdCInterface.h:170
MittelmannDistCntrlDiriBase::N_
Index N_
Number of mesh points in one dimension (excluding boundary)
Definition: MittelmannDistCntrlDiri.hpp:164
MittelmannDistCntrlDiriBase::x1_grid
Number x1_grid(Index i) const
Compute the grid coordinate for given index in x1 direction.
Definition: MittelmannDistCntrlDiri.hpp:207
MittelmannDistCntrlDiri1::y_d_cont
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Definition: MittelmannDistCntrlDiri.hpp:247
MittelmannDistCntrlDiri2
Class implementating Example 2.
Definition: MittelmannDistCntrlDiri.hpp:280
obj_scaling
Number obj_scaling
Definition: IpStdCInterface.h:210
eval_h
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB Eval_Grad_F_CB Eval_Jac_G_CB Eval_H_CB eval_h
Callback function for evaluating Hessian of Lagrangian function.
Definition: IpStdCInterface.h:180
MittelmannDistCntrlDiri3::d_cont_dydy
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
Definition: MittelmannDistCntrlDiri.hpp:385
MittelmannDistCntrlDiri2::d_cont_du
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:320
MittelmannDistCntrlDiri3a::~MittelmannDistCntrlDiri3a
virtual ~MittelmannDistCntrlDiri3a()
Definition: MittelmannDistCntrlDiri.hpp:406
MittelmannDistCntrlDiri2::d_cont_dy
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:315
MittelmannDistCntrlDiriBase::u_index
Index u_index(Index i, Index j) const
Translation of mesh point indices to NLP variable indices for u(x_ij)
Definition: MittelmannDistCntrlDiri.hpp:196
MittelmannDistCntrlDiri3a::y_d_cont
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Definition: MittelmannDistCntrlDiri.hpp:426
MittelmannDistCntrlDiri3::~MittelmannDistCntrlDiri3
virtual ~MittelmannDistCntrlDiri3()
Definition: MittelmannDistCntrlDiri.hpp:345
MittelmannDistCntrlDiriBase::y_d_
Number * y_d_
Array for the target profile for y.
Definition: MittelmannDistCntrlDiri.hpp:183
eval_grad_f
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB Eval_Grad_F_CB eval_grad_f
Callback function for evaluating gradient of objective function.
Definition: IpStdCInterface.h:175
MittelmannDistCntrlDiri3::d_cont_dy
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:375
MittelmannDistCntrlDiri3::MittelmannDistCntrlDiri3
MittelmannDistCntrlDiri3()
Definition: MittelmannDistCntrlDiri.hpp:341
MittelmannDistCntrlDiri1
Class implementating Example 1.
Definition: MittelmannDistCntrlDiri.hpp:220
g_scaling
Number Number Number * g_scaling
Definition: IpStdCInterface.h:212
MittelmannDistCntrlDiri2::MittelmannDistCntrlDiri2
MittelmannDistCntrlDiri2()
Definition: MittelmannDistCntrlDiri.hpp:283
MittelmannDistCntrlDiri1::d_cont_dydy
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
Definition: MittelmannDistCntrlDiri.hpp:267
MittelmannDistCntrlDiri3a
Definition: MittelmannDistCntrlDiri.hpp:399
MittelmannDistCntrlDiri3a::MittelmannDistCntrlDiri3a
MittelmannDistCntrlDiri3a()
Definition: MittelmannDistCntrlDiri.hpp:402
g
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
Definition: IpStdCInterface.h:240
Ipopt::TNLP::IndexStyleEnum
IndexStyleEnum
overload this method to return the number of variables and constraints, and the number of non-zeros i...
Definition: IpTNLP.hpp:80
MittelmannDistCntrlDiriBase::lb_u_
Number lb_u_
overall lower bound on u
Definition: MittelmannDistCntrlDiri.hpp:174
MittelmannDistCntrlDiri1::d_cont_du
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Definition: MittelmannDistCntrlDiri.hpp:262
MittelmannDistCntrlDiri2::~MittelmannDistCntrlDiri2
virtual ~MittelmannDistCntrlDiri2()
Definition: MittelmannDistCntrlDiri.hpp:285
Ipopt::SolverReturn
SolverReturn
enum for the return from the optimize algorithm (obviously we need to add more)
Definition: IpAlgTypes.hpp:22
MittelmannDistCntrlDiri3::d_cont
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
Definition: MittelmannDistCntrlDiri.hpp:370
MittelmannDistCntrlDiri3
Class implementating Example 3.
Definition: MittelmannDistCntrlDiri.hpp:338
RegisteredTNLP.hpp
MittelmannDistCntrlDiriBase::y_index
Index y_index(Index i, Index j) const
Translation of mesh point indices to NLP variable indices for y(x_ij)
Definition: MittelmannDistCntrlDiri.hpp:190
MittelmannDistCntrlDiriBase::u_init_
Number u_init_
Initial value for the constrols u.
Definition: MittelmannDistCntrlDiri.hpp:178
index_style
Number Number Index Number Number Index Index Index index_style
indexing style for iRow & jCol, 0 for C style, 1 for Fortran style
Definition: IpStdCInterface.h:168
MittelmannDistCntrlDiri3::y_d_cont
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Definition: MittelmannDistCntrlDiri.hpp:365
MittelmannDistCntrlDiriBase::lb_y_
Number lb_y_
overall lower bound on y
Definition: MittelmannDistCntrlDiri.hpp:170
x_scaling
Number Number * x_scaling
Definition: IpStdCInterface.h:211
m
Number Number Index m
Number of constraints.
Definition: IpStdCInterface.h:146
MittelmannDistCntrlDiri3a::InitializeProblem
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Definition: MittelmannDistCntrlDiri.hpp:408