Energy and charge dynamics in ion-irradiated surfaces and 2D materials from first principles