Residual stresses in thick, nonhomogeneous coatings