46 const std::string& _commonHeaderName
100 for( i = 0; i <
outputs.size(); i++ ) {
101 if(
outputs[i].getGlobalExportVariable().getDim() >= max.
getDim() ) {
102 max =
outputs[i].getGlobalExportVariable();
161 if(
NX2 > 0 ||
NXA > 0 ) {
170 outputs[i].setGlobalExportVariable( max );
177 s <<
"#pragma omp threadprivate( " 189 if(
NX2 > 0 ||
NXA > 0 ) {
202 s <<
" )" << endl << endl;
211 if(
NX2 > 0 ||
NXA > 0 ) {
227 for( i = 0; i <
outputs.size(); i++ ) {
243 std::string tempString;
310 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
312 numMeas.push_back( numMeasTmp );
322 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
334 for( run5 = 0; run5 <
NXA; run5++ ) {
354 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
355 loop->addStatement( tmp_index1 ==
numMeas[run5] );
357 loop->addStatement( tmp_index1 == tmp_index1+1 );
358 loop->addStatement( std::string(
"}\n") );
359 loop->addStatement( std::string(tmp_meas.get( 0,run5 )) +
" = " + tmp_index1.
getName() +
" - " +
numMeas[run5].getName() +
";\n" );
365 loop->addStatement( std::string(
"if( run > 0 ) {\n") );
370 loop->addStatement( loopTemp1 );
376 loop->addStatement( loopTemp2 );
382 loop->addStatement( loopTemp3 );
384 loop->addStatement( std::string(
"}\n") );
407 sensitivitiesImplicitSystem( &loop4, run1, i, j, tmp_index1, tmp_index2, Ah, Bh, determinant,
true, 1 );
409 sensitivitiesOutputSystem( &loop4, run1, i, j, k, tmp_index1, tmp_index2, Ah, Bh,
true, 1 );
411 sensitivitiesOutputs( &loop4, run, run1, i, tmp_index1, tmp_index2, tmp_index3, tmp_meas, time_tmp,
true, 0 );
412 loop->addStatement( loop4 );
417 sensitivitiesImplicitSystem( &loop4, run1, i, j, tmp_index1, tmp_index2, Ah, Bh, determinant,
true, 2 );
419 sensitivitiesOutputSystem( &loop4, run1, i, j, k, tmp_index1, tmp_index2, Ah, Bh,
true, 2 );
421 sensitivitiesOutputs( &loop4, run, run1, i, tmp_index1, tmp_index2, tmp_index3, tmp_meas, time_tmp,
true,
NX1 );
422 loop->addStatement( loop4 );
427 sensitivitiesOutputSystem( &loop4, run1, i, j, k, tmp_index1, tmp_index2, Ah, Bh,
true, 3 );
429 sensitivitiesOutputs( &loop4, run, run1, i, tmp_index1, tmp_index2, tmp_index3, tmp_meas, time_tmp,
true,
NX1+
NX2 );
430 loop->addStatement( loop4 );
440 sensitivitiesImplicitSystem( &loop5, run1, i, j, tmp_index1, tmp_index2, Ah, Bh, determinant,
false, 0 );
442 sensitivitiesOutputSystem( &loop5, run1, i, j, k, tmp_index1, tmp_index2, Ah, Bh,
false, 0 );
444 sensitivitiesOutputs( &loop5, run, run1, i, tmp_index1, tmp_index2, tmp_index3, tmp_meas, time_tmp,
false, 0 );
445 loop->addStatement( loop5 );
449 for( run5 = 0; run5 <
NX; run5++ ) {
455 loop->addStatement( std::string(
"if( run == 0 ) {\n") );
457 for( run5 = 0; run5 <
NXA; run5++ ) {
461 loop->addStatement( std::string(
"}\n") );
468 loop->addStatement( std::string(
"if( run == 0 ) {\n" ) );
478 loop->addStatement( std::string(
"}\n" ) );
479 loop->addStatement( std::string(
"else {\n" ) );
489 propagateOutputs( loop, run, run1, i, j, k, tmp_index1, tmp_index2, tmp_index3, tmp_index4, tmp_meas );
493 loop->addStatement( std::string(
"}\n" ) );
496 loop->addStatement( std::string(
reset_int.
get(0,0) ) +
" = 0;\n" );
498 for( run5 = 0; run5 <
rk_outputs.size(); run5++ ) {
503 loop->addStatement(
numMeas[run5].getName() +
" += " + tmp_meas.get(0,run5) +
";\n" );
510 loop->addStatement(
"}\n" );
571 uint outputDim = numOutputs*(
NX+
NU+1);
661 for( i = 0; i <
NX1; i++ ) {
664 for( k = 0; k <
NX1; k++ ) {
665 vec(j*NX1+k) =
A11(k,i);
670 for( k = 0; k <
NX1; k++ ) {
671 sens(i*NX1+k,j) = sol(j*NX1+k);
675 for( i = 0; i <
NU; i++ ) {
678 for( k = 0; k <
NX1; k++ ) {
679 vec(j*NX1+k) =
B11(k,i);
684 for( k = 0; k <
NX1; k++ ) {
685 sens(NX1*NX1+i*NX1+k,j) = sol(j*NX1+k);
710 for( i = 0; i <
NX3; i++ ) {
713 for( k = 0; k <
NX3; k++ ) {
714 vec(j*NX3+k) =
A33(k,i);
719 for( k = 0; k <
NX3; k++ ) {
720 sens(i*NX3+k,j) = sol(j*NX3+k);
755 returnValue ForwardIRKExport::sensitivitiesImplicitSystem(
ExportStatementBlock*
block,
const ExportIndex& index1,
const ExportIndex& index2,
const ExportIndex& index3,
const ExportIndex& tmp_index1,
const ExportIndex& tmp_index2,
const ExportVariable& Ah,
const ExportVariable& Bh,
const ExportVariable& det,
bool STATES,
uint number )
763 if( STATES && number == 1 ) {
778 else if( STATES && number == 2 ) {
779 for( i = 0; i <
NX2+
NXA; i++ ) {
801 if( STATES && (number == 1 ||
NX1 == 0) ) {
807 if( STATES && (number == 1 ||
NX1 == 0) ) block->
addStatement( std::string(
"}\n" ) );
823 block->
addStatement( std::string(
"if( run == 0 ) {\n") );
839 returnValue ForwardIRKExport::sensitivitiesOutputSystem(
ExportStatementBlock*
block,
const ExportIndex& index1,
const ExportIndex& index2,
const ExportIndex& index3,
const ExportIndex& index4,
const ExportIndex& tmp_index1,
const ExportIndex& tmp_index2,
const ExportVariable& Ah,
const ExportVariable& Bh,
bool STATES,
uint number )
844 if( STATES && number == 1 ) {
868 else if( STATES && number == 2 ) {
912 if( !STATES || number != 3 ) block->
addStatement( loop1 );
915 if( STATES && number == 3 ) {
984 DVector dependencyX, dependencyZ, dependencyDX;
990 for( j = 0; j <
NX; j++ ) {
992 if( STATES && j >= base ) {
995 else if( j >= base ) {
1017 uint outputDim = numOutputs*(NX+
NU+1);
1020 for( j = 0; j < numOutputs; j++ ) {
1028 offset = numOutputs+j*
NX;
1032 offset = numOutputs*(1+
NX)+j*
NU;
1036 for( k = base; k <
NX; k++ ) {
ExportVariable rk_diffsPrev1
virtual returnValue setup()
ExportVariable getRow(const ExportIndex &idx) const
DVector evaluatePolynomial(double time)
returnValue initializeDDMatrix()
ExportVariable getGlobalExportVariable() const
std::vector< ExportVariable > gridVariables
double getFirstTime() const
returnValue sensitivitiesOutputs(ExportStatementBlock *block, const ExportIndex &index0, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportIndex &tmp_index3, const ExportVariable &tmp_meas, const ExportVariable &time_tmp, bool STATES, uint base)
std::vector< Grid > outputGrids
std::vector< ExportVariable > polynVariables
virtual returnValue updateImplicitSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index)
ExportAcadoFunction diffs_rhs
std::vector< ExportAcadoFunction > outputs
ExportVariable rk_diffsPrev3
virtual returnValue prepareInputSystem(ExportStatementBlock &code)
Allows to pass back messages to the calling function.
virtual returnValue prepareOutputSystem(ExportStatementBlock &code)
returnValue initializeCoefficients()
ExportLinearSolver * solver
returnValue addComment(const std::string &_comment)
Block< Derived > block(Index startRow, Index startCol, Index blockRows, Index blockCols)
std::vector< DMatrix > outputDependencies
virtual returnValue propagateImplicitSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &_index3, const ExportIndex &tmp_index)
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
std::vector< ExportAcadoFunction > diffs_outputs
ExportVariable rk_diffsPrev2
Allows to export code of a for-loop.
string toString(T const &value)
returnValue setName(const std::string &_name)
const std::string getNameDiffsOUTPUT(uint index) const
virtual returnValue propagateOutputs(ExportStatementBlock *block, const ExportIndex &index, const ExportIndex &index0, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportIndex &tmp_index3, const ExportIndex &tmp_index4, const ExportVariable &tmp_meas)
virtual returnValue solveImplicitSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index, const ExportIndex &k_index, const ExportVariable &Ah, const ExportVariable &C, const ExportVariable &det, bool DERIVATIVES=false)
ForwardIRKExport(UserInteraction *_userInteraction=0, const std::string &_commonHeaderName="")
ExportVariable getElement(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
ExportVariable rk_diffsTemp2
ForwardIRKExport & operator=(const ForwardIRKExport &arg)
#define CLOSE_NAMESPACE_ACADO
ExportVariable rk_diffsNew3
ExportVariable getSubMatrix(const ExportIndex &rowIdx1, const ExportIndex &rowIdx2, const ExportIndex &colIdx1, const ExportIndex &colIdx2) const
GenericMatrix< double > DMatrix
virtual returnValue getCode(ExportStatementBlock &code)
Defines a scalar-valued index variable to be used for exporting code.
virtual returnValue copy(const ImplicitRungeKuttaExport &arg)
std::vector< uint > totalMeas
Allows to export a tailored implicit Runge-Kutta integrator for fast model predictive control...
ExportAcadoFunction diffs_rhs3
std::vector< ExportVariable > numMeasVariables
static std::string fcnPrefix
DVector evaluateDerivedPolynomial(double time)
ExportVariable getCols(const ExportIndex &idx1, const ExportIndex &idx2) const
virtual returnValue getFunctionDeclarations(ExportStatementBlock &declarations) const
ExportVariable rk_auxSolver
int acadoRoundAway(double x)
virtual returnValue solveOutputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index, const ExportVariable &Ah, bool DERIVATIVES=false)
const std::string getNameSolveReuseFunction()
virtual ExportVariable getAuxVariable() const
const std::string get(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
virtual returnValue propagateOutputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index)
virtual ~ForwardIRKExport()
Encapsulates all user interaction for setting options, logging data and plotting results.
ExportVariable rk_diffsOutputTemp
virtual returnValue sensitivitiesOutputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &index4, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportVariable &Ah, const ExportVariable &Bh, bool STATES, uint number)
virtual uint getDim() const
returnValue setDataStruct(ExportStruct _dataStruct)
virtual returnValue propagateInputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index)
virtual DMatrix formMatrix(const DMatrix &mass, const DMatrix &jacobian)
returnValue addStatement(const ExportStatement &_statement)
virtual returnValue updateInputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index)
virtual returnValue getFunctionDeclarations(ExportStatementBlock &declarations) const
std::string getFullName() const
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
returnValue addLinebreak(uint num=1)
std::vector< ExportVariable > polynDerVariables
uint getDimOUTPUT(uint index) const
returnValue generateOutput(ExportStatementBlock *block, const ExportIndex &index0, const ExportIndex &index1, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportVariable &tmp_meas, const ExportVariable &time_tmp, const uint directions)
ExportVariable rk_diffsNew2
uint getNumIntervals() const
returnValue setGlobalExportVariable(const ExportVariable &var)
ImplicitRungeKuttaExport & operator=(const ImplicitRungeKuttaExport &arg)
returnValue prepareOutputEvaluation(ExportStatementBlock &code)
ExportVariable getRows(const ExportIndex &idx1, const ExportIndex &idx2) const
returnValue addDeclaration(const ExportVariable &_data, ExportStruct _dataStruct=ACADO_ANY)
ExportAcadoFunction lin_input
double getLastTime() const
virtual returnValue sensitivitiesImplicitSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportVariable &Ah, const ExportVariable &Bh, const ExportVariable &det, bool STATES, uint number)
std::vector< ExportVariable > rk_outputs
const std::string getNameSolveFunction()
#define BEGIN_NAMESPACE_ACADO
ExportVariable error_code
ExportVariable rk_rhsTemp
Allows to export a tailored implicit Runge-Kutta integrator with forward sensitivity generation for f...
returnValue addFunction(const ExportFunction &_function)
ExportVariable rk_diffsNew1
ExportVariable rk_diffsTemp3
std::vector< ExportIndex > numMeas
ExportVariable polynEvalVar
virtual returnValue clear()
virtual returnValue sensitivitiesInputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportVariable &Bh, bool STATES)
virtual returnValue getCode(ExportStatementBlock &code)=0
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
Allows to export code for a block of statements.
virtual returnValue solveInputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index, const ExportVariable &Ah)
ExportArgument getAddress(const ExportIndex &_rowIdx, const ExportIndex &_colIdx=emptyConstExportIndex) const
virtual returnValue updateOutputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index)
virtual returnValue appendVariableNames(std::stringstream &string)=0
ExportVariable getCol(const ExportIndex &idx) const
GenericVector< T > getRow(unsigned _idx) const
ExportFunction & addIndex(const ExportIndex &_index)
#define ACADOERROR(retval)
virtual bool equidistantControlGrid() const
Defines a matrix-valued variable to be used for exporting code.
returnValue addFunctionCall(const std::string &_fName, const ExportArgument &_argument1=emptyConstExportArgument, const ExportArgument &_argument2=emptyConstExportArgument, const ExportArgument &_argument3=emptyConstExportArgument, const ExportArgument &_argument4=emptyConstExportArgument, const ExportArgument &_argument5=emptyConstExportArgument, const ExportArgument &_argument6=emptyConstExportArgument, const ExportArgument &_argument7=emptyConstExportArgument, const ExportArgument &_argument8=emptyConstExportArgument, const ExportArgument &_argument9=emptyConstExportArgument)
virtual returnValue setup()
std::string getName() const