Mathematical Foundations of Computational Electromagnetism