Solenoids and electromagnets