# Algorithmic Optimal Control - CO2 Uptake of the Ocean

Homepage

Installed at the Department of Computer Science under

There are two different Modes:

• Tapeless Mode (only forwards mode):
• prepare program code:
• maximum number of independent variables: #define NUMBER_DIRECTIONS 10
• use special namespace for "tapeless": using namespace adtl;
• declare all active variables and functions as type adouble
• initialize the Seed-Matrix via  x[i].setADValue(i,1) (here dx[i]/dx[i]=1)
• Get the i-th component of the derivative via y.getADValue(i)  (here for y=f(x))
• Compile: with option -I/home/numtools/adolc_base/include  ( - capitali)
• Link: no further library is needed
• Tape Mode (forwards and backwards mode):
• prepare program code:
• initialize tape: Before the part of the program that will be differentiated:
trace_on(tag,keep);
tag is the tapenumber (if you only need one, set tag=0)
Parameter keep (optional) is only necessary if there's a call for reverse mode directly afterwards (without using the forwards mode first) and is set to the order of the highest derivative that will be calculated (thus trace_on(0,1) for 1. derivative in reverse mode)
• Shift values of the independent variables into the adouble variables. Examplel:
double x[n];
for (i=0;i<n;i++) ax[i] <<= x[i];
• The declare all actice variables as type adouble and don't change the rest of the program code, Example:
ay=f(ax);
• Shift result back into adouble-Variable:
double y;
ay >>= y;
• deactivate tape:
trace_off();
• Calculate the derivative by evaluating the tape:
• Directly call forward mode (Manual p. 41):
• Jacobian matrix for a function f:R^n-> R^m:
define and initialize Seed Matrix :
double **X=new double*[n];
...
define Jacobian matrix:
double**Y = new double*[m];
for(int i=0;i<m;i++) Y[i]=new double[n];
Call forward mode:
forward(tag,m,n,n,x,X,y,Y);     // y=vector of function values
• Gradient of a function f:R^n-> R:
define and initialize Seed-Matrix:
double **X=new double*[n];
...

double*Y = new double[n];
Call forward mode:
forward(tag,m,n,n,x,X,&y,&Y);     // y= function value (scalar size, thus deliver reference)
• Call reverse mode directly (Manual p. 40):
• Gradient of a function f:R^n -> R:

double w=1;
double *Y = new double[n];
reverse(tag,1,n,0,&w,Y);

It is either necessary to set keep=1 in trace_on() or a run in forward mode must have been executed!!!

• or drivers for Gradient etc.: