# Why i am getting "-nan" value in cuda kernel after few iteration?

I am writting 3d Navier stokes solver using cuda. Probleam i am facing is I am getting “-nan” value in cuda kernel after few iteration. cuda kernel have wrriten as follows:

global void odd_u(double *ae,double *aw,double as,double an,doubleat,doubleab,double *ap1,double ap2,doubleap3,double *se,double *sw,double ss,double sn,doublest,doublesb,double *u,double *p,double uo,doubledu) {//printf("\neven_u");

int i = blockDim.x * blockIdx.x + threadIdx.x;
int j = blockDim.y * blockIdx.y + threadIdx.y;
int k = blockDim.z * blockIdx.z + threadIdx.z;
int index = iml+jl+k;
int indexW = (i-1)ml+(j)l+k;
if (indexW > ((n
m
l)-1)) indexW = (nml) -1;
if (indexW < 0) indexW = 0;
int indexE = (i+1)ml+(j)l+k;
if (indexE > ((n
ml)-1)) indexE = (nml) -1;
if (indexE < 0) indexE = 0;
int indexN = i
ml+(j-1)l+k;
if (indexN > ((n
m
l)-1)) indexN = (nml) -1;
if (indexN < 0) indexN = 0;
int indexS = iml+(j+1)l+k;
if (indexS > ((n
ml)-1)) indexS = (nml) -1;
if (indexS < 0) indexS = 0;
int indexT = i
ml+(j)l+(k-1);
if (indexT > ((n
m
l)-1)) indexT = (nml) -1;
if (indexT < 0) indexT = 0;
int indexB = iml+(j)l+(k+1);
if (indexB > ((n
ml)-1)) indexB = (nm*l) -1;
if (indexB < 0) indexB = 0;

if(i>=0 && i<(n-1))
{if(j>0 && j<(m-1))
{if(k>0 && k<(l-1))
{
if (((i+j+k)%2)!=0)
{

if(i==0){
u[index]=ae[index]*u[indexE]+an[index]*u[indexS]+as[index]*u[indexN]+ab[index]*u[indexT]+at[index]u[indexB]+sw[index]-se[index]+ss[index]-sn[index]+sb[index]-st[index]-(p[indexE]-p[index])deltaydeltaz+((1-alu)(ap1[index]+ap2[index]+ap3[index])/alu)*uo[index];

}else
{ u[index]=aw[index]*u[indexW]+ae[index]*u[indexE]+an[index]*u[indexS]+as[index]*u[indexN]+ab[index]*u[indexT]+at[index]u[indexB]+sw[index]-se[index]+ss[index]-sn[index]+sb[index]-st[index]-(p[indexE]-p[index])deltaydeltaz+((1-alu)(ap1[index]+ap2[index]+ap3[index])/alu)uo[index];
}
u[index]=alu
u[index]/(ap1[index]+ap2[index]+ap3[index]);
``````}