Mechanisms of porosity formation during solidification: A theoretical analysis