45 const std::string& _commonHeaderName
136 if(
NDX2 > 0 && (NDX2 < NX2 || NDX2 > (
NX1+
NX2)) ) {
143 for(
uint i = 0; i < rhs_.getDim(); i++ ) {
177 if(
NX2 > 0 ||
NXA > 0 ) {
191 for( i = 0; i <
outputs.size(); i++ ) {
192 if(
outputs[i].getGlobalExportVariable().getDim() >= max.
getDim() ) {
193 max =
outputs[i].getGlobalExportVariable();
213 if ( (
bool)debugMode == true ) {
269 if(
NX2 > 0 ||
NXA > 0 ) {
277 outputs[i].setGlobalExportVariable( max );
283 s <<
"#pragma omp threadprivate( " 290 if(
NX2 > 0 ||
NXA > 0 ) {
296 s <<
" )" << endl << endl;
305 if(
NX2 > 0 ||
NXA > 0 ) {
319 for( i = 0; i <
outputs.size(); i++ ) {
335 std::string tempString;
402 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
404 numMeas.push_back( numMeasTmp );
414 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
426 for( run5 = 0; run5 <
NXA; run5++ ) {
446 for( run5 = 0; run5 <
outputGrids.size(); run5++ ) {
447 loop->addStatement( tmp_index1 ==
numMeas[run5] );
449 loop->addStatement( tmp_index1 == tmp_index1+1 );
450 loop->addStatement( std::string(
"}\n") );
451 loop->addStatement( std::string(tmp_meas.get( 0,run5 )) +
" = " + tmp_index1.
getName() +
" - " +
numMeas[run5].getName() +
";\n" );
467 generateOutput( loop, run, i, tmp_index2, tmp_index3, tmp_meas, time_tmp, 0 );
470 for( run5 = 0; run5 <
NX; run5++ ) {
476 loop->addStatement( std::string(
"if( run == 0 ) {\n") );
478 for( run5 = 0; run5 <
NXA; run5++ ) {
482 loop->addStatement( std::string(
"}\n") );
486 loop->addStatement( std::string(
reset_int.
get(0,0) ) +
" = 0;\n" );
488 for( run5 = 0; run5 <
rk_outputs.size(); run5++ ) {
493 loop->addStatement(
numMeas[run5].getName() +
" += " + tmp_meas.get(0,run5) +
";\n" );
500 loop->addStatement(
"}\n" );
559 for( i2 = 0; i2 < vars; i2++ ){
560 for( j2 = 0; j2 < vars; j2++ ) {
562 result(i1*vars+i2, j1*vars+j2) = mass(i2,j2) -
AA(i1,j1)*h*
jacobian(i2,j2);
565 result(i1*vars+i2, j1*vars+j2) = -
AA(i1,j1)*h*
jacobian(i2,j2);
572 return result.inverse();
605 if(
NX2 > 0 ||
NXA > 0 ) {
611 evaluateMatrix( &loop11, index2, index3, tmp_index, k_index,
rk_A, Ah, C,
true, DERIVATIVES );
637 evaluateMatrix( &loop3, index2, index3, tmp_index, k_index,
rk_A, Ah, C,
false, DERIVATIVES );
644 if ( (
bool)debugMode == true ) {
708 for( i = 0; i <
NX1+
NX2; i++ ) {
714 for( i = 0; i <
NX3; i++ ) {
717 for( i = 0; i <
NXA3; i++ ) {
720 for( i = 0; i <
NDX3; i++ ) {
829 DVector dependencyX, dependencyZ, dependencyDX;
835 for( j = 0; j <
NX; j++ ) {
852 uint outputDim = numOutputs*(1+directions);
853 loop1->
addStatement( tmp_index1 ==
numMeas[i]*outputDim+index1*(numOutputs*(1+directions)) );
854 for( j = 0; j < numOutputs; j++ ) {
874 DD( i, j ) *= ((1+
cc(i))-
cc(k))/(
cc(j)-
cc(k));
893 coeffs( i, j ) = 1/((double) numStages-i);
906 for( k = 0; k < products.
getDim(); k++ ) {
913 coeffs( i, j ) *= (-1.0*sum);
933 for( k = index; k < cVec.
getDim()-numEls+1; k++ ) {
935 for( l = 0; l < temp.
getDim(); l++ ) {
971 coeffsPolyn( j ) = 0.0;
973 coeffsPolyn( j ) +=
pow( time, static_cast<int>(numStages-i) )*
coeffs( i,j );
1032 coeffsPolyn( i ) = 1.0;
1035 coeffsPolyn( i ) *= (time-
cc(j))/(
cc(i)-
cc(j));
1051 if( (i == 0 && j == 1) || (i != j && j == 0) ) {
1071 meas(interv) = meas(interv)+1;
1103 if (newNumIts >= 0) {
1109 if (newNumItsInit >= 0) {
1125 if(
NX2 > Xmax ) Xmax =
NX2;
1126 if(
NX3 > Xmax ) Xmax =
NX3;
1144 if ( (
bool)debugMode ==
true && useOMP ) {
1168 reset_int.
setDoc(
"The internal memory of the integrator can be reset." );
1171 integrate.
doc(
"Performs the integration and sensitivity propagation for one shooting interval." );
1179 fullRhs.
doc(
"Evaluates the right-hand side of the full model." );
1184 bool gradientUpdate = (bool) gradientUp;
1188 if(
NX2 > 0 ||
NXA > 0 ) {
1229 if( NDX2 > 0 ||
NXA > 0 ) {
1242 if( NDX2 > 0 ||
NXA > 0 ) {
1268 if( NDX2 > 0 ||
NXA > 0 ) {
1279 if( NDX2 > 0 ||
NXA > 0 ) {
1373 uint maxOutputs = 0;
1379 uint numOutputs = outputExpressions_[i].getDim();
1381 if( !sensGen ) outputDim =
outputGrids[i].getNumIntervals( )*numOutputs;
1383 if( numOutputs > maxOutputs ) maxOutputs = numOutputs;
1386 f_Output << outputExpressions_[i];
1395 for(
uint j = 0; j < outputExpressions_[i].getDim(); j++ ) {
1410 val = val & OUTPUT.
init( f_Output,std::string(
"acado_output")+
toString(i)+
"_rhs",
NX,
NXA,
NU,
NP,
NDX,
NOD ) & diffs_OUTPUT.
init( g_Output,std::string(
"acado_output")+
toString(i)+
"_diffs",
NX,
NXA,
NU,
NP,
NDX,
NOD );
1448 const std::vector<std::string> _outputNames,
1449 const std::vector<std::string> _diffs_outputNames,
1450 const std::vector<uint> _dims_output ) {
1458 if( outputGrids_.size() != _outputNames.size() || outputGrids_.size() != _diffs_outputNames.size() || outputGrids_.size() != _dims_output.size() ) {
1472 uint maxOutputs = 0;
1479 if( !sensGen ) outputDim =
outputGrids[i].getNumIntervals( )*numOutputs;
1481 if( numOutputs > maxOutputs ) maxOutputs = numOutputs;
1528 const std::vector<std::string> _outputNames,
1529 const std::vector<std::string> _diffs_outputNames,
1530 const std::vector<uint> _dims_output,
1531 const std::vector<DMatrix> _outputDependencies ) {
1536 return setupOutput( outputGrids_, _outputNames, _diffs_outputNames, _dims_output );
1562 if(
NXA > 0 ||
NDX > 0 ) {
DVector computeCombinations(const DVector &cVec, uint index, uint numEls)
ExportVariable rk_diffsPrev1
returnValue setTransformations(const DMatrix &_transf1, const DMatrix &_transf2, const DMatrix &_transf1_T, const DMatrix &_transf2_T)
returnValue setStepSize(double _stepsize)
uint getIntegrationInterval(double time)
ExportVariable getRow(const ExportIndex &idx) const
DMatrix simplified_transf2
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)
DVector evaluatePolynomial(double time)
Allows to setup and evaluate output functions based on SymbolicExpressions.
returnValue initializeDDMatrix()
double getTime(uint pointIdx) const
ExportVariable getGlobalExportVariable() const
virtual returnValue setupOutput(const std::vector< Grid > outputGrids_, const std::vector< Expression > rhs)
returnValue setTransformations(const DMatrix &_transf1, const DMatrix &_transf2, const DMatrix &_transf1_T, const DMatrix &_transf2_T)
std::vector< ExportVariable > gridVariables
returnValue setImplicit(BooleanType _implicit)
returnValue setSimplifiedTransformations(const DMatrix &_transf1, const DMatrix &_transf2)
double getFirstTime() const
Allows to export a tailored IRK solver based on Gaussian elimination of specific dimensions.
GenericMatrix & appendCols(const GenericMatrix &_arg)
Allows to export a tailored Runge-Kutta integrator for fast model predictive control.
std::vector< Grid > outputGrids
returnValue setStepSize(double _stepsize)
std::vector< ExportVariable > polynVariables
UserInteraction * userInteraction
Allows to export code of an ACADO function.
ExportAcadoFunction diffs_rhs
returnValue get(OptionsName name, int &value) const
returnValue setTranspose(const bool &transpose)
std::vector< ExportAcadoFunction > outputs
virtual ExportVariable getGlobalExportVariable(const uint factor) const
virtual returnValue evaluateRhsImplicitSystem(ExportStatementBlock *block, const ExportIndex &k_index, const ExportIndex &stage)
ExportVariable rk_diffsPrev3
Allows to pass back messages to the calling function.
virtual returnValue setModel(const std::string &_name_ODE, const std::string &_name_diffs_ODE)
returnValue initializeCoefficients()
Expression forwardDerivative(const Expression &arg1, const Expression &arg2)
ExportLinearSolver * solver
DMatrix simplified_transf1_T
virtual ~ImplicitRungeKuttaExport()
returnValue addComment(const std::string &_comment)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
Block< Derived > block(Index startRow, Index startCol, Index blockRows, Index blockCols)
std::vector< DMatrix > outputDependencies
const std::string getNameOUTPUT(uint index) const
ImplicitRungeKuttaExport(UserInteraction *_userInteraction=0, const std::string &_commonHeaderName="")
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
std::vector< ExportAcadoFunction > diffs_outputs
ExportVariable rk_diffsPrev2
virtual returnValue prepareInputSystem(ExportStatementBlock &code)
Allows to export code of a for-loop.
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)
string toString(T const &value)
returnValue setName(const std::string &_name)
const std::string getNameOutputDiffs() const
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)
ExportVariable getElement(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
ExportVariable rk_diffsTemp2
#define CLOSE_NAMESPACE_ACADO
ExportVariable rk_diffsNew3
returnValue setImplicit(BooleanType _implicit)
ExportVariable rk_rhsOutputTemp
returnValue setSingleTransformations(const double _tau, const DVector &_low_tria, const DMatrix &_transf1, const DMatrix &_transf2)
ExportVariable getSubMatrix(const ExportIndex &rowIdx1, const ExportIndex &rowIdx2, const ExportIndex &colIdx1, const ExportIndex &colIdx2) const
GenericMatrix< double > DMatrix
const std::string getNameDiffsRHS() const
Defines a scalar-valued index variable to be used for exporting code.
virtual returnValue copy(const ImplicitRungeKuttaExport &arg)
returnValue setImplicit(BooleanType _implicit)
returnValue setTransformations(const double _tau, const DVector &_low_tria, const DMatrix &_transf1, const DMatrix &_transf2, const DMatrix &_transf1_T, const DMatrix &_transf2_T)
std::vector< uint > totalMeas
Base class for all variables within the symbolic expressions family.
Allows to export a tailored implicit Runge-Kutta integrator for fast model predictive control...
virtual returnValue setDoc(const std::string &_doc)
std::string commonHeaderName
Expression jacobian(const Expression &arg1, const Expression &arg2)
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)
std::vector< ExportVariable > numMeasVariables
virtual ExportFunction & doc(const std::string &_doc)
static std::string fcnPrefix
DVector evaluateDerivedPolynomial(double time)
std::vector< Expression > outputExpressions
const std::string getNameOutputRHS() const
ExportVariable getCols(const ExportIndex &idx1, const ExportIndex &idx2) const
returnValue setModel(const std::string &_rhs, const std::string &_diffs_rhs)
uint getNumItsInit() const
ExportVariable rk_auxSolver
Allows to export Gaussian elimination for solving linear systems of specific dimensions.
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)
GenericMatrix & setRow(unsigned _idx, const GenericVector< T > &_values)
const std::string getNameSolveReuseFunction()
const std::string getNameRHS() const
const std::string get(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
returnValue setImplicit(BooleanType _implicit)
Allows to export a tailored IRK solver based on Gaussian elimination of specific dimensions.
returnValue setTransformations(const double _tau, const DVector &_low_tria, const DMatrix &_transf1, const DMatrix &_transf2, const DMatrix &_transf1_T, const DMatrix &_transf2_T)
Derived & setZero(Index size)
Encapsulates all user interaction for setting options, logging data and plotting results.
ExportVariable rk_diffsOutputTemp
Allows to export code of an arbitrary function.
virtual uint getDim() const
returnValue setDataStruct(ExportStruct _dataStruct)
virtual DMatrix formMatrix(const DMatrix &mass, const DMatrix &jacobian)
returnValue addStatement(const ExportStatement &_statement)
virtual returnValue getFunctionDeclarations(ExportStatementBlock &declarations) const
returnValue setEigenvalues(const DMatrix &_eig)
returnValue setReuse(const bool &reuse)
std::string getFullName() const
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
returnValue evaluateStatesOutputSystem(ExportStatementBlock *block, const ExportVariable &Ah, const ExportIndex &stage)
unsigned getNumRows() const
returnValue addLinebreak(uint num=1)
std::vector< ExportVariable > polynDerVariables
GenericVector & append(const GenericVector &_arg)
std::vector< uint > num_outputs
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)
ExportFunction & setReturnValue(const ExportVariable &_functionReturnValue, bool _returnAsPointer=false)
ExportVariable rk_diffsNew2
unsigned getNumCols() const
uint getNumIntervals() const
GenericVector< double > DVector
virtual returnValue setup()=0
returnValue setGlobalExportVariable(const ExportVariable &var)
ImplicitRungeKuttaExport & operator=(const ImplicitRungeKuttaExport &arg)
returnValue setStepSize(double _stepsize)
returnValue prepareOutputEvaluation(ExportStatementBlock &code)
DifferentialStateDerivative dx
std::string getName() const
ExportVariable getRows(const ExportIndex &idx1, const ExportIndex &idx2) const
returnValue addDeclaration(const ExportVariable &_data, ExportStruct _dataStruct=ACADO_ANY)
ExportAcadoFunction lin_input
returnValue setEigenvalues(const DMatrix &_eig)
double getLastTime() const
std::vector< ExportVariable > rk_outputs
const std::string getNameSolveFunction()
#define BEGIN_NAMESPACE_ACADO
ExportVariable error_code
ExportVariable rk_rhsTemp
returnValue clearStaticCounters()
RungeKuttaExport & operator=(const RungeKuttaExport &arg)
returnValue setEigenvalues(const DMatrix &_eig)
Allows to export a tailored IRK solver based on Gaussian elimination of specific dimensions.
DMatrix simplified_transf2_T
returnValue addFunction(const ExportFunction &_function)
Allows to export Householder QR Factorization for solving linear systems of specific dimensions...
virtual returnValue prepareOutputSystem(ExportStatementBlock &code)
virtual ExportVariable getAuxVariable() const
virtual returnValue getDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const =0
Allows to export a tailored IRK solver based on Gaussian elimination of specific dimensions.
ExportVariable rk_diffsNew1
ExportVariable rk_diffsTemp3
std::vector< ExportIndex > numMeas
virtual returnValue setDifferentialEquation(const Expression &rhs)
DVector divideMeasurements(uint index)
ExportVariable polynEvalVar
virtual returnValue clear()
virtual returnValue getCode(ExportStatementBlock &code)=0
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)
returnValue setStepSize(double _stepsize)
ExportArgument getAddress(const ExportIndex &_rowIdx, const ExportIndex &_colIdx=emptyConstExportIndex) const
GenericMatrix getRows(unsigned _start, unsigned _end) const
returnValue init(const uint newDim, const bool &reuse=true, const bool &unrolling=false)
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)
ExportFunction & addIndex(const ExportIndex &_index)
virtual returnValue getCode(ExportStatementBlock &code)
#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()
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
std::string getName() const
DMatrix simplified_transf1