Consider the following linear, scalar advection-diffusion equation for the primal solution
, in the domain
with Dirichlet boundary conditions:

Let the output of interest be the following linear functional:

Derive the weak form by multiplying the primal equation with a weighting function
and performing integration by parts:

where,

Then, consider an infinitesimal perturbation to
which produces an infinitesimal change in
as follows:

Note that the solution perturbation
must vanish at the boundary, since the Dirichlet boundary condition does not admit variations on
.
Using the weak form above and the definition of the adjoint
given below:

we obtain:

Next, use integration by parts to transfer derivatives of
into derivatives of
:
![{\displaystyle {\begin{aligned}\int _{\partial \Omega }\psi \left({\vec {c}}u'-\mu \nabla u'\right)\cdot {\vec {n}}dA-\int _{\Omega }\nabla \psi \cdot \left({\vec {c}}u'-\mu \nabla u'\right)dV-\int _{\Omega }gu'\ dV&=0\\\int _{\partial \Omega }\psi \left({\vec {c}}u'-\mu \nabla u'\right)\cdot {\vec {n}}dA+\int _{\Omega }u'\left(-{\vec {c}}\cdot \nabla \psi \right)dV+\int _{\Omega }\nabla u'\cdot \left(\mu \nabla \psi \right)dV-\int _{\Omega }gu'\ dV&=0\\\int _{\partial \Omega }\psi \left({\vec {c}}u'-\mu \nabla u'\right)\cdot {\vec {n}}dA+\int _{\Omega }u'\left(-{\vec {c}}\cdot \nabla \psi \right)dV+\int _{\partial \Omega }u'\left(\mu \nabla \psi \right)\cdot {\vec {n}}dA-\int _{\Omega }u'\nabla \cdot \left(\mu \nabla \psi \right)dV-\int _{\Omega }gu'\ dV&=0\qquad {\text{(Repeating integration by parts on diffusion volume term)}}\\\int _{\Omega }u'\left[-{\vec {c}}\cdot \nabla \psi -\nabla \cdot \left(\mu \nabla \psi \right)-g\right]dV+\int _{\partial \Omega }\psi \left({\vec {c}}u'-\mu \nabla u'\right)\cdot {\vec {n}}dA+\int _{\partial \Omega }u'\left(\mu \nabla \psi \right)\cdot {\vec {n}}dA&=0.\end{aligned}}}](//wikimedia.org/api/rest_v1/media/math/render/svg/5cce9f8d92055503b644a7e5c36fd3f492d330f8)
The adjoint PDE and its boundary conditions can be deduced from the last equation above. Since
is generally non-zero within the domain
, it is required that
be zero in
, in order for the volume term to vanish. Similarly, since the primal flux
is generally non-zero at the boundary, we require
to be zero there in order for the first boundary term to vanish. The second boundary term vanishes trivially since the primal boundary condition requires
at the boundary.
Therefore, the adjoint problem is given by:

Note that the advection term reverses the sign of the convective velocity
in the adjoint equation, whereas the diffusion term remains self-adjoint.