Modeling slack flow in hydraulic pipelines by means of a consistent thermodynamic theory