Permanent magnets are essential for a modern, environmentally friendly society. Magnets are key building blocks for energy generation and energy conversion. We use numerical optimization tools to search for new hard magnetic materials with reduced or zero rare earth content. Using finite element techniques we compute the key figures of merit in particular the energy that can be reversibly used in magnetic circuits as a function of the magnets structure. Structural optimization is of utmost importance in non-scale, multiphase magnets where a specific mixture of phases is used to improve the magnet's properties.