ianhinder / Kranc

A Mathematica package for generating code for solving time dependent partial differential equations
http://kranccode.org
GNU General Public License v2.0
28 stars 10 forks source link

Example SimpleWaveODE cannot be compiled #147

Open xuyumeng opened 4 years ago

xuyumeng commented 4 years ago

I want to use Kranc to calculate some model contains ODE equation, and I tried the SimpleWaveODE.m. But it cannot pass the build process of Cactus. Below is the error message

Cactus/arrangements/KrancExamples/SimpleWaveODE/src/calc_rhs.cc: In function 'void SimpleWaveODE::calc_rhs_Body(const cGH*, int, int, const CCTK_REAL8*, const CCTK_REAL8*, const CCTK_REAL8*, const int*, const int*, int, CCTK_REAL8* const __restrict__*)':
Cactus/arrangements/KrancExamples/SimpleWaveODE/src/calc_rhs.cc:88:47: error: invalid types 'CCTK_REAL8* const __restrict__ {aka double* const __restrict__}[char*(const char*, int)]' for array subscript
   88 |   CCTK_REAL aL CCTK_ATTRIBUTE_UNUSED = a[index];
      |                                               ^
Cactus/arrangements/KrancExamples/SimpleWaveODE/src/calc_rhs.cc:89:47: error: invalid types 'CCTK_REAL8* const __restrict__ {aka double* const __restrict__}[char*(const char*, int)]' for array subscript
   89 |   CCTK_REAL bL CCTK_ATTRIBUTE_UNUSED = b[index];
      |                                               ^
make[3]: *** [calc_rhs.cc.o] Error 1
rhaas80 commented 4 years ago

This looks to me like there is a function index with prototype

char * index(const char*, int)

in your code that somehow messes up Kranc's use of the name index for a local variable.

Looking at the calc_rhs.cc in Kranc's repo for the SimpleWaveODE example the code seems to be just wrong as it tries to use index in line 88 before it has been properly declared:

    86    /* Assign local copies of arrays functions */
    87
    88    CCTK_REAL aL CCTK_ATTRIBUTE_UNUSED = a[index];
    89    CCTK_REAL bL CCTK_ATTRIBUTE_UNUSED = b[index];
    90
    91    /* Calculate temporaries and arrays functions */
    92    CCTK_REAL arhsL CCTK_ATTRIBUTE_UNUSED = bL;
    93
    94    CCTK_REAL brhsL CCTK_ATTRIBUTE_UNUSED = -aL;

this seems to be bug in the generated code. Re-running SimpleWaveODE.m through Kranc

rm -rf SimpleWaveODE
make SimpleWaveODE

does not fix the issue. So this seems to be a bug in how Kranc generates code for ODEGroups type groups that would seem to try and allow ODEs for simple grid arrays rather than grid functions.

For the example you may just want to remove all mention of the variables a and b and eg replace them both by the value 1.