Accelerators with a general magnetic field