# Testing numerical solver: Finding example Heat Equation in 2D

For testing a numerical solver (FEM with linear elements with Crank Nicolson) for the heat equation with homogeneous Neumann boundary conditions.

$$\begin{cases} \frac{\partial u}{\partial t} - \Delta u = f \text{ in } \Omega \\ \frac{\partial u}{\partial n} = 0 \text{ on } \partial \Omega \end{cases}$$

on $\Omega = (0,1) \times (0,1) \subset \mathbb R^2$, where $\frac{\partial u}{\partial n}$ denotes the gradient in the direction of the normal on $\partial \Omega$, i.e. $\nabla u \cdot n$.

I want to find suitable functions $f$ and $u$ for testing the convergence of this solver. However I wasn't able to come up with such a pair $f$ and $u$, can anyone recommend any or explain how to find examples?

• You may takean eigenfunction for the laplacian with Neumann conditions as the spatial part, e.g. $u(t,x,y) = g(t) \cos \pi x \cos \pi y$. It's then trivial to find corresponding $g(t)$. Assuming that $f = 0$ – uranix Dec 29 '16 at 13:59
• Thank you! Unfortunately I don't know much of the theory. So with your ansatz $0=f \overset{!}{=} u_t - \Delta u = g'(t)\cos(\pi x)\cos(\pi y) + 2\pi^2g(t) \cos(\pi x)\cos(\pi y)$ So I just need to solve $g'(t) = -2\pi^2 g(t)$ for $g$ and plug it back into $u$ to get such an example, right? Feel free to add your comment as an answer, so I could accept it! – flawr Dec 29 '16 at 14:27

There's a Fourier method (separation of variables) used for homogeneous $f = 0$ problem. Consider solution in form $u(t, x, y) = T(t) V(x, y)$ $$T' V - T \Delta V = 0 \text{ in } \Omega\\ T \frac{\partial V}{\partial n} = 0 \text{ on }\partial \Omega$$ Dividing the equation by $TV$ we obtain $$\frac{T'}{T} = \frac{\Delta V}{V}$$ Since the left side does not depend on $x,y$ and the right does not depend on $t$, the quotient is some number $\lambda$.
Thus, $V$ should be an eigenfunction of the Laplacian with Neumann boundary conditions. $$\Delta V = \lambda V \text{ in } \Omega\\ \frac{\partial V}{\partial n} = 0 \text{ on }\partial \Omega\\ T(t) = T(0) e^{\lambda t}$$ Since the problem is homogeneous, any linear combination of solutions is also a solution. I.e. you can use the following general form $$u(t,x,y) = \sum_{i=1}^{n} T_i(0) e^{-\lambda_i t} V_i(x, y)$$ where $(\lambda_i, V_i)$ is an eigenpair of the Laplacian with Neumann b.c. and $T_i(0)$ are arbitrary constants.
For the unit square domain the eigenpairs are $$V_{k,l}(x, y) = \cos \pi k x \cos \pi l y, \qquad k, l = 0, 1, 2, \dots\\ \lambda_{k,l} = -\pi^2 (k^2 + l^2).$$