Calculation of strayfields near grain edges in permanent magnet material