fancompute / angler

Frequency-domain photonic simulation and inverse design optimization for linear and nonlinear devices
https://arxiv.org/abs/1811.01255
MIT License
158 stars 49 forks source link

Resetting or rescaling sources #7

Closed momchilmm closed 6 years ago

momchilmm commented 6 years ago

It would be nice to be able to change or remove a simulation source once it is added. If I want to run the same simulation but with a different input power, right now I don't see any other way but to initialize the simulation object anew. We can add sources, but we cannot remove or edit them. Editing might be too much to ask at this point, but a simple method that removes all sources will suffice.

momchilmm commented 6 years ago

Ok I realized that to reset you can just set simulation.src to np.zeros(eps_r.shape). I think this is good enough.

twhughes commented 6 years ago

Related: @momchilmm @ianwilliamson ideally we should set simulation.src and simulation.eps_r each as a @property of the simulation class. Then we can do setting and getting more cleanly than we do now. (for example, if we make eps_r a property, we can automatically have it create A whenever simulation.eps_r = new_array.

twhughes commented 6 years ago

I just assigned myself to this. but if anyone else has time go for it.

ianwilliamson commented 6 years ago

Technically this pertains to fdfdpy but yes, Momchil's approach will work as a temporary solution. Agreed that its better to have as a @property.

twhughes commented 6 years ago

Regarding momchil's first point, what's the problem with just reassigning simulation.src?

  simulation.src = new_src

Maybe I don't understand the use case

momchilmm commented 6 years ago

Oh it's just that when we set modal sources up we use simulation.add_mode and simulation.setup_src, we don't assign simulation.src directly. So there is a method to add a modal source but no method to remove existing modal sources, that was my concern initially.

ianwilliamson commented 6 years ago

A function that clears the list of sources in the simulation object is probably the best option. It could also be redesigned to store sources in a dict. This would allow you to reference sources by name to edit.

twhughes commented 6 years ago

why not just pop them off the simulation.modes list? or make simulation.modes a dict would be fine too. We could also add @property to simulation.modes as well

momchilmm commented 6 years ago

Ah yes good point. I also realized that instead of doing simulation.src *= scale_fact to rescale the source, we can also do for example

simulation.modes[0].scale *= scale_fact
simulation.setup_modes()

This has the advantage for example that simulation.W_in will be re-computed with the new scale.