Simulation of the thermal history dependence of primary spacing during directional solidification