Is this difference of surface integrals zero? $\oint_S\bar{\psi}\nabla(x\cdot\nabla\psi)\cdot n dS-\oint_S(x\cdot\nabla\psi)\nabla\bar{\psi}\cdot ndS$ This is the follow-up question of When does this integral vanish, which appears in the derivation of the quantum virial theorem? and building on this answer.
Does the following difference of surface integrals vanish, if all we know is $\nabla|\psi|^2\cdot\mathbf{n}=0$, i.e. the gradient vector field of $|\psi|^2=\bar\psi\psi$ is of zero local flux on the surface.
$$
\oint_S\bar{\psi}\nabla\left(\mathbf{x}\cdot\nabla\psi\right)\cdot\mathbf{n}\mathrm{d}S-\oint_S(\mathbf{x}\cdot\nabla\psi)\nabla\bar{\psi}\cdot\mathbf{n}\mathrm{d}S
$$
First of all, let us break $\nabla|\psi|^2$ apart:
$$
\nabla|\psi|^2=\nabla(\bar\psi\psi)=\psi\nabla\bar\psi + \bar\psi\nabla\psi
$$
This does not really help us, but for real $\psi$, we can continue. Since $\nabla|\psi|^2=2\psi\nabla\psi$, we know, that $\psi\nabla\psi\cdot\mathbf{n}=0$ at the surface of our zero-flux domains. This still does not really help, so let us assume, that $\nabla\psi\cdot\mathbf{n}=0$ (even if $\psi=0$). Finally, the second term disappears, which leaves us with:
$$
=\oint_S\psi\nabla\left(\mathbf{x}\cdot\nabla\psi\right)\cdot\mathbf{n}\mathrm{d}S
$$
Now, we can continue with the gradient of the scalar product. Here, $\nabla\mathbf{A}$ is the transposed of the Jacobian of $\mathbf{A}$. It does not really matter, that it is transposed, since the Jacobians should be symmetric here.
$$
\begin{aligned}
=&\oint_S\psi\nabla\left(\mathbf{x}\cdot\nabla\psi\right)\cdot\mathbf{n}\mathrm{d}S\\
=&\oint_S\psi\left[\left(\nabla\nabla\psi\right)\cdot\mathbf{x}\right]\cdot\mathbf{n}\mathrm{d}S
+\oint_S\psi\left[\left(\nabla\mathbf{x}\right)\cdot\nabla\psi\right]\cdot\mathbf{n}\mathrm{d}S
\end{aligned}
$$
Now the Jacobi matrix of $\mathbf{x}$ is the unit matrix, so that:
$$
\begin{aligned}
=&\oint_S\psi\left[\left(\nabla\nabla\psi\right)\cdot\mathbf{x}\right]\cdot\mathbf{n}\mathrm{d}S
+\oint_S\psi\nabla\psi\cdot\mathbf{n}\mathrm{d}S\\
=&\oint_S\psi\left[\left(\nabla\nabla\psi\right)\cdot\mathbf{x}\right]\cdot\mathbf{n}\mathrm{d}S
\end{aligned}
$$
From here, I don't really know how to continue. I can write everything as sums again, but that does not help:
$$
=\oint_S\psi\sum_jn_j\sum_ix_i
\frac{\partial^2\psi}{\partial x_i\partial x_j}\mathrm{d}S
$$
Can the initial difference be shown to be zero for the given conditions for a) any function, b) a real function?
PS: the function should be in $L^2$, i.e. it should be square integrable and vanish for any $x_i\rightarrow\pm\infty$. It should be continuous and almost everywhere differentiable.
 A: $\def\vk{{\bf k}}
\def\vx{{\bf x}}
\def\vn{{\bf n}}
\def\j{\psi}
\def\jc{\overline\j}
\def\o{\cdot}
\def\VF{{\bf F}}$The difference does not generally vanish. Denote the difference by $I$.
Counterexample 1 ($\j$ complex):
Let $\j = e^{i\vk\o\vx}$ and $S$ the sphere  of radius $a$ centered at the origin.
One finds
$\nabla|\j|^2 = \nabla 1 = {\bf 0}$,
but
$I = -\frac 8 3 \pi a^3 \vk^2$.
Counterexample 2 ($\j$ real):
Let $\j = \cos x$ and $S$ the surface of the cube $[0,\pi]^3$.
One finds
$\nabla|\j|^2 = \langle-\sin x,0,0\rangle$,
so $\nabla|\j|^2=0$ on all facets of the cube,
but
$I = -\pi^3$.
Addendum 1
To satisfy the requirement that $\j$ be a wavefunction, let $\j$ go to zero in some smooth way outside of $S$ and normalize as necessary.
Nothing much about the calculation is changed.
Addendum 2
Counterexample 3:
Let
$$\j_{200} = \frac{1}{4\sqrt{2\pi}a_0^{3/2}} \left(2-\frac{r}{a_0}\right)e^{-r/2a_0}$$
be the 2s stationary state of the hydrogen atom and $S$ the surface of the sphere of radius $2a_0$ centered at the origin.
One finds that
$\nabla|\j|^2 = {\bf 0}$ on $S$ but that
$I=-1/(e a_0)^2$.
A: No, the surface integrals don't have to be equal. Take for example $ψ = r^2 - 1$, where $r(\mathbf{x}) = \sum_i {x_i}^2$ is the radial distance function from the origin and $S$ to be the unit sphere. Then $ψ^2 = (r^2-1)^2$ and so $∇(ψ^2) = (r^2-1) 2 r$ vanishes on the unit sphere. But
\begin{equation}
 \renewcommand{\d}{\mathop{}\!\mathrm{d}}
 \int_S ψ ∇(\mathbf{x} \cdot ψ) \cdot \mathbf{n} \d S = 0
\end{equation}
because $ψ$ vanishes on the sphere while
\begin{equation}
 \int_S (\mathbf{x} \cdot ∇ ψ) ∇ ψ \cdot \mathbf{n} \d S = \int_S r \cdot 2r \cdot 2r \d S = 16 π
\end{equation}
since $∇ ψ = 2r \hat{e}_r$
