Ipopt 3.11.9
Loading...
Searching...
No Matches
MittelmannBndryCntrlDiri3D_27.hpp
Go to the documentation of this file.
1// Copyright (C) 2005, 2007 International Business Machines and others.
2// All Rights Reserved.
3// This code is published under the Eclipse Public License.
4//
5// $Id: MittelmannBndryCntrlDiri3D_27.hpp 2005 2011-06-06 12:55:16Z stefan $
6//
7// Authors: Olaf Schenk (Univ. of Basel) 2007-08-01
8// modified MittelmannBndryCntrlDiri.hpp for 3-dim problem
9// based on MyNLP.hpp
10
11#ifndef __MITTELMANNBNDRYCNTRLDIRI3D_27_HPP__
12#define __MITTELMANNBNDRYCNTRLDIRI3D_27_HPP__
13
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
42using namespace Ipopt;
43
54{
55public:
58
61
65 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
66 Index& nnz_h_lag, IndexStyleEnum& index_style);
67
69 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
70 Index m, Number* g_l, Number* g_u);
71
73 virtual bool get_starting_point(Index n, bool init_x, Number* x,
74 bool init_z, Number* z_L, Number* z_U,
75 Index m, bool init_lambda,
76 Number* lambda);
77
79 virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
80
82 virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
83
85 virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
86
91 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
92 Index m, Index nele_jac, Index* iRow, Index *jCol,
93 Number* values);
94
99 virtual bool eval_h(Index n, const Number* x, bool new_x,
100 Number obj_factor, Index m, const Number* lambda,
101 bool new_lambda, Index nele_hess, Index* iRow,
102 Index* jCol, Number* values);
103
105
108 bool& use_x_scaling, Index n,
110 bool& use_g_scaling, Index m,
112
117 virtual void finalize_solution(SolverReturn status,
118 Index n, const Number* x, const Number* z_L, const Number* z_U,
119 Index m, const Number* g, const Number* lambda,
120 Number obj_valu,
121 const IpoptData* ip_data,
124
125protected:
130 Number ub_y, Number lb_u, Number ub_u,
131 Number d_const, Number B, Number C);
132
136 virtual Number y_d_cont(Number x1, Number x2, Number x3) const =0;
138
139private:
154
181
186 inline Index y_index(Index i, Index j, Index k) const
187 {
188 return k + (N_+2)*j + (N_+2)*(N_+2)*i;
189 }
192 inline Index pde_index(Index i, Index j, Index k) const
193 {
194 return (k-1) + N_*(j-1) + N_*N_*(i-1);
195 }
197 inline Number x1_grid(Index i) const
198 {
199 return h_*(Number)i;
200 }
202 inline Number x2_grid(Index i) const
203 {
204 return h_*(Number)i;
205 }
207 inline Number x3_grid(Index i) const
208 {
209 return h_*(Number)i;
210 }
212 inline Number PenObj(Number t) const
213 {
214 if (B_ == 0.) {
215 return 0.5*t*t;
216 }
217 else if (t > B_) {
218 return B_*B_/2. + C_*(t - B_);
219 }
220 else if (t < -B_) {
221 return B_*B_/2. + C_*(-t - B_);
222 }
223 else {
224 const Number t2 = t*t;
225 const Number t4 = t2*t2;
226 const Number t6 = t4*t2;
227 return PenA_*t2 + PenB_*t4 + PenC_*t6;
228 }
229 }
231 inline Number PenObj_1(Number t) const
232 {
233 if (B_ == 0.) {
234 return t;
235 }
236 else if (t > B_) {
237 return C_;
238 }
239 else if (t < -B_) {
240 return -C_;
241 }
242 else {
243 const Number t2 = t*t;
244 const Number t3 = t*t2;
245 const Number t5 = t3*t2;
246 return 2.*PenA_*t + 4.*PenB_*t3 + 6.*PenC_*t5;
247 }
248 }
250 inline Number PenObj_2(Number t) const
251 {
252 if (B_ == 0.) {
253 return 1.;
254 }
255 else if (t > B_) {
256 return 0.;
257 }
258 else if (t < -B_) {
259 return 0.;
260 }
261 else {
262 const Number t2 = t*t;
263 const Number t4 = t2*t2;
264 return 2.*PenA_ + 12.*PenB_*t2 + 30.*PenC_*t4;
265 }
266 }
268
277};
278
281{
282public:
285
288
289 virtual bool InitializeProblem(Index N)
290 {
291 if (N<1) {
292 printf("N has to be at least 1.");
293 return false;
294 }
295 Number alpha = 1e-2;
296 Number lb_y = -1e20;
297 Number ub_y = 3.5;
298 Number lb_u = 0.;
299 Number ub_u = 10.;
300 Number d_const = -20.;
301 Number B = 0.; // convex case (quadratic penalty)
302 Number C = 0.;
303 SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const, B, C);
304 return true;
305 }
306protected:
308 virtual Number y_d_cont(Number x1, Number x2, Number x3) const
309 {
310 return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
311 }
312private:
318
319};
320
324{
325public:
328
331
332 virtual bool InitializeProblem(Index N)
333 {
334 if (N<1) {
335 printf("N has to be at least 1.");
336 return false;
337 }
338 Number alpha = 1e-2;
339 Number lb_y = -1e20;
340 Number ub_y = 3.5;
341 Number lb_u = 0.;
342 Number ub_u = 10.;
343 Number d_const = -20.;
344 Number B = .25; // nonconves case with beaton-tukey-type penalty function
345 Number C = 0.01;
346 SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const, B, C);
347 return true;
348 }
349protected:
351 virtual Number y_d_cont(Number x1, Number x2, Number x3) const
352 {
353 return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
354 }
355private:
361
362};
363
364#endif
Number * x
Input: Starting point Output: Optimal solution.
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
Number Number * x_scaling
Number obj_scaling
Number Number Number * g_scaling
Number Number Index m
Number of constraints.
Number Number Index Number Number Index Index Index index_style
indexing style for iRow & jCol, 0 for C style, 1 for Fortran style
Class for all IPOPT specific calculated quantities.
Class to organize all the data required by the algorithm.
IndexStyleEnum
overload this method to return the number of variables and constraints, and the number of non-zeros i...
Definition IpTNLP.hpp:80
Class implementating case with nonconvex Beaton-Tukey like penalty function.
MittelmannBndryCntrlDiri3D_27BT & operator=(const MittelmannBndryCntrlDiri3D_27BT &)
MittelmannBndryCntrlDiri3D_27BT(const MittelmannBndryCntrlDiri3D_27BT &)
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
virtual Number y_d_cont(Number x1, Number x2, Number x3) const
Target profile function for y.
Class implementating case with convex quadratic penalty function.
virtual Number y_d_cont(Number x1, Number x2, Number x3) const
Target profile function for y.
MittelmannBndryCntrlDiri3D_27(const MittelmannBndryCntrlDiri3D_27 &)
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
MittelmannBndryCntrlDiri3D_27 & operator=(const MittelmannBndryCntrlDiri3D_27 &)
Base class for boundary control problems with Dirichlet boundary conditions, as formulated by Hans Mi...
virtual void finalize_solution(SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_valu, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
This method is called after the optimization, and could write an output file with the optimal profile...
MittelmannBndryCntrlDiriBase3D_27 & operator=(const MittelmannBndryCntrlDiriBase3D_27 &)
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
Method to return some info about the nlp.
void SetBaseParameters(Index N, Number alpha, Number lb_y, Number ub_y, Number lb_u, Number ub_u, Number d_const, Number B, Number C)
Method for setting the internal parameters that define the problem.
Index N_
Number of mesh points in one dimension (excluding boundary)
Index y_index(Index i, Index j, Index k) const
Translation of mesh point indices to NLP variable indices for y(x_ijk)
MittelmannBndryCntrlDiriBase3D_27()
Constructor.
Number PenObj(Number t) const
value of penalty function term
virtual bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f)
Method to return the gradient of the objective.
MittelmannBndryCntrlDiriBase3D_27(const MittelmannBndryCntrlDiriBase3D_27 &)
Number x1_grid(Index i) const
Compute the grid coordinate for given index in x1 direction.
virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value)
Method to return the objective value.
virtual bool get_scaling_parameters(Number &obj_scaling, bool &use_x_scaling, Index n, Number *x_scaling, bool &use_g_scaling, Index m, Number *g_scaling)
Method for returning scaling parameters.
Number x2_grid(Index i) const
Compute the grid coordinate for given index in x2 direction.
virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
Method to return: 1) The structure of the jacobian (if "values" is NULL) 2) The values of the jacobia...
virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda)
Method to return the starting point for the algorithm.
Number d_const_
Constant value of d appearing in elliptical equation.
virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g)
Method to return the constraint residuals.
Number alpha_
Weighting parameter for the control target deviation functional in the objective.
virtual ~MittelmannBndryCntrlDiriBase3D_27()
Default destructor.
Number PenObj_2(Number t) const
second derivative of penalty function term
virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)
Method to return the bounds for my problem.
virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values)
Method to return: 1) The structure of the hessian of the lagrangian (if "values" is NULL) 2) The valu...
Index pde_index(Index i, Index j, Index k) const
Translation of interior mesh point indices to the corresponding PDE constraint number.
virtual Number y_d_cont(Number x1, Number x2, Number x3) const =0
Target profile function for y.
Number x3_grid(Index i) const
Compute the grid coordinate for given index in x3 direction.
Number PenObj_1(Number t) const
first derivative of penalty function term
Number * y_d_
Array for the target profile for y.
Class implemented the NLP discretization of.
SolverReturn
enum for the return from the optimize algorithm (obviously we need to add more)
int Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:19
double Number
Type of all numbers.
Definition IpTypes.hpp:17