  We use molecular dynamics with a first-principles-based shell model potential
to study the electrocaloric effect (ECE) in lithium niobate, LiNbO$_3$, and
find a giant electrocaloric effect along a line passing through the
ferroelectric transition. With applied electric field, a line of maximum ECE
passes through the zero field ferroelectric transition, continuing along a
Widom line at high temperatures with increasing field, and along the
instability that leads to homogeneous ferroelectric switching below $T_c$ with
an applied field antiparallel to the spontaneous polarization. This line is
defined as the minimum in the inverse capacitance under applied electric field.
We investigate the effects of pressure, temperature and applied electric field
on the ECE. The behavior we observe in LiNbO$_3$ should generally apply to
ferroelectrics; we therefore suggest that the operating temperature for
refrigeration and energy scavenging applications should be above the
ferroelectric transition region to obtain large electrocaloric response. We
find a relationship among $T_c$, the Widom line and homogeneous switching that
should be universal among ferroelectrics, relaxors, multiferroics, and the same
behavior should be found under applied magnetic fields in ferromagnets.
