#include "lu.h"

__kernel void pintgr2(__global double *g_u,
                      __global double *g_phi1,
                      __global double *g_phi2,
                      int ibeg,
                      int ifin,
                      int jbeg,
                      int jfin,
                      int ki1,
                      int ki2)
{
  int i, k;

  k = get_global_id(1) + ki1;
  i = get_global_id(0) + ibeg;
  if (k >= ki2 || i >= ifin) return;

  __global double (*u)[ISIZ2/2*2+1][ISIZ1/2*2+1][5] =
    (__global double (*)[ISIZ2/2*2+1][ISIZ1/2*2+1][5])g_u;
  __global double (*phi1)[ISIZ2+2] = (__global double (*)[ISIZ2+2])g_phi1;
  __global double (*phi2)[ISIZ2+2] = (__global double (*)[ISIZ2+2])g_phi2;

  phi1[k][i] = C2*(  u[k][jbeg][i][4]
      - 0.50 * (  u[k][jbeg][i][1] * u[k][jbeg][i][1]
                + u[k][jbeg][i][2] * u[k][jbeg][i][2]
                + u[k][jbeg][i][3] * u[k][jbeg][i][3] )
               / u[k][jbeg][i][0] );

  phi2[k][i] = C2*(  u[k][jfin-1][i][4]
      - 0.50 * (  u[k][jfin-1][i][1] * u[k][jfin-1][i][1]
                + u[k][jfin-1][i][2] * u[k][jfin-1][i][2]
                + u[k][jfin-1][i][3] * u[k][jfin-1][i][3] )
               / u[k][jfin-1][i][0] );
}

