  Shape optimization with respect to eigenvalues of a cavity plays an important
role in the design of new resonators or in the optimization of existing ones.
In our paper, we propose a gradient-based optimization scheme, which we enhance
with closed-form shape derivatives of the system matrices. Based on these, we
can compute accurate derivatives of eigenvalues, eigenmodes and the cost
function with respect to the geometry, which significantly reduces the
computational effort of the optimizer. We demonstrate our work by applying it
to the 9-cell TESLA cavity, for which we tune the design parameters of the
computational model to match the design criteria for devices in realistic use
cases. Since eigenvalues may cross during the shape optimization of a cavity,
we propose a new algorithm based on an eigenvalue matching procedure, to ensure
the optimization of the desired mode in order to also enable successful
matching along large shape variations.
