sim_export.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/code_generation/templates/templates.hpp>
42 
43 #ifdef WIN32
44 #include <windows.h>
45 #endif
46 
47 using namespace std;
48 
50 
51 
52 //
53 // PUBLIC MEMBER FUNCTIONS:
54 //
55 
56 SIMexport::SIMexport( const uint simIntervals, const double totalTime ) : ExportModule( )
57 {
58  setN(simIntervals);
59  T = totalTime;
60  integrator = 0;
61  timingSteps = 100;
62 
63  _initStates = "initStates.txt";
64  _controls = "controls.txt";
65  _results = "results.txt";
66  _ref = "ref.txt";
67  referenceProvided = false;
68  PRINT_DETAILS = true;
69 
70  timingCalls = 0;
71 
73 }
74 
75 
77  ) : ExportModule( arg )
78 {
79  copy( arg );
80 }
81 
82 
84 {
85  clear( );
86 }
87 
88 
90  )
91 {
92  if( this != &arg )
93  {
94  clear( );
96  copy( arg );
97  }
98 
99  return *this;
100 }
101 
102 
103 
104 returnValue SIMexport::exportCode( const std::string& dirName,
105  const std::string& _realString,
106  const std::string& _intString,
107  int _precision
108  )
109 {
111  set( QP_SOLVER, QP_NONE );
112 
113  string moduleName, modulePrefix;
114  get(CG_MODULE_NAME, moduleName);
115  get(CG_MODULE_PREFIX, modulePrefix);
116 
117  ExportDataInternal::fcnPrefix = moduleName;
118  ExportStatement::fcnPrefix = moduleName;
119  ExportStatement::varPrefix = modulePrefix;
120 
121  //
122  // Create the export folders
123  //
124 
125  set(CG_EXPORT_FOLDER_NAME, dirName);
126 
127  returnValue dirStatus = acadoCreateFolder( dirName );
128  if (dirStatus != SUCCESSFUL_RETURN)
129  return dirStatus;
130 
131  if ( setup( ) != SUCCESSFUL_RETURN )
133 
134  int printLevel;
135  get( PRINTLEVEL,printLevel );
136 
137  // export mandatory source code files
138  if ( exportAcadoHeader( dirName,commonHeaderName,_realString,_intString,_precision ) != SUCCESSFUL_RETURN )
140 
141  if( integrator != 0 )
142  {
143  std::string fileName( dirName );
144  fileName += "/" + moduleName + "_integrator.c";
145 
146  ExportFile integratorFile( fileName,commonHeaderName,_realString,_intString,_precision );
147  integrator->getCode( integratorFile );
148 
149  if ( integratorFile.exportCode( ) != SUCCESSFUL_RETURN )
151 
152  int sensGen;
153  get( DYNAMIC_SENSITIVITY, sensGen );
154  if( (ExportSensitivityType)sensGen == SYMMETRIC_FB ) sensGen = SYMMETRIC;
155  int measGrid;
156  get( MEASUREMENT_GRID, measGrid );
157  int generateMatlabInterface;
158  get( GENERATE_MATLAB_INTERFACE, generateMatlabInterface );
159  int debugMode;
160  get( INTEGRATOR_DEBUG_MODE, debugMode );
161  if ( (bool)generateMatlabInterface == true ) {
162  std::string integrateInterface = dirName;
163  integrateInterface += "/" + moduleName + "_integrate.c";
164  ExportMatlabIntegrator exportMexFun( INTEGRATOR_MEX_TEMPLATE, integrateInterface, commonHeaderName,_realString,_intString,_precision );
165  exportMexFun.configure((ExportSensitivityType)sensGen, (MeasurementGrid)measGrid == ONLINE_GRID, (bool)debugMode, timingCalls, ((RungeKuttaExport*)integrator)->getNumStages());
166  exportMexFun.exportCode();
167 
168  ExportTemplatedFile mexInterfaceMake;
169  mexInterfaceMake.dictionary[ "@MODULE_NAME@" ] = moduleName;
170  mexInterfaceMake.dictionary[ "@MODULE_PREFIX@" ] = modulePrefix;
171  integrateInterface = dirName + std::string("/make_" + moduleName + "_integrator.m");
172 
173  //acadoCopyTemplateFile(MAKE_MEX_INTEGRATOR, integrateInterface, "%", true);
174  mexInterfaceMake.setup( MAKE_MEX_INTEGRATOR,integrateInterface, "","real_t","int",16,"%" );
175  mexInterfaceMake.configure();
176  mexInterfaceMake.exportCode();
177 
178 
179  // NOT SUPPORTED ANYMORE:
180 // std::string rhsInterface = dirName;
181 // rhsInterface += "/" + moduleName + "_rhs.c";
182 // ExportMatlabRhs exportMexFun2( RHS_MEX_TEMPLATE, rhsInterface, commonHeaderName,_realString,_intString,_precision );
183 // exportMexFun2.configure(integrator->getNameFullRHS());
184 // exportMexFun2.exportCode();
185 //
186 // rhsInterface = dirName + std::string("/make_acado_model.m");
187 // acadoCopyTempateFile(MAKE_MEX_MODEL, rhsInterface, "%", true);
188  }
189  }
190 
191 
192  // export template for main file, if desired
193  if ( (PrintLevel)printLevel >= HIGH )
194  cout << "--> Exporting remaining files... ";
195 
196  // Export auxiliary functions, always
197  //
199  dirName + string("/") + moduleName + "_auxiliary_sim_functions.h",
200  dirName + string("/") + moduleName + "_auxiliary_sim_functions.c",
201  moduleName,
202  modulePrefix );
203  eaf.configure();
204  eaf.exportCode();
205 
206  // export a basic Makefile, if desired
207  int generateMakeFile;
208  get( GENERATE_MAKE_FILE,generateMakeFile );
209  if ( (bool)generateMakeFile == true )
210  if ( exportMakefile( dirName,"Makefile",_realString,_intString,_precision ) != SUCCESSFUL_RETURN )
212 
213  // export the evaluation file
214  int exportTestFile;
215  get( GENERATE_TEST_FILE, exportTestFile );
216  if ( exportTestFile && exportEvaluation( dirName, std::string( moduleName + "_compare.c" ) ) != SUCCESSFUL_RETURN )
218 
219  if ( (PrintLevel)printLevel >= HIGH )
220  cout << "done.\n";
221 
222  if ( (PrintLevel)printLevel > NONE )
224 
225  return SUCCESSFUL_RETURN;
226 }
227 
228 
229 
230 //
231 // PROTECTED MEMBER FUNCTIONS:
232 //
233 
235  )
236 {
237  integrator = arg.integrator;
238 
239  _initStates = arg._initStates;
240  _controls = arg._controls;
241  _results = arg._results;
242  _ref = arg._ref;
246  timingSteps = arg.timingSteps;
247 
248  return SUCCESSFUL_RETURN;
249 }
250 
251 
253 {
254  if ( integrator != 0 )
255  delete integrator;
256 
257  return SUCCESSFUL_RETURN;
258 }
259 
260 
261 
263 {
264  returnValue returnvalue = checkConsistency( );
265  if ( returnvalue != SUCCESSFUL_RETURN )
266  return ACADOERROR( returnvalue );
267 
268  //
269  // Set common header name
270  //
271  string moduleName;
272  get(CG_MODULE_NAME, moduleName);
273  commonHeaderName = moduleName + "_common.h";
274 
275  int numSteps;
276  get( NUM_INTEGRATOR_STEPS, numSteps );
277 
278  if ( numSteps <= 0 )
279  return ACADOERROR( RET_INVALID_OPTION );
280 
281  int integratorType;
282  get( INTEGRATOR_TYPE, integratorType );
283 
284  if ( integrator != NULL )
285  delete integrator;
286 
287  integrator = IntegratorExportFactory::instance().createAlgorithm(this, commonHeaderName, static_cast<ExportIntegratorType>(integratorType));
288 
289  if ( integrator == NULL )
290  return ACADOERROR( RET_INVALID_OPTION );
291 
292  Grid grid( 0.0, T, modelData.getN()+1 );
293  modelData.setIntegrationGrid( grid, numSteps );
294  returnvalue = integrator->setModelData( modelData );
295  if ( returnvalue != SUCCESSFUL_RETURN )
296  return returnvalue;
297 
298  if( modelData.hasOutputs() ) {
299  uint i;
300 
301  std::vector<Grid> newGrids_;
302  if( !referenceProvided ) _refOutputFiles.clear();
303  _outputFiles.clear();
304  for( i = 0; i < modelData.getNumOutputs(); i++ ) {
305  if( !referenceProvided ) _refOutputFiles.push_back( (std::string)"refOutput" + toString(i) + ".txt" );
306  _outputFiles.push_back( (std::string)"output" + toString(i) + ".txt" );
307  }
308  }
309 
311 
312  setStatus( BS_READY );
313 
314  return SUCCESSFUL_RETURN;
315 }
316 
317 
319 {
320  // consistency checks:
321  // only time-continuous DAEs without parameter and disturbances supported!
323  modelData.getModel(f);
324  if ( f.isDiscretized( ) == true )
326 
327  if ( ( f.getNUI( ) > 0 ) ||
328  /*( f.getNP( ) > 0 ) ||*/ ( f.getNPI( ) > 0 ) || ( f.getNW( ) > 0 ) )
330 
331  int mode;
332  get( IMPLICIT_INTEGRATOR_MODE, mode );
334 
335  return SUCCESSFUL_RETURN;
336 }
337 
338 
339 
341  ExportStruct dataStruct
342  ) const
343 {
344  if ( integrator->getDataDeclarations( declarations,dataStruct ) != SUCCESSFUL_RETURN )
346 
347  return SUCCESSFUL_RETURN;
348 }
349 
350 
352  ) const
353 {
354  if ( integrator->getFunctionDeclarations( declarations ) != SUCCESSFUL_RETURN )
356 
357  return SUCCESSFUL_RETURN;
358 }
359 
360 
361 returnValue SIMexport::exportTest( const std::string& _dirName,
362  const std::string& _fileName,
363  const std::string& _resultsFile,
364  const std::vector<std::string>& outputFiles,
365  const bool& TIMING,
366  const uint jumpReference
367  ) const
368 {
369  int i;
370  int sensGen;
371  get( DYNAMIC_SENSITIVITY, sensGen );
372  bool DERIVATIVES = ((ExportSensitivityType) sensGen != NO_SENSITIVITY);
373 
374  string moduleName, modulePrefix;
375  get(CG_MODULE_NAME, moduleName);
376  get(CG_MODULE_PREFIX, modulePrefix);
377 
378  std::vector<Grid> outputGrids;
379  std::vector<Expression> outputExpressions;
380  std::vector<std::string> outputNames;
381  modelData.getOutputGrids(outputGrids);
382  modelData.getOutputExpressions(outputExpressions);
383  modelData.getNameOutputs(outputNames);
384  if( outputFiles.size() != outputGrids.size() || (outputFiles.size() != outputExpressions.size() && outputFiles.size() != outputNames.size()) ) {
385  return ACADOERROR( RET_INVALID_OPTION );
386  }
387 
388  std::string fileName( _dirName );
389  fileName += "/" + _fileName;
390 
391  ExportFile main( fileName,commonHeaderName );
392 
393  main.addStatement( "#include <stdio.h>\n" );
394  main << "#include \"" + moduleName + "_auxiliary_sim_functions.h\"\n";
395  main.addLinebreak( 1 );
396  main.addComment( "SOME CONVENIENT DEFINTIONS:" );
397  main.addComment( "---------------------------------------------------------------" );
398  main.addStatement( (std::string)" #define JUMP " + toString(jumpReference) + " /* jump for the output reference */\n" );
399  main.addStatement( (std::string)" #define h " + toString(T/modelData.getN()) + " /* length of one simulation interval */\n" );
400  if( TIMING == true ) main.addStatement( (std::string)" #define STEPS_TIMING " + toString(timingSteps) + " /* number of steps for the timing */\n" );
401  if( TIMING == true ) main.addStatement( (std::string)" #define CALLS_TIMING " + toString(timingCalls) + " /* number of calls for the timing */\n" );
402  main.addStatement( (std::string)" #define RESULTS_NAME \"" + _resultsFile + "\"\n" );
403  for( i = 0; i < (int)outputGrids.size(); i++ ) {
404  main.addStatement( (std::string)" #define OUTPUT" + toString(i) + "_NAME \"" + outputFiles[i] + "\"\n" );
405  }
406  main.addStatement( (std::string)" #define CONTROLS_NAME \"" + _controls + "\"\n" );
407  main.addStatement( (std::string)" #define INIT_NAME \"" + _initStates + "\"\n" );
408  main.addComment( "---------------------------------------------------------------" );
409  main.addLinebreak( 2 );
410  main.addComment( "GLOBAL VARIABLES FOR THE ACADO REAL-TIME ALGORITHM:" );
411  main.addComment( "---------------------------------------------------" );
412  main.addStatement( " " + modulePrefix + "workspace " + moduleName + "Workspace;\n" );
413  main.addStatement( " " + modulePrefix + "variables " + moduleName + "Variables;\n" );
414  main.addLinebreak( );
415 
416  main.addLinebreak( 2 );
417  main.addComment( "A TEMPLATE FOR TESTING THE INTEGRATOR:" );
418  main.addComment( "----------------------------------------------------" );
419  main.addStatement( "int main(){\n" );
420  main.addLinebreak( );
421  main.addComment( 3,"INTRODUCE AUXILIARY VAIRABLES:" );
422  main.addComment( 3,"------------------------------" );
423  main.addStatement( " FILE *file, *controls, *initStates;\n" );
424  for( i = 0; i < (int)outputGrids.size(); i++ ) {
425  main.addStatement( (std::string)" FILE *output" + toString(i) + ";\n" );
426  }
427  main.addStatement( " int i,j,k,nil,reset;\n" );
428  for( i = 0; i < (int)outputGrids.size(); i++ ) {
429  if( !DERIVATIVES ) main.addStatement( (std::string)" const int dimOut" + toString(i) + " = " + modulePrefix + "_NOUT[" + toString(i) + "];\n" );
430  else main.addStatement( (std::string)" const int dimOut" + toString(i) + " = " + modulePrefix + "_NOUT[" + toString(i) + "]*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU);\n" );
431  }
432  if( !DERIVATIVES ) main.addStatement( " real_t x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA+" + modulePrefix + "_NU];\n" );
433  else main.addStatement( " real_t x[(" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU)+" + modulePrefix + "_NU];\n" );
434 
435  for( i = 0; i < (int)outputGrids.size(); i++ ) {
436  main.addStatement( (std::string)" real_t out" + toString(i) + "[" + modulePrefix + "_NMEAS[" + toString(i) + "]*dimOut" + toString(i) + "];\n" );
437  }
438  main.addStatement( " real_t u[" + modulePrefix + "_NU];\n" );
439  if( modelData.getNXA() > 0 ) main.addStatement( " real_t norm;\n" );
440  for( i = 0; i < (int)outputGrids.size(); i++ ) {
441  main.addStatement( (std::string)" real_t step" + toString(i) + " = h/" + modulePrefix + "_NMEAS[" + toString(i) + "];\n" );
442  }
443  if( TIMING == true ) {
444  main.addStatement( " struct timeval theclock;\n" );
445  main.addStatement( " real_t start, end, time;\n" );
446  if( !DERIVATIVES ) main.addStatement( " real_t xT[" + modulePrefix + "_NX+" + modulePrefix + "_NXA+" + modulePrefix + "_NU];\n" );
447  else main.addStatement( " real_t xT[(" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU)+" + modulePrefix + "_NU];\n" );
448  }
449  main.addStatement( " const " + modulePrefix + "workspace nullWork2 = {0};\n" );
450  main.addStatement( " " + moduleName + "Workspace = nullWork2;\n" );
451  main.addLinebreak( 2 );
452 
453  main.addComment( 3,"INITIALIZATION:" );
454  main.addComment( 3,"----------------------------------------" );
455  main.addStatement( " initStates = fopen( INIT_NAME,\"r\" );\n" );
456  main.addStatement( " for( j = 0; j < " + modulePrefix + "_NX+" + modulePrefix + "_NXA; j++) {\n" );
457  main.addStatement( " nil = fscanf( initStates, \"%lf\", &x[j] );\n" );
458  main.addStatement( " }\n" );
459  main.addStatement( " fclose( initStates );\n" );
460  main.addLinebreak( 1 );
461  if( DERIVATIVES ) {
462  main.addStatement( " for( i = 0; i < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA); i++ ) {\n" );
463  main.addStatement( " for( j = 0; j < " + modulePrefix + "_NX; j++ ) {\n" );
464  main.addStatement( " if( i == j ) {\n" );
465  main.addStatement( " x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA+i*" + modulePrefix + "_NX+j] = 1;\n" );
466  main.addStatement( " } else {\n" );
467  main.addStatement( " x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA+i*" + modulePrefix + "_NX+j] = 0;\n" );
468  main.addStatement( " }\n" );
469  main.addStatement( " }\n" );
470  main.addStatement( " }\n" );
471  main.addStatement( " for( i = 0; i < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA); i++ ) {\n" );
472  main.addStatement( " for( j = 0; j < " + modulePrefix + "_NU; j++ ) {\n" );
473  main.addStatement( " x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA+(" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*" + modulePrefix + "_NX+i*" + modulePrefix + "_NU+j] = 0;\n" );
474  main.addStatement( " }\n" );
475  main.addStatement( " }\n" );
476  }
477  main.addLinebreak( 1 );
478  main.addStatement( " reset = 1;\n" );
479  main.addLinebreak( 1 );
480  main.addComment( 3,"RUN INTEGRATOR:" );
481  main.addComment( 3,"----------------------------------------" );
482  main.addStatement( " file = fopen(RESULTS_NAME,\"w\");\n" );
483  for( i = 0; i < (int)outputGrids.size(); i++ ) {
484  main.addStatement( (std::string)" output" + toString(i) + " = fopen(OUTPUT" + toString(i) + "_NAME,\"w\");\n" );
485  }
486  main.addStatement( " controls = fopen(CONTROLS_NAME,\"r\");\n" );
487  main.addStatement( " for( i = 0; i < " + modulePrefix + "_N; i++ ) {\n" );
488  main.addStatement( " fprintf(file, \"%.16f \", i*h);\n" );
489  if( !DERIVATIVES ) main.addStatement( " for( j = 0; j < " + modulePrefix + "_NX+" + modulePrefix + "_NXA; j++) {\n" );
490  else main.addStatement( " for( j = 0; j < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU); j++) {\n" );
491  main.addStatement( " fprintf(file, \"%.16f \", x[j]);\n" );
492  main.addStatement( " }\n" );
493  main.addStatement( " fprintf(file, \"\\n\");\n" );
494  main.addLinebreak( );
495  if( !DERIVATIVES ) main.addStatement( " nil = fscanf( controls, \"%lf\", &x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA] );\n" );
496  else main.addStatement( " nil = fscanf( controls, \"%lf\", &x[(" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU)] );\n" );
497  main.addStatement( " for( j = 0; j < " + modulePrefix + "_NU; j++) {\n" );
498  if( !DERIVATIVES ) main.addStatement( " nil = fscanf( controls, \"%lf\", &x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA+j] );\n" );
499  else main.addStatement( " nil = fscanf( controls, \"%lf\", &x[(" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU)+j] );\n" );
500  main.addStatement( " }\n" );
501  main.addLinebreak( );
502  if( TIMING == true ) {
503  main.addStatement( " if( i == 0 ) {\n" );
504  if( !DERIVATIVES ) main.addStatement( " for( j=0; j < " + modulePrefix + "_NX+" + modulePrefix + "_NXA+" + modulePrefix + "_NU; j++ ) {\n" );
505  else main.addStatement( " for( j=0; j < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU)+" + modulePrefix + "_NU; j++ ) {\n" );
506  main.addStatement( " xT[j] = x[j];\n" );
507  main.addStatement( " }\n" );
508  main.addStatement( " }\n" );
509  }
510  main.addLinebreak( );
511  std::string integrate( " integrate( x" );
512  for( i = 0; i < (int)outputGrids.size(); i++ ) {
513  integrate += string(", out") + toString(i);
514  }
515  integrate += ", reset";
516  main.addStatement( integrate + " );\n" );
517  main.addStatement( " reset = 0;\n" );
518  main.addLinebreak( );
519  for( i = 0; i < (int)outputGrids.size(); i++ ) {
520  main.addStatement( (std::string)" for( j = 0; j < " + modulePrefix + "_NMEAS[" + toString(i) + "]; j=j+JUMP ) {\n" );
521  main.addStatement( (std::string)" fprintf(output" + toString(i) + ", \"%.16f \", i*h+(j+1)*step" + toString(i) + ");\n" );
522  main.addStatement( (std::string)" for( k = 0; k < dimOut" + toString(i) + "; k++ ) {\n" );
523  main.addStatement( (std::string)" fprintf(output" + toString(i) + ", \"%.16f \", out" + toString(i) + "[j*dimOut" + toString(i) + "+k]);\n" );
524  main.addStatement( " }\n" );
525  main.addStatement( (std::string)" fprintf(output" + toString(i) + ", \"%s\", \"\\n\");\n" );
526  main.addStatement( " }\n" );
527  }
528  main.addStatement( " }\n" );
529  main.addStatement( " fprintf(file, \"%.16f \", " + modulePrefix + "_N*h);\n" );
530  if( !DERIVATIVES ) main.addStatement( " for( j = 0; j < " + modulePrefix + "_NX+" + modulePrefix + "_NXA; j++) {\n" );
531  else main.addStatement( " for( j = 0; j < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU); j++) {\n" );
532  main.addStatement( " fprintf(file, \"%.16f \", x[j]);\n" );
533  main.addStatement( " }\n" );
534  main.addStatement( " fprintf(file, \"\\n\");\n" );
535  main.addLinebreak( );
536  main.addStatement( " fclose(file);\n" );
537  for( i = 0; i < (int)outputGrids.size(); i++ ) {
538  main.addStatement( (std::string)" fclose(output" + toString(i) + ");\n" );
539  }
540  main.addStatement( " fclose(controls);\n" );
541  if( TIMING == true ) {
542  main.addStatement( " gettimeofday( &theclock,0 );\n" );
543  main.addStatement( " start = 1.0*theclock.tv_sec + 1.0e-6*theclock.tv_usec;\n" );
544  main.addStatement( " reset = 1;\n" );
545  main.addStatement( " for( i=0; i < CALLS_TIMING; i++ ) {\n" );
546  main.addStatement( " for( j=0; j < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA); j++ ) {\n" );
547  main.addStatement( " x[j] = xT[j];\n" );
548  main.addStatement( " }\n" );
549  integrate = std::string( " integrate( x" );
550  for( i = 0; i < (int)outputGrids.size(); i++ ) {
551  integrate += string(", out") + toString(i);
552  }
553  integrate += ", reset";
554  main.addStatement( integrate + " );\n" );
555  main.addStatement( " reset = 0;\n" );
556  main.addStatement( " }\n" );
557  main.addStatement( " gettimeofday( &theclock,0 );\n" );
558  main.addStatement( " end = 1.0*theclock.tv_sec + 1.0e-6*theclock.tv_usec;\n" );
559  main.addStatement( " time = (end-start);\n" );
560  main.addLinebreak( );
561  main.addStatement( " printf( \"\\n\\n AVERAGE DURATION OF ONE INTEGRATION STEP: %.3g μs\\n\\n\", 1e6*time/STEPS_TIMING );\n" );
562  }
563  main.addLinebreak( );
564  main.addStatement( " return 0;\n" );
565  main.addStatement( "}\n" );
566 
567 
568  return main.exportCode( );
569 }
570 
571 
572 returnValue SIMexport::exportEvaluation( const std::string& _dirName,
573  const std::string& _fileName
574  ) const
575 {
576  int i;
577  int sensGen;
578  get( DYNAMIC_SENSITIVITY, sensGen );
579  bool DERIVATIVES = ((ExportSensitivityType) sensGen != NO_SENSITIVITY);
580 
581  string moduleName, modulePrefix;
582  get(CG_MODULE_NAME, moduleName);
583  get(CG_MODULE_PREFIX, modulePrefix);
584 
585  DVector nMeasV = modelData.getNumMeas();
586  DVector nOutV = modelData.getDimOutputs();
587 
588  std::vector<Grid> outputGrids;
589  modelData.getOutputGrids(outputGrids);
590 
591  std::string fileName = _dirName;
592  fileName += string("/") + _fileName;
593 
594  ExportFile main( fileName,commonHeaderName );
595 
596  main.addStatement( "#include <stdio.h>\n" );
597  main.addStatement( "#include \"" + moduleName + "_auxiliary_sim_functions.h\"\n" );
598  main.addLinebreak( 1 );
599  main.addComment( "SOME CONVENIENT DEFINTIONS:" );
600  main.addComment( "---------------------------------------------------------------" );
601  main.addStatement( (std::string)" #define h " + toString(T/modelData.getN()) + " /* length of one simulation interval */\n" );
602  main.addStatement( (std::string)" #define RESULTS_NAME \"" + _results + "\"\n" );
603  for( i = 0; i < (int)outputGrids.size(); i++ ) {
604  main.addStatement( (std::string)" #define OUTPUT" + toString(i) + "_NAME \"" + _outputFiles[i] + "\"\n" );
605  main.addStatement( (std::string)" #define REF_OUTPUT" + toString(i) + "_NAME \"" + _refOutputFiles[i] + "\"\n" );
606  }
607  main.addStatement( (std::string)" #define REF_NAME \"" + _ref + "\"\n" );
608  main.addComment( "---------------------------------------------------------------" );
609  main.addLinebreak( 2 );
610  main.addComment( "GLOBAL VARIABLES FOR THE ACADO REAL-TIME ALGORITHM:" );
611  main.addComment( "---------------------------------------------------" );
612  main.addStatement( " " + modulePrefix + "workspace " + moduleName + "Workspace;\n" );
613  main.addStatement( " " + modulePrefix + "variables " + moduleName + "Variables;\n" );
614  main.addLinebreak( );
615 
616  main.addLinebreak( 2 );
617  main.addComment( "A TEMPLATE FOR TESTING THE INTEGRATOR:" );
618  main.addComment( "----------------------------------------------------" );
619  main.addStatement( "int main(){\n" );
620  main.addLinebreak( );
621  main.addComment( 3,"INTRODUCE AUXILIARY VAIRABLES:" );
622  main.addComment( 3,"------------------------------" );
623  main.addStatement( " FILE *file, *ref;\n" );
624  for( i = 0; i < (int)outputGrids.size(); i++ ) {
625  main.addStatement( (std::string)" FILE *output" + toString(i) + ";\n" );
626  main.addStatement( (std::string)" FILE *refOutput" + toString(i) + ";\n" );
627  }
628  main.addStatement( " int i, j, nil;\n" );
629  main.addStatement( " real_t x[" + modulePrefix + "_NX+" + modulePrefix + "_NXA];\n" );
630  main.addStatement( " real_t xRef[" + modulePrefix + "_NX+" + modulePrefix + "_NXA];\n" );
631  for( i = 0; i < (int)outputGrids.size(); i++ ) {
632  main.addStatement( (std::string)" real_t step" + toString(i) + " = h/" + modulePrefix + "_NMEAS[" + toString(i) + "];\n" );
633  main.addStatement( (std::string)" real_t out" + toString(i) + "[" + modulePrefix + "_NMEAS[" + toString(i) + "]*" + modulePrefix + "_NOUT[" + toString(i) + "]];\n" );
634  main.addStatement( (std::string)" real_t refOut" + toString(i) + "[" + modulePrefix + "_NMEAS[" + toString(i) + "]*" + modulePrefix + "_NOUT[" + toString(i) + "]];\n" );
635  }
636  main.addStatement( " real_t maxErr, meanErr, maxErrX, meanErrX, maxErrXA, meanErrXA, temp;\n" );
637  main.addStatement( " const " + modulePrefix + "workspace nullWork2 = {0};\n" );
638  main.addStatement( " " + moduleName + "Workspace = nullWork2;\n" );
639  main.addLinebreak( 2 );
640 
641  main.addComment( 3,"START EVALUATION RESULTS:" );
642  main.addComment( 3,"----------------------------------------" );
643  main.addStatement( " meanErrX = 0;\n" );
644  main.addStatement( " meanErrXA = 0;\n" );
645  main.addStatement( " file = fopen(RESULTS_NAME,\"r\");\n" );
646  main.addStatement( " ref = fopen(REF_NAME,\"r\");\n" );
647  if( DERIVATIVES ) main.addStatement( " for( i = 0; i < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(1+" + modulePrefix + "_NX+" + modulePrefix + "_NU)+1; i++ ) {\n" );
648  else main.addStatement( " for( i = 0; i < " + modulePrefix + "_NX+" + modulePrefix + "_NXA+1; i++ ) {\n" );
649  main.addStatement( " nil = fscanf( file, \"%lf\", &temp );\n" );
650  main.addStatement( " nil = fscanf( ref, \"%lf\", &temp );\n" );
651  main.addStatement( " }\n" );
652  main.addStatement( " printf( \" STATES:\\n\" );\n" );
653  main.addLinebreak( );
654  main.addStatement( " for( i = 1; i <= " + modulePrefix + "_N; i++ ) {\n" );
655  main.addStatement( " nil = fscanf( file, \"%lf\", &temp );\n" );
656  main.addStatement( " nil = fscanf( ref, \"%lf\", &temp );\n" );
657  main.addLinebreak( );
658  main.addStatement( " maxErrX = 0;\n" );
659  main.addStatement( " for( j = 0; j < " + modulePrefix + "_NX; j++ ) {\n" );
660  main.addStatement( " nil = fscanf( file, \"%lf\", &x[j] );\n" );
661  main.addStatement( " nil = fscanf( ref, \"%lf\", &xRef[j] );\n" );
662  main.addStatement( " temp = fabs(x[j] - xRef[j])/fabs(xRef[j]);\n" );
663  main.addStatement( " if( temp > maxErrX ) maxErrX = temp;\n" );
664  main.addStatement( " if( isnan(x[j]) ) maxErrX = sqrt(-1);\n" );
665  main.addStatement( " }\n" );
666  main.addLinebreak( );
667  main.addStatement( " maxErrXA = 0;\n" );
668  main.addStatement( " for( j = 0; j < " + modulePrefix + "_NXA; j++ ) {\n" );
669  main.addStatement( " nil = fscanf( file, \"%lf\", &x[" + modulePrefix + "_NX+j] );\n" );
670  main.addStatement( " nil = fscanf( ref, \"%lf\", &xRef[" + modulePrefix + "_NX+j] );\n" );
671  main.addStatement( " temp = fabs(x[" + modulePrefix + "_NX+j] - xRef[" + modulePrefix + "_NX+j])/fabs(xRef[" + modulePrefix + "_NX+j]);\n" );
672  main.addStatement( " if( temp > maxErrXA ) maxErrXA = temp;\n" );
673  main.addStatement( " if( isnan(x[" + modulePrefix + "_NX+j]) ) maxErrXA = sqrt(-1);\n" );
674  main.addStatement( " }\n" );
675  main.addLinebreak( );
676  if( PRINT_DETAILS && modelData.getNXA() > 0 ) {
677  main.addStatement( " printf( \"MAX ERROR AT %.3f s: %.4e %.4e \\n\", i*h, maxErrX, maxErrXA );\n" );
678  }
679  else if( PRINT_DETAILS ) {
680  main.addStatement( " printf( \"MAX ERROR AT %.3f s: %.4e \\n\", i*h, maxErrX );\n" );
681  }
682  main.addStatement( " meanErrX += maxErrX;\n" );
683  main.addStatement( " meanErrXA += maxErrXA;\n" );
684  main.addLinebreak( );
685  if( DERIVATIVES ) {
686  main.addStatement( " for( j = 0; j < (" + modulePrefix + "_NX+" + modulePrefix + "_NXA)*(" + modulePrefix + "_NX+" + modulePrefix + "_NU); j++ ) {\n" );
687  main.addStatement( " nil = fscanf( file, \"%lf\", &temp );\n" );
688  main.addStatement( " nil = fscanf( ref, \"%lf\", &temp );\n" );
689  main.addStatement( " }\n" );
690  }
691  main.addStatement( " }\n" );
692  main.addStatement( " meanErrX = meanErrX/" + modulePrefix + "_N;\n" );
693  main.addStatement( " meanErrXA = meanErrXA/" + modulePrefix + "_N;\n" );
694  if( PRINT_DETAILS ) main.addStatement( " printf( \"\\n\" );\n" );
695  if( modelData.getNXA() > 0 ) {
696  main.addStatement( " printf( \"TOTAL MEAN ERROR: %.4e %.4e \\n\", meanErrX, meanErrXA );\n" );
697  }
698  else {
699  main.addStatement( " printf( \"TOTAL MEAN ERROR: %.4e \\n\", meanErrX );\n" );
700  }
701  main.addStatement( " printf( \"\\n\\n\" );\n" );
702  for( i = 0; i < (int)outputGrids.size(); i++ ) {
703  main.addLinebreak( );
704  main.addStatement( (std::string)" printf( \" OUTPUT FUNCTION " + toString(i+1) + ":\\n\" );\n" );
705  main.addStatement( (std::string)" meanErr = 0;\n" );
706  main.addStatement( (std::string)" output" + toString(i) + " = fopen(OUTPUT" + toString(i) + "_NAME,\"r\");\n" );
707  main.addStatement( (std::string)" refOutput" + toString(i) + " = fopen(REF_OUTPUT" + toString(i) + "_NAME,\"r\");\n" );
708  main.addLinebreak( );
709  main.addStatement( (std::string)" for( i = 1; i <= " + modulePrefix + "_N*" + modulePrefix + "_NMEAS[" + toString(i) + "]; i++ ) {\n" );
710  main.addStatement( (std::string)" nil = fscanf( output" + toString(i) + ", \"%lf\", &temp );\n" );
711  main.addStatement( (std::string)" nil = fscanf( refOutput" + toString(i) + ", \"%lf\", &temp );\n" );
712  main.addLinebreak( );
713  main.addStatement( " maxErr = 0;\n" );
714  main.addStatement( (std::string)" for( j = 0; j < " + modulePrefix + "_NOUT[" + toString(i) + "]; j++ ) {\n" );
715  main.addStatement( (std::string)" nil = fscanf( output" + toString(i) + ", \"%lf\", &out" + toString(i) + "[j] );\n" );
716  main.addStatement( (std::string)" nil = fscanf( refOutput" + toString(i) + ", \"%lf\", &refOut" + toString(i) + "[j] );\n" );
717  main.addStatement( (std::string)" temp = fabs(out" + toString(i) + "[j] - refOut" + toString(i) + "[j])/fabs(refOut" + toString(i) + "[j]);\n" );
718  main.addStatement( " if( temp > maxErr ) maxErr = temp;\n" );
719  main.addStatement( (std::string)" if( isnan(out" + toString(i) + "[j]) ) maxErr = sqrt(-1);\n" );
720  main.addStatement( " }\n" );
721  main.addLinebreak( );
722  if( PRINT_DETAILS ) main.addStatement( (std::string)" printf( \"MAX ERROR AT %.3f s: %.4e \\n\", (i-1)*step" + toString(i) + ", maxErr );\n" );
723  main.addStatement( " meanErr += maxErr;\n" );
724  main.addLinebreak( );
725  if( DERIVATIVES ) {
726  main.addStatement( (std::string)" for( j = 0; j < " + modulePrefix + "_NOUT[" + toString(i) + "]*(" + modulePrefix + "_NX+" + modulePrefix + "_NU); j++ ) {\n" );
727  main.addStatement( (std::string)" nil = fscanf( output" + toString(i) + ", \"%lf\", &temp );\n" );
728  main.addStatement( (std::string)" nil = fscanf( refOutput" + toString(i) + ", \"%lf\", &temp );\n" );
729  main.addStatement( " }\n" );
730  }
731  main.addStatement( " }\n" );
732  main.addStatement( (std::string)" meanErr = meanErr/(" + modulePrefix + "_N*" + modulePrefix + "_NMEAS[" + toString(i) + "]);\n" );
733  if( PRINT_DETAILS ) main.addStatement( " printf( \"\\n\" );\n" );
734  main.addStatement( " printf( \"TOTAL MEAN ERROR: %.4e \\n\", meanErr );\n" );
735  main.addStatement( " printf( \"\\n\\n\" );\n" );
736  }
737  main.addLinebreak( );
738  main.addStatement( " return 0;\n" );
739  main.addStatement( "}\n" );
740 
741  return main.exportCode( );
742 }
743 
744 
745 
746 returnValue SIMexport::exportAndRun( const std::string& dirName,
747  const std::string& initStates,
748  const std::string& controls,
749  const std::string& results,
750  const std::string& ref
751  )
752 {
753  string moduleName;
754  get(CG_MODULE_NAME, moduleName);
755 
756  std::string test( moduleName + "_test.c" );
757  set( GENERATE_TEST_FILE, 1 );
758 
759  Grid integrationGrid;
760  modelData.getIntegrationGrid(integrationGrid);
761  std::vector<Grid> outputGrids;
762  modelData.getOutputGrids(outputGrids);
763 
764  int measGrid;
765  get( MEASUREMENT_GRID, measGrid );
766  if( (MeasurementGrid)measGrid == ONLINE_GRID ) return ACADOERROR( RET_INVALID_OPTION );
767 
768  _initStates = initStates;
769  _controls = controls;
770  _results = results;
771  _ref = ref;
772 
773  int numSteps;
774  get( NUM_INTEGRATOR_STEPS, numSteps );
775  timingCalls = (uint) ceil((double)(timingSteps*modelData.getN())/((double) numSteps) - 10.0*EPS);
776  timingSteps = (uint) ceil((double)timingCalls*((double) numSteps/((double) modelData.getN())) - 10.0*EPS);
777 
778  if( !referenceProvided ) {
779  // REFERENCE:
780  set( NUM_INTEGRATOR_STEPS, (int)factorRef*numSteps );
781  exportCode( dirName );
782  exportTest( dirName, test, _ref, _refOutputFiles, false, 1 );
783  executeTest( dirName );
784  }
786 
787  // THE INTEGRATOR:
788  set( NUM_INTEGRATOR_STEPS, numSteps );
789  exportCode( dirName );
790  if(timingSteps > 0 && timingCalls > 0) exportTest( dirName, test, _results, _outputFiles, true, 1 );
791  else exportTest( dirName, test, _results, _outputFiles, false, 1 );
792  executeTest( dirName );
793 
794  // THE EVALUATION:
795  int nil;
796  nil = system( (dirName + "/./" + moduleName + "_compare").c_str() );
797  nil = nil+1;
798 
799  return SUCCESSFUL_RETURN;
800 }
801 
802 
803 returnValue SIMexport::exportAcadoHeader( const std::string& _dirName,
804  const std::string& _fileName,
805  const std::string& _realString,
806  const std::string& _intString,
807  int _precision
808  ) const
809 {
810  string moduleName, modulePrefix;
811  get(CG_MODULE_NAME, moduleName);
812  get(CG_MODULE_PREFIX, modulePrefix);
813 
814  int qpSolver;
815  get(QP_SOLVER, qpSolver);
816 
817  int useSinglePrecision;
818  get(USE_SINGLE_PRECISION, useSinglePrecision);
819 
820  string fileName;
821  fileName = _dirName + "/" + _fileName;
822 
823 
824  map<string, pair<string, string> > options;
825 
826  DVector nMeasV = getNumMeas();
827  DVector nOutV = getDimOutputs();
828 
829  options[ modulePrefix + "_N" ] = make_pair(toString( getN() ), "Number of control/estimation intervals.");
830  options[ modulePrefix + "_NX" ] = make_pair(toString( getNX() ), "Number of differential variables.");
831  options[ modulePrefix + "_NXD" ] = make_pair(toString( getNDX() ), "Number of differential derivative variables.");
832  options[ modulePrefix + "_NXA" ] = make_pair(toString( getNXA() ), "Number of algebraic variables.");
833  options[ modulePrefix + "_NU" ] = make_pair(toString( getNU() ), "Number of control variables.");
834  options[ modulePrefix + "_NOD" ] = make_pair(toString( getNOD() ), "Number of online data values.");
835  options[ modulePrefix + "_NUMOUT" ] = make_pair(toString( nOutV.getDim() ), "Number of output functions.");
836 
837  if( !nMeasV.isEmpty() && !nOutV.isEmpty() ) {
838  std::ostringstream acado_nout;
839  ExportVariable( modulePrefix + "_NOUT",nOutV,STATIC_CONST_INT ).exportDataDeclaration(acado_nout);
840  std::ostringstream acado_nmeas;
841  ExportVariable( modulePrefix + "_NMEAS",nMeasV,STATIC_CONST_INT ).exportDataDeclaration(acado_nmeas);
842  options[ modulePrefix + "_OUTPUTS_DEFINED" ] = make_pair("\n" + acado_nout.str() + acado_nmeas.str(), "Dimension and measurements of the output functions per shooting interval.");
843  }
844 
845  //
846  // ACADO variables and workspace
847  //
848  ExportStatementBlock variablesBlock;
849  stringstream variables;
850 
853  variablesBlock.exportCode(variables, _realString, _intString, _precision);
854 
855  ExportStatementBlock workspaceBlock;
856  stringstream workspace;
857 
860  workspaceBlock.exportCode(workspace, _realString, _intString, _precision);
861 
862  ExportStatementBlock functionsBlock;
863  stringstream functions;
864 
865  if (collectFunctionDeclarations( functionsBlock ) != SUCCESSFUL_RETURN)
867  functionsBlock.exportCode(functions, _realString);
868 
869  ExportCommonHeader ech(fileName, "", _realString, _intString, _precision);
870  ech.configure( moduleName, modulePrefix, useSinglePrecision, false, (QPSolverName)qpSolver,
871  options, variables.str(), workspace.str(), functions.str());
872 
873  return ech.exportCode();
874 }
875 
876 
877 returnValue SIMexport::exportMakefile( const std::string& _dirName,
878  const std::string& _fileName,
879  const std::string& _realString,
880  const std::string& _intString,
881  int _precision
882  ) const
883 {
884  string moduleName, modulePrefix;
885  get(CG_MODULE_NAME, moduleName);
886  get(CG_MODULE_PREFIX, modulePrefix);
887 
888  ExportTemplatedFile makefile;
889  makefile.dictionary[ "@MODULE_NAME@" ] = moduleName;
890  makefile.dictionary[ "@MODULE_PREFIX@" ] = modulePrefix;
891 
892  std::string fileName( _dirName );
893  fileName += "/" + _fileName;
894 
895  //acadoCopyTemplateFile(MAKEFILE_INTEGRATOR, fileName, "#", true);
896  makefile.setup( MAKEFILE_INTEGRATOR,fileName, "","real_t","int",16,"#" );
897  makefile.configure();
898  makefile.exportCode();
899 
900  return SUCCESSFUL_RETURN;
901 }
902 
903 
904 returnValue SIMexport::setReference( const std::string& reference, const std::vector<std::string>& outputReference ) {
905  if( hasOutputs() && outputReference.size() == 0 ) {
906  referenceProvided = false;
908  }
909  referenceProvided = true;
910  _ref = reference;
911  if( outputReference.size() > 0 ) _refOutputFiles = outputReference;
912 
913  return SUCCESSFUL_RETURN;
914 }
915 
916 
918  timingSteps = _timingSteps;
919 
920  return SUCCESSFUL_RETURN;
921 }
922 
923 
925  PRINT_DETAILS = details;
926 
927  return SUCCESSFUL_RETURN;
928 }
929 
930 
931 returnValue SIMexport::executeTest( const std::string& _dirName ) {
932  //sleep(2); does not compile on windows!!
933 
934  string moduleName;
935  get(CG_MODULE_NAME, moduleName);
936 
937  int nil;
938  nil = system((string("make clean -s -C ") + _dirName).c_str());
939  nil = system((string("make -s -C ") + _dirName).c_str());
940  nil = system((_dirName + "/./" + moduleName + "_test").c_str());
941  nil = nil+1;
942 
943  return SUCCESSFUL_RETURN;
944 }
945 
947  timingCalls = _timingCalls;
948 
949  return SUCCESSFUL_RETURN;
950 }
951 
952 
954 
955 // end of file.
virtual returnValue setTimingCalls(uint _timingCalls)
Definition: sim_export.cpp:946
BooleanType exportRhs() const
returnValue executeTest(const std::string &_dirName)
Definition: sim_export.cpp:931
returnValue collectDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
Definition: sim_export.cpp:340
returnValue clear()
Definition: sim_export.cpp:252
virtual returnValue setup(const std::string &_templateName, const std::string &_fileName, const std::string &_commonHeaderName="", const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16, const std::string &_commentString=std::string())
uint getN() const
returnValue setIntegrationGrid(const Grid &_ocpGrid, const uint _numSteps)
Definition: model_data.cpp:396
double T
Definition: sim_export.hpp:323
UserInteraction & operator=(const UserInteraction &rhs)
virtual ~SIMexport()
Definition: sim_export.cpp:83
int getNPI() const
Definition: function.cpp:239
virtual returnValue getCode(ExportStatementBlock &code)=0
std::map< std::string, std::string > dictionary
virtual BooleanType isDiscretized() const
DVector getNumMeas() const
Definition: model_data.cpp:614
virtual returnValue printDetails(bool details)
Definition: sim_export.cpp:924
DVector getDimOutputs() const
Definition: model_data.cpp:591
returnValue getOutputExpressions(std::vector< Expression > &outputExpressions_) const
Definition: model_data.cpp:166
Allows to export a tailored Runge-Kutta integrator for fast model predictive control.
Definition: rk_export.hpp:54
#define ACADOINFO(retval)
returnValue setStatus(BlockStatus _status)
BEGIN_NAMESPACE_ACADO const double EPS
uint getNOD() const
Allows to pass back messages to the calling function.
A class for generating some helper functions.
BooleanType modelDimensionsSet() const
Centralized place to export the common header for a generated module.
int getNUI() const
Definition: function.cpp:227
returnValue addComment(const std::string &_comment)
returnValue getModel(DifferentialEquation &_f) const
Definition: model_data.cpp:203
virtual returnValue setReference(const std::string &reference, const std::vector< std::string > &outputReference=*(new std::vector< std::string >()))
Definition: sim_export.cpp:904
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
virtual returnValue setTimingSteps(uint _timingSteps)
Definition: sim_export.cpp:917
std::string _initStates
Definition: sim_export.hpp:332
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
uint getNU() const
DVector getDimOutputs() const
string toString(T const &value)
std::string _ref
Definition: sim_export.hpp:335
returnValue configure(const uint firstOrder, const uint online, const uint debugMode, const uint timingCalls, const uint numStages)
ImplicitIntegratorMode
#define CLOSE_NAMESPACE_ACADO
virtual returnValue exportCode(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
returnValue collectFunctionDeclarations(ExportStatementBlock &declarations) const
Definition: sim_export.cpp:351
returnValue exportMakefile(const std::string &_dirName, const std::string &_fileName, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
Definition: sim_export.cpp:877
bool isEmpty() const
Definition: vector.hpp:176
uint getNXA() const
virtual returnValue getFunctionDeclarations(ExportStatementBlock &declarations) const =0
uint timingSteps
Definition: sim_export.hpp:330
AlgorithmBase * createAlgorithm(UserInteraction *_userInteraction, const std::string &_commonHeaderName, const AlgorithmType &id)
Allows to export files containing automatically generated algorithms for fast model predictive contro...
Definition: export_file.hpp:52
std::string commonHeaderName
User-interface to automatically generate simulation algorithms for fast optimal control.
Definition: sim_export.hpp:60
Allows export of template files.
User-interface to automatically generate algorithms for fast model predictive control.
returnValue exportEvaluation(const std::string &_dirName, const std::string &_fileName) const
Definition: sim_export.cpp:572
int getNW() const
Definition: function.cpp:245
returnValue setN(const uint N_)
#define TIMING
Definition: AD_test.c:51
returnValue configure(const std::string &_moduleName, const std::string &_modulePrefix, bool _useSinglePrecision, bool _useComplexArithmetic, QPSolverName _qpSolver, const std::map< std::string, std::pair< std::string, std::string > > &_options, const std::string &_variables, const std::string &_workspace, const std::string &_functions)
IntegratorExport * integrator
Definition: sim_export.hpp:324
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const =0
ExportStruct
uint getN() const
Definition: model_data.cpp:557
virtual returnValue exportDataDeclaration(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
static std::string fcnPrefix
returnValue getIntegrationGrid(Grid &integrationGrid_) const
Definition: model_data.cpp:389
unsigned getDim() const
Definition: vector.hpp:172
uint timingCalls
Definition: sim_export.hpp:321
returnValue getOutputGrids(std::vector< Grid > &outputGrids_) const
Definition: model_data.cpp:196
virtual returnValue exportAndRun(const std::string &dirName, const std::string &initStates, const std::string &controls, const std::string &results=std::string("results.txt"), const std::string &ref=std::string("ref.txt"))
Definition: sim_export.cpp:746
virtual returnValue exportCode(const std::string &dirName, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16)
Definition: sim_export.cpp:104
BooleanType hasOutputs() const
static std::string fcnPrefix
BooleanType hasOutputs() const
Definition: model_data.cpp:145
returnValue setup()
Definition: sim_export.cpp:262
bool PRINT_DETAILS
Definition: sim_export.hpp:327
returnValue acadoCreateFolder(const std::string &name)
returnValue addStatement(const ExportStatement &_statement)
std::vector< std::string > _outputFiles
Definition: sim_export.hpp:338
PrintLevel
returnValue clearIntegrationGrid()
Definition: model_data.cpp:431
std::string _controls
Definition: sim_export.hpp:333
returnValue addLinebreak(uint num=1)
uint getNXA() const
Definition: model_data.cpp:525
uint getNumOutputs() const
Definition: model_data.cpp:601
uint getNDX() const
bool referenceProvided
Definition: sim_export.hpp:326
virtual returnValue setModelData(const ModelData &data)
DVector getNumMeas() const
returnValue checkConsistency() const
Definition: sim_export.cpp:318
#define BEGIN_NAMESPACE_ACADO
returnValue exportTest(const std::string &_dirName, const std::string &_fileName, const std::string &_resultsFile, const std::vector< std::string > &_outputFiles, const bool &TIMING=false, const uint jumpReference=1) const
Definition: sim_export.cpp:361
std::vector< std::string > _refOutputFiles
Definition: sim_export.hpp:337
returnValue exportAcadoHeader(const std::string &_dirName, const std::string &_fileName, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
Definition: sim_export.cpp:803
MeasurementGrid
static ExportAlgorithmFactory & instance()
returnValue getNameOutputs(std::vector< std::string > &names) const
Definition: model_data.cpp:649
QPSolverName
virtual returnValue configure()
Allows to export code for a block of statements.
SIMexport(const uint simIntervals=1, const double totalTime=1.0)
Definition: sim_export.cpp:56
std::string _results
Definition: sim_export.hpp:334
SIMexport & operator=(const SIMexport &arg)
Definition: sim_export.cpp:89
virtual returnValue exportCode() const
Definition: export_file.cpp:82
static std::string varPrefix
#define ACADOERROR(retval)
virtual bool equidistantControlGrid() const
Defines a matrix-valued variable to be used for exporting code.
returnValue copy(const SIMexport &arg)
Definition: sim_export.cpp:234
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
static const uint factorRef
Definition: sim_export.hpp:329
uint getNX() const


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