# Mpm99, for-loop 裡面添加 if 判斷式造成結果不一致

``````    w_old[0][0] = 0.5 * (1.5 - fx[0])**2
w_old[0][1] = 0.5 * (1.5 - fx[1])**2
w_old[1][0] = 0.75 - (fx[0] - 1)**2
w_old[1][1] = 0.75 - (fx[1] - 1)**2
w_old[2][0] = 0.5 * (fx[0] - 0.5)**2
w_old[2][1] = 0.5 * (fx[1] - 0.5)**2
for idx, idy in ti.static(ti.ndrange(numNeighbor, dim)):  # Loop over possible neighbor in x y direction
distReg = abs(fx[idy]-float(idx))# this is the x or y in the kernel expression, the reason for 1 is because of the float of idx
if (distReg) >= 0 and (distReg) <= 0.5:
w[idx][idy] = 0.75-distReg**2
elif (distReg) > 0.5 and (distReg) <= 1.5:
w[idx][idy] = 0.5*(1.5-distReg)**2
elif (distReg) > 1.5:
w[idx][idy] = 0
``````

``````    w_old[0][0] = 0.5 * (1.5 - fx[0])**2
w_old[0][1] = 0.5 * (1.5 - fx[1])**2
w_old[1][0] = 0.75 - (fx[0] - 1)**2
w_old[1][1] = 0.75 - (fx[1] - 1)**2
w_old[2][0] = 0.5 * (fx[0] - 0.5)**2
w_old[2][1] = 0.5 * (fx[1] - 0.5)**2
for idx, idy in ti.static(ti.ndrange(numNeighbor, dim)):  # Loop over possible neighbor in x y direction
distReg = abs(fx[idy]-float(idx))# this is the x or y in the kernel expression, the reason for 1 is because of the float of idx
if (distReg) >= 0 and (distReg) <= 0.5:
w[idx][idy] = 0.75-distReg**2
elif (distReg) > 0.5 and (distReg) <= 1.5:
w[idx][idy] = 0.5*(1.5-distReg)**2
elif (distReg) > 1.5:
w[idx][idy] = 0

# double check if the proposed algorithm matches the original setting, if not, output the information**
if abs(w_old[idx][idy]-w[idx][idy]) > 1e-4:  **
print('x[p] :',x[p])**
print('base :',base)**
print('distReg :',distReg)**
print('fx[0] :',fx[idy])**
print('w_old[idx][idy]',w_old[idx][idy])**
print('w[idx][idy]',w[idx][idy])**
``````