  The shape gradient quantifies the change in some figure of merit resulting
from differential perturbations to a shape. Shape gradients can be applied to
gradient-based optimization, sensitivity analysis, and tolerance calculation.
An efficient method for computing the shape gradient for toroidal 3D MHD
equilibria is presented. The method is based on the self-adjoint property of
the equations for driven perturbations of MHD equilibria and is similar to the
Onsager symmetry of transport coefficients. Two versions of the shape gradient
are considered. One describes the change in a figure of merit due to an
arbitrary displacement of the outer flux surface; the other describes the
change in the figure of merit due to the displacement of a coil. The method is
implemented for several example figures of merit and compared with direct
calculation of the shape gradient. In these examples the adjoint method reduces
the number of equilibrium computations by factors of $\mathcal{O}(N)$, where
$N$ is the number of parameters used to describe the outer flux surface or coil
shapes.
