# Variational formulation of mixed boundary value problem (Dirichlet + Neumann)

I'm sitting over this problem quite a while now, but im not sure about the answer. Given is the following mixed boundary value problem: \begin{align*} -\nabla \cdot(A(x)\nabla u) &= f \qquad \ \ x \in \Omega, \\ u &= g_D \qquad x \in \Gamma_D, \\ \frac{\partial u}{\partial \nu} &= g_N \qquad x \in \Gamma_N, \end{align*} I want to use the Deep Ritz Method (arXiv:1710.00211). What does the variational fomulation for numerical minimization look like? My best guess is: \begin{align*} I(u) = & \int\limits_{\Omega} \frac{1}{2}A\nabla u \cdot \nabla u -fu \ dx + \underbrace{\frac{\beta}{2} \int\limits_{\Gamma_D}{} (g_D - u)^2 \ d \sigma(x)}_{\text{just a penalty term}} + \int\limits_{\Gamma_N}{} g_N u \ d \sigma(x). \end{align*}

The similar questions didn't help me :/

$$\text{Find } u\in H_g: = \{v\in H^1: \, \text{trace of } v \text{ on } \Gamma_D = g_D\} \text{ to minimize } I(u) = \frac{1}{2}a(u,u) - l(u),$$ where $$a(u,u) = \int_{\Omega} \frac{1}{2}A|\nabla u|^2, \quad \text{ and }\quad l(u) = \int_{\Omega} fu\, dx + \int_{\Gamma_N}{} g_N u \ d \sigma(x).$$
If you use what you proposed, the boundary condition on $$\Gamma_D$$ cannot be met in an interpolation sense, i.e., $$u(x_i) \neq g_D(x_i)$$ at the discretization point.