46 const std::string& _commonHeaderName
106 for( i = 0; i <
outputs.size(); i++ ) {
107 if(
outputs[i].getGlobalExportVariable().getDim() >= max.
getDim() ) {
108 max =
outputs[i].getGlobalExportVariable();
188 if(
NDX2 > 0 && (NDX2 < NX2 || NDX2 > (
NX1+
NX2)) ) {
195 for(
uint i = 0; i < rhs_.getDim(); i++ ) {
214 if(NXA == 0 &&
NDX2 == 0) {
227 bool gradientUpdate = (bool) gradientUp;
230 if( gradientUpdate ) {
274 bool gradientUpdate = (bool) gradientUp;
275 if( gradientUpdate ) grad =
NX;
285 if(
NX2 > 0 ||
NXA > 0 ) {
295 outputs[i].setGlobalExportVariable( max );
302 s <<
"#pragma omp threadprivate( " 314 if(
NX2 > 0 ||
NXA > 0 ) {
328 s <<
" )" << endl << endl;
337 if(
NX2 > 0 ||
NXA > 0 ) {
357 for( i = 0; i <
outputs.size(); i++ ) {
373 std::string tempString;
441 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
443 numMeas.push_back( numMeasTmp );
453 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
463 if( gradientUpdate ) {
469 if( liftMode == 1 || liftMode == 4 ) {
478 if( gradientUpdate ) {
495 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
496 loop->addStatement( tmp_index1 ==
numMeas[run5] );
498 loop->addStatement( tmp_index1 == tmp_index1+1 );
499 loop->addStatement( std::string(
"}\n") );
500 loop->addStatement( std::string(tmp_meas.get( 0,run5 )) +
" = " + tmp_index1.
getName() +
" - " +
numMeas[run5].getName() +
";\n" );
506 loop->addStatement( std::string(
"if( run > 0 ) {\n") );
517 loop->addStatement( loopTemp2 );
525 loop->addStatement( std::string(
"}\nelse{\n") );
529 loop->addStatement( std::string(
"}\n") );
542 loop->addStatement( loopTemp1 );
554 if( liftMode == 1 ) {
555 loop->addStatement( std::string(
"if( run > 0 ) {\n") );
557 for( run5 = 0; run5 <
numStages; run5++ ) {
571 loop->addStatement( deltaLoop );
572 loop->addStatement( std::string(
"}\nelse{\n") );
574 loop->addStatement( std::string(
"}\n") );
581 if( liftMode == 1 ) {
592 if( gradientUpdate ) {
599 if( liftMode == 1 ) {
602 for( run5 = 0; run5 <
NX; run5++ ) {
608 for( run5 = 0; run5 <
NX2; run5++ ) {
616 for( run5 = 0; run5 <
NXA; run5++ ) {
624 loop->addStatement( loopTemp );
625 if( liftMode == 1 ) {
630 for( run5 = 0; run5 <
numStages; run5++ ) {
633 for( run5 = 0; run5 <
numStages; run5++ ) {
640 for( run5 = 0; run5 <
NX; run5++ ) {
646 loop->addStatement( std::string(
"if( run == 0 ) {\n") );
648 for( run5 = 0; run5 <
NXA; run5++ ) {
652 loop->addStatement( std::string(
"}\n") );
655 if( liftMode != 1 ) {
697 for( run5 = 0; run5 <
rk_outputs.size(); run5++ ) {
702 loop->addStatement(
numMeas[run5].getName() +
" += " + tmp_meas.get(0,run5) +
";\n" );
709 loop->addStatement(
"}\n" );
715 if( gradientUpdate ) {
735 loop2->addStatement( k_index == run*(NX+NXA)*(NX+
NU) );
741 for( run5 = 0; run5 <
numStages; run5++ ) {
747 for( run5 = 0; run5 <
numStages; run5++ ) {
751 for( run6 = 0; run6 <
numStages; run6++ ) {
762 for( run5 = 0; run5 <
numStages; run5++ ) {
784 loop1.addStatement(
rk_eta.
getCols( i*NX+NX+grad+NXA+
NX1,i*NX+NX+grad+NXA+NX ) == zeroR );
789 if( NX2 > 0 &&
NX3 > 0 ) {
794 if( NXA > 0 &&
NX3 > 0 ) {
825 if(
NX2 > 0 ||
NXA > 0 ) {
828 if( liftMode == 4 ) {
864 evaluateMatrix( &loop01, index2, index3, tmp_index, k_index,
rk_A, Ah, C,
true,
false );
881 evaluateMatrix( &loop1, index2, index3, tmp_index, k_index,
rk_A, Ah, C,
true, DERIVATIVES );
1024 for( i = 0; i <
NX2; i++ ) {
1029 for( i = 0; i <
NX2; i++ ) {
1033 for( i = 0; i <
NXA; i++ ) {
1158 loop22.
addStatement( tmp_index2 == tmp_index1+index1 );
1192 loop25.
addStatement( tmp_index2 == tmp_index1+index1 );
1221 loop42.
addStatement( tmp_index2 == tmp_index1+index1 );
1223 for(
uint loop_i = 0; loop_i <
NX; loop_i++ ) {
1228 loop43.
addStatement( tmp_index2 == tmp_index1+NX+index1 );
1232 for(
uint loop_i = 0; loop_i <
NX; loop_i++ ) {
1244 loop31.
addStatement( tmp_index2 == tmp_index1+index1 );
1252 block->
addStatement( std::string(
"if( run == 0 ) {\n") );
1257 loop51.
addStatement( tmp_index2 == tmp_index1+index1 );
1300 bool gradientUpdate = (bool) gradientUp;
1301 if( gradientUpdate ) grad =
NX;
1339 returnValue ForwardLiftedIRKExport::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 )
1367 integrate.
doc(
"Performs the integration and sensitivity propagation for one shooting interval." );
1395 if( liftMode == 1 || liftMode == 4 ) {
1418 bool gradientUpdate = (bool) gradientUp;
1420 if( gradientUpdate ) {
1435 if( liftMode == 1 ) {
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
ExportVariable rk_diffsPrev1
ExportVariable rk_adj_diffs_tmp
ExportVariable rk_xxx_traj
virtual returnValue setup()
ExportVariable rk_b_trans
Allows to export a tailored lifted implicit Runge-Kutta integrator with forward sensitivity generatio...
ForwardLiftedIRKExport(UserInteraction *_userInteraction=0, const std::string &_commonHeaderName="")
ExportVariable rk_Xhat_traj
virtual returnValue allSensitivitiesImplicitSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportIndex &tmp_index3, const ExportIndex &k_index, const ExportVariable &Bh, bool update)
ExportVariable getRow(const ExportIndex &idx) const
Expression backwardDerivative(const Expression &arg1, const Expression &arg2)
returnValue addArgument(const ExportArgument &_argument1, 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)
const std::string getNameSolveTransposeReuseFunction()
returnValue initializeDDMatrix()
ExportVariable getGlobalExportVariable() const
std::vector< ExportVariable > gridVariables
double getFirstTime() const
ExportVariable getTranspose() const
virtual returnValue getFunctionDeclarations(ExportStatementBlock &declarations) const
GenericMatrix & appendCols(const GenericMatrix &_arg)
std::vector< Grid > outputGrids
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)
ExportAcadoFunction diffs_rhs
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)
std::vector< ExportAcadoFunction > outputs
ExportVariable rk_diffsPrev3
Allows to pass back messages to the calling function.
returnValue initializeCoefficients()
Expression forwardDerivative(const Expression &arg1, const Expression &arg2)
ExportLinearSolver * solver
returnValue addComment(const std::string &_comment)
Block< Derived > block(Index startRow, Index startCol, Index blockRows, Index blockCols)
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
std::vector< ExportAcadoFunction > diffs_outputs
ExportVariable rk_diffsPrev2
Allows to export code of a for-loop.
virtual ~ForwardLiftedIRKExport()
string toString(T const &value)
returnValue setName(const std::string &_name)
ExportVariable rk_xxx_lin
ExportVariable rk_diffK_local
ExportVariable getElement(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
ExportVariable rk_diffsTemp2
ForwardIRKExport & operator=(const ForwardIRKExport &arg)
#define CLOSE_NAMESPACE_ACADO
ExportVariable rk_diffsNew3
virtual returnValue evaluateRhsSensitivities(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2)
ExportVariable getSubMatrix(const ExportIndex &rowIdx1, const ExportIndex &rowIdx2, const ExportIndex &colIdx1, const ExportIndex &colIdx2) const
GenericMatrix< double > DMatrix
virtual returnValue prepareInputSystem(ExportStatementBlock &code)
const std::string getNameDiffsRHS() const
Defines a scalar-valued index variable to be used for exporting code.
virtual returnValue prepareOutputSystem(ExportStatementBlock &code)
virtual returnValue copy(const ImplicitRungeKuttaExport &arg)
virtual returnValue evaluateRhsImplicitSystem(ExportStatementBlock *block, const ExportIndex &k_index, const ExportIndex &stage)
std::vector< uint > totalMeas
Base class for all variables within the symbolic expressions family.
virtual returnValue evaluateMatrix(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index, const ExportIndex &k_index, const ExportVariable &_rk_A, const ExportVariable &Ah, const ExportVariable &C, bool evaluateB, bool DERIVATIVES)
ExportAcadoFunction diffs_rhs3
std::vector< ExportVariable > numMeasVariables
virtual ExportFunction & doc(const std::string &_doc)
static std::string fcnPrefix
DVector evaluateDerivedPolynomial(double time)
virtual returnValue sensitivitiesInputSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportVariable &Bh, bool STATES)
ExportVariable getAuxVariable() const
ExportVariable getCols(const ExportIndex &idx1, const ExportIndex &idx2) const
Expression multipleForwardDerivative(const Expression &arg1, const Expression &arg2, const Expression &seed)
virtual returnValue getFunctionDeclarations(ExportStatementBlock &declarations) const
ExportVariable rk_auxSolver
ExportVariable makeRowVector() const
const std::string getNameSolveReuseFunction()
const std::string getNameRHS() const
ExportVariable rk_Khat_traj
Encapsulates all user interaction for setting options, logging data and plotting results.
Allows to export code of an arbitrary function.
virtual uint getDim() const
returnValue setDataStruct(ExportStruct _dataStruct)
returnValue addStatement(const ExportStatement &_statement)
virtual returnValue evaluateStatesImplicitSystem(ExportStatementBlock *block, const ExportIndex &k_index, const ExportVariable &Ah, const ExportVariable &C, const ExportIndex &stage, const ExportIndex &i, const ExportIndex &tmp_index)
std::string getFullName() const
ExportVariable rk_diffSweep
returnValue addLinebreak(uint num=1)
virtual returnValue evaluateAllStatesImplicitSystem(ExportStatementBlock *block, const ExportIndex &k_index, const ExportVariable &Ah, const ExportVariable &C, const ExportIndex &stage, const ExportIndex &i, const ExportIndex &tmp_index)
ExportFunction & setReturnValue(const ExportVariable &_functionReturnValue, bool _returnAsPointer=false)
ExportVariable rk_diffsNew2
uint getNumIntervals() const
returnValue setGlobalExportVariable(const ExportVariable &var)
returnValue prepareOutputEvaluation(ExportStatementBlock &code)
DifferentialStateDerivative dx
virtual uint getNumCols() const
std::string getName() const
ExportVariable getRows(const ExportIndex &idx1, const ExportIndex &idx2) const
returnValue addDeclaration(const ExportVariable &_data, ExportStruct _dataStruct=ACADO_ANY)
virtual returnValue evaluateRhsInexactSensitivities(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &index3, const ExportIndex &tmp_index1, const ExportIndex &tmp_index2, const ExportIndex &tmp_index3, const ExportIndex &k_index, const ExportVariable &Ah)
ExportAcadoFunction lin_input
virtual returnValue updateImplicitSystem(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index)
double getLastTime() const
ExportVariable rk_stageValues
std::vector< ExportVariable > rk_outputs
const std::string getNameSolveFunction()
#define BEGIN_NAMESPACE_ACADO
ExportVariable error_code
ExportVariable rk_rhsTemp
returnValue clearStaticCounters()
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)
ExportAcadoFunction adjoint_sweep
Allows to export a tailored implicit Runge-Kutta integrator with forward sensitivity generation for f...
virtual returnValue setDifferentialEquation(const Expression &rhs)
virtual returnValue setup()
returnValue addFunction(const ExportFunction &_function)
ExportVariable rk_diffsNew1
ExportVariable rk_diffsTemp3
std::vector< ExportIndex > numMeas
ExportVariable polynEvalVar
Expression & appendCols(const Expression &arg)
virtual returnValue clear()
ExportAcadoFunction forward_sweep
virtual returnValue getCode(ExportStatementBlock &code)=0
virtual returnValue evaluateInexactMatrix(ExportStatementBlock *block, const ExportIndex &index1, const ExportIndex &index2, const ExportIndex &tmp_index, const ExportIndex &k_index, const ExportVariable &_rk_A, const ExportVariable &Ah, const ExportVariable &C, bool evaluateB, bool DERIVATIVES)
ExportVariable rk_adj_traj
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
Allows to export code for a block of statements.
ExportArgument getAddress(const ExportIndex &_rowIdx, const ExportIndex &_colIdx=emptyConstExportIndex) const
virtual returnValue appendVariableNames(std::stringstream &string)=0
ExportVariable getCol(const ExportIndex &idx) const
returnValue init(const Function &_f, const std::string &_name="acadoFcn", const uint _numX=0, const uint _numXA=0, const uint _numU=0, const uint _numP=0, const uint _numDX=0, const uint _numOD=0)
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)
GenericVector< T > getRow(unsigned _idx) const
ExportFunction & addIndex(const ExportIndex &_index)
#define ACADOERROR(retval)
virtual bool equidistantControlGrid() const
ForwardLiftedIRKExport & operator=(const ForwardLiftedIRKExport &arg)
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)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
std::string getName() const
virtual returnValue getCode(ExportStatementBlock &code)