dynamic_system.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 
34 
35 
36 
38 
39 
40 //
41 // PUBLIC MEMBER FUNCTIONS:
42 //
43 
45 {
46  nDiffEqn = 0;
47  nSwitchFcn = 0;
48 
49  diffEqn = 0;
50  outputFcn = 0;
51 
52  switchFcn = 0;
53  selectFcn = 0;
54 }
55 
56 
58  )
59 {
60  OutputFcn _outputFcn;
61 
62  nDiffEqn = 1;
63  nSwitchFcn = 0;
64 
65  diffEqn = (DifferentialEquation**) calloc( 1,sizeof(DifferentialEquation*) );
66  diffEqn[0] = _diffEqn.clone();
67 
68  outputFcn = (OutputFcn**) calloc( 1,sizeof(OutputFcn*) );
69  outputFcn[0] = new OutputFcn( _outputFcn );
70 
71  switchFcn = 0;
72  selectFcn = 0;
73 }
74 
75 
77  const OutputFcn& _outputFcn
78  )
79 {
80  nDiffEqn = 1;
81  nSwitchFcn = 0;
82 
83  diffEqn = (DifferentialEquation**) calloc( 1,sizeof(DifferentialEquation*) );
84  diffEqn[0] = _diffEqn.clone();
85 
86  outputFcn = (OutputFcn**) calloc( 1,sizeof(OutputFcn*) );
87  outputFcn[0] = new OutputFcn( _outputFcn );
88 
89  switchFcn = 0;
90  selectFcn = 0;
91 }
92 
93 
95 {
96  nDiffEqn = rhs.nDiffEqn;
97  nSwitchFcn = rhs.nSwitchFcn;
98 
99  if ( ( rhs.diffEqn != 0 ) && ( rhs.outputFcn != 0 ) )
100  {
102  for( uint i=0; i<nDiffEqn; ++i )
103  diffEqn[i] = (rhs.diffEqn[i])->clone();
104 
105  outputFcn = (OutputFcn**) calloc( nDiffEqn,sizeof(OutputFcn*) );
106  for( uint i=0; i<nDiffEqn; ++i )
107  outputFcn[i] = new OutputFcn( *(rhs.outputFcn[i]) );
108  }
109  else
110  {
111  nDiffEqn = 0;
112 
113  diffEqn = 0;
114  outputFcn = 0;
115  }
116 
117  if ( rhs.switchFcn != 0 )
118  {
119  switchFcn = (Function**) calloc( nSwitchFcn,sizeof(Function*) );
120  for( uint i=0; i<nSwitchFcn; ++i )
121  switchFcn[i] = new Function( *(rhs.switchFcn[i]) );
122  }
123  else
124  {
125  switchFcn = 0;
126  nSwitchFcn = 0;
127  }
128 
129  if ( rhs.selectFcn != 0 )
130  selectFcn = new Function( *(rhs.selectFcn) );
131  else
132  selectFcn = 0;
133 }
134 
135 
137 {
138  if ( diffEqn != 0 )
139  {
140  for( uint i=0; i<nDiffEqn; ++i )
141  delete diffEqn[i];
142  free( diffEqn );
143  }
144 
145  if ( outputFcn != 0 )
146  {
147  for( uint i=0; i<nDiffEqn; ++i )
148  delete outputFcn[i];
149  free( outputFcn );
150  }
151 
152  if ( switchFcn != 0 )
153  {
154  for( uint i=0; i<nSwitchFcn; ++i )
155  delete switchFcn[i];
156  free( switchFcn );
157  }
158 
159  if ( selectFcn != 0 )
160  delete selectFcn;
161 }
162 
163 
165 {
166  if ( this != &rhs )
167  {
168  if ( diffEqn != 0 )
169  {
170  for( uint i=0; i<nDiffEqn; ++i )
171  delete diffEqn[i];
172  free( diffEqn );
173  }
174 
175  if ( outputFcn != 0 )
176  {
177  for( uint i=0; i<nDiffEqn; ++i )
178  delete outputFcn[i];
179  free( outputFcn );
180  }
181 
182  if ( switchFcn != 0 )
183  {
184  for( uint i=0; i<nSwitchFcn; ++i )
185  delete switchFcn[i];
186  free( switchFcn );
187  }
188 
189  if ( selectFcn != 0 )
190  delete selectFcn;
191 
192 
193  nDiffEqn = rhs.nDiffEqn;
194  nSwitchFcn = rhs.nSwitchFcn;
195 
196  if ( ( rhs.diffEqn != 0 ) && ( rhs.outputFcn != 0 ) )
197  {
199  for( uint i=0; i<nDiffEqn; ++i )
200  diffEqn[i] = (rhs.diffEqn[i])->clone();
201 
202  outputFcn = (OutputFcn**) calloc( nDiffEqn,sizeof(OutputFcn*) );
203  for( uint i=0; i<nDiffEqn; ++i )
204  outputFcn[i] = new OutputFcn( *(rhs.outputFcn[i]) );
205  }
206  else
207  {
208  nDiffEqn = 0;
209 
210  diffEqn = 0;
211  outputFcn = 0;
212  }
213 
214  if ( rhs.switchFcn != 0 )
215  {
216  switchFcn = (Function**) calloc( nSwitchFcn,sizeof(Function*) );
217  for( uint i=0; i<nSwitchFcn; ++i )
218  switchFcn[i] = new Function( *(rhs.switchFcn[i]) );
219  }
220  else
221  {
222  switchFcn = 0;
223  nSwitchFcn = 0;
224  }
225 
226  if ( rhs.selectFcn != 0 )
227  selectFcn = new Function( *(rhs.selectFcn) );
228  else
229  selectFcn = 0;
230  }
231 
232  return *this;
233 }
234 
235 
236 
238 {
239  OutputFcn emptyOutputFcn;
240  return addSubsystem( _diffEqn,emptyOutputFcn );
241 }
242 
243 
245  const OutputFcn& _outputFcn
246  )
247 {
248  if ( isConsistentDiffEqn( _diffEqn ) == BT_FALSE )
250 
251  if ( isConsistentOutputFcn( _outputFcn ) == BT_FALSE )
253 
254  ++nDiffEqn;
255 
257  diffEqn[ nDiffEqn-1 ] = _diffEqn.clone();
258 
259  outputFcn = (OutputFcn**) realloc( outputFcn,nDiffEqn*sizeof(OutputFcn*) );
260  outputFcn[ nDiffEqn-1 ] = new OutputFcn( _outputFcn );
261 
262  //return SUCCESSFUL_RETURN;
264 }
265 
266 
267 
269  )
270 {
271  ++nSwitchFcn;
272 
273  switchFcn = (Function**) realloc( switchFcn,nSwitchFcn*sizeof(Function*) );
274  switchFcn[ nSwitchFcn-1 ] = new Function( _switchFcn );
275 
276  //return SUCCESSFUL_RETURN;
278 }
279 
280 
281 
283  )
284 {
285  if ( selectFcn == 0 )
286  selectFcn = new Function( _selectFcn );
287  else
288  *selectFcn = _selectFcn;
289 
290  //return SUCCESSFUL_RETURN;
292 }
293 
294 
295 
296 //
297 // PROTECTED MEMBER FUNCTIONS:
298 //
299 
301  ) const
302 {
303  if ( nDiffEqn == 0 )
304  return BT_TRUE;
305 
306  if ( diffEqn[0]->getNumDynamicEquations( ) != _diffEqn.getNumDynamicEquations( ) )
307  return BT_FALSE;
308 
309  if ( diffEqn[0]->getNumAlgebraicEquations( ) != _diffEqn.getNumAlgebraicEquations( ) )
310  return BT_FALSE;
311 
312  if ( diffEqn[0]->isDiscretized( ) != _diffEqn.isDiscretized( ) )
313  return BT_FALSE;
314 
315  return BT_TRUE;
316 }
317 
318 
320  ) const
321 {
322  if ( nDiffEqn == 0 )
323  return BT_TRUE;
324 
325  if ( outputFcn[0]->getDim( ) != _outputFcn.getDim( ) )
326  return BT_FALSE;
327 
328  if ( ( diffEqn[0]->isODE( ) == BT_TRUE ) && ( _outputFcn.getNXA( ) > 0 ) )
329  return BT_FALSE;
330 
331  return BT_TRUE;
332 }
333 
334 
335 
337 
338 // end of file.
returnValue addSubsystem(const DifferentialEquation &_diffEqn)
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
Allows to setup and evaluate output functions based on SymbolicExpressions.
Definition: output_fcn.hpp:55
int getNumDynamicEquations() const
virtual BooleanType isDiscretized() const
Stores a DifferentialEquation together with an OutputFcn.
uint getNumDynamicEquations() const
BooleanType isDiscretized() const
Allows to pass back messages to the calling function.
int getNumAlgebraicEquations() const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
uint getNumAlgebraicEquations() const
#define CLOSE_NAMESPACE_ACADO
int getNXA() const
Definition: function.cpp:212
BooleanType isConsistentOutputFcn(const OutputFcn &_outputFcn) const
int getDim() const
BooleanType isConsistentDiffEqn(const DifferentialEquation &_diffEqn) const
BooleanType isODE() const
DifferentialEquation ** diffEqn
void rhs(const real_t *x, real_t *f)
#define BT_TRUE
Definition: acado_types.hpp:47
OutputFcn ** outputFcn
virtual DifferentialEquation * clone() const
#define BEGIN_NAMESPACE_ACADO
#define BT_FALSE
Definition: acado_types.hpp:49
returnValue setSelectFunction(const Function &_selectFcn)
returnValue addSwitchFunction(const Function &_switchFcn)
DynamicSystem & operator=(const DynamicSystem &rhs)
Function * selectFcn
Function ** switchFcn
#define ACADOERROR(retval)
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:32