Electromagnets and their application