Modeling water flow in two- and three-dimensional applications. I. General theory for non-swelling and swelling soils