Theoretical model for heterogeneous nucleation of grains during solidification