def move_density_to_bdry(x, phi, P):
    """
    P tells us how much should be removed, by multiplying phi*P
    Take that density and instead of deleting it, move straight to boundary
    P - stores how much denstity from each grid point should be moved to diagonal
    """
    for ii in range(len(x)):
        for jj in range(len(x)):
            if P[ii, jj] == 0:
                continue
            else:
                amnt = P[ii, jj]
                s = ii + jj
                if ii == 1 and jj == len(x) - 3:
                    phi[ii + 1, jj] += phi[ii, jj] * amnt / 4.0 * 2
                    phi[ii, jj + 1] += phi[ii, jj] * amnt / 4.0 * 2
                    phi[ii - 1, jj] += phi[ii, jj] * amnt / 2 * 2
                    phi[ii, jj] *= 1 - amnt
                elif ii == len(x) - 3 and jj == 1:
                    phi[ii + 1, jj] += phi[ii, jj] * amnt / 4.0 * 2
                    phi[ii, jj + 1] += phi[ii, jj] * amnt / 4.0 * 2
                    phi[ii, jj - 1] += phi[ii, jj] * amnt / 2 * 2
                    phi[ii, jj] *= 1 - amnt
                elif (len(x) - 1 - s) % 2 == 1:
                    dist = (len(x) - 1 - s) // 2
                    phi[ii + dist + 1, jj + dist] += phi[ii, jj
                        ] * amnt / 2.0 * 2
                    phi[ii + dist, jj + dist + 1] += phi[ii, jj
                        ] * amnt / 2.0 * 2
                    phi[ii, jj] *= 1 - amnt
                else:
                    dist = (len(x) - 1 - s) // 2
                    phi[ii + dist, jj + dist] += phi[ii, jj] * amnt * 2
                    phi[ii, jj] *= 1 - amnt
    return phi
