Custom Maxwell Solvers#
Our FDFD Maxwell solver is great for simple tasks. The solver does not need to be fast: to compute limits, you only need to compute the inverse of the background Green’s function mapping currents in the design region to fields in the design region, once.
Still, if you want to slot in your own Maxwell solver, this tutorial will cover how to do so. This might help have better numerical consistency between the limits and your own inverse designs, or allow you to calculate limits for more complex systems.
[ ]:
import inspect
from dolphindes import photonics, maxwell, geometry
[ ]:
# The photonics class has an attribute, self.EM_solver, which it calls to compute electromagnetic quantities. This is calculated in setup_EM_solver():
print(inspect.getsource(photonics.Photonics_TM_FDFD.setup_EM_solver))
[ ]:
# TM_FDFD is our TM FDFD code. All you have to do is over-write this function with your own custom solver. i.e.
class custom_maxwell_photonics(photonics.Photonics_TM_FDFD):
def setup_EM_solver(self, geometry):
# Do whatever you want with the parameters
self.EM_solver = None # here replace your custom solver
pass
[ ]:
# What should the EM_solver know what to do?
# At minimum, it should be able to compute the off-diagonal block of the inverse of the Green's function which corresponds to design -> design. This gets called in setup_EM_operators, which is needed for setting up the QCQP for limit calculations.
# (This may look different once everything has been implemented)
print(inspect.getsource(photonics.Photonics_TM_FDFD.setup_EM_operators))
[ ]:
# For reference, this is what our get_GaaInv looks like:
print(inspect.getsource(maxwell.TM_FDFD.get_GaaInv))
[ ]:
# What else should the EM_solver know what to do? If you plan to pass an incident current, it needs to know how to calculate fields from the currents. This is called in get_ei()
print(inspect.getsource(photonics.Photonics_TM_FDFD.get_ei))
# Alternatively, you can just pass ji = None and set_ei with a known incident field of size Nx, Ny via the attribute self.ei or by calling set_ei()