Constructal thermal optimization of an electromagnet