Mechanics of flow over ripples and dunes