**4. Optimality Condition**

The necessary optimality condition for the functional *Jα* can be written in the form:

$$
\alpha u + A^\* A u = A^\* \varphi,\tag{24}
$$

.

˜

˜

where *A*∗ is the adjoint to *A*:

$$A^\* = \begin{bmatrix} B\_{op}^\* L\_1^{\*-1} \mathcal{C}\_{\text{obs}}^\* & B\_{op}^\* L\_1^{\*-1} \mathcal{C}\_1^\* \\ B\_1^\* L\_1^{\*-1} \mathcal{C}\_{\text{obs}}^\* & B\_1^\* L\_1^{\*-1} \mathcal{C}\_1^\* + B\_2^\* L\_2^{\*-1} \mathcal{C}\_2^\* \end{bmatrix}.$$

Introduce the following adjoint problem:

$$L\_1^\* q\_1 = \mathcal{C}\_{obs}^\* \left( \mathcal{C}\_{obs} \mathfrak{z}^{(1)} - \mathfrak{z}\_{obs}^\* \right) + \mathcal{C}\_1^\* \left( \mathcal{C}\_1 \mathfrak{z}^{(1)} - \mathcal{C}\_2 \mathfrak{z}^{(2)} \right), \tag{25}$$

$$L\_2^\* q\_2 = \mathcal{C}\_2^\*(\mathcal{C}\_1 \mathfrak{g}^{(1)} - \mathcal{C}\_2 \mathfrak{g}^{(2)}).\tag{26}$$

The optimality Equation (24) takes the form:

$$\begin{cases} ad\_{\sf s} + B\_{\sf op}^{\*} q\_1 = 0, \\ av + B\_1^{\*} q\_1 + B\_2^{\*} q\_2 = 0. \end{cases} \tag{27}$$

We compute the scalar product of vector function *u*ˆ = ( ˆ*ds*, *v*<sup>ˆ</sup>)*<sup>T</sup>* ∈ **H***c* and Equation (27) in **H***<sup>c</sup>*. Using Equations (14) and (15) and representations of the bilinear forms of Equation (19), we receive the integral analogue of the optimality Equation (27):

$$\begin{split} \mathop{\rm l.p.} \int\_{\Gamma\_{\rm sp}} \sqrt{\operatorname{gH}} \mathop{d}\_{\rm s} \mathop{d}\_{\rm s} \mathop{d} \mathop{\rm l.} + \int\_{\Gamma\_{\rm sp}} \sqrt{\operatorname{gH}} q\_1 \mathop{d}\_{\rm s} \mathop{d} \mathop{\rm l.} \quad + \\ & + \mathop{\rm a.p.} \int\_{\Gamma\_{\rm in}} \sqrt{\operatorname{gH}} \mathop{\rm v\hat{v}} \mathop{d} \mathop{\rm l.p.} + \int\_{\Gamma\_{\rm in}} \sqrt{\operatorname{gH}} (q\_1 + q\_2) \hat{v} = 0 \quad \forall \hat{u} = (\hat{d}\_{\rm s}, \hat{v})^{\top} \in \mathbf{H}\_{\rm c}. \end{split}$$

Similarly, integral relations for adjoint Equations (25) and (26) can be obtained. Adjoint Equations (25) and (26) in differential form (*ξ*<sup>∗</sup>,(1) = *q*1, *ξ*<sup>∗</sup>,(2) = *q*2) are given by:

$$\begin{cases} \frac{\partial \mathcal{I}^{\ast}(i)}{\Delta t} - \begin{bmatrix} 0 & -\ell \\ \ell & 0 \end{bmatrix} \dot{\mathcal{U}}^{\ast,(i)} + R\_{f} \dot{\mathcal{U}}^{\ast,(i)} + \mathcal{g} \cdot \mathbf{grad} \, \xi^{\ast,(i)} = 0, \quad \text{in } \Omega\_{i}, \\\ \frac{\xi^{\ast,(i)}}{\Delta t} + \text{div} \left( H \dot{\mathcal{U}}^{\ast,(i)} \right) = 0, \quad \text{in } \Omega\_{i}, \\\ -H \dot{\mathcal{U}}^{\ast,(1)} \cdot \vec{n}\_{1} + m\_{op} \sqrt{\mathcal{g} \mathcal{H}} \xi^{\ast,(1)} = m\_{op} \sqrt{\mathcal{g} \mathcal{H}} (\xi^{(1)} - \vec{\xi}\_{\text{obs}}) + m\_{\text{in}} \sqrt{\mathcal{g} \mathcal{H}} (\xi^{(1)} - \xi^{(2)}), \quad \text{on } \partial \Omega\_{1}, \\\ -H \dot{\mathcal{U}}^{\ast,(2)} \cdot \vec{n}\_{2} = m\_{\text{in}} \sqrt{\mathcal{g} \mathcal{H}} (\xi^{(1)} - \xi^{(2)}), \quad \text{on } \partial \Omega\_{2}. \end{cases} \tag{28}$$

The optimality conditions take the form:

$$ad\_{\mathbb{S}} + \mathfrak{J}^{\*,(1)} = 0, \quad \text{on } \Gamma\_{op\_{\prime}} \tag{29}$$

$$
\hbar \upsilon + (\mathfrak{f}^{\ast,(1)} + \mathfrak{f}^{\ast,(2)}) = 0, \quad \text{on } \Gamma\_{\text{in}}.\tag{30}
$$

So, the functions *ds*, *v* minimizing *J<sup>α</sup>*, *α* ≥ 0, satisfy the optimality Equations (29) and (30), where *ξ*<sup>∗</sup>,(*i*), *i* = 1, 2 are the weak solutions of Equation (28), *i* = 1, 2, in which *ξ*(*i*) are the weak solutions of the systems of Equation (9).
