  The performance in finite time of a discrete heat engine with internal
friction is analyzed. The working fluid of the engine is composed of an
ensemble of noninteracting two level systems. External work is applied by
changing the external field and thus the internal energy levels. The friction
induces a minimal cycle time. The power output of the engine is optimized with
respect to time allocation between the contact time with the hot and cold baths
as well as the adiabats. The engine's performance is also optimized with
respect to the external fields. By reversing the cycle of operation a heat pump
is constructed. The performance of the engine as a heat pump is also optimized.
By varying the time allocation between the adiabats and the contact time with
the reservoir a universal behavior can be identified. The optimal performance
of the engine when the cold bath is approaching absolute zero is studied. It is
found that the optimal cooling rate converges linearly to zero when the
temperature approaches absolute zero.
