The calculus of variations and materials science