differential_equation.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 
39 
40 
42 
43 
44 
45 
46 //
47 // PUBLIC MEMBER FUNCTIONS:
48 //
49 
51 
52  T1 = 0;
53  T2 = 0;
54  t1 = 0.0;
55  t2 = 1.0;
56  setup();
57 }
58 
59 
60 DifferentialEquation::DifferentialEquation( const double &tStart, const double &tEnd ){
61 
62  T1 = 0;
63  T2 = 0;
64  t1 = tStart;
65  t2 = tEnd;
66  setup();
67 }
68 
69 
70 DifferentialEquation::DifferentialEquation( const double &tStart, const Parameter &tEnd ){
71 
72  ASSERT( tEnd.getDim() == 1 );
73 
74  T1 = 0;
75  T2 = new Parameter(tEnd);
76  t1 = tStart;
77  t2 = 0.0;
78  setup();
79 }
80 
81 
82 DifferentialEquation::DifferentialEquation( const Parameter &tStart, const double &tEnd ){
83 
84  ASSERT( tStart.getDim() == 1 );
85 
86  T1 = new Parameter(tStart);
87  T2 = 0;
88  t1 = 0.0;
89  t2 = tEnd;
90  setup();
91 }
92 
93 
95 
96  ASSERT( tStart.getDim() == 1 );
97  ASSERT( tEnd.getDim() == 1 );
98 
99  T1 = new Parameter(tStart);
100  T2 = new Parameter(tEnd);
101  t1 = 0.0;
102  t2 = 0.0;
103  setup();
104 }
105 
106 
108 
109  det = DET_UNKNOWN;
112 
113  counter = 0;
114  component = 0;
115 
116  stepLength = -INFTY;
117 }
118 
119 
121 
122  det = arg.det ;
123  is_implicit = arg.is_implicit;
125 
126  lyap = arg.lyap;
127  counter = arg.counter;
128 
129  if( arg.component == 0 ){
130  component = 0;
131  }
132  else{
133  int run1;
134  component = (int*)calloc(counter,sizeof(int));
135  for( run1 = 0; run1 < counter; run1++ ){
136  component[run1] = arg.component[run1];
137  }
138  }
139 
140  if( arg.T1 != 0 ) T1 = new Parameter(*arg.T1);
141  else T1 = 0;
142 
143  if( arg.T2 != 0 ) T2 = new Parameter(*arg.T2);
144  else T2 = 0;
145 
146  t1 = arg.t1;
147  t2 = arg.t2;
148 
149  stepLength = arg.stepLength;
150 }
151 
152 
153 
155  :Function( arg ){
156 
157  copy( arg );
158 }
159 
160 
161 
163 
164  if( component != 0 )
165  free(component);
166 
167  if( T1 != 0 ) delete T1;
168  if( T2 != 0 ) delete T2;
169 }
170 
171 
172 
174 
175  if ( this != &arg ){
176 
177  if( component != 0 )
178  free(component);
179 
180  if( T1 != 0 ) delete T1;
181  if( T2 != 0 ) delete T2;
182 
183  Function::operator=( arg );
184 
185  copy( arg );
186  }
187  return *this;
188 }
189 
190 
192 
193  return new DifferentialEquation(*this);
194 }
195 
196 
197 
199 
200  uint run1;
201 
203 
204  if( det == DET_DAE ){
206  ASSERT(1 == 0);
207  return *this;
208  }
209 
210  component = (int*)realloc(component,(counter+arg.getDim())*sizeof(int));
211 
212  for( run1 = 0; run1 < arg.getDim(); run1++ ){
213  counter++;
214  component[counter-1] = arg.getComponent(run1);
215  }
216 
217  return *this;
218  }
219  addDifferential( arg );
220  if( getNDX() > 0 ) is_implicit = BT_TRUE;
221  return *this;
222 }
223 
224 
226 
227  if( arg != 0 ){
229  return *this;
230  }
231 
232  det = DET_DAE;
233  return *this;
234 }
235 
236 
238 
239  if( T1 == 0 && T2 == 0 ){
241  }
242  if( T1 != 0 && T2 == 0 ){
243  Function::operator<<( (t2-T1[0])*arg );
244  }
245  if( T1 == 0 && T2 != 0 ){
246  Function::operator<<( (T2[0]-t1)*arg );
247  }
248  if( T1 != 0 && T2 != 0 ){
249  Function::operator<<( (T2[0]-T1[0])*arg );
250  }
251 
253 
254  det = DET_DAE;
255  }
256  else{
257  if( det != DET_DAE )
258  det = DET_ODE;
259  }
260 
261  return *this;
262 }
263 
264 
265 
267 
268  Expression tmp;
269  tmp = arg;
270  return addDifferential( tmp );
271 }
272 
273 
275 
277  det = DET_DAE;
278  return *this;
279 }
280 
281 
283 
284  det = DET_DAE;
285  if( fabs(arg) < EPS ) return *this;
287  return *this;
288 }
289 
290 
292 
293  uint run1;
294 
295  for( run1 = 0; run1 < arg.getDim(); run1++ )
296  addDifferential( arg(run1) );
297 
298  return *this;
299 }
300 
301 
303 
304  uint run1;
305 
306  for( run1 = 0; run1 < arg.getDim(); run1++ )
307  addAlgebraic( arg(run1) );
308 
309  return *this;
310 }
311 
312 
314 
315  uint run1, run2;
316 
317  for( run1 = 0; run1 < arg.getNumRows(); run1++ )
318  for( run2 = 0; run2 < arg.getNumCols(); run2++ )
319  addDifferential( arg.operator()(run1,run2) );
320 
321  return *this;
322 }
323 
324 
326 
327  uint run1, run2;
328 
329  for( run1 = 0; run1 < arg.getNumRows(); run1++ )
330  for( run2 = 0; run2 < arg.getNumCols(); run2++ )
331  addAlgebraic( arg.operator()(run1,run2) );
332 
333  return *this;
334 }
335 
336 
338 
339  lyap = arg;
340 
341  return operator==( arg.A*arg.P+arg.P*(arg.A).transpose()+(arg.B)*(arg.B).transpose() );
342 }
343 
344 
345 
347 
348  return lyap;
349 }
350 
352 {
353  if( lyap.isEmpty() == BT_TRUE ) return BT_FALSE;
354  return BT_TRUE;
355  }
356 
357 
358 
360 
361  if( det == DET_DAE ) return addAlgebraic(arg);
362  return addDifferential(arg);
363 }
364 
365 
367 
368  if( det == DET_DAE ) return addAlgebraic(arg);
369  return addDifferential(arg);
370 }
371 
372 
374 
375  if( det == DET_DAE ) return addAlgebraic(arg);
376  return addDifferential(arg);
377 }
378 
379 
381 
382  if( det == DET_DAE ) return addAlgebraic(arg);
383  return addDifferential(arg);
384 }
385 
386 
387 
389 {
390  if( getNumAlgebraicEquations() > 0 ) return BT_TRUE;
391  return BT_FALSE;
392 }
393 
394 
396 {
397  if( getNumAlgebraicEquations() == 0 ) return BT_TRUE;
398  return BT_FALSE;
399 }
400 
401 
403 
404  if ( order < 0 ){ ACADOERROR( RET_INDEX_OUT_OF_BOUNDS ); return 0; }
405 
406  Expression rhs;
407  getExpression(rhs);
408 
409  return rhs.getODEexpansion( order, component );
410 }
411 
412 
413 
415 
416  if ( is_implicit == BT_FALSE ){
417 
420 
421  return BT_TRUE;
422  }
423  return BT_FALSE;
424 }
425 
426 
428 
429  return is_discretized;
430 }
431 
432 
434 
435  return stepLength;
436 }
437 
438 
440 
441 // end of file.
virtual double getStepLength() const
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
BooleanType isEmpty() const
Definition: lyapunov.cpp:178
Expression A
Definition: lyapunov.hpp:116
virtual BooleanType isDiscretized() const
const double INFTY
BEGIN_NAMESPACE_ACADO const double EPS
int getNDX() const
Definition: function.cpp:217
DifferentialEquation & operator=(const DifferentialEquation &arg)
DifferentialEquation & addAlgebraic(const Expression &arg)
int getNumAlgebraicEquations() const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
#define CLOSE_NAMESPACE_ACADO
returnValue getExpression(Expression &expression) const
Definition: function.cpp:139
BooleanType isODE() const
Lyapunov getLyapunovObject() const
Expression P
Definition: lyapunov.hpp:118
BooleanType isDependingOn(VariableType type) const
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
Expression getODEexpansion(const int &order) const
BooleanType isDAE() const
void copy(const DifferentialEquation &arg)
unsigned getDim() const
Definition: vector.hpp:172
int getDim() const
FunctionEvaluationTree evaluationTree
Definition: function_.hpp:519
Function & operator=(const Function &rhs)
Definition: function.cpp:78
Expression B
Definition: lyapunov.hpp:117
DifferentialEquationType det
void rhs(const real_t *x, real_t *f)
virtual BooleanType makeImplicit()
unsigned getNumRows() const
Definition: matrix.hpp:185
Expression transpose() const
Definition: expression.cpp:811
#define ASSERT(x)
#define BT_TRUE
Definition: acado_types.hpp:47
unsigned getNumCols() const
Definition: matrix.hpp:189
VariableType getVariableType() const
BooleanType hasLyapunovEquation() const
DifferentialEquation & operator<<(const Expression &arg)
Expression getODEexpansion(const int &order, const int *arg) const
DifferentialEquation & addDifferential(const Expression &arg)
DifferentialEquation & operator==(const Expression &arg)
virtual DifferentialEquation * clone() const
uint getComponent(const unsigned int idx) const
#define ACADOWARNING(retval)
#define BEGIN_NAMESPACE_ACADO
#define BT_FALSE
Definition: acado_types.hpp:49
Function & operator<<(const Expression &arg)
Definition: function.cpp:102
Implements a parameter.
Definition: lyapunov.hpp:54
#define ACADOERROR(retval)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
virtual returnValue makeImplicit()
uint getDim() const


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