Optimization of the magnetostatic field in SMES devices