# Interior Control of the Heat Equation with the Steepest Descent Method and OpenFOAM

Authors: - 29 June 2018

This is an OpenFOAM solver for the distributed control of the heat equation through the minimization problem

\begin{align*} \min_{u \in L^2 \left( \Omega \times \left( 0 , T \right) \right)} \mathcal{J} \left( u , y \left( u \right) \right) = & \min_{u \in L^2 \left( \Omega \times \left( 0 , T \right) \right)} \frac{\beta_1}{2} \int_0^T \int_{\Omega} u^2 \mathrm{d} \Omega \, \mathrm{d}t + \frac{\beta_2}{2}\int_0^T \int_{\Omega} \left( y - y_d \right)^2 \mathrm{d} \Omega \, \mathrm{d}t + \frac{\beta_3}{2} \int_{\Omega} \left( y\left( \cdot, T \right) - Y_d \right)^2 \mathrm{d} \Omega, \quad \beta_1, \ \beta_2, \ \beta_3 \in \mathbb{R}^+, \end{align*}

subject to the state equation

$\begin{cases} \partial_t y - \Delta y = f + u & \text{in } Q = \Omega \times \left( 0, T \right),\\ y = y_D & \text{on } \Sigma_D = \Gamma_D \times \left( 0, T \right),\\ \displaystyle \frac{\partial y}{\partial n} = y_N & \text{on } \Sigma_N = \Gamma_N \times \left( 0, T \right),\\ y \left( \cdot, 0 \right) = y_0 & \text{in } \Omega, \end{cases}$

with $\Gamma = \Gamma_D \cup \Gamma_N$ and $\Gamma_D \cap \Gamma_N= \emptyset$.

$\mathcal{J}^\prime \left( u \right) = \varphi + \beta_1 u,$

where $\varphi$ solves the adjoint problem

$\begin{cases} -\partial_t \varphi - \Delta \varphi = \beta_2 \left( y - y_d \right), & \text{in } Q, \\ \varphi\left( \cdot, T \right) = \beta_3 \left( y \left( \cdot, T \right) - Y_d \right), & \text{in } \Omega, \\ \varphi = 0, & \text{on } \Sigma_D, \\ \displaystyle \frac{\partial \varphi}{\partial n} = 0, & \text{on } \Sigma_N. \end{cases}$

In the steepest descent method the cost gradient is used to update the control as

$u^{\left( n + 1 \right)} = u^{\left( n \right)} - \epsilon \mathcal{J}^\prime \left( u^{\left( n \right)} \right), \quad \epsilon \in \mathbb{R}^+,$

with $\epsilon$ sufficiently small.

## Getting Started

The solver must be compiled in the terminal. It is advisable to first clean previous compilations with

wclean


and then use

wmake


### Prerequisites

OpenFOAM C++ library must be installed in order to compile the code.

The OpenFOAM distribution provided by the OpenFOAM Foundation was used.

## Running a Case

In order to run the solver move to the case folder heatAdjoinFoamCase and type in the command line

./Allprepare


• The heatAdjointFoam solver has been tested in a square domain $[0, 1] \times [0, 1]$ with zero Dirichlet boundary conditions, $\epsilon=100$, and $\beta_1 = 10^{-3},10^{-4},10^{-5},10^{-6}$, $\beta_2 = 1$, $\beta_3 = 0$. The target function is $y_d = xy \sin \left( \pi x \right) \sin \left( \pi y \right)$.

• The heatAdjointFoam solver has been tested in a square domain $[0, 1] \times [0, 1]$ with zero Dirichlet boundary conditions, $\epsilon=10$, and $\beta_1 = 10^{-3},10^{-4},10^{-5},10^{-6}$, $\beta_2 = 0$, $\beta_3 = 1$. The target function is $Y_d = xy \sin \left( \pi x \right) \sin \left( \pi y \right)$.

### Warning

It might be needed to use

sed -i -e 's/\r\$//' filename


and

chmod +x filename


in order to be able to execute

./filename