  Magnetic fields play an important role in many astrophysical systems and a
detailed understanding of their impact on the gas dynamics requires robust
numerical simulations. Here we present a new method to evolve the ideal
magnetohydrodynamic (MHD) equations on unstructured static and moving meshes
that preserves the magnetic field divergence-free constraint to machine
precision. The method overcomes the major problems of using a cleaning scheme
on the magnetic fields instead, which is non-conservative, not fully Galilean
invariant, does not eliminate divergence errors completely, and may produce
incorrect jumps across shocks. Our new method is a generalization of the
constrained transport (CT) algorithm used to enforce the $\nabla\cdot
\mathbf{B}=0$ condition on fixed Cartesian grids. Preserving $\nabla\cdot
\mathbf{B}=0$ at the discretized level is necessary to maintain the
orthogonality between the Lorentz force and $\mathbf{B}$. The possibility of
performing CT on a moving mesh provides several advantages over static mesh
methods due to the quasi-Lagrangian nature of the former (i.e., the mesh
generating points move with the flow), such as making the simulation
automatically adaptive and significantly reducing advection errors. Our method
preserves magnetic fields and fluid quantities in pure advection exactly.

Instrumentation and Methods for Astrophysics;Cosmology and Nongalactic Astrophysics;Computational Physics