Heated pipe flow is widely used in thermal engineering applications, but the presence of buoyancy force can cause intermittency, or multiple flow states at the same parameter values. Such changes in the flow lead to substantial changes in its heat transfer properties and thereby significant changes in the axial temperature gradient. We therefore introduce a model that features a time-dependent background axial temperature gradient, and consider two temperature boundary conditions-fixed temperature difference and fixed boundary heat flux. Direct numerical simulations (DNSs) are based on the pseudo-spectral framework, and good agreement is achieved between present numerical results and experimental results. The code extends Openpipeflow and is available at the website. The effect of the axially periodic domain on flow dynamics and heat transfer is examined, using pipes of length L=5D and L=25D. Provided that the flow is fully turbulent, results show close agreement for the mean flow and temperature profiles, and only slight differences in root-mean-square fluctuations. When the flow shows spatial intermittency, heat transfer tends to be overestimated using a short pipe, as shear turbulence fills the domain. This is particularly important when shear turbulence starts to be suppressed at intermediate buoyancy numbers. Finally, at such intermediate buoyancy numbers, we confirm that the decay of localised shear turbulence in the heated pipe flow follows a memoryless process, similar to that in isothermal flow. While isothermal flow then laminarises, convective turbulence in the heated flow can intermittently trigger bursts of shear-like turbulence.