Some optimization problems in electromagnetism