This study presents numerical findings on the flow and heat transfer irreversibility when metal foams are partially filled in a horizontal pipe. A heater is embedded in the pipe's circumference with a known heat input. Aluminum metal foam, characterized by a pore density of 10 and porosity of 0.95, is placed next to the inner wall of the pipe to enhance heat transfer. To determine the optimal thickness of the metal foam for thermodynamic performance enhancement, metal foams of five different thicknesses (10–80 mm) are examined under forced convection heat transfer conditions. The study integrates the Darcy Extended Forchheimer and local thermal nonequilibrium models to predict flow and heat transfer characteristics through the metal foams. Validation of the numerical methodology is conducted by comparing the results with experimental data available in the literature. A novel aspect of this investigation is the application of the second law of thermodynamics to analyze the thermodynamic performance of metal foams. Exergy and irreversibility analyses are used to evaluate the thermodynamic performance, revealing that a pipe filled with metal foams up to a thickness of 40 mm exhibits superior thermodynamic performance compared to other cases examined in the study.