Following my previous question and its answer, after some reading of the advised books, I'm still confused about how to get the derivative of the functional to find the best parameter of my reaction diffusion problem.
In short, I need to find the best (time independent, space dependent) parameters $D$ and $k$ which minimize the functional
$$ \mathcal{G}(u,D,k) = \int_{\Omega} (u(t=T_f)-u_f)^2 d\Omega + \int_{\Omega} (u(t=0)-u_i)^2 d\Omega + \frac{1}{2}\int_{\Omega} D^2 d\Omega + \frac{1}{2}\int_{\Omega} k^2 d\Omega $$
subject to $$ \partial_t{u} - \nabla \cdot (D\nabla{u}) - k u (1-u) = 0 $$ $$ u(t=0,x)=u_i \space \forall x$$ $$ u(t,x)=0 \space \forall x \in \Gamma $$ where $\Gamma$ is the border of $\Omega$
Using the adjoint method, I define the Lagrangian $\cal L$ as
$$ \mathcal{L} = \mathcal{G} - \int_t\int_\Omega{\lambda( \partial_t{u} - \nabla \cdot (D\nabla{u}) - k u (1-u)) d\Omega.dt }$$
So for exemple, in order to find the optimal equations according to the parameter $D$, my understanding is that I need to specify that $$ \frac{\mathcal{L}(u,D+\epsilon\tilde D,k) - \mathcal{L}(u,D,k)}{\epsilon}=0 \space\space \forall{\tilde D} $$
which gives me (considering $u$, $D$, $k$ and $\lambda$ as independent variables) $$ \int_\Omega{D \tilde D d\Omega} + \int_t\int_\Omega{\lambda \nabla \cdot (\tilde D \nabla u) d\Omega dt} = 0 \space \forall {\tilde D}$$
Using integration by parts, I get
$$ \int_\Omega{D \tilde D} d\Omega + \int_t\int_\Omega{\nabla (\lambda\tilde D\nabla u) d\Omega dt} - \int_t\int_\Omega{\tilde D\nabla u \nabla\lambda d\Omega dt }= 0 \space \forall {\tilde D}$$
and using the divergence theorem,
$$ \int_\Omega{D \tilde D} d\Omega + \int_t\oint_\Gamma{(\lambda\tilde D\nabla u) {\vec n} d\Gamma dt} - \int_t\int_\Omega{\tilde D \nabla u \nabla\lambda d\Omega dt }= 0 \space \forall {\tilde D}$$ the goal of these transformation being to factorize the expression with $\tilde D$ in order to get a relation between $D$, $k$, $\lambda$, $u$ and their derivatives.
However, with such an expression, while the $\tilde D$ is indeed factorized, the domains of each part of the equation are different (the first is time independent, the second is a surface integral and the third is volumetric), so I can't merge them together to get a unique equation like
$$ D + \lambda\nabla u - \nabla u\nabla\lambda =0 $$
I can eventually require each part to be 0 at the same time, but then
$$ \int_\Omega{D \tilde D} d\Omega= 0 \space \forall {\tilde D}$$
leads just to $D=0$ which is obviously wrong...
Any help would be very welcome...