# Chapter 04

(quarteroni:4.1)=
## Exercise 04.01 - Heat transfer in a thin rod

```{admonition} Task
Let us consider a thin rod of length $L$, having temperature $t_0$ at the endpoint $x=0$ and insulated at the other endpoint $x=L$. Let us suppose that the cross-section of the rod has constant area equal to $A$ and that the perimeter of $A$ is $p$. The temperature $t$ of the rod at a generic point $x \in (0,L)$ then satisfies the following mixed boundary-value problem:

$$
\left\{
  \begin{array}{ll}
    - k A t'' + \sigma p t = 0 & x \in (0,L), \\
    t(0) = t_0, & t'(L) = 0,
  \end{array}
\right.
$$ (quarteroni:4.1:strong_eq)

having denoted by $k$ the thermal conducitivity coefficient and by $\sigma$ the convective transfer coefficient.

Verify that the exact solution of this problem is

$$
\hat{t}(x) = t_0 \frac{\cosh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)},
$$

with $m = \sqrt{\sigma p / k A}$. Write the weak formulation of {eq}`quarteroni:4.1:strong_eq`, then its Galerkin-finite element approximation. Show how the approximation error in the $H^1_0 (0, L)$-norm depends on the parameters $k$, $\sigma$, $p$, and $t_0$.

Finally, solve this problem using linear and quadratic finite elements on uniform grids, then evaluate the approximation error.
```

Let us evaluate the derivatives of $\hat{t}$ to check if is the solution of {eq}`quarteroni:4.1:strong_eq`.

$$
\hat{t}' (x) = - m t_0 \frac{\sinh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)}
$$

$$
\hat{t}'' (x) = m^2 t_0 \frac{\cosh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)}
$$

Then

$$
&- k A \hat{t}'' + \sigma p \hat{t} \\
&= - k A m^2 t_0 \frac{\cosh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)} + \sigma p t_0 \frac{\cosh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)} \\
&= - \cancel{k} \cancel{A} \frac{\sigma p }{\cancel{k} \cancel{A}} t_0 \frac{\cosh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)} + \sigma p t_0 \frac{\cosh \left[ m \left( L - x \right) \right]}{\cosh \left( mL \right)} = 0
$$

and the boundary conditions are satisfied, so $\hat{t}$ is a solution.

To derive the weak formulation, we first need to apply a *lifting* (see {cite}`quarteroni2017{Section 3.2.2}`).
Let $\Omega := (0, L)$, and $y = t - R$, where the constant lifting function $R$ is simply defined as $R(x) = t_0$ in $\Omega$. Then, since $t = y + R$, we have

$$
- k A t'' + \sigma p t = - k A y'' + \sigma p y + \sigma p t_0 \qquad \text{for } x \in (0, L).
$$

Hence, solving {eq}`quarteroni:4.1:strong_eq` is equivalent solving to the homogeneous problem

$$
\left\{
  \begin{array}{ll}
    - k A y'' + \sigma p y = - \sigma p t_0 & x \in (0,L), \\
    y(0) = 0, & y'(L) = 0,
  \end{array}
\right.
$$ (quarteroni:4.1:lifted)

Now, let $V = \{ v \in H^1 (\Omega) : v(0) = 0 \}$.
We obtain the weak formulation of {eq}`quarteroni:4.1:lifted` after multiplying the differential equation for a test function $\varphi \in V$ and integrating in $\Omega$. In particular, we observe that

$$
- k A \int_\Omega y'' \varphi \dx + \sigma p \int_\Omega y \varphi \dx = \cancel{- k A \left[ y' \varphi \right]_0^L} + k A \int_\Omega y' \varphi' \dx + \sigma p \int_\Omega y \varphi \dx,
$$

since $y'\varphi$ is zero both in $x=0$ (because $\varphi(0)=0$) and in $x=L$ (because $y'(L)=0$).

Putting together the weak formulation of left and right hand side of {eq}`quarteroni:4.1:lifted`, we get

$$
k A \int_\Omega y' \varphi' \dx + \sigma p \int_\Omega y \varphi \dx = - \sigma p t_0 \int_\Omega \varphi \dx \quad \forall \varphi \in V.
$$

The Galerkin approximation is obtained by defining an approximate space $V_h$ and a basis $\{ \varphi_j \}_{j=1}^{N_h}$ of $V_h$. The space $V_h$ is a Hilbert space with the norm of $V$.
The approximate problem is now

$$
a(y_h, \varphi) = f(\varphi) \qquad \forall \varphi \in V_h,
$$

or equivalently

$$
a(y_h, \varphi_j) = f(\varphi_j) \qquad \text{for } j = 1, \dots, N_h.
$$

where

$$
a(y_h, \varphi_j) = k A \int_\Omega y_h' \varphi_j' \dx + \sigma p \int_\Omega y_h \varphi_j \dx
$$

and

$$
f(\varphi_j) = - \sigma p t_0 \int_\Omega \varphi_j \dx
$$

Notice that a solution to the Galerkin approximation exist for the Lax-Milgram lemma (see {cite}`quarteroni2017{Lemma 3.1}`), since:

- $a$ is bilinear (trivial to prove)

- $a$ is continuous:

  $$
  \left| a(u,v) \right| = \left| k A \int_\Omega u' v' \dx + \sigma p \int_\Omega u v \dx \right| \le \max\{ kA, \sigma p\} \| u \|_V \| v \|_V
  $$

- $a$ is coercive:

  $$
  a(u,u) = k A \left| y \right|_{H^1(\Omega)} + \sigma p \| y \|_{L^2(\Omega)} \ge \min\{kA, \sigma p\} \| u \|_V
  $$

- $f$ is linear (trivial to prove)

- $f$ is bounded (so continuous)

  $$
  \left| f(v) \right| \le \sigma p t_0 \| v \|_{L^2(\Omega)}.
  $$

Using the Céa Lemma (see {cite}`quarteroni2017{(4.10)}`), we get

$$
\| y - y_h \|_V \le \frac{M}{\alpha} \inf_{w_h \in V_h} \| y - w_h \|_V,
$$

where $M$ is the continuity constant of $a$, i.e. $M = \max\{ kA, \sigma p\}$ and $\alpha$ is the coercivity constant, i.e. $\alpha = \min\{kA, \sigma p\}$. The rest of the estimate depends on the choice of the approximate space $V_h$.



## Exercise 04.02 - Temperature of a fluid between two parallel plates.

```{admonition} Task
We consider a viscous fluid located between two horizontal parallel plates, at a distance of $2H$. Suppose that the upper plate, which has temperature $t_{\mathsf{sup}}$, moves at a relative speed of $U$ with respect to the lower one, having temperature $t_{\mathsf{inf}}$. In such case the  temperature $t: (0, 2H) \to \mathbb{R}$ of the fluid satisfies the following Dirichlet problem:

$$
\left\{
  \begin{array}{ll}\displaystyle
    - t''(x) = \alpha (H - x)^2, & x \in (0, 2H), \\
    t(0) = t_{\mathsf{inf}}, & t(2H) = t_{\mathsf{sup}},
  \end{array}
\right.
$$ (quarteroni:4.2:strong_eq)

where $\alpha = \frac{4 U^2 \mu}{H^4 k}$, $k$ being the thermal conductivity coefficient and $\mu$ the viscosity of the fluid. Find the exact solution $t(x)$, then write the weak formulation and the Galerkin finite element formulation.
```

By integrating twice, we get

$$
t(x)
&= \int^x \int^z t''(x') \, \dx' \, \mathrm{d}z \\
&= - \alpha \int^x \int^z (H - x')^2 \, \dx' \, \mathrm{d}z \\
&= \alpha \int^x \left[ \frac{1}{3} (H - z)^3 + c_1 \right] \, \mathrm{d}z \\
&= - \frac{\alpha}{12} (H - x)^4 + \alpha \, c_1 x + c_2.
$$

By applying the boundary values, we get

$$
\left\{
  \begin{array}{l}
    \displaystyle t_{\mathsf{inf}} = t(0) = - \frac{\alpha}{12} H^4 + c_2 \\
    \displaystyle t_{\mathsf{sup}} = t(2H) = - \frac{\alpha}{12} H^4 + 2 \, \alpha H c_1 + c_2
  \end{array}
\right.
$$

The system gives

$$
c_2 = t_{\mathsf{inf}} + \frac{\alpha H^4}{12}
$$

and

$$
c_1 = \frac{1}{2 \, \alpha H} \left( t_{\mathsf{sup}} + \frac{\alpha H^4}{12} - c_2 \right) = \frac{1}{2 \, \alpha H} \left( t_{\mathsf{sup}} + \frac{\alpha H^4}{12} - t_{\mathsf{inf}} - \frac{\alpha H^4}{12} \right) = \frac{t_{\mathsf{sup}} - t_{\mathsf{inf}}}{2 \, \alpha H}.
$$

So the solution reads

$$
t(x) = - \frac{\alpha}{12} (H - x)^4 + \frac{t_{\mathsf{sup}} - t_{\mathsf{inf}}}{2 \, H} x + t_{\mathsf{inf}} + \frac{\alpha H^4}{12} .
$$

To derive the weak formulation, we first need to apply a *lifting* (see {cite}`quarteroni2017{Section 3.2.2}`).
Let $\Omega := (0, 2H)$, and $y = t - R$, where the linear lifting function $R$ is defined as

$$
R(x) = t_\mathsf{inf} \frac{2H - x}{2H} + t_\mathsf{sup} \frac{x}{2H}, \qquad x \in \Omega.
$$

Then, since $t = y + R$, we have $t'' = y''$ for all $x \in \Omega$.

Therefore, to solve {eq}`quarteroni:4.2:strong_eq` we can first solve the homogeneous problem

$$
\left\{
  \begin{array}{ll}\displaystyle
    - y''(x) = \alpha (H - x)^2, & x \in (0, 2H), \\
    y(0) = 0, & y(2H) = 0,
  \end{array}
\right.
$$ (quarteroni:4.2:lifted)

and then define $t = y + R$.

Now, let us define $V = \{ v \in H^1(\Omega) : v(0) = v(2H) = 0 \}$ and $g(x) = \alpha (H - x)^2$ in $\Omega$.
We obtain the weak formulation of {eq}`quarteroni:4.2:lifted` after multiplying the differential equation for a test function $\varphi \in V$ and integrating in $\Omega$.
By the divergence theorem and by using that $\varphi$ is zero on the boundary, we get

$$
- \int_\Omega y'' \varphi \dx = - \cancel{\left[ y' \varphi \right]_0^{2H}} + \int_\Omega y' \varphi' \dx \qquad \forall \varphi \in V.
$$

So the weak formulation of {eq}`quarteroni:4.2:lifted` reads

$$
\int_\Omega y' \varphi' \dx = \int_\Omega g \varphi \dx \qquad \forall \varphi \in V.
$$

Similarly to [Exercise 1](quarteroni:4.1), the Galerkin formulation is

$$
a(y_h, \varphi) = f(\varphi) \qquad \forall \varphi \in V_h.
$$



## Exercise 04.03 - Deformation of a rope

```{admonition} Task
Let us consider a rope with tension $T$ and unit length, fixed at the endpoints. The function $u(x)$, measuring the vertical displacement of the rope when subject to a transversal charge of intensity $w$, satisfies the following Dirichlet problem:

$$
\left\{
  \begin{array}{ll}\displaystyle
    - u'' + \frac{k}{T}u = \frac{w}{T}, & x \in (0, 1
    ), \\
    u(0) = 0, & t(1) = 0,
  \end{array}
\right.
$$ (quarteroni:4.3:strong_eq)

having indicated with $k$ the elasticity coefficient of the rope. Write the weak formulation and the Galerkin-finite element formulation.
```

Let $\Omega := (0, 1)$, $V = \{ v \in H^1(\Omega) : v(0) = v(2H) = 0 \}$, and $g(x) = \frac{w}{T}$ in $\Omega$.
As in the previous exercises, we obtain the weak formulation of {eq}`quarteroni:4.3:strong_eq` after multiplying the differential equation for a test function $\varphi \in V$ and integrating in $\Omega$.
By the divergence theorem and by using that $\varphi$ is zero on the boundary, we get

$$
- \int_\Omega u'' \varphi \dx = - \cancel{\left[ u' \varphi \right]_0^{2H}} + \int_\Omega u' \varphi' \dx \qquad \forall \varphi \in V.
$$

So the weak formulation of {eq}`quarteroni:4.3:strong_eq` reads

$$
\int_\Omega u' \varphi' \dx + \frac{k}{T} \int_\Omega u \varphi \dx = \int_\Omega g \varphi \dx \qquad \forall \varphi \in V.
$$

Similarly to [Exercise 1](quarteroni:4.1), the Galerkin formulation is

$$
a(y_h, \varphi) = f(\varphi) \qquad \forall \varphi \in V_h.
$$
