Flow over heated terrain. Part I. Linear theory and idealized numerical simulations