Boundary version of the fundamental lemma of calculus of variations I was looking for a detailed version with proof of the following statement:
$$\int_{\partial D} (f\varphi  +X \cdot \operatorname{grad}\varphi ) \,\,\mathrm d a =0
~~~~\forall \varphi:D \to \mathbb R ~~~~~\Longrightarrow~~~~~ f=0,~X=0 ~~\text{on}~ \partial D .$$
Here $D$ is a three-dimensional domain.
It is some sort of boundary version of the fundamental lemma of calculus of variations with the derivatives of the test function.
A simple reference would be ok.
Thanks!
 A: $\newcommand{\R}{\mathbb{R}}$
$\newcommand{\n}{\mathbf{n}}$
$\newcommand{\pl}{\partial}$
$\DeclareMathOperator{\dv}{div}$
$\newcommand{\vp}{\varphi}$
For simplicity, let me assume that $D \subseteq \R^n$ is a bounded smooth domain, so that $\pl D$ is a closed submanifold. Let me also assume that $f \colon \pl D \to \R$ and $X \colon \pl D \to \R^n$ are smooth. Our assumption is that
$$
\int_{\pl D} f \vp + X \cdot \nabla \vp = 0 
\quad \text{for all smooth } \vp,
$$
where $\vp$ is defined on all of $\overline{D}$ (or even $\R^n$) and $\nabla \vp$ is the full gradient.
Let us denote by $\n$ the unit outer normal to $\pl D$ and decompose $X$ and $\nabla \vp$ into their tangent and normal parts:
$$
X = X^\top + X^\perp \cdot \n, 
\quad 
\nabla \vp = \nabla_{\pl D} \vp + \pl_\n \vp \cdot \n,
$$
so that $X \cdot \nabla \vp$ becomes
$$ 
X \cdot \nabla \vp 
= X^\top \cdot \nabla_{\pl D} \vp + X^\perp \cdot \pl_\n \vp.
$$
The first part can be integrated by parts over $\pl D$, yielding
$$
\int_{\pl D} X^\top \cdot \nabla_{\pl D} \vp 
= - \int_{\pl D} \dv_{\pl D} X^\top \cdot \vp.
$$
Our main assumption then translates to the statement that for each smooth $\vp$ we have
$$
0 = \int_{\pl D} f \vp + X \cdot \nabla \vp 
= \int_{\pl D} (f - \dv_{\pl D} X^\top) \cdot \vp + \int_{\pl D} X^\perp \cdot \pl_\n \vp.
$$
I claim that $\vp$ and $\pl_\n \vp$ can be chosen as arbitrary smooth functions on $\pl D$, so our starting assumption is equivalent to
$$
f = \dv_{\pl D} X^\top, \quad 
X^\perp = 0 
\quad \text{on } \pl D.
$$
To justify the claim, let us choose arbitrary smooth functions $a,b \colon \pl D \to \R$. The formula
$$
\vp(x+t\n) = a(x)+tb(x)
$$
gives us a well-defined function on a tubular neighborhood of $\pl D$, which can be extended elsewhere, if needed. Of course, $\vp = a$ and $\pl_\n \vp = b$ on $\pl D$.

What about curvature? The integration by parts formula $\int_{\pl D} X^\top \cdot \nabla_{\pl D} \vp = - \int_{\pl D} \dv_{\pl D} X^\top \cdot \vp$ is a consequence of  the formula $\int_{\pl D} \dv_{\pl D} V = 0$ valid for tangent fields $V$ on $\pl D$.
If in doubts, this can be further translated to an intrinsic formula (Gauss-Green, Stokes) for abstract manifolds, e.g. by translating fields and divergences into forms and differentials.
The mean curvature pops out when one applies $\dv_{\pl D} V$ (understood as $\operatorname{tr}(DV \circ (T_x \pl D)_\#)$) to a general (not tangent) vector field. The result is indeed
$$
\int_{\pl D} \dv_{\pl D} V = - \int_{\pl D} V \cdot \mathbf{h},
$$
where $\mathbf{h}$ is the mean curvature vector. See the definition of first variation here (sorry for unnecessary generality).
