Updated grad_func to support boundary condition
Simplified eikonal_solve