Enhancing mechanical properties of hard ceramics, inorganic semiconductors, and Mg alloys