A framework for simulation and inversion in electromagnetics. (October 2017)