access the objective function during optimisation #2931
-
From the meepcon2022 tutorial notebook, there is a cell in which the optimisation problem is set up. The objective function TE0 = mpa.EigenmodeCoefficient(sim,
mp.Volume(center=mp.Vector3(x=-Sx/2 + pml_size + 2*waveguide_length/3),
size=mp.Vector3(y=1.5)),mode)
TE_top = mpa.EigenmodeCoefficient(sim,
mp.Volume(center=mp.Vector3(Sx/2 - pml_size - 2*waveguide_length/3,arm_separation/2,0),
size=mp.Vector3(y=arm_separation)),mode)
TE_bottom = mpa.EigenmodeCoefficient(sim,
mp.Volume(center=mp.Vector3(Sx/2 - pml_size - 2*waveguide_length/3,-arm_separation/2,0),
size=mp.Vector3(y=arm_separation)),mode)
ob_list = [TE0,TE_top,TE_bottom]
def J(source,top,bottom):
power = npa.abs(top/source) ** 2 + npa.abs(bottom/source) ** 2
return npa.mean(power)
opt = mpa.OptimizationProblem(
simulation = sim,
objective_functions = J,
objective_arguments = ob_list,
design_regions = [design_region],
frequencies=frequencies |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you already have defined an OptimizationProblem, |
Beta Was this translation helpful? Give feedback.
If you already have defined an OptimizationProblem,
opt
, you can simply callopt()
and it will return the objective function value and the gradient with respect to the design variables; you can additionally pass the argumentneed_gradient=False
so that it will only compute the objective function value without the gradient.Alternatively, with the simulation object
sim
alone, you can first add the mode monitors with "sim.add_mode_monitor(...)", run the simulation, and then call "sim.get_eigenmode_coefficients(...)" to compute the corresponding values. See the tutorial example https://meep.readthedocs.io/en/master/Python_Tutorials/Mode_Decomposition/