.. _sec.eigen: Eigenvalue problems ==================== In this section, we consider the treatment of eigenvalue problems with $\texttt{FreeFem}$. Beyond its physical relevance and ubiquity in applications, this task is a good opportunity to learn how to handle the Finite Element matrices involved in variational formulations. .. #################@ .. #################@ .. _sec.FEmats: Handling Finite Element matrices ---------------------------------- .. #################@ .. #################@ Since :numref:`sec.lap`, we have been solving variational problems with $\texttt{FreeFem}$ via the keyword :code:`problem`. This practice conveniently conceals the operations involved in the numerical resolution, notably the assembly and inversion of the stiffness matrix. This section describes an alternative way to solve a variational problem with $\texttt{FreeFem}$ which is more intrusive, but also more flexible; the source code corresponding to this presentation can be downloaded :download:`here <./codes/laplace_with_matrix.edp>`. To set ideas, let us consider again the Laplace equation in an L-shaped domain $\Omega$, introduced in :numref:`sec.lap`: we look for the solution $u \in H^1_0(\Omega)$ to the following boundary-value problem: $$\left\{ \begin{array}{cl} -\Delta u = f & \text{in } \Omega, \\ u = 0 & \text{on } \partial \Omega, \end{array} \right. \quad \text{ where } f = 1.$$ As we have seen, the variational formulation for this problem reads: .. #################@ .. math:: :label: eq.varfmathandle \text{Search for } u \in H^1_0(\Omega) \text{ s.t. } \forall v \in H^1_0(\Omega), \quad \int_\Omega \nabla u\cdot \nabla v \:\d \x = \int_\Omega fv\:\d \x, .. #################@ which becomes, after Finite Element discretization: .. #################@ .. math:: :label: eq.varfmathandlemat \text{Search for the coefficient vector } \bU_h \in \mathbb{R}^{N_{V_h}} \:\: \text{ s.t. } \:\: K_h \bU_h = \bF_h, .. #################@ where $K_h$ is the $N_{V_h} \times N_{V_h}$ stiffness matrix, and $\bF_h \in\mathbb{R}^{N_{V_h}}$ is the force vector. The main components of such a variational problem -- i.e. its bilinear form and its right-hand side -- may be entered in $\texttt{FreeFem}$ thanks to the keyword :code:`varf`, as in the following listing. .. #################@ .. code-block:: /* Finite Element spaces and functions */ fespace Vh(Th,P1); Vh uh; /* Variational formulation of the Laplace equation */ varf varlap(u,v) = int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v)) + int2d(Th)(f()*v) // Watch out for the sign! + on(1,u=0); .. #################@ Note that the sign between the bilinear and linear parts differs between this syntax and that attached to the keyword :code:`problem`; this is because the present encoding does not allow to solve directly the variational problem. The stiffness matrix $K_h$ and the force vector $\bF_h$ of the Finite Element discretization :math:numref:`eq.varfmathandlemat` are constructed as follows. .. #################@ .. code-block:: /* Assembly of the stiffness matrix */ matrix A; A = varlap(Vh,Vh,solver=UMFPACK); /* Assembly of the right-hand side */ Vh rhs; rhs[] = varlap(0,Vh); // rhs[] is the array with size //the number of dofs of the Finite Element // space, whose entries are the coefficients of rhs. .. #################@ Here, we recall from :numref:`rm.ucoef` that the array containing the coefficients of a Finite Element function $u$ is obtained by the command $\texttt{u[]}$. Finally, the Finite Element system :math:numref:`eq.varfmathandlemat` is inverted by the following natural command: .. #################@ .. code-block:: /* Resolution of the Finite Element system */ uh[] = A^-1 *rhs[]; .. #################@ .. #################@ .. #################@ An eigenvalue problem --------------------- .. #################@ .. #################@ Let $\Omega$ be a bounded domain in $\mathbb{R}^2$; we consider the following eigenvalue problem: .. #################@ .. math:: :label: eq.evlap \text{Search for } \lambda \in \mathbb{R} \text{ and } u \in H^1_0(\Omega), \: u\neq 0,\:\: \text{ s.t. } \left\{ \begin{array}{cl} -\Delta u = \lambda u & \text{in } \Omega, \\ u=0 & \text{on } \partial\Omega. \end{array} \right. .. #################@ Obviously, for any real value $\lambda$, $u = 0$ is solution to this problem. The sought eigenvalues are precisely those values $\lambda$ for which a non trivial eigenfunction exists. It can actually be proved that these eigenvalues form a sequence of positive real numbers going to infinity: .. #################@ .. math:: 0\leq \lambda_1 \leq \lambda_2 \leq ... \: \to \: \infty; .. #################@ The peculiar property of eigenvalues is at the core of the modeling of multiple physical phenomena. For instance, - When $\Omega$ represents an elastic membrane, the values $\lambda_n$ are its self-vibration frequencies; - When $\Omega$ is a thermal cavity, one may prove that the solution to the unsteady heat equation :math:numref:`eq.LaplaceUnsteady` decays exponentially fast in time, at the rate $e^{-\lambda_1 t}$; the asymptotic profile of the temperature is then given by the first eigenvector $u_1$. In this tutorial, we shall not say much about the difficult, but fascinating spectral theory, dealing with the eigenelements of boundary-value problems, and we shall only formally describe their numerical calculation. We refer for instance to :cite:`allaire2007numerical` for a glimpse of the rigorous framework. The resolution of :math:numref:`eq.evlap` relies on a variational formulation, similar to that of a classical boundary-value problem, and we briefly rephrase the argument. Since the sought function $u$ satisfies homogeneous Dirichlet boundary conditions, it is natural to work with the functional space $V = H^1_0(\Omega)$, defined in :numref:`sec.H10`. Multiplying the main equation of :math:numref:`eq.evlap` by an arbitrary test function $v \in H^1_0(\Omega)$ and using :ref:`Green's formula