How do mechanical engineers optimize the design of structures to withstand various loads and stresses encountered during operation, ensuring both safety and longevity?