  The Kelvin-Helmholtz instability (KHI) is a standard test of hydrodynamic and
magnetohydrodynamic (MHD) simulation codes and finds many applications in
astrophysics. The classic linear theory considers a discontinuity in density
and velocity at the interface of two fluids. However, for numerical simulations
of the KHI such initial conditions do not yield converged results even at the
linear stage of the instability. Instead, smooth profiles of velocity and
density are required for convergence. This renders analytical theory to be only
approximately valid and hinders quantitative comparisons between the classical
theory and simulations. In this paper we derive a linear theory for the KHI
with smooth profiles and illustrate code testing with the MHD code Athena. We
provide the linear solution for the KHI with smooth initial conditions in three
different limits: inviscid hydrodynamics, ideal MHD and Braginskii-MHD. These
linear solutions are obtained numerically with the framework Psecas
(Pseudo-Spectral Eigenvalue Calculator with an Automated Solver), which
generates and solves numerical eigenvalue problems using an equation-parser and
pseudo-spectral methods. The Athena simulations are carried out on a periodic,
Cartesian domain which is useful for code testing purposes. Using Psecas and
analytic theory, we outline the differences between this artificial numerical
setup and the KHI on an infinite Cartesian domain and the KHI in cylindrical
geometry. We discuss several astrophysical applications, such as cold flows in
galaxy formation and cold fronts in galaxy cluster mergers. Psecas, and the
linear solutions used for code testing, are publicly available and can be
downloaded from the web.
