70 b4 =
new double [
dim];
71 b5 =
new double [
dim];
74 for( run1 = 0; run1 <
dim; run1++ ){
75 A[run1] =
new double[
dim];
91 b4 =
new double [
dim];
92 b5 =
new double [
dim];
95 for( run1 = 0; run1 <
dim; run1++ ){
96 A[run1] =
new double[
dim];
138 k = 0;
k2 = 0;
l = 0;
l2 = 0;
x = 0;
173 eta4 =
new double [
m];
174 eta5 =
new double [
m];
178 for( run1 = 0; run1 <
m; run1++ ){
186 k =
new double*[
dim];
187 k2 =
new double*[
dim];
188 l =
new double*[
dim];
189 l2 =
new double*[
dim];
199 for( run1 = 0; run1 <
dim; run1++ ){
200 k [run1] =
new double[
m];
201 k2 [run1] =
new double[
m];
203 for( run2 = 0; run2 <
m; run2++ ){
204 k [run1][run2] = 0.0;
205 k2[run1][run2] = 0.0;
212 l [run1][run2] = 0.0;
213 l2[run1][run2] = 0.0;
221 for( run1 = 0; run1 <
m; run1++ ){
230 for( run1 = 0; run1 <
mu; run1++ ){
236 for( run1 = 0; run1 <
mp; run1++ ){
242 for( run1 = 0; run1 <
mui; run1++ ){
248 for( run1 = 0; run1 <
mpi; run1++ ){
254 for( run1 = 0; run1 <
mw; run1++ ){
261 for( run1 = 0; run1 <
m; run1++ )
299 for( run1 = 0; run1 <
dim; run1++ ){
324 for( run1 = 0; run1 <
dim; run1++ ){
325 if(
k[run1] != NULL )
327 if(
k2[run1] != NULL )
329 if(
l[run1] != NULL )
331 if(
l2[run1] != NULL )
431 A =
new double*[
dim];
432 b4 =
new double [
dim];
433 b5 =
new double [
dim];
434 c =
new double [
dim];
436 for( run1 = 0; run1 <
dim; run1++ ){
438 b4[run1] = arg.
b4[run1];
439 b5[run1] = arg.
b5[run1];
440 c [run1] = arg.
c [run1];
442 A[run1] =
new double[
dim];
443 for( run2 = 0; run2 <
dim; run2++ )
444 A[run1][run2] = arg.
A[run1][run2];
449 eta4 =
new double [
m];
450 eta5 =
new double [
m];
454 for( run1 = 0; run1 <
m; run1++ ){
462 k =
new double*[
dim];
463 k2 =
new double*[
dim];
464 l =
new double*[
dim];
465 l2 =
new double*[
dim];
469 x[run1] = arg.
x[run1];
475 for( run1 = 0; run1 <
dim; run1++ ){
476 k [run1] =
new double[
m];
477 k2 [run1] =
new double[
m];
479 for( run2 = 0; run2 <
m; run2++ ){
480 k [run1][run2] = arg.
k [run1][run2];
481 k2[run1][run2] = arg.
k2[run1][run2];
488 l [run1][run2] = arg.
l [run1][run2];
489 l2[run1][run2] = arg.
l2[run1][run2];
496 h = (
double*)calloc(arg.
maxAlloc,
sizeof(
double));
497 for( run1 = 0; run1 < arg.
maxAlloc; run1++ ){
498 h[run1] = arg.
h[run1];
514 for( run1 = 0; run1 <
m; run1++ ){
523 for( run1 = 0; run1 <
mu; run1++ ){
529 for( run1 = 0; run1 <
mp; run1++ ){
535 for( run1 = 0; run1 <
mui; run1++ ){
541 for( run1 = 0; run1 <
mpi; run1++ ){
547 for( run1 = 0; run1 <
mw; run1++ ){
638 h = (
double*)realloc(
h,
maxAlloc*
sizeof(
double));
682 if(
h[0] < 10.0*
EPS )
693 for( run1 = 0; run1 <
m; run1++ ){
694 eta4[run1] = x0(run1);
695 eta5[run1] = x0(run1);
696 xStore(0,run1) = x0(run1);
700 for( run1 = 0; run1 <
m; run1++ ){
709 for( run1 = 0; run1 <
mp; run1++ ){
718 for( run1 = 0; run1 <
mu; run1++ ){
728 for( run1 = 0; run1 <
mw; run1++ ){
744 for( run1 = 0; run1 <
m; run1++ )
754 cout <<
"RK: t = " <<
t <<
"\t";
755 for( run1 = 0; run1 <
m; run1++ )
756 cout <<
"x[" << run1 <<
"] = " << scientific <<
eta4[ run1 ];
774 for( run1 = 0; run1 <
mn; run1++ )
809 cout <<
"\n Results at t = " <<
t <<
"\t";
810 for( run1 = 0; run1 <
m; run1++ )
811 cout <<
"x[" << run1 <<
"] = " << scientific <<
eta4[ run1 ];
817 int printIntegratorProfile = 0;
827 cout <<
"RK: number of steps: " <<
count - 1 << endl;
844 if( order < 1 || order > 2 ){
875 etaG =
new double[
m];
877 if( xSeed.
getDim() != 0 ){
878 for( run2 = 0; run2 <
m; run2++ ){
883 if( pSeed.
getDim() != 0 ){
884 for( run2 = 0; run2 <
mp; run2++ ){
890 if( uSeed.
getDim() != 0 ){
891 for( run2 = 0; run2 <
mu; run2++ ){
897 if( wSeed.
getDim() != 0 ){
899 for( run2 = 0; run2 <
mw; run2++ ){
951 if( xSeed.
getDim() != 0 ){
952 for( run2 = 0; run2 <
m; run2++ ){
957 if( pSeed.
getDim() != 0 ){
958 for( run2 = 0; run2 <
mp; run2++ ){
964 if( uSeed.
getDim() != 0 ){
965 for( run2 = 0; run2 <
mu; run2++ ){
971 if( wSeed.
getDim() != 0 ){
972 for( run2 = 0; run2 <
mw; run2++ ){
986 if( order < 1 || order > 2 ){
1018 if( seed.
getDim() != 0 ){
1019 for( run2 = 0; run2 <
m; run2++ ){
1020 bseed(run2) = seed(run2);
1043 if(
etaH2 != NULL ){
1048 if(
etaH3 != NULL ){
1065 if( seed.
getDim() != 0 ){
1066 for( run2 = 0; run2 <
m; run2++ ){
1067 bseed2(run2) = seed(run2);
1092 for( run1 = 0; run1 <
m; run1++ ){
1104 for( run1 = 0; run1 <
m; run1++ ){
1112 for( run1 = 0; run1 <
m; run1++ ){
1126 for( run1 = 0; run1 <
m; run1++ ){
1140 int oldCount =
count;
1173 for( run1 = 0; run1 <
m; run1++ )
1177 for( run1 = 0; run1 <
m; run1++ )
1222 int number_of_rejected_steps = 0;
1230 while( E >=
TOL*
h[0] ){
1233 cout <<
"STEP REJECTED: error estimate = " << scientific << E << endl
1234 <<
" required local tolerance = " <<
TOL*h[0] << endl;
1237 number_of_rejected_steps++;
1239 for( run1 = 0; run1 <
m; run1++ ){
1269 count3 += number_of_rejected_steps;
1275 double *etaG_ =
new double[
m];
1276 double *etaG3_ =
new double[
m];
1284 for( run1 = 0; run1 <
m; run1++ )
1285 etaG_[run1] =
etaG[run1];
1310 for( run1 = 0; run1 <
m; run1++ )
1311 etaG3_[run1] =
etaG3[run1];
1350 cout <<
"RK: t = " << scientific <<
t <<
" h = " <<
h[ 0 ] <<
" ";
1363 h = (
double*)realloc(
h,
maxAlloc*
sizeof(
double));
1372 for( jj = i1+1; jj <= i2; jj++ ){
1378 for( run1 = 0; run1 <
mn; run1++ )
1392 for( run1 = 0; run1 <
m; run1++ ){
1419 for( run1 = 0; run1 <
m; run1++ )
1428 if( E < Emin ) E = Emin ;
1429 if( E < 10.0*
EPS ) E = 10.0*
EPS;
1465 if( (
int) xEnd[0].
getDim() !=
m )
1468 for( run1 = 0; run1 <
m; run1++ )
1469 xEnd[0](run1) =
eta4[run1];
1483 if( order == 1 &&
nFDirs2 == 0 ){
1484 for( run1 = 0; run1 <
m; run1++ ){
1485 Dx[0](run1,0) =
etaG[run1];
1490 for( run1 = 0; run1 <
m; run1++ ){
1491 Dx[0](run1,0) =
etaG3[run1];
1495 if( order == 1 &&
nFDirs2 > 0 ){
1496 for( run1 = 0; run1 <
m; run1++ ){
1497 Dx[0](run1,0) =
etaG2[run1];
1501 if( order < 1 || order > 2 ){
1517 if( order == 1 &&
nBDirs2 == 0 ){
1519 if( Dx_x0.
getDim() != 0 ){
1520 for( run2 = 0; run2 <
m; run2++ )
1523 if( Dx_p.
getDim() != 0 ){
1524 for( run2 = 0; run2 <
mp; run2++ ){
1528 if( Dx_u.
getDim() != 0 ){
1529 for( run2 = 0; run2 <
mu; run2++ ){
1533 if( Dx_w.
getDim() != 0 ){
1534 for( run2 = 0; run2 <
mw; run2++ ){
1540 if( order == 1 &&
nBDirs2 > 0 ){
1542 if( Dx_x0.
getDim() != 0 ){
1543 for( run2 = 0; run2 <
m; run2++ ){
1547 if( Dx_u.
getDim() != 0 ){
1548 for( run2 = 0; run2 <
mu; run2++ ){
1552 if( Dx_p.
getDim() != 0 ){
1553 for( run2 = 0; run2 <
mp; run2++ ){
1557 if( Dx_w.
getDim() != 0 ){
1558 for( run2 = 0; run2 <
mw; run2++ ){
1567 if( Dx_x0.
getDim() != 0 ){
1568 for( run2 = 0; run2 <
m; run2++ ){
1572 if( Dx_u.
getDim() != 0 ){
1573 for( run2 = 0; run2 <
mu; run2++ ){
1577 if( Dx_p.
getDim() != 0 ){
1578 for( run2 = 0; run2 <
mp; run2++ ){
1582 if( Dx_w.
getDim() != 0 ){
1583 for( run2 = 0; run2 <
mw; run2++ ){
1589 if( order < 1 || order > 2 ){
1627 int run1, run2, run3;
1632 for( run1 = 0; run1 <
dim; run1++ ){
1634 for( run2 = 0; run2 <
m; run2++ ){
1636 for( run3 = 0; run3 < run1; run3++ ){
1637 x[diff_index[run2]] =
x[diff_index[run2]] +
1638 A[run1][run3]*h[0]*
k[run3][run2];
1655 for( run1 = 0; run1 <
m; run1++ ){
1664 for( run1 = 0; run1 <
dim; run1++ ){
1665 for( run2 = 0; run2 <
m; run2++ ){
1667 eta5[run2] =
eta5[run2] +
b5[run1]*
h[0]*k[run1][run2];
1675 for( run2 = 0; run2 <
m; run2++ ){
1691 int run1, run2, run3;
1696 for( run1 = 0; run1 <
dim; run1++ ){
1698 for( run2 = 0; run2 <
m; run2++ ){
1700 for( run3 = 0; run3 < run1; run3++ ){
1701 x[diff_index[run2]] =
x[diff_index[run2]] +
1702 A[run1][run3]*h[0]*
k[run3][run2];
1719 for( run1 = 0; run1 <
m; run1++ ){
1726 for( run1 = 0; run1 <
dim; run1++ ){
1727 for( run2 = 0; run2 <
m; run2++ ){
1729 eta5[run2] =
eta5[run2] +
b5[run1]*
h[0]*k[run1][run2];
1737 for( run2 = 0; run2 <
m; run2++ ){
1750 int run1, run2, run3;
1754 for( run1 = 0; run1 <
dim; run1++ ){
1755 for( run2 = 0; run2 <
m; run2++ ){
1757 for( run3 = 0; run3 < run1; run3++ ){
1758 G[diff_index[run2]] =
G[diff_index[run2]] +
1759 A[run1][run3]*
h[0]*
k[run3][run2];
1770 for( run1 = 0; run1 <
dim; run1++ ){
1771 for( run2 = 0; run2 <
m; run2++ ){
1781 int run1, run2, run3;
1785 for( run1 = 0; run1 <
dim; run1++ ){
1786 for( run2 = 0; run2 <
m; run2++ ){
1788 G3[diff_index[run2]] =
etaG3[run2];
1789 for( run3 = 0; run3 < run1; run3++ ){
1790 G2[diff_index[run2]] =
G2[diff_index[run2]] +
1791 A[run1][run3]*
h[0]*
k[run3][run2];
1792 G3[diff_index[run2]] =
G3[diff_index[run2]] +
1793 A[run1][run3]*
h[0]*
k2[run3][run2];
1797 if(
rhs[0].AD_forward2( number_+run1,
G2,
G3,
k[run1],
k2[run1] )
1807 for( run1 = 0; run1 <
dim; run1++ ){
1808 for( run2 = 0; run2 <
m; run2++ ){
1819 int run1, run2, run3;
1822 for( run1 = 0; run1 <
dim; run1++ ){
1823 for( run2 = 0; run2 < ndir; run2++ ){
1824 l[run1][run2] = 0.0;
1827 for( run1 = dim-1; run1 >= 0; run1--){
1828 for( run2 = 0; run2 <
m; run2++ ){
1830 for( run3 = run1+1; run3 <
dim; run3++ ){
1831 H[run2] =
H[run2] +
A[run3][run1]*
h[0]*
l[run3][diff_index[run2]];
1843 for( run1 = 0; run1 <
dim; run1++ ){
1844 for( run2 = 0; run2 < ndir; run2++ ){
1845 etaH[run2] =
etaH[run2] +
l[run1][run2];
1853 int run1, run2, run3;
1856 for( run1 = 0; run1 <
dim; run1++ ){
1857 for( run2 = 0; run2 < ndir; run2++ ){
1858 l [run1][run2] = 0.0;
1859 l2[run1][run2] = 0.0;
1863 for( run1 = dim-1; run1 >= 0; run1--){
1864 for( run2 = 0; run2 <
m; run2++ ){
1866 H3[run2] =
b4[run1]*
h[0]*
etaH3[diff_index[run2]];
1867 for( run3 = run1+1; run3 <
dim; run3++ ){
1868 H2[run2] =
H2[run2] +
A[run3][run1]*
h[0]*
l[run3][diff_index[run2]];
1869 H3[run2] =
H3[run2] +
A[run3][run1]*
h[0]*
l2[run3][diff_index[run2]];
1872 if(
rhs[0].AD_backward2( number_+run1,
H2,
H3,
l[run1],
l2[run1] )
1882 for( run1 = 0; run1 <
dim; run1++ ){
1883 for( run2 = 0; run2 < ndir; run2++ ){
1896 for( run1 = 0; run1 <
m; run1++ ){
1897 cout <<
"x[" << run1 <<
"] = " <<
eta4[run1] <<
" ";
1910 cout <<
"RK: Forward Sensitivities:\n";
1911 for( run1 = 0; run1 <
m; run1++ ){
1912 cout << scientific <<
etaG[run1] <<
" ";
1923 cout <<
"RK: First Order Forward Sensitivities:\n";
1924 for( run1 = 0; run1 <
m; run1++ ){
1925 cout << scientific <<
etaG2[run1] <<
" ";
1929 cout <<
"RK: Second Order Forward Sensitivities:\n";
1930 for( run1 = 0; run1 <
m; run1++ ){
1931 cout << scientific <<
etaG3[run1] <<
" ";
1941 cout <<
"RK: Backward Sensitivities:\n";
1943 cout <<
"w.r.t. the states:\n" << scientific;
1944 for( run2 = 0; run2 <
m; run2++ ){
1950 cout <<
"w.r.t. the controls:\n" << scientific;
1951 for( run2 = 0; run2 <
mu; run2++ ){
1957 cout <<
"w.r.t. the parameters:\n" << scientific;;
1958 for( run2 = 0; run2 <
mp; run2++ ){
1964 cout <<
"w.r.t. the disturbances:\n" << scientific;;
1965 for( run2 = 0; run2 <
mw; run2++ ){
1978 cout <<
"RK: First order Backward Sensitivities:\n";
1980 cout <<
"w.r.t. the states:\n" << scientific;;
1981 for( run2 = 0; run2 <
m; run2++ ){
1987 cout <<
"w.r.t. the controls:\n" << scientific;;
1988 for( run2 = 0; run2 <
mu; run2++ ){
1994 cout <<
"w.r.t. the parameters:\n" << scientific;;
1995 for( run2 = 0; run2 <
mp; run2++ ){
2001 cout <<
"w.r.t. the disturbances:\n" << scientific;;
2002 for( run2 = 0; run2 <
mw; run2++ ){
2008 cout <<
"RK: Second order Backward Sensitivities:\n";
2010 cout <<
"w.r.t. the states:\n" << scientific;
2011 for( run2 = 0; run2 <
m; run2++ ){
2017 cout <<
"w.r.t. the controls:\n" << scientific;
2018 for( run2 = 0; run2 <
mu; run2++ ){
2025 cout <<
"w.r.t. the parameters:\n" << scientific;
2026 for( run2 = 0; run2 <
mp; run2++ ){
2033 cout <<
"w.r.t. the disturbances:\n" << scientific;
2034 for( run2 = 0; run2 <
mw; run2++ ){
2046 for( run1 = 0; run1 <
m; run1++ ){
2048 double cc = e1[run1];
2049 double bb = d1[run1];
2050 double aa = (e2[run1] - bb*
h[0] - cc)/(
h[0]*
h[0]);
2054 poly( jj, run1 ) = aa*tt*tt + bb*tt + cc;
returnValue setLast(LogName _name, int lastValue, double time=-INFTY)
int getStateEnumerationIndex(int index_)
virtual int getNumberOfSteps() const
IntermediateState sqrt(const Expression &arg)
double getTime(uint pointIdx) const
int * int_parameter_index
void determineEtaHBackward(int number)
double getFirstTime() const
void constructAll(const IntegratorRK &arg)
virtual returnValue init(const DifferentialEquation &rhs_)
virtual returnValue getProtectedBackwardSensitivities(DVector &Dx_x0, DVector &Dx_p, DVector &Dx_u, DVector &Dx_w, int order) const
void initializeVariables()
BEGIN_NAMESPACE_ACADO const double EPS
virtual returnValue setProtectedForwardSeed(const DVector &xSeed, const DVector &pSeed, const DVector &uSeed, const DVector &wSeed, const int &order)
void init(unsigned _dim=0)
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
AlgorithmicBase & operator=(const AlgorithmicBase &rhs)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
virtual double getStepSize() const
Allows to conveniently handle (one-dimensional) grids consisting of time points.
RealClock functionEvaluation
virtual returnValue getProtectedX(DVector *xEnd) const
#define CLOSE_NAMESPACE_ACADO
virtual returnValue stop()
virtual int getDim() const
Abstract base class for all kinds of algorithms for integrating differential equations (ODEs or DAEs)...
uint getFloorIndex(double time) const
BooleanType acadoIsNaN(double x)
virtual returnValue getProtectedForwardSensitivities(DMatrix *Dx, int order) const
void determineEtaGForward(int number)
virtual returnValue evaluate(const DVector &x0, const DVector &xa, const DVector &p, const DVector &u, const DVector &w, const Grid &t_)
virtual returnValue unfreeze()
void determineEtaGForward2(int number)
double scale(VariableType variableType_, int index_) const
returnValue acadoPrintCopyrightNotice(const std::string &subpackage)
Derived & setZero(Index size)
int index(VariableType variableType_, int index_) const
virtual returnValue freezeAll()
void interpolate(int jj, double *e1, double *d1, double *e2, VariablesGrid &poly)
virtual returnValue freezeMesh()
virtual returnValue start()
virtual IntegratorRK & operator=(const IntegratorRK &arg)
virtual returnValue setBackwardSeed2(const DVector &seed)
virtual int getNumberOfRejectedSteps() const
virtual returnValue stop()
double getLastTime() const
#define ACADOWARNING(retval)
#define BEGIN_NAMESPACE_ACADO
virtual returnValue step(int number)
Abstract base class for all kinds of Runge-Kutta schemes for integrating ODEs.
virtual returnValue printRunTimeProfile() const
returnValue setForwardSeed2(const DVector &xSeed, const DVector &pSeed, const DVector &uSeed, const DVector &wSeed)
void printIntermediateResults()
virtual returnValue evaluateSensitivities()
virtual returnValue setProtectedBackwardSeed(const DVector &seed, const int &order)
int getNumberOfVariables() const
#define ACADOERROR(retval)
virtual returnValue setDxInitialization(double *dx0)
virtual returnValue getTime(double &_elapsedTime)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
DifferentialEquation * rhs
void determineEtaHBackward2(int number)