Chapter 1: Make the code run on different grids

1.1 Source code transformation tool: conv

  • Original, ‘single-grid’ code must be re-written

    to be made grid-independent

  • Source-to-source transformation tool: conv

  • Global variables are handled internally by Agrif library

_images/conv.png

conv as transformation tool

Example: Original code

subroutine do_stuff (data_in)
use mod_global
real(8), dimension(:,:):: data_in
gridvar = data_in   ! modifies global variable 'gridvar'
end subroutine do_stuff
  • ‘gridvar’ is declared global in a common or module
  • ‘data_in’ is function argument

Example: Conv’ed code

subroutine do_stuff(data_in)

        use Agrif_Util

        use mod_global

        real(8), dimension(:,:):: data_in

        call Sub_Loop_do_stuff(data_in, Agrif_tabvars(12) % array2)

        ! 12 ---> index of the gridvar variable

 contains

        subroutine Sub_Loop_do_stuff(data_in,gridvar)

                use Agrif_Util

                real(8), dimension(:,:):: data_in

                real(8), allocatable, dimension(:,:):: gridvar

                gridvar = data_in   ! modifies global variable 'gridvar'

        end subroutine Sub_Loop_do_stuff

 end subroutine do_stuff

1.2 A typical compilation organization

1. Preprocessing

This part should be done only if the original code needs to be preprocessed.

cpp -P -Dkey_AGRIF src/code.F90 > work/code.F90_cpp

2. Call to conv program

cd work ; ../AGRIF/conv ../src/agrif.in -rm -comdirout AGRIF_MODEL_FILES -convfile code.F90_cpp

3. Re-preprocessing

cd work; cpp -P -Dkey_AGRIF -I./AGRIF_INC ./AGRIF_MODEL_FILES/code.F90_cpp > code.F90

4. Fortran compiltations

gfortran -I./AGRIF/AGRIF_OBJS -o code.o -c work/code.F90 -LAGRIF -lagrif