Thermodynamics of particle engulfment by solidifying melts