The answer to this question: Divergence-free vector field on a 2-sphere. shows that every divergence-free vector field on the 2-sphere can be generated from a scalar function. (A commenter noted that, given the standard metric, the procedure to get the vector field is to take the gradient of the scalar field and rotate it 90 degrees.)
Can the same thing be said about divergence-free vector fields on the plane? What about on the 2-torus?