Solution (source code)

= Solution

For a continuously differentiable <vector field> $\mathbf G$ on a bounded volume $V$ with piecewise smooth closed boundary $\partial V$, the <divergence theorem> states
$$
\boxed{\int_{\partial V}\mathbf G\cdot\mathbf n\,dS=\int_V\nabla\cdot\mathbf G\,dV,}
$$
where $\mathbf n$ is the outward <unit normal vector>. Thus total outward <flux> through a closed surface equals the integral of the local <divergence> inside it. A nonclosed surface first needs a suitable closure, with the added surface's <flux> accounted for separately.