Ipopt  3.12.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MittelmannBndryCntrlNeum.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: MittelmannBndryCntrlNeum.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 __MITTELMANNBNDRYCNTRLNEUM_HPP__
11 #define __MITTELMANNBNDRYCNTRLNEUM_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 
50 {
51 public:
55 
58 
62  virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
63  Index& nnz_h_lag, IndexStyleEnum& index_style);
64 
66  virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
67  Index m, Number* g_l, Number* g_u);
68 
70  virtual bool get_starting_point(Index n, bool init_x, Number* x,
71  bool init_z, Number* z_L, Number* z_U,
72  Index m, bool init_lambda,
73  Number* lambda);
74 
76  virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
77 
79  virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
80 
82  virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
83 
88  virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
89  Index m, Index nele_jac, Index* iRow, Index *jCol,
90  Number* values);
91 
96  virtual bool eval_h(Index n, const Number* x, bool new_x,
97  Number obj_factor, Index m, const Number* lambda,
98  bool new_lambda, Index nele_hess, Index* iRow,
99  Index* jCol, Number* values);
100 
102 
104  virtual bool get_scaling_parameters(Number& obj_scaling,
105  bool& use_x_scaling, Index n,
106  Number* x_scaling,
107  bool& use_g_scaling, Index m,
108  Number* g_scaling);
109 
114  virtual void finalize_solution(SolverReturn status,
115  Index n, const Number* x, const Number* z_L, const Number* z_U,
116  Index m, const Number* g, const Number* lambda,
117  Number obj_value,
118  const IpoptData* ip_data,
121 
122 protected:
126  void SetBaseParameters(Index N, Number alpha, Number lb_y,
127  Number ub_y, Number lb_u, Number ub_u,
128  Number u_init);
129 
133  virtual Number y_d_cont(Number x1, Number x2) const =0;
135  virtual Number d_cont(Number x1, Number x2, Number y) const =0;
137  virtual Number d_cont_dy(Number x1, Number x2, Number y) const =0;
139  virtual Number d_cont_dydy(Number x1, Number x2, Number y) const =0;
142  virtual bool d_cont_dydy_alwayszero() const =0;
144  virtual Number b_cont(Number x1, Number x2, Number y, Number u) const =0;
146  virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const =0;
148  virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const =0;
150  virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const =0;
153  virtual bool b_cont_dydy_alwayszero() const =0;
155 
156 private:
171 
196 
201  inline Index y_index(Index i, Index j) const
202  {
203  return j + (N_+2)*i;
204  }
207  inline Index u0j_index(Index j) const
208  {
209  return (N_+2)*(N_+2) + j-1;
210  }
213  inline Index u1j_index(Index j) const
214  {
215  return (N_+2)*(N_+2) + N_ + j-1;
216  }
219  inline Index ui0_index(Index j) const
220  {
221  return (N_+2)*(N_+2) + 2*N_ + j-1;
222  }
225  inline Index ui1_index(Index j) const
226  {
227  return (N_+2)*(N_+2) + 3*N_ + j-1;
228  }
230  inline Number x1_grid(Index i) const
231  {
232  return h_*(Number)i;
233  }
235  inline Number x2_grid(Index j) const
236  {
237  return h_*(Number)j;
238  }
240 };
241 
244 {
245 public:
247  {}
248 
250  {}
251 
252  virtual bool InitializeProblem(Index N)
253  {
254  if (N<1) {
255  printf("N has to be at least 1.");
256  return false;
257  }
258  Number alpha = 0.01;
259  Number lb_y = -1e20;
260  Number ub_y = 2.071;
261  Number lb_u = 3.7;
262  Number ub_u = 4.5;
263  Number u_init = (ub_u+lb_u)/2.;
264 
265  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
266  return true;
267  }
268 protected:
270  virtual Number y_d_cont(Number x1, Number x2) const
271  {
272  return 2. - 2.*(x1*(x1-1.) + x2*(x2-1.));
273  }
275  virtual Number d_cont(Number x1, Number x2, Number y) const
276  {
277  return 0.;
278  }
280  virtual Number d_cont_dy(Number x1, Number x2, Number y) const
281  {
282  return 0.;
283  }
285  virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
286  {
287  return 0.;
288  }
291  virtual bool d_cont_dydy_alwayszero() const
292  {
293  return true;
294  }
296  virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
297  {
298  return u - y*y;
299  }
301  virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
302  {
303  return - 2.*y;
304  }
306  virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
307  {
308  return 1.;
309  }
311  virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
312  {
313  return -2.;
314  }
317  virtual bool b_cont_dydy_alwayszero() const
318  {
319  return false;
320  }
321 private:
327 };
328 
331 {
332 public:
334  {}
335 
337  {}
338 
339  virtual bool InitializeProblem(Index N)
340  {
341  if (N<1) {
342  printf("N has to be at least 1.");
343  return false;
344  }
345  Number alpha = 0.;
346  Number lb_y = -1e20;
347  Number ub_y = 2.835;
348  Number lb_u = 6.;
349  Number ub_u = 9.;
350  Number u_init = (ub_u+lb_u)/2.;
351 
352  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
353  return true;
354  }
355 protected:
357  virtual Number y_d_cont(Number x1, Number x2) const
358  {
359  return 2. - 2.*(x1*(x1-1.) + x2*(x2-1.));
360  }
362  virtual Number d_cont(Number x1, Number x2, Number y) const
363  {
364  return 0.;
365  }
367  virtual Number d_cont_dy(Number x1, Number x2, Number y) const
368  {
369  return 0.;
370  }
372  virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
373  {
374  return 0.;
375  }
378  virtual bool d_cont_dydy_alwayszero() const
379  {
380  return true;
381  }
383  virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
384  {
385  return u - y*y;
386  }
388  virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
389  {
390  return - 2.*y;
391  }
393  virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
394  {
395  return 1.;
396  }
398  virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
399  {
400  return -2.;
401  }
404  virtual bool b_cont_dydy_alwayszero() const
405  {
406  return false;
407  }
408 private:
414 };
415 
418 {
419 public:
421  {}
422 
424  {}
425 
426  virtual bool InitializeProblem(Index N)
427  {
428  if (N<1) {
429  printf("N has to be at least 1.");
430  return false;
431  }
432  Number alpha = 0.01;
433  Number lb_y = -1e20;
434  Number ub_y = 2.7;
435  Number lb_u = 1.8;
436  Number ub_u = 2.5;
437  Number u_init = (ub_u+lb_u)/2.;
438 
439  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
440  return true;
441  }
442 protected:
444  virtual Number y_d_cont(Number x1, Number x2) const
445  {
446  return 2. - 2.*(x1*(x1-1.) + x2*(x2-1.));
447  }
449  virtual Number d_cont(Number x1, Number x2, Number y) const
450  {
451  return y*y*y-y;
452  }
454  virtual Number d_cont_dy(Number x1, Number x2, Number y) const
455  {
456  return 3.*y*y-1.;
457  }
459  virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
460  {
461  return 6.*y;
462  }
465  virtual bool d_cont_dydy_alwayszero() const
466  {
467  return false;
468  }
470  virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
471  {
472  return u;
473  }
475  virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
476  {
477  return 0.;
478  }
480  virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
481  {
482  return 1.;
483  }
485  virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
486  {
487  return 0.;
488  }
491  virtual bool b_cont_dydy_alwayszero() const
492  {
493  return true;
494  }
495 private:
501 };
502 
505 {
506 public:
508  {}
509 
511  {}
512 
513  virtual bool InitializeProblem(Index N)
514  {
515  if (N<1) {
516  printf("N has to be at least 1.");
517  return false;
518  }
519  Number alpha = 0.;
520  Number lb_y = -1e20;
521  Number ub_y = 2.7;
522  Number lb_u = 1.8;
523  Number ub_u = 2.5;
524  Number u_init = (ub_u+lb_u)/2.;
525 
526  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
527  return true;
528  }
529 protected:
531  virtual Number y_d_cont(Number x1, Number x2) const
532  {
533  return 2. - 2.*(x1*(x1-1.) + x2*(x2-1.));
534  }
536  virtual Number d_cont(Number x1, Number x2, Number y) const
537  {
538  return y*y*y-y;
539  }
541  virtual Number d_cont_dy(Number x1, Number x2, Number y) const
542  {
543  return 3.*y*y-1.;
544  }
546  virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
547  {
548  return 6.*y;
549  }
552  virtual bool d_cont_dydy_alwayszero() const
553  {
554  return false;
555  }
557  virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
558  {
559  return u;
560  }
562  virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
563  {
564  return 0.;
565  }
567  virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
568  {
569  return 1.;
570  }
572  virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
573  {
574  return 0.;
575  }
578  virtual bool b_cont_dydy_alwayszero() const
579  {
580  return true;
581  }
582 private:
588 };
589 
590 #endif
Number * x
Input: Starting point Output: Optimal solution.
virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
Number x1_grid(Index i) const
Compute the grid coordinate for given index in x1 direction.
Index u1j_index(Index j) const
Translation of mesh point indices to NLP variable indices for u(x_ij) on {1} x (0,1) boudnary.
Class for all IPOPT specific calculated quantities.
Number Number Index Number Number Index Index Index index_style
indexing style for iRow &amp; jCol, 0 for C style, 1 for Fortran style
Number ub_u_
overall upper bound on u
virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of b_cont w.r.t.
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Number Number Index m
Number of constraints.
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
Index y_index(Index i, Index j) const
Translation of mesh point indices to NLP variable indices for y(x_ij)
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.
Index u0j_index(Index j) const
Translation of mesh point indices to NLP variable indices for u(x_ij) on {0} x (0,1) boudnary.
virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
virtual bool d_cont_dydy_alwayszero() const
returns true if second partial derivative of d_cont w.r.t.
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
virtual Number d_cont(Number x1, Number x2, Number y) const
Forcing function for the elliptic equation.
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.
Index ui0_index(Index j) const
Translation of mesh point indices to NLP variable indices for u(x_ij) on (0,1) x {0} boudnary...
Number lb_y_
overall lower bound on y
virtual Number d_cont_dy(Number x1, Number x2, Number y) const
First partial derivative of forcing function w.r.t.
Number * y_d_
Array for the target profile for y.
Number ub_y_
overall upper bound on y
virtual bool d_cont_dydy_alwayszero() const
returns true if second partial derivative of d_cont w.r.t.
virtual bool b_cont_dydy_alwayszero() const
returns true if second partial derivative of b_cont w.r.t.
virtual Number d_cont_dy(Number x1, Number x2, Number y) const
First partial derivative of forcing function w.r.t.
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
virtual Number d_cont(Number x1, Number x2, Number y) const
Forcing function for the elliptic equation.
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of b_cont w.r.t.
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.
Number x2_grid(Index j) const
Compute the grid coordinate for given index in x2 direction.
SolverReturn
enum for the return from the optimize algorithm (obviously we need to add more)
Definition: IpAlgTypes.hpp:22
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
Second partial derivative of forcing function w.r.t y,y.
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
virtual bool d_cont_dydy_alwayszero() const
returns true if second partial derivative of d_cont w.r.t.
virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
virtual Number d_cont_dy(Number x1, Number x2, Number y) const
First partial derivative of forcing function w.r.t.
Class implementating Example 7.
virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
Function in Neuman boundary condition.
Class implementating Example 5.
virtual Number d_cont(Number x1, Number x2, Number y) const
Forcing function for the elliptic equation.
virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
Second partial derivative of forcing function w.r.t y,y.
virtual Number b_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
Second partial derivative of forcing function w.r.t y,y.
virtual Number d_cont_dy(Number x1, Number x2, Number y) const
First partial derivative of forcing function w.r.t.
virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
Function in Neuman boundary condition.
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:83
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB eval_g
Callback function for evaluating constraint functions.
Number u_init_
Initial value for the constrols u.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of b_cont w.r.t.
virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
Function in Neuman boundary condition.
Number Number * x_scaling
virtual bool b_cont_dydy_alwayszero() const
returns true if second partial derivative of b_cont w.r.t.
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Class implementating Example 8.
Index ui1_index(Index j) const
Translation of mesh point indices to NLP variable indices for u(x_ij) on (0,1) x {1} boudnary...
Class implemented the NLP discretization of.
Class implementating Example 6.
virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
Base class for boundary control problems with Neumann boundary conditions, as formulated by Hans Mitt...
Number lb_u_
overall lower bound on u
virtual Number d_cont_dydy(Number x1, Number x2, Number y) const
Second partial derivative of forcing function w.r.t y,y.
Number Number Number * g_scaling
virtual bool b_cont_dydy_alwayszero() const
returns true if second partial derivative of b_cont w.r.t.
virtual bool b_cont_dydy_alwayszero() const
returns true if second partial derivative of b_cont w.r.t.
IndexStyleEnum
overload this method to return the number of variables and constraints, and the number of non-zeros i...
Definition: IpTNLP.hpp:80
Index N_
Number of mesh points in one dimension (excluding boundary)
virtual Number b_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of b_cont w.r.t.
virtual Number d_cont(Number x1, Number x2, Number y) const
Forcing function for the elliptic equation.
virtual Number b_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of b_cont w.r.t.
Number obj_scaling
Number Number Index Number Number Index Index Index Eval_F_CB eval_f
Callback function for evaluating objective function.
virtual bool d_cont_dydy_alwayszero() const
returns true if second partial derivative of d_cont w.r.t.
virtual Number b_cont(Number x1, Number x2, Number y, Number u) const
Function in Neuman boundary condition.
Number alpha_
Weighting parameter for the control target deviation functional in the objective. ...