We develop a second-order accurate Navier–Stokes solver based on r-adaptivity of the underlying numerical discretization. The motion of the mesh is based on the fluid velocity field; however, certain adjustments to the Lagrangian velocities are introduced to maintain quality of the mesh. The adjustments are based on the variational approach of energy minimization to redistribute grid points closer to the areas of rapid solution variation. To quantify the numerical diffusion inherent to each method, we monitor changes in the background potential energy, computation of which is based on the density field. We demonstrate on a standing interfacial gravity wave simulation how using our method of grid evolution decreases the rate of increase of the background potential energy compared with using the same advection scheme on the stationary grid. To further highlight the benefit of the proposed moving grid method, we apply it to the nonhydrostatic lock-exchange flow where the evolution of the interface is more complex than in the standing wave test case. Naive grid evolution based on the fluid velocities in the lock-exchange flow leads to grid tangling as Kelvin–Helmholtz billows develop at the interface. This is remedied by grid refinement using the variational approach. Copyright © 2012 John Wiley & Sons, Ltd.