integrator/hydroscal.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
38 #include <acado_integrators.hpp>
39 #include "hydroscal_model.hpp"
40 #include <acado_gnuplot.hpp>
41 
42 
43 void ffcn_model( double *x, double *f, void *user_data ){
44 
45  int i;
46 
47  double *xd = new double[NXD];
48  double *xa = new double[NXA];
49  double *u = new double[ NU];
50  double *p = new double[ NP];
51 
52  for( i = 0; i < NXD; i++ ) xd[i] = x[ 1+i ];
53  for( i = 0; i < NXA; i++ ) xa[i] = x[ NXD+1+i ];
54  for( i = 0; i < NU; i++ ) u[i] = x[ NXA+NXD+1+i ];
55 
56  p[ 0] = 1.5458567140000001E-01;
57  p[ 1] = 1.7499999999999999E-01;
58  p[ 2] = 3.4717208398678062E-01;
59  p[ 3] = 6.1895708603484367E-01;
60  p[ 4] = 1.6593025789999999E-01;
61  p[ 5] = 5.0695122527590109E-01;
62  p[ 6] = 8.5000000000000000E+00;
63  p[ 7] = 1.7000000000000001E-01;
64  p[ 8] = 9.3885430857029321E+04;
65  p[ 9] = 2.5000000000000000E+02;
66  p[10] = 1.4026000000000000E+01;
67  p[11] = 3.2000000000000001E-01;
68  p[12] = 7.1054000000000002E+01;
69  p[13] = 4.7163089489100003E+01;
70  p[14] = 4.1833910753991770E+00;
71  p[15] = 2.4899344810136301E+00;
72  p[16] = 1.8760537088149468E+02;
73 
74  ffcn( &x[0], xd, xa, u, p, f );
75  gfcn( &x[0], xd, xa, u, p, &(f[NXD]) );
76 
77  delete[] xd;
78  delete[] xa;
79  delete[] u;
80  delete[] p;
81 }
82 
83 
84 
85 
86 int main( ){
87 
89 
90  const int nx = 82; // the number of differential states
91  const int nxa = 122; // the number of algebraic states
92  const int nu = 2; // the number of controls
93  //const int np = 0; // the number of parameters
94  //const int nw = 0; // the number of disturbances
95 
96  TIME t;
97  DifferentialState x("", nx, 1);
98  AlgebraicState z("", nxa, 1);
99  Control u("", nu, 1);
100 
101 
102  IntermediateState is(1+nx+nxa+nu);
103  is(0) = t;
104  for (int i=0; i < nx; ++i) is(1+i) = x(i);
105  for (int i=0; i < nxa; ++i) is(1+nx+i) = z(i);
106  for (int i=0; i < nu; ++i) is(1+nx+nxa+i) = u(i);
107 
108  CFunction hydroscalModel( nx+nxa, ffcn_model );
109 
110 
111  // Define a Right-Hand-Side:
112  // -------------------------
113 
115  f << hydroscalModel(is);
116 
117 
118  // DEFINE AN INTEGRATOR:
119  // ---------------------
120  IntegratorBDF integrator( f );
121 
122 
123  // DEFINE INITIAL VALUES:
124  // ----------------------
125 
126  double xd_init[NXD] = { 2.1936116177990631E-01,
127  3.3363028623863722E-01,
128  3.7313133250625952E-01,
129  3.9896472354654333E-01,
130  4.1533719381260475E-01,
131  4.2548399372287182E-01,
132  4.3168379354213621E-01,
133  4.3543569751236455E-01,
134  4.3768918647214428E-01,
135  4.3903262905928286E-01,
136  4.3982597315656735E-01,
137  4.4028774979047969E-01,
138  4.4055002518902953E-01,
139  4.4069238917008052E-01,
140  4.4076272408112094E-01,
141  4.4078980543461005E-01,
142  4.4079091412311144E-01,
143  4.4077642312834125E-01,
144  4.4075255679998443E-01,
145  4.4072304911231042E-01,
146  4.4069013958173919E-01,
147  6.7041926189645151E-01,
148  7.3517997375758948E-01,
149  7.8975978943631409E-01,
150  8.3481725159539033E-01,
151  8.7125377077380739E-01,
152  9.0027275078767721E-01,
153  9.2312464536394301E-01,
154  9.4096954980798608E-01,
155  9.5481731262797742E-01,
156  9.6551271145368878E-01,
157  9.7374401773010488E-01,
158  9.8006186072166701E-01,
159  9.8490109485675337E-01,
160  9.8860194771099286E-01,
161  9.9142879342008328E-01,
162  9.9358602331847468E-01,
163  9.9523105632238640E-01,
164  9.9648478785701988E-01,
165  9.9743986301741971E-01,
166  9.9816716097314861E-01,
167  9.9872084014280071E-01,
168  3.8633811956730968E+00,
169  3.9322260498028840E+00,
170  3.9771965626392531E+00,
171  4.0063070333869728E+00,
172  4.0246026844143410E+00,
173  4.0358888958821835E+00,
174  4.0427690398786789E+00,
175  4.0469300433477020E+00,
176  4.0494314648020326E+00,
177  4.0509267560029381E+00,
178  4.0518145583397631E+00,
179  4.0523364846379799E+00,
180  4.0526383977460299E+00,
181  4.0528081437632766E+00,
182  4.0528985491134542E+00,
183  4.0529413510270169E+00,
184  4.0529556049324462E+00,
185  4.0529527471448805E+00,
186  4.0529396392278008E+00,
187  4.0529203970496912E+00,
188  3.6071164950918582E+00,
189  3.7583754503438387E+00,
190  3.8917148481441974E+00,
191  4.0094300698741563E+00,
192  4.1102216725798293E+00,
193  4.1944038520620675E+00,
194  4.2633275166560596E+00,
195  4.3188755452109175E+00,
196  4.3630947909857642E+00,
197  4.3979622247841386E+00,
198  4.4252580012497740E+00,
199  4.4465128947193868E+00,
200  4.4630018314791968E+00,
201  4.4757626150015568E+00,
202  4.4856260094946823E+00,
203  4.4932488551808500E+00,
204  4.4991456959629330E+00,
205  4.5037168116896273E+00,
206  4.5072719605639726E+00,
207  4.5100498969782414E+00 };
208 
209 
210  double xa_init[NXA] = { 8.7651079143636981E+00,
211  8.7871063316432316E+00,
212  8.7893074703670067E+00,
213  8.7901954544445342E+00,
214  8.7901233416606477E+00,
215  8.7894020661781447E+00,
216  8.7882641216255362E+00,
217  8.7868655382627203E+00,
218  8.7853059232818165E+00,
219  8.7836472367940104E+00,
220  8.7819274715696096E+00,
221  8.7801697317787344E+00,
222  8.7783879979338462E+00,
223  8.7765907033291164E+00,
224  8.7747829241037341E+00,
225  8.7729677102977046E+00,
226  8.7711468912374286E+00,
227  8.7693215615475513E+00,
228  8.7674923739534876E+00,
229  8.7656597155017142E+00,
230  2.7825469403413372E+00,
231  2.8224111125799740E+00,
232  2.8351257821612172E+00,
233  2.8455862495713884E+00,
234  2.8539999172723634E+00,
235  2.8606290594307993E+00,
236  2.8657653801220269E+00,
237  2.8696861889639877E+00,
238  2.8726352758900391E+00,
239  2.8748174364382795E+00,
240  2.8763998227654772E+00,
241  2.8775162576841131E+00,
242  2.8782724559458406E+00,
243  2.8787511355838511E+00,
244  2.8790165741126224E+00,
245  2.8791184656798956E+00,
246  2.8790950843473126E+00,
247  2.8789758246804231E+00,
248  2.8787832131565576E+00,
249  2.8785344845386325E+00,
250  3.7489688386445703E+00,
251  3.7511699771858589E+00,
252  3.7520579611269311E+00,
253  3.7519858482265618E+00,
254  3.7512645726312401E+00,
255  3.7501266279652898E+00,
256  3.7487280444903774E+00,
257  3.7471684294005221E+00,
258  3.7455097428065072E+00,
259  3.7437899774766037E+00,
260  3.7420322375793442E+00,
261  3.7402505036278120E+00,
262  3.7384532089192324E+00,
263  3.7366454295969547E+00,
264  3.7348302157041928E+00,
265  3.7330093965681632E+00,
266  3.7311840668122449E+00,
267  3.7293548791598456E+00,
268  3.7275222206556560E+00,
269  3.5295879437000068E+00,
270  3.5694521158072119E+00,
271  3.5821667852381145E+00,
272  3.5926272524800611E+00,
273  3.6010409200004330E+00,
274  3.6076700619776987E+00,
275  3.6128063825021988E+00,
276  3.6167271912042991E+00,
277  3.6196762780219980E+00,
278  3.6218584384893231E+00,
279  3.6234408247540211E+00,
280  3.6245572596202216E+00,
281  3.6253134578357198E+00,
282  3.6257921374340887E+00,
283  3.6260575759313443E+00,
284  3.6261594674751652E+00,
285  3.6261360861254119E+00,
286  3.6260168264456856E+00,
287  3.6258242149122157E+00,
288  3.6255754862872984E+00,
289  3.5278596344996789E+00,
290  8.7075189603180618E+01,
291  8.2548857813137090E+01,
292  8.1085116711116342E+01,
293  8.0140698658642663E+01,
294  7.9532219332963521E+01,
295  7.9135751980236464E+01,
296  7.8870294691608407E+01,
297  7.8684803169784061E+01,
298  7.8547757165561293E+01,
299  7.8439916843235665E+01,
300  7.8349617512390665E+01,
301  7.8269815515229979E+01,
302  7.8196267858564511E+01,
303  7.8126422374424024E+01,
304  7.8058745287858954E+01,
305  7.7992315317564561E+01,
306  7.7926579216690257E+01,
307  7.7861204749145912E+01,
308  7.7795992344269862E+01,
309  7.7730822041668659E+01,
310  7.7665621642015878E+01,
311  7.1094961608415730E+01,
312  6.9448805116206330E+01,
313  6.8122261394548488E+01,
314  6.7060799125769435E+01,
315  6.6217795308026254E+01,
316  6.5550027436041674E+01,
317  6.5020432750221772E+01,
318  6.4598581400619508E+01,
319  6.4260125467265169E+01,
320  6.3985893352644759E+01,
321  6.3760944540013256E+01,
322  6.3573715428857163E+01,
323  6.3415297789173543E+01,
324  6.3278851294230762E+01,
325  6.3159135609293749E+01,
326  6.3052142835899517E+01,
327  6.2954811408060124E+01,
328  6.2864804764641939E+01,
329  6.2780340868928761E+01,
330  6.2700061296306565E+01,
331  6.2622930929692828E+01 };
332 
333  double u_init[ NU] = { 4.1833910982822058E+00, 2.4899344742988991E+00 };
334 
335  double t_start = 0.0;
336  double t_end = 120.0;
337 
338 
339  // START THE INTEGRATION:
340  // ----------------------
341 
342  integrator.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
343  integrator.set( INTEGRATOR_TOLERANCE, 1e-6 );
344  integrator.set( ABSOLUTE_TOLERANCE , 1e-2 );
345  integrator.set( PRINT_INTEGRATOR_PROFILE, YES );
346  //integrator.set( LINEAR_ALGEBRA_SOLVER, SPARSE_LU );
347 
348  Grid tt( t_start, t_end, 100 );
349 
350  integrator.integrate( tt, xd_init, xa_init, 0, u_init );
351 
352  integrator.printRunTimeProfile();
353 
354 
355  // GET THE RESULTS
356  // ---------------
357 
358  VariablesGrid differentialStates;
359  VariablesGrid algebraicStates ;
360  VariablesGrid intermediateStates;
361 
362  integrator.getX ( differentialStates );
363  integrator.getXA( algebraicStates );
364  integrator.getI ( intermediateStates );
365 
366  GnuplotWindow window;
367  window.addSubplot( differentialStates(0) );
368  window.addSubplot( algebraicStates (0) );
369 
370  window.plot();
371 
372 
373  return 0;
374 }
375 
376 
377 
#define NXD
returnValue getX(DVector &xEnd) const
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
Implements the backward-differentiation formula for integrating DAEs.
returnValue set(OptionsName name, int value)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue addSubplot(PlotWindowSubplot &_subplot)
#define YES
Definition: acado_types.hpp:51
void ffcn_model(double *x, double *f, void *user_data)
const int nu
#define NXA
returnValue getI(VariablesGrid &I) const
int main()
static void gfcn(double *t, double *xd, double *xa, double *u, double *p, double *rhs)
static void ffcn(double *t, double *xd, double *xa, double *u, double *p, double *rhs)
returnValue getXA(DVector &xaEnd) const
const double t_end
const double t_start
#define NP
(no description yet)
Definition: c_function.hpp:54
#define NU
virtual returnValue printRunTimeProfile() const
Definition: integrator.cpp:624
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue integrate(double t0, double tend, double *x0, double *xa=0, double *p=0, double *u=0, double *w=0)
Definition: integrator.cpp:207
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:41