The homogenization design method (HDM) is extended to obtain an optimal topology of magnetic fields. This is accomplished by maximizing the magnetic mean compliance in a given region of the device. HDM is applied to a three-dimensional case, taking into account the saturation effect of the material. Results show that HDM is valid to maximize the vector potential and the magnetic energy. This method can also be applied to increase the performance of motors and antennas.