A 3D electromagnetic field algorithm and the stability condition of the electromagnetic were analyzed based on the 3D Yee grid model and the leapfrog model. The average-weighting and charge-conserving ways to realize the interaction between electromagnetic and particles were discussed. At the same time the perfect conductor boundary condition, the free space absorbing boundary and explosive emission model were discussed. Finally, inward-emitting coaxial diode was used as an example to validate the simulation of current-voltage correlation and characteristics of electron beam movement.