If one has the equation: $$v\cdot \nabla_x f = g(x),$$ where the domain is $D =\{x:x = (x_1,x_2,x_3)\in\mathbb{R}^3\},$ how does one write down a closed formula for $f$ in terms of $g$ ? I looked at method of characteristics but every example I looked at was dealing with either bounded domains or domains that has boundaries. So I am not sure how to write down the closed formula for $f,$ if it is possible at all.
I am not particularly concerned with the smoothness assumptions, so we can assume $g$ whatever necessary to make the problem well-posed.
Let us consider that $f$ and $g$ are scalar fields, which depend on the position $x = (x_1,x_2,x_3)^\top \in \Bbb R^3$. Moreover, we assume that the vector $v = (v_1,v_2,v_3)^\top \neq 0$ does not depend on $x$. The PDE $v\cdot \nabla f = g$ reads $$ \sum_{i=1}^3 v_i \frac{\partial}{\partial x_i} f(x) = g(x) \, . $$ The method of characteristics for the above PDE leads to the system
$\frac{\text d}{\text d s} x = v$, letting $x(0) = x^\circ$ we know $x(s) = x^\circ + s v$;
$\frac{\text d}{\text d s} f = g$, letting $f(0) = f^\circ$ we know $f(s) = f^\circ + \int_0^s g(x(\sigma)) \, \text d \sigma$.
A condition to deduce $f(x)$ from the above system is that $x - x^\circ$ and $v$ are collinear vectors, i.e. we need to know the value $f^\circ$ of $f$ at some position $x^\circ$ such that the cross product $(x - x^\circ) \times v$ equals zero. Hence, the knowledge of boundary conditions is crucial.
If $v_1\neq 0$, division by $v_1$ in the PDE restricts the study to vectors $v$ of the form $v = (1,a,b)^\top$, for which we must have $(x - x^\circ) \times v=0$. For instance, we can let $x^\circ$ describe the plane of equation $x_1^\circ = 0$. In other words, we know the boundary data $f^\circ(x_2^\circ,x_3^\circ) = f(0,x_2^\circ,x_3^\circ)$ for all $x_2^\circ$, $x_3^\circ$. The corresponding characteristics satisfy $$x(s) = (s, x_2^\circ + a s, x_3^\circ + b s)^\top \qquad\text{and}\qquad f(s) = f^\circ(x_2^\circ,x_3^\circ) + \int_0^s g(x(\sigma)) \, \text d \sigma \, .$$ Finally, we are left with $$ f(x) = f^\circ(x_2-ax_1,x_3-bx_1) + \int_0^{x_1} g\big(\sigma, x_2 - a (x_1-\sigma), x_3 - b (x_1-\sigma)\big) \, \text d \sigma \, . $$ Note that if $g = 0$, then the two-dimensional advection equation is recovered (cf. §18.2 of (1)), for which the initial density $f^\circ$ simply translates at the velocity $a,b$ along $x_2$, $x_3$. Also, note that if both $a$ and $b$ equal zero, then we recover the evolution equation $f_{x_1} = g$.
(1) R.J. LeVeque, Finite Volume Methods for Hyperbolic Problems, Cambridge university press, 2002. doi:10.1017/CBO9780511791253