Statistical thermodynamic foundation for photovoltaic and photothermal conversion. I. Theory