Long time dynamics of layered solutions to the shallow water equations