I am studying Galdi's Introduction to the mathematical theory of Navier-Stokes equations and somewhere in a proof, he "glued" two functions in $W^{1, 2}(\Omega_1)$ and $W^{1, 2}(\Omega_2)$ to obtain a function in $W^{1, 2}(\Omega_1 \cup \Omega_2)$ and I don't really understand why it is true. Let me explain it in more details.
Let $B_1$ and $B_2$ be the open balls in $\mathbb R^n$ of radius $1$ and $2$ respectively. Let $\Omega_1 = B_1$ and $\Omega_2 = B_2 \cap (\overline{B_1}^c)$. We consider $\boldsymbol{u}_1 \in W^{1, 2}(\Omega_1)$ and $\boldsymbol{u}_2 \in W^{1, 2}(\Omega_2)$ (where $\boldsymbol{u}= (u^1, \ldots, u^m)$ and $\boldsymbol{u}_i \in W^{1, 2}(\Omega_i)$ actually means $\boldsymbol{u}_i \in [W^{1, 2}(\Omega_i)]^m$) verifying
$$\nabla \cdot \boldsymbol{u}_i = 0 ~~\text{in }\Omega_i \quad \text{and} \quad \boldsymbol{u}_1 = \boldsymbol{u}_2 ~~~\text{at }\partial \Omega_1,$$
in the trace sens. My question is, if we consider
$$\boldsymbol{u}: x \in \overline{\Omega_1} \cup \Omega_2 = \Omega \mapsto
\begin{cases}
\boldsymbol{u}_1(x) & \text{if } x \in \Omega_1\\
\boldsymbol{u}_2(x) & \text{if } x \in \Omega_2\\
\end{cases},
$$
is that true that $\boldsymbol{u} \in W^{1, 2}(\overline{\Omega_1} \cup \Omega_2)$ and that $\nabla \cdot \boldsymbol{u} = 0$ in $\overline{\Omega_1} \cup \Omega_2 $ ? I don't really see why this should be true because if we take $\boldsymbol{\psi} \in C^\infty_0(\overline{\Omega_1} \cup \Omega_2)$, we should be able to show that
$$\int_{\overline{\Omega_1} \cup \Omega_2} \boldsymbol{u} \cdot \partial_i\boldsymbol{\psi} = - \int_{\overline{\Omega_1} \cup \Omega_2} \partial_i\boldsymbol{u} \cdot \boldsymbol{\psi}$$
but
$$\int_{\overline{\Omega_1} \cup \Omega_2} \boldsymbol{u} \cdot \partial_i\boldsymbol{\psi} = \int_{\Omega_1} \boldsymbol{u} \cdot \partial_i\boldsymbol{\psi} + \int_{\Omega_2} \boldsymbol{u} \cdot \partial_i\boldsymbol{\psi} \stackrel{?}{=}-\int_{\Omega_1} \partial_i\boldsymbol{u} \cdot \boldsymbol{\psi} - \int_{\Omega_2} \partial_i\boldsymbol{u} \cdot \boldsymbol{\psi} = -\int_{\overline{\Omega_1} \cup \Omega_2} \partial_i\boldsymbol{u} \cdot \boldsymbol{\psi} $$
where I don't see why the second equality could be satisfied as $\boldsymbol{\psi}|_{\Omega_i} \notin C^\infty_0(\Omega_i)$. Could someone help me with this ?
The identity follows from the divergence theorem on $\Omega_i$: $$ \int_{\Omega_i} \text{div}(u) \psi \, dx = - \int_{\Omega_i} u\cdot \nabla \psi\, dx + \int_{\partial\Omega_i} u\cdot n\psi\, dx, $$ where $n$ is the outer normal to $\Omega_i$.
Now, since the support of $\psi$ is on the union, the last integral is really on $\partial\Omega_1\cap \partial\Omega_2$, but with opposite orientations depending on which domain we're on. Since both functions agree on the boundary, this means that the boundary integrals will cancel each other out and give your identity.