A variational theory for frictional flow of fluids in inhomogeneous porous systems