Types

Core data structures for problem definition and state management.

Problem Definition

DistributedEmitterOpt.EnvironmentType
Environment(; mat_design, mat_substrate=mat_design, mat_fluid=1.33)

Fields

  • mat_design — Design region material (typically metal)
  • mat_substrate — Substrate material (defaults to mat_design)
  • mat_fluid — Fluid/background material (default 1.33 for water)
DistributedEmitterOpt.MaxwellProblemType
MaxwellProblem

PDE definition for Maxwell curl-curl equation. Specifies the physical environment, input/output field configurations, and solver parameters.

This type describes WHAT to solve (environment + configs), not HOW to solve (that's in simulation + caches).

ObjectiveFunction Interface

DistributedEmitterOpt.ObjectiveFunctionType
ObjectiveFunction

Abstract type for optimization objectives. Implementations define how to compute the objective value and gradients from field solutions.

Required interface

  • compute_objective(obj, pde, fields, pt, sim) — Objective value g
  • compute_adjoint_sources(obj, pde, fields, pt, sim) — ∂g/∂E for each field
  • explicit_sensitivity(obj, pde, fields, pf, pt, sim, control) — Explicit ∂g/∂pf

Fields is a Dict{CacheKey, CellField} mapping (λ, θ, pol) → E. pde provides the input/output FieldConfig lists and weights.

DistributedEmitterOpt.compute_objectiveFunction
compute_objective(obj::SERSObjective, pde, fields, pt, sim) → Float64

Compute SERS objective using trace formula. Sums over all input/output combinations with their weights.

DistributedEmitterOpt.compute_adjoint_sourcesFunction
compute_adjoint_sources(obj::SERSObjective, pde, fields, pt, sim) → Dict{CacheKey, Vector}

Compute adjoint RHS vectors ∂g/∂E for each field. Sums contributions over all input/output combinations with weights.

DistributedEmitterOpt.explicit_sensitivityFunction

Default: no explicit sensitivity term.

explicit_sensitivity(obj::SERSObjective, pde, fields, pf, pt, sim, control; space=sim.Pf) → Vector

Explicit ∂g/∂pf term from objective's direct dependence on pt. Sums contributions over all input/output combinations with weights.

Optimization Problem

The main entry point. Use the meshfile-based constructor for most cases:

prob = OptimizationProblem(pde, objective, meshfile, solver; per_x, per_y, foundry_mode, control)

This automatically creates a SimulationBundle with simulations for both x and y polarizations.

DistributedEmitterOpt.OptimizationProblemType
OptimizationProblem

Main container for topology optimization. Holds the PDE config, objective, FEM infrastructure, solver caches, and current optimization state.

Missing docstring.

Missing docstring for num_dofs. Check Documenter's build log for details.

Simulation Infrastructure

A Simulation holds the FEM infrastructure (spaces, measures, mesh). A SimulationBundle groups simulations by polarization for mixed-polarization problems.

DistributedEmitterOpt.SimulationType
Simulation

Container for all FEM infrastructure: discrete model, function spaces, integration measures, and FoundryGrid for 2D DOF mode.

FE Spaces

  • V, U — Nédélec spaces for E-field
  • P — Piecewise constant (raw design on mesh)
  • Pf — Continuous Lagrange (filtered design)

Integration Measures

  • — Full domain
  • dΩ_design — Design region
  • dΩ_raman — Raman/target region
  • dS_top, dS_bottom — ABC boundaries
  • dΓ_source — Source plane
DistributedEmitterOpt.build_simulationFunction
build_simulation(meshfile; kwargs...) -> Simulation

Build Simulation from mesh file.

Arguments

  • meshfile — Path to .msh file
  • order — Nédélec element order (default 0)
  • degree — Quadrature degree (default 4)
  • dir_x, dir_y — Dirichlet boundaries for PEC symmetry
  • source_y — Source polarization (true=y, false=x)
  • foundry_mode — Use 2D DOF grid
  • sizes — Manual (xlo, xhi, ylo, yhi, zlo, zhi) for grid
DistributedEmitterOpt.SimulationBundleType
SimulationBundle

Container for multiple Simulation objects (per polarization), sharing the same underlying discrete model.

Fields

  • default::Simulation: The primary simulation (usually y-polarized)
  • by_pol::Dict{Symbol,Simulation}: Sims keyed by polarization (:x, :y)
DistributedEmitterOpt.sim_forFunction
sim_for(sim_or_bundle, fc::FieldConfig)

Get the appropriate Simulation for a given FieldConfig (based on polarization).

Solver Caches

Caches for LU factorizations, keyed by wavelength. SolverPoolBundle mirrors SimulationBundle for polarization-aware caching.

DistributedEmitterOpt.AbstractSolverType
AbstractSolver

Interface for sparse direct solvers. Concrete implementations wrap Pardiso, UMFPACK, etc.

Required interface

  • lu!(cache, A) — Factorize matrix A
  • solve!(cache, b) — Solve Ax = b (forward)
  • solve_adjoint!(cache, b) — Solve A'x = b (adjoint)
DistributedEmitterOpt.SolverCacheType
SolverCache{S<:AbstractSolver}

Caches LU factorizations for reuse across optimization iterations. Separate caches for:

  • Maxwell system (complex, A_factor)
  • Eigen shift system (complex, Afactor in eigencache)
  • Filter PDE (real, F_factor)

Fields

  • A_factor — Maxwell LU factorization
  • F_factor — Filter Helmholtz LU factorization
  • E2_factor — E² regularization LU factorization (optional)
  • x — Solution vector cache
  • am_head — True if this process performs solves (MPI compatibility)
  • solver — Solver backend
DistributedEmitterOpt.SolverCachePoolType
SolverCachePool{S<:AbstractSolver}

Pool of solver caches, one per unique (λ, θ, polarization) configuration. Deduplicates caches so identical configs share the same LU factorization.

Also holds a shared filter cache and a shared eigen cache for shift-invert solves.

DistributedEmitterOpt.SolverPoolBundleType
SolverPoolBundle

Container for multiple SolverCachePool objects (per polarization), corresponding to the Simulation objects in a bundle.

Fields

  • default::SolverCachePool: The primary pool
  • by_pol::Dict{Symbol,SolverCachePool}: Pools keyed by polarization (:x, :y)

Foundry Grid (2D DOF Mode)

DistributedEmitterOpt.FoundryGridType
FoundryGrid

2D rectilinear grid for lithography-compatible topology optimization. Design parameters live on a regular (x, y) grid and are interpolated to the 3D FEM mesh via bilinear interpolation.

Fields

  • x — Grid x-coordinates (monotonic)
  • y — Grid y-coordinates (monotonic)
  • params — Design parameter matrix (nx × ny)
  • nodes — Mesh node coordinates for Jacobian computation
  • jacobian — Cached ∂(mesh node values)/∂(grid param) mapping
  • adj_idx — Cached grid indices for adjoint scatter (4 × nnodes)
  • adj_w — Cached weights for adjoint scatter (4 × nnodes)
  • adj_ready — Whether adjoint cache is initialized
DistributedEmitterOpt.getgridFunction
getgrid(labels, Ω, np, nodes; sizes=nothing) -> FoundryGrid

Build a FoundryGrid from mesh topology. The grid covers the x-y extent of the design region with approximately √np points per side.

DistributedEmitterOpt.pf_gridFunction
pf_grid(r, params, gridx, gridy) -> Real

Bilinear interpolation of grid parameters at point r = (x, y, z).

Convenience method using FoundryGrid.

Control Parameters

DistributedEmitterOpt.ControlType
Control

Hyperparameters for the topology optimization pipeline: filtering, projection, and linewidth constraints.

Filtering

  • use_filter — Enable filtering step
  • R_filter — Filter radius (rx, ry, rz) in nm
  • use_dct — Use DCT convolution (true) or Helmholtz PDE (false)

Projection / SSP

  • SSP on the FEM mesh is always used (pf → pt).
  • β — Projection steepness (higher = sharper, use continuation)
  • η — Threshold point (typically 0.5)
  • R_ssp — SSP smoothing radius

Linewidth Constraints

  • use_constraints — Enable erosion/dilation constraints
  • η_erosion — Erosion threshold (typically 0.75)
  • η_dilation — Dilation threshold (typically 0.25)
  • b1 — Constraint tolerance
  • c0 — Indicator function steepness
DistributedEmitterOpt.tanh_projectionFunction
tanh_projection(x, η, β) -> Real

Heaviside-ish projection: smooth step from 0 to 1 centered at η. As β → ∞, approaches true Heaviside function.

Vectorized tanh projection for arrays.

Convenience with Control struct.

DistributedEmitterOpt.ThresholdFunction
Threshold(pf; control) -> Real

Tanh projection for lazy composition with Gridap's operator. This is the function form used in ComposedFunctions.

Reference: Old codebase Controls.jl:Threshold