Transient heat transfer of superfluid He4 in nonhomogeneous geometries: Second sound, rarefaction, and thermal layer