A multiscale analysis of heat transfer in porous media