tutorials:basics

2. The Basics#

We learn the basic concepts to program in NGSolve, we start with an easy example and we explore the single steps to solve a PDE problem. Then we apply the same steps and concepts to a more complex problem.

basic topics

2.1. Finite Element Method in a Nutshell#

Problem: (Strong)
Let \(\Omega\) be a domain in \(\mathbb{R}^n\) .

Find \(u\) such that

\[\begin{align*} -\Delta u &= f \quad \text{in } \Omega, \\ u &= u_D \quad \text{on } \Gamma_D,\\ n\cdot \nabla u &= g \quad \text{on } \Gamma_N, \end{align*}\]

With \(\Gamma_D \sqcup \Gamma_N = \partial \Omega\)

Multiply the equation by a test function \(v\) and integrate by parts we get the weak formulation:

Problem: (Weak)
Find \(u \in H^1(\Omega)\) such that \(u = u_D\) on \(\Gamma_D\) and

\[\begin{align*} \int_{\Omega} \nabla u \cdot \nabla v \, dx &= \int_{\Omega} f v \, dx - \int_{\Gamma_N} g v \, ds \quad \forall v \in H^1_{\Gamma_D}(\Omega), \end{align*}\]

Let \(\mathcal{T}\) ba a triangulation of the space \(\Omega\) the discrete weak formulation is given by:

Problem: (Discrete-Weak)
Find \(u_h \in V_{h}\) such that \(u_h = u_D\) on \(\Gamma_D\) and

\[\begin{align*} \int_{\Omega} \nabla u_h \cdot \nabla v_h \, dx &= \int_{\Omega} f v_h \, dx - \int_{\Gamma_N} g v_h \, ds\quad \forall v_h \in V_{h,\Gamma_D}(\mathcal{T}), \end{align*}\]

Applying the Galerkin method: Suppose that on the triangulation \(\mathcal{T}\) we the finite dimensional function space \(V_{h}(\mathcal{T})\) has a basis \(\{\phi^i\}_{i=1}^{N}\), and let

\[\begin{align*} v_h = \sum_{i=1}^{N} v^i \phi_i\quad \text{and} \quad u_h = \sum_{j=1}^{N} u^j \phi_j \end{align*}\]

Then, by substituting \(v_h\) and \(u_h\) in the discrete weak formulation we obtain the following linear system:

\[\begin{align*} \sum_{i,j} v^i u^j \overbrace{\int_{\Omega} \nabla \phi_j \cdot \nabla \phi_i \, dx }^{A_{ij}}&= \sum_{i} v^i \overbrace{ \left(\int_{\Omega} f \phi_i \, dx - \int_{\Gamma_N} g \phi_i \, ds \right)}^{f_i} \end{align*}\]

Then the problem reduces to solve the linear system \(A u = f\).