Polarization of a permanent magnet to yield specific magnetic field distribution