Theory of strain relaxation in heteroepitaxial systems