Finite element analysis of residual stresses in machining