Simulating dendrite growth in lithium batteries under cycling conditions