The dynamics of magnetically trapped fluids. I - Implications for umbral dots and penumbral grains