  We consider a generic diffusion on the 1D torus and give a simple
representation formula for the large deviation rate functional of its invariant
probability measure, in the limit of vanishing noise. Previously, this rate
functional had been characterized by M.I. Freidlin and A.D.\ Wentzell as
solution of a rather complex optimization problem. We discuss this last problem
in full generality and show that it leads to our formula. We express the rate
functional by means of a geometric transformation that, with a Maxwell-like
construction, creates flat regions.
  We then consider piecewise deterministic Markov processes on the 1D torus and
show that the corresponding large deviation rate functional for the stationary
distribution is obtained by applying the same transformation. Inspired by this,
we prove a universality result showing that the transformation generates
viscosity solution of stationary Hamilton--Jacobi equation associated to any
Hamiltonian $H$ satisfying suitable weak conditions.
