Optimal energy decay rate for partially damped systems by spectral compensation