# Interior Control of the Poisson Equation with the Conjugate Gradient Method in OpenFOAM

Authors: - 03 July 2018

Download Code

In this work we solve the optimal control problem

$\min _{u \in L^2 \left( \Omega \right)} \mathcal{J}\left( u\right) = \min _{u \in L^2 \left( \Omega \right)} \frac{1}{2} \int_{\Omega} \left( y - y_d \right) ^2 \mathrm{d} \Omega + \frac{\beta}{2} \int_{\Omega} u ^2 \mathrm{d} \Omega,$

where $u$ is the control variable, $y$ the state variable and $y_d$ a target function. The minimization problem is subject to the elliptic partial differential equation

$\begin{cases} -\Delta y = f + u & \text{in } \Omega, \\ y = 0 & \text{on } \Gamma. \end{cases}$

In order to use the conjugate gradient method, the state variable is separated in two terms as

$y = y_u + y_{f},$

where $y_u$ solves the state equation with zero Dirichlet boundary conditions,

$\begin{cases} -\Delta y_u = u & \text{in } \Omega, \\ y_u = 0 & \text{on } \Gamma, \end{cases}$

and $y_f$ is the control-free solution to the state equation,

$\begin{cases} -\Delta y_{f} = f & \text{in } \Omega, \\ y_{f} = 0 & \text{on } \Gamma. \end{cases}$

With the above separation of the state variable, the cost functional can be expressed as

$\mathcal{J} \left( u \right) = \frac{1}{2} \left( y_u + y_f - y_d, y_u + y_f - y_d \right)_{L^2\left( \Omega \right)} + \frac{\beta}{2} \left( u , u \right) _{L^2\left( \Omega \right)}.$

We define a linear operator

\begin{align*} \Lambda: L^2\left( \Omega \right) & \rightarrow L^2\left( \Omega \right) \\ u & \rightarrow y_u \end{align*}2

and its adjoint

\begin{align*} \Lambda: L^2\left( \Omega \right) & \rightarrow L^2\left( \Omega \right) \\ \phi & \rightarrow \lambda \end{align*}

with $\lambda$ solution to

$\begin{cases} - \Delta \lambda = \phi & \text{in } \Omega, \\ \lambda = 0 & \text{on } \Gamma. \end{cases}$

The directional derivative of the cost function then reads as

$\mathcal{D}_{\delta u} \mathcal{J}\left( u \right) = \left( \underbrace{ \left( \Lambda^* \Lambda + \beta I \right)}_{A_{cg}} u - \underbrace{ \Lambda^* \left( y_d - y_f \right)}_{b_{cg}}, \delta u \right) _{L^2\left( \Omega \right)}.$

After having identified $A_{cg}$ and $b_{cg}$ we can use the conjugate gradient method to reach the optimal control faster.

## 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 poissonCGAdjoinFoamCase and type in the command line

./Allprepare

poissonCGAdjointFoam


The poissonCGAdjointFoam solver has been tested in a square domain $[0, 1] \times [0, 1]$ with zero Dirichlet boundary conditions and $\beta = 10^{-3},10^{-4},10^{-5},10^{-6}$. 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


## References

• F. Tröltzsch. Optimal control of partial differential equations: theory, methods, and applications. American Mathematical Soc., 2010.