Thermodynamics for fluid flow in porous structures