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 BaseFom and specializes adjoint source setup, adjoint field scaling, and port position management for port-based monitors.

Parameters:
sim_resultsPortResults or list of PortResults

One or more port monitor result objects.

fctcallable(), 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.

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 profiles em/hm, and effective index neff), the local FDTD mesh size at the port, and the global FDTD time step dt. The session-level FdtdSession cache 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) extra getresult round-trips of ~0.9 s each, which adds up over a long optimization.

PortFom therefore 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() (which lumopt2.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.

PortFom.create_project_folder()

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.

PortFom.setup_adjoint_simulation(...)

Configure the FDTD session for an adjoint port simulation.

Attributes

PortFom.supports_concurrent_adjoint

Port-based adjoint sources are independent of forward simulation results, so forward and adjoint simulations can be queued and run simultaneously.