Optimization of electromagnetic devices and materials