Why does NDSolve return the stiff system error in this case?

I was playing with the WhenEvent method of NDSolve and was simulating the dynamics of a spring-mass system with two degrees-of-freedom (EDO: $M\ddot x+Kx=0$). WhenEvent was used to simulate an obstacle with a coefficient of restitution e (the velocity after impact is -e times the velocity before impact).

This works perfectly well, however when e=0, it returns the stiff system suspected error. I can't understand what's so special when e=0, on the contrary I would have thought this was the simplest case from a numerical point of view.

Full code (change to e=0 to get the error):

m = DiagonalMatrix[{1, 1}];
k = {{2, -1}, {-1, 1}};
eqs = Thread[m.{x1''[t], x2''[t]} + k.{x1[t], x2[t]} == 0];
ics = {x1[0] == -1, x1'[0] == 0, x2[0] == -0.5, x2'[0] == 1};
e = 0.1;
sol = NDSolve[
eqs~Join~ics~
Join~{WhenEvent[x2[t] == 1, x2'[t] -> -e*x2'[t]]}, {x1, x2}, {t,
0, 20}];
Plot[Evaluate[{x1[t], x2[t], 1} /. sol], {t, 0, 20}]

• Didn't yet have the time to solve this using ParametricNDSolve but it would seem that your solution for x2'[t] as the value of your parameter e is decreased, forms some sort of a singularity. Singularities can be associated with stiffness. Also, does your solution tends to unstable oscillations as e>2 or so? Commented Nov 7, 2016 at 17:06
• @drN Seen from the mechanical standpoint: e>1 means at each "bounce", the kinetic energy increases, so it should be unstable. For e=1 the energy should be conserved (the time integration might dissipate some of it numerically, however). For e<1, each bounce results in a loss of kinetic energy. Commented Nov 7, 2016 at 17:10
• Does performing a parametric NDSolve such as this: sol = ParametricNDSolve[ eqs~Join~ics~ Join~{WhenEvent[x2[t] == 1, x2'[t] -> -param*x2'[t]]}, {x1, x2}, {t, 0, 20}, {param}] help you determine the issue? Plot[Evaluate[Table[x2[param][t] /. sol, {param, 0.1, 1, 0.1}]], {t, 3, 20}] Commented Nov 7, 2016 at 17:15
• @drN I think I understood while I was explaining why your comment did not help :). I am going to write an answer. Commented Nov 7, 2016 at 17:20
• so in essence, my comment helped... >:) Commented Nov 7, 2016 at 17:35