NanoComp / meep

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

Caching / reusing the results of MPB eigenmode calculations #1533

Open ianwilliamson opened 3 years ago

ianwilliamson commented 3 years ago

It seems that every time a mode overlap calculation is performed via get_eigenmode_coefficients(), MPB is called to solve for the eigenmodes of the cross section. I am wondering if there is some way to reuse or cache the results of these MPB calculations. Alternatively, perhaps get_eigenmode_coefficients() could return a reference to the MPB results that could be used in subsequent calls to get_eigenmode_coefficients(). Thus, the eigenmode calculcation could be avoided and the function would only need to perform the overlap calculation. Perhaps this would end up being just a more general interface for performing overlap integrals?

One example of where this might be useful is when using a step function to monitor the convergence of the mode overlaps for deciding when to terminate a simulation. I imagine this feature could also be useful for your adjoint module to avoid redundant eigenmode calculations on the waveguide cross sections (which are not changing during optimization). When many frequencies or monitors are of interest, the overhead here could be significant.

stevengj commented 3 years ago

It would certainly be possible to implement this…

In most cases (e.g. the adjoint solver), the cost of the eigenmode solver is negligible compared to the FDTD timestepping, which is why this optimization has not been a priority up to now. I agree that it could be more of problem if you want to perform the overlap calculation every few timesteps to check convergence.

smartalecH commented 3 years ago

Aside from this particular use case, I do think a more general interface for overlap integrals would be rather useful!