![]() ![]() ![]() ![]() Next: Cactus Variables Up: C Routines Previous: Complex variables Contents Specifically for C ProgrammersGrid functions are held in memory as 1-dimensional C arrays. These are laid out in memory as in Fortran. This means that the first index should be incremented through most rapidly. This is illustrated in the example below. Cactus provides macros to find the 1-dimensional index which is needed from the multidimensional indices which are usually used. There is a macro for each dimension of grid function. Below is an artificial example to demonstrate this using the 3D macro CCTK_GFINDEX3D: for (k=0; k<cctk_lsh[2]; k++) { for (j=0; j<cctk_lsh[1]; j++) { for (i=0; i<cctk_lsh[0]; i++) { My3D_GF[CCTK_GFINDEX3D(cctkGH,i,j,k)] = i*j*k; } } }Here, CCTK_GFINDEX3D(cctkGH,i,j,k) expands to
((i) + cctkGH->cctk_lsh[0]*((j)+cctkGH->cctk_lsh[1]*(k)))
|