Thermodynamics and Optimal Control of Porous Media Flows in Oil Field Development