User-defined non-uniform magnetic field