A fast numerical method for computing the linear and nonlinear mechanical properties of composites