In order to understand the divergence theorem better, I tried to compute an easy example. But somehow my calculations do not work out. Could you please check, what my mistake is?
My domain $D\subset \mathbb{R}^2$ is the triangle with vertices $(0,0), (L_2, 0), (L_1, m\cdot L_1)$, where $m,L_1, L_2>0$ are fixed and $0<L_1<L_2$. My vector field is given as follows: $V:\mathbb{R}^2\rightarrow\mathbb{R}^2, (x,y)\mapsto(y,0)$. Therefore, the divergence of $V$ vanishes and we get:
$$\int_{D}\operatorname{div}(V) = 0.$$
But on the other hand, when I compute the boundary integral $\int_{\partial D} V\cdot n$, I get a different answer depending on $L_1, L_2$. First, I separated the boundary integral into three different line integrals each corresponding to one side of the triangle.
The integral corresponding to the side which lies on the $x$-axis must vanish, because $V(x,0)=0$.
For the left side of the triangle, the normal vector field is constant with $n=(-m,1)$ and I get after parametrizing the side by the curve $[0,L_1]\ni x\mapsto (x,mx)\in\mathbb{R}^2$:
$$\int_0^{L_1} V(x, mx) \cdot (-m,1) \cdot \sqrt{1+m^2} \,dx = -m^2\cdot \frac{L_1^2}{2}\sqrt{1+m^2}.$$
- Similarly, for the right side, I get the value
$$m^2\frac{L_1^2}{2}\sqrt{1+\left(\frac{m L_1}{L_2-L_1} \right)^2}$$
As you can see, the sum of both values do not cancel out (except for $L_2 = 2 L_1$, i.e. if the left and right side of the triangle have the same length).
Is there a basic misunderstanding of the divergence theorem or where did I go wrong? (If needed, I can provide more details of my calculation)
You defined $\vec F = (y,0)$
a) When going from $(L_2, 0) \text { to } (L_1, m L_1)$, $r(t) = (L_2, 0) + t (L_1 - L_2, m L_1), 0 \leq t \leq 1$
$r'(t) = (L_1-L_2, - m L_1) \implies {\vec n} = (mL_1, L_2-L_1)$
$\vec F(r(t)) = (mL_1 t, 0)$
So the flux is $ \displaystyle \int_0^1 m^2L_1^2 \ t \ dt = \dfrac{m^2L_1^2}{2}$
b) Now for segment from $(L_1, m L_1)$ to $(0, 0)$,
$r(t) = (0, 0) + t (- L_1, - mL_1), {-1} \leq t \leq 0$
$r'(t) = (-L_1, - mL_1), \vec n = (- mL_1, L_1)$
$\vec F(r(t)) = (- mL_1 t, 0)$
So the flux is $ \displaystyle \int_{-1}^0 m^2L_1^2 \ t \ dt = - \dfrac{m^2L_1^2}{2}$
c) You can similarly show that from $(0, 0)$ to $(L_2, 0)$, the integral is zero.
Summing a) and b), the net outward flux is zero, which is expected as the divergence is zero.