Inspired by the epidemic contact tracing technique, we propose a method to efficiently solve electromagnetics by tracing the energy distribution. The computational domain is adaptively decomposed, and the available computational resources are focused on those energy-active (infections) and their adjacent (exposed) domains, while avoiding the unnecessary computation of energy-null (unexposed) domains. As an example, we employ this method to solve several optics problems. The proposed method shows high efficiency while maintaining a good accuracy. The energy tracing method is based on the causality principle, and therefore is potentially transformative into other computational physics and associated algorithms.