A general framework for the numerical solution of second order ODEs