Text this: Variational analysis for simulating free-surface flows in a porous medium