A very common problem in physics is to search for a function $f:\mathbb{R}^n \rightarrow \mathbb{R}^n$ such that $$ \nabla \cdot f = g $$ for some given source density $g: \mathbb{R}^n \rightarrow \mathbb{R}$ (and typically $n=3$ or less) together with some appropriate boundary conditions.
For example, this can be Gauß' law in electrodynamics with $f$ being the dielectric displacement, the incompressibility condition in fluid dynamics ($f$ being the velocity field) or we could be searching for a particle flux $f$ with some given sources and sinks.
Now, as far as I understand the above equation alone does not have a unique solution. A remedy for this is using $f$ as the gradient of a potential: In electrostatics this is possible due to Faraday's law, in fluid dynamics this is the assumption of potential flow. The result is the Poisson equation for which (proper boundary conditions given) indeed a unique solution exists and can even be found more or less conveniently using Green functions.
My question is: What if $f$ is not the gradient of a potential? (For example in the third physical problem mentioned above.) Are there other techniques to ensure that the equation has a unique solution? Do boundary conditions play a role? (I mean, of course they do, but can they alone provide uniqueness?)