Algorithm for finite-difference time-domain analysis of electromagnetic systems with space-charge effects