NanoComp / meep

free finite-difference time-domain (FDTD) software for electromagnetic simulations
GNU General Public License v2.0
1.16k stars 596 forks source link

Inconsistency in interface for `get_eigenmode_coefficients` and `EigenModeSource` constructor affecting adjoint solver #2755

Closed oskooi closed 5 months ago

oskooi commented 6 months ago

There is an inconsistency in the interface for the related functions get_eigenmode_coefficients and the constructor for the EigenModeSource class object involving the argument eig_vol.

get_eigenmode_coefficients contains an argument eig_vol of type meep.Volume:

https://github.com/NanoComp/meep/blob/0dc44daf9fd4bfea17c209bcd25f110c08341080/python/simulation.py#L4133-L4143

The constructor for the EigenModeSource class object does not have an eig_vol argument and instead uses eig_lattice_size and eig_lattice_center:

https://github.com/NanoComp/meep/blob/0dc44daf9fd4bfea17c209bcd25f110c08341080/python/source.py#L459-L475

These two arguments are used to create an eig_vol object in a separate function add_source:

https://github.com/NanoComp/meep/blob/0dc44daf9fd4bfea17c209bcd25f110c08341080/python/source.py#L646-L651

eig_vol and (eig_lattice_center, eig_lattice_size) are doing the same thing. It would be good to remove this inconsistency in the interface which currently prevents using eig_vol to define an meep.adjoint.EigenmodeCoefficient objective function because it is not possible to create an adjoint source. The problem is that the keyword arguments passed to EigenmodeCoefficient are passed directly to EigenModeSource in the function place_adjoint_source:

https://github.com/NanoComp/meep/blob/0dc44daf9fd4bfea17c209bcd25f110c08341080/python/adjoint/objective.py#L262-L272