There is an implementation of 2 phase flow in porous media in goma that can include the effects of gravity. The code is open source so you could reverse engineer the model, but the available documentation is limited.
It's not much of answer but it is a direction you might want to look into.