A helper class for the access of the various derivatives in higher order AD types.
A higher order derivative that is combined via the CoDiPack types has possible derivative values (including the primal value) where is the number of types that are nested. If a second and third order type are constructed via
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
then the second order type t2s has 4 possible values and the third order type has 8 possible values . The number of derivatives per derivative order can be computed via the binomial coefficient where is the derivative order. For a second order type this yields 1 derivative of order zero (the primal value), two derivatives of first order, and one derivative of second order. For a third order type this is 0:1, 1:3, 2:3, 3:1 (order:number).
Given the derivative order and the index of the derivative within that order , the algorithm in this class selects the corresponding derivative value.
The class provides methods for the run time selection of the derivatives. If these methods are used, then the AD types need to be defined such that all primal and derivative values have the same type. If this is not the case, then the compiler will show errors that it cannot convert a value.
The class provides methods for the compile time selection of the derivatives, too. These methods do not have the restriction that all the primal and derivative types need to have the same type. On the other hand, the usual compile time restrictions apply to the parameters of the templates, that is, they must be compile time constants. Also, the setDerivatives method which sets all derivatives of one order may not be used if different primal and gradient types are used. The provided objects must be convertible into all possible types that are used at the leaf points of the recursion.
The selection algorithm walks along the nodes in the nested classes. From the specified order and the derivative number the algorithm checks if the derivative is in the lower (value) or upper (gradient) branch of the nested classes. The value is compared against the number of derivatives of that order in the lower branch. If smaller, the lower branch is taken. If larger or equal, the upper branch is taken. For a third order type, the graph looks as follows.
The two columns at the end show the derivative order under the column 'order' and the index in that order class under the column 'index'. It can be seen that the different derivative values of the same order are not continuously ordered in the graph. For the 2nd order derivatives in the above example, the indices correspond to the following calls.