The AD Code of SHEMAT-Suite comprises the differentiated code routines, which are required when compiling in ad-mode for inverse simulations. The AD code needs to be updated when developments and changes were made in SHEMAT-Suite routines.
Some AD files were generated manually. They are in folder */inverse/g_tap*. For example, the routine for `arrays.f90` is derivated manually. Note that these AD-files have to be adapted manually, if any changes are made in the respective forward routines. E.g. if a new array is introduced in `arrays.f90` it has to be added in `/inverse/g_tap/g_arrays.f90`, too!
Most of the AD routines are generated automatically by the [TAPENADE](http://www-sop.inria.fr/tropics/tapenade.html) automatic differentiation engine. This automatic generation is steered by the cmake file `cmake/AD.cmake`. User directories and property modules which shall be differentiated are defined in `cmake/Sources.cmake`.
## Generating automatic AD code:
* Prerequisites:
Get a license for the [TAPENADE software](http://www-sop.inria.fr/tropics/tapenade.html)(free academic usage upon request), then download and unpack it. Then add its path to the PATH environment variable (e.g. /home/Tapenade/tapenade_3.14/bin).
Python 2 is required for preprocessing scripts.
* Execute `generate-ad-head.sh` for head-based AD-code generation and `generate-ad-pres.sh` for pressure-based AD-code generation.
OR:
* Make a build-folder in the SHEMAT-Suite code directory:
```
mkdir build_ad
cd build_ad
```
* cmake with desired flags and options:
```
cmake -DPROPS=bas -DUSER=none -Dphys_base=head ..
```
* make ad-forward code:
```
make tap_tlm_clean
make tap_tlm
```
* make ad-reverse code:
```
make tap_adm_clean
make tap_adm
```
Note that the procedure has to be repeated for the pressure-based code (cmake with -Dphys_base=pres) in order to obtain the full AD code.