[Users] Loop over the grid points of the base grid

Ian Hinder ian.hinder at manchester.ac.uk
Fri Oct 25 05:28:21 CDT 2019



On 25 Oct 2019, at 09:23, Erik Rodrígo Jiménez Vázquez <erjive at ciencias.unam.mx<mailto:erjive at ciencias.unam.mx>> wrote:

Dear all

I want to subtract an array at t-dt and t times only at the base grid (refinement level 0),  following http://lists.einsteintoolkit.org/pipermail/users/2013-May/003004.html, I implemented the suggestion in my code as

BEGIN_GLOBAL_MODE(cctkGH) {
  ENTER_LEVEL_MODE(cctkGH, 0) {

 for(int k=0;k<cctk_lsh[2];k++) {
        for(int j=0;j<cctk_lsh[1];j++) {
            for(int i=0;i<cctk_lsh[0];i++) {
                int index= CCTK_GFINDEX3D(cctkGH,i,j,k);
                lres += abs(phi[index]-phi_p[index]);
             }
        }
  }
 } LEAVE_LEVEL_MODE;
} END_GLOBAL_MODE;

However I got a segmentation fault. I think is because of the array index, if I comment
the line

lres += abs(phi[index]-phi_p[index]);

 the code works fine.
My questions are: 1) How can I perform this operation only at the base grid?, 2) How can I get the correct index at the base level? .. any help is very welcome. Thanks.

Hi Erik,

Can you check whether the phi and phi_p pointers are null?

I'm not sure whether you can access grid data in level mode.

I would have done this by scheduling the function in local mode in schedule.ccl and putting

if (cctk_levfac[0] == 1) {


}

around the loop over grid points.  I wouldn't have used the global and level mode macros.

cctk_levfac is described in the documentation (https://einsteintoolkit.org/usersguide/UsersGuidech9.html, search for cctk_levfac):

cctk_levfac
An array of  cctk_dim integer factors by which the local grid is refined in the corresponding direction with respect to the base grid.

--
Ian Hinder
Research Software Engineer
University of Manchester, UK

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.einsteintoolkit.org/pipermail/users/attachments/20191025/f81d3cf0/attachment-0001.html 


More information about the Users mailing list