PortFom#
- class lumopt2.fom.port_fom.PortFom(sim_results, fct=None)#
Figure of merit calculator for port-based (waveguide mode) simulations.
Inherits all shared FOM logic from
BaseFomand specializes adjoint source setup, adjoint field scaling, and port position management for port-based monitors.- Parameters:
- sim_results
PortResultsorlistofPortResults One or more port monitor result objects.
- fct
callable(),optional Scalar-valued function of the monitor values. Defaults to
PNorm()with default parameters (target=1, p=1, weights=1), applied element-wise to each monitor.
- sim_results
Notes
Iteration-spanning caches#
A typical port FOM evaluation needs several quantities that are set at simulation-setup time and never change during the optimization loop: the port’s injection axis and propagation direction, the mode-solver outputs (spatial coords
x/y/z, mode profilesem/hm, and effective indexneff), the local FDTD mesh size at the port, and the global FDTD time stepdt. The session-levelFdtdSessioncache de-duplicates these reads within a single iteration, but invalidates them every time the forward.fsp’s mtime changes – i.e. once per iteration. Re-reading on every iteration costs O(N_ports) extragetresultround-trips of ~0.9 s each, which adds up over a long optimization.PortFomtherefore keeps a small per-port cache (_port_aux_cache) of port geometry constants (axis, direction, sign, baseline position, local mesh resolution), populated lazily on the first_collect_fwd_side_aux()for each port, and cleared by_get_port_monitor_info()(whichlumopt2.Project.generate()calls every time the simulation is rebuilt – the natural moment when the mesh / ports may have been reconfigured).Methods
PortFom.calculate_fom(fdtd_session)Compute the figure of merit using the user-defined function and monitor results.
PortFom.calculate_gradient_fields(...[, ...])Compute the gradient of the FOM with respect to permittivity using adjoint fields.
Create the project folder based on the project name in the config map.
PortFom.get_adjoint_fields(fdtd_session, entry)Extract and scale adjoint fields for port-based simulation, one per wavelength.
PortFom.get_jacobian(fdtd_session)Compute the Jacobian of the FOM with respect to monitor result values.
PortFom.get_scaling_factor(fdtd_session, ...)Compute a per-wavelength scaling factor for the adjoint gradient (port-based).
PortFom.set_project_name(project_name)Set the project name used to determine the simulation output folder.
Configure the FDTD session for an adjoint port simulation.
Attributes
Port-based adjoint sources are independent of forward simulation results, so forward and adjoint simulations can be queued and run simultaneously.