AD Code Generation
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 folders /inverse/g_tap for AD-forward-mode and /inverse/ad_tap for AD-reverse-mode. 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 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
.
The automatic AD code generation with TAPENADE is described in the following paragraph. Note that some manual adaptions might still be necessary at the end.
Generating automatic AD code:
-
Prerequisites:
Get a license for the TAPENADE software (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 the AD-generation shell scipts available at https://git.rwth-aachen.de/SHEMAT-Suite/shemat-suite_scripts/-/tree/master/shell:
generate-ad-head.sh
for head-based AD-code generation,generate-ad-pres.sh
for pressure-based AD-code generation,generate-ad-rm-head.sh
for head-based reverse-mode AD-code generation, andgenerate-ad-rm-pres.sh
for pressure-based reverse-mode 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.