Capabilities#
What gfem solves, which results it differentiates, and what it refuses, at v0.1.
What you can solve#
Problems:
gfem.Driven(the response of a model to its ports and sources over a frequency grid, uniform or adaptive sweep),gfem.Eigenmode(resonant modes nearest a target frequency, with their Q; lumped and wave ports, a wave port on one process with a target above its mode’s cutoff; with a permittivity law, outside the law’s unresolved band),gfem.Electrostatic(the Maxwell capacitance matrix between named terminals) andgfem.PortMode(the mode of a wave port’s cross-section, with its group index and dispersion at every frequency, Find the group index and dispersion of a waveguide; a permittivity law in it where \(\mathrm{Re}\,\varepsilon > 0\)). Eigenmode and uniform driven problems take a Bloch wave vector (wave_vector=, rad/m) on a periodic model; a uniform driven sweep may keep the incidence angle fixed (wave_vector_frequency).gfem.band_diagram()solves an eigenmode problem along a wave vector path and returns the bands, their connections and their band group velocity (Solve a periodic cell).2D models: a plane of triangles read with
gfem.Mesh.from_gmsh(), where neither the structure nor the field varies along z. A uniform driven sweep solves one polarization,Driven(polarization="Ez")or"Hz", with line ports, PEC, PMC and first- or second-order absorbing lines, materials (permittivity laws included), material fields and layer-grid designs, with their gradients. Powers and fields are per metre along z, and S equals the slab’s (Solve a structure that does not vary along one axis). Piezoelectric problems also solve on 2D meshes (below).Ports:
gfem.LumpedPorton one or several surfaces driven together, andgfem.WavePorton an exterior surface, fed by its port mode; several wave ports on one surface each request a different mode of it, each its own row and column of S (Request several modes on one port surface); wave ports also load an eigenmode solve and report each one’s coupling Q (q_port);gfem.FloquetPorton the open face of a periodic cell: one diffraction order in one polarization (TE or TM) of a plane wave, each its own row and column of S, \(|S|^2\) the diffraction efficiency (Shine a plane wave on a periodic cell).Boundaries:
gfem.PEC,gfem.PMC(symmetry planes),gfem.Absorbing(first or second order),gfem.Conductor(a finite-conductivity metal, by its surface impedance),gfem.Impedance(per-square R, L and C), andgfem.Periodic(a periodic pair of surfaces, with plain periodicity or a Bloch wave vector set on the problem; Solve a periodic cell).Open space:
gfem.PMLon meshed layer regions around the air box: absorbs outgoing waves at any angle, for driven and eigenmode solves, wave ports and periodic cells (Absorb outgoing waves with a perfectly matched layer).Free space: sources beside the ports, each a column of the same factorization (
Driven(sources=...)): incident fields on a background stack (Model(background=...), one material or a planargfem.Backgroundof layers, optionally over a ground plane), asgfem.PlaneWave(TE, TM, circular or Jones, oblique, past the critical angle too),gfem.GaussianBeam(an exact beam carrying 1 W) orgfem.IncidentField(a field you give as a function); and point dipoles,gfem.ElectricDipoleandgfem.MagneticDipole. WithDriven(source_fields=False)a dipole’s port waves are read from the ports’ own solutions by reciprocity, one solve per port for any number of positions. Results: the total, scattered and incident fields,gfem.cross_sections,emitted_power,gfem.purcell_factor, port waves, the far field with the IEEE 145 antenna quantities and the radar cross section (gfem.far_field), andgfem.beam_couplinginto a fiber’s beam (Light a scatterer with an incident field, Measure cross sections, Emit from a point dipole: emitted power, Purcell and beta factors, Read a far field: patterns, directivity, gain and radar cross section).Multipoles: the electric and magnetic multipoles a scatterer radiates under an incident field, their partial scattering cross sections and the exact dipoles and quadrupoles (
gfem.multipoles); the long-wavelength and toroidal dipoles of the induced current (gfem.current_moments) (Decompose scattering into multipoles).Periodic surfaces (
gfem.diffraction): diffraction efficiency per order and polarization, power balance (reflectance, transmittance, absorptance), Jones, circular and Mueller matrices of a cell, angle sweeps (conical incidence included), emissivity by Kirchhoff’s law (directional and hemispherical), a cell’s response sampled against one meta-atom parameter with its derivative, the effective permittivity and permeability of a slab retrieved from its S (Effective medium of a periodic slab), and aperture fields of large metasurfaces in the locally periodic approximation with angular-spectrum propagation, differentiable except in the angle (Efficiencies, power balance and polarization of a periodic cell, Emissivity of a periodic surface, From a cell response to a metasurface).Materials and designs:
gfem.Materialper region (isotropic, or anisotropic: real symmetric tensors on shared principal axes, Model an anisotropic material),gfem.MaterialFieldper element (isotropic, or principal values on fixed axes), andgfem.SheetFieldfor the fill of a patterned metal sheet (Design a patterned metal sheet). AMaterial’s permittivity may follow agfem.PermittivityLawof Drude, Lorentz, Debye and Djordjevic-Sarkar terms, metals included (Frequency-dependent materials and their gradients).gfem.materialsbuilds silicon, silica, silicon nitride, gold, copper, aluminium and lithium niobate from cited sources, andgfem.fit_permittivityfits a law to a measured table (Fit a measured n, k table to a permittivity law).Fabricable layer patterns: a layer-grid design’s pattern as polygons (
gfem.design.LayerPattern), checked against a minimum width and spacing and written to GDS (gfem.design.write_gds); a fabrication model (blur, edge bias) and length-scale constraints inside the gradient (Export a design’s layer pattern to GDS, Optimize a design for fabrication: etch, blur and minimum features).Tolerance report:
gfem.tolerance_report(the spread of named quantities under named fabrication tolerances, each parameter’s effect and variance share, the worst case, the linearized yield against spec windows and a linearity check, from one adjoint pass per quantity) (Estimate fabrication tolerances and yield).Measurements:
gfem.characteristic_impedance,gfem.interface_participation,gfem.power_flow,gfem.dissipated_power(a driven field’s loss per region and metal surface),gfem.optical_force(the force and torque on a body, differentiable; Measure the optical force and torque on a body) andgfem.electric_energy(Measure fields after the solve); the free-space measurements above.Circuits:
gfem.SaxComponentputs a driven solve in a SAX circuit as a photonic block (wavelength in µm) or an RF block (frequency in Hz, on one reference impedance for the circuit), answering any wavelength or frequency in its band;NetworkParameters.to_sdictand.to_skrfhand a solved S to SAX or scikit-rf (Differentiate a SAX circuit with gfem blocks).Quantum metrics:
gfem.quantum.dressed_modes(the dressed frequencies, Lamb shifts, anharmonicities and dispersive shifts of one junction on the solved modes) andEigenmodeResult.sheet_participation(the kinetic inductance fraction of a film), with their gradients (Superconducting-circuit metrics and their gradients). A mode’s loss splits into a \(1/Q\) budget and \(T_1\) limits (Budget a mode’s loss and its T1 limits).Thermal problems:
gfem.SteadyThermal(the temperature under heat sources),gfem.TransientThermal(the temperature over time under switched sources, with traces recorded at every step) andgfem.DCConduction(the current through conductors between terminals: their conductance and Joule heat), on 3D meshes and on 2D cross-sections read withgfem.Mesh.from_gmsh_cross_section(). Boundariesgfem.FixedTemperature,gfem.Convectionandgfem.HeatFlux; a surface no thermal boundary names is insulated. Materials takethermal_conductivity,mass_density,specific_heat, an electricalconductivity, athermo_optic_coefficient, anonlinear_indexand atwo_photon_absorption, andexcluded=leaves regions out of one physics at a time (Heat a device with a current and read its temperature).Heat and phase:
gfem.joule_heating,gfem.electromagnetic_heating(the heat of a driven result’s loss, in volumes and on metal sheets, for one port or several fed coherently; Heat a device with its electromagnetic loss) andgfem.HeatSource.uniform()(heat sources);gfem.heat_flowandgfem.heat_flow_per_length(the heat leaving a steady temperature through surfaces or a set of elements) andgfem.Trace.heat_out()(the heat that has left since the start of a transient run);gfem.thermo_optic_shift(a guided mode’s phase per length under a rise, on a cross-section) andgfem.route_phase(the phase along routes through a 3D rise) (Find the phase a heater puts on a waveguide);gfem.rise_timeandgfem.time_constantof a step response (Follow a temperature over time);gfem.element_mean.Electro-optic shift:
gfem.electro_optic_shift(a guided mode’s index and phase per volt from an electrostatic potential, on a cross-section, through any 6 × 3 electro-optic tensor; \(V_\pi L\) per arm and push-pull) andElectrostaticResult.capacitance_per_length. Materials take anelectro_optic_tensoron explicitaxes(Find the phase a voltage puts on a waveguide).Acousto-optic shift:
gfem.acousto_optic_shift(a guided mode’s index and phase per volt on a transducer’s terminal, as a complex phasor at every kept frequency of a piezoelectric result, through aphotoelastic_tensorand anelectro_optic_tensor; photoelastic and electro-optic parts, \(V_\pi L\) per arm and push-pull; differentiable in the tensors, the acoustic inputs and the windows’offset) (Find the index change a sound wave puts on a waveguide).Optomechanical coupling:
gfem.optomechanical_coupling(the vacuum coupling \(\tilde g_0\) of the mechanical modes of a section to a wave port’s mode, with one optical mode for all of them, with its moving-boundary and photoelastic parts; \(g_0(L)\) of a length; the forward Brillouin gain follows) andgfem.optomechanical_overlap(the change of \(n_\mathrm{eff}\) per unit amplitude of any displacement); differentiable in every input of the mechanical solve and thephotoelastic_tensor, the optical mode held constant (Find how strongly sound in a wire couples to the light it guides).Kerr nonlinearity:
gfem.kerr_nonlinearity(a port mode’s \(\gamma_\mathrm{NL}\) and two-photon loss at every row of its grid) andgfem.kerr_coupling(the tensor between its waves, for self- and cross-phase modulation and four-wave mixing), from the materials’nonlinear_indexandtwo_photon_absorption(Find the Kerr nonlinearity of a waveguide).Second-order nonlinearity:
gfem.second_harmonic(a pump mode and its harmonic: \(\kappa\), \(\Delta\beta\), poling period, undepleted efficiency of a poled guide) andgfem.three_wave_coupling(the tensor between the waves of a port, for sum- and difference-frequency generation), from a material’ssecond_order_nonlinear_tensor(Find the second-harmonic efficiency of a waveguide).Photon pairs:
gfem.spdcandgfem.sfwm(spontaneous down-conversion and four-wave mixing of port modes: pair rate, spectral brightness, joint spectrum of a pulse, heralded purity, differentiable) (Find the photon pairs of a waveguide source).Broadband models and time responses:
NetworkParameters.fit_rational(a passive rational model of S, written as a SPICE subcircuit or a Verilog-A module) andNetworkParameters.step_response/impulse_response(TDR, TDT and the impedance profile, differentiable; the fit is not) (Export S as a SPICE or Verilog-A model, See S in the time domain: TDR, TDT and impedance profiles).Piezoelectric problems:
gfem.Piezoelectric(the admittance per length between electrodes of a 2D section of piezoelectric, elastic and dielectric regions over a list of frequencies, the clamped capacitance, and the displacement and potential fields; any stiffness and piezoelectric tensor on explicitaxes, mechanical loss through a quality factor, graded damping frames as absorbing edges, meshed or line electrodes),PiezoelectricResult.network_parameters(S-parameters and Touchstone for an aperture and a series resistance) andgfem.strain(Find a transducer’s admittance and reflection).Mechanical eigenmodes:
gfem.MechanicalEigenmode(the complex frequencies, quality factors, displacements normalized to 1 J/m and group velocities of the elastic modes of a 2D section nearest a target, at an axial wavenumber: Lamb, shear horizontal and Rayleigh waves, ribs; any stiffness, the piezoelectric coupling with grounded electrodes, mechanical loss through a quality factor and damping frames, clamped lines or components;omegaand the mode fields differentiate in the material constants and node coordinates) (Find the mechanical modes of a film or a rib).
Solvers#
linear_solver="direct": pick it for a model whose factorization fits in one machine’s memory, for eigenmode problems, and for the repeated solves of an optimization loop, where a design can solve on the previous design’s factorization (Differentiate S-parameters and driven fields). It factorizes once per frequency and reuses the factorization for every port. The default ("auto") picks it for a driven problem on one machine while its factorization fits in half the memory. Install themklextra for its fastest factorization.linear_solver="pmg_gmres": pick it for a driven model several wavelengths across that the direct solver cannot hold, such as a photonic device in dielectric cladding, with absorbing faces or a perfectly matched layer, or a metal circuit on a fine mesh. Its iterations stay near 10 as the model grows, it needs about a quarter of the direct solver’s memory at order 2, and it is faster than the direct solver from a few million unknowns on. Driven problems at order 2 or 3 on one CPU process, with gradients, and without Bloch, periodic or Floquet models."auto"picks it where the direct solver does not fit and it does (Solve a driven model too large for the direct solver).linear_solver="bddc_gmres": pick it across MPI ranks, for periodic and Bloch models, and for electrostatic problems, when the direct factorization does not fit;"auto"picks it for a driven problem that neither the direct solver nor"pmg_gmres"takes, and for electrostatic problems. A model with a perfectly matched layer refuses it: use"pmg_gmres".linear_solver="petsc"andeigen_solver="slepc": pick them for MUMPS and its options, your own PETSc Krylov method and preconditioner, or SLEPc’s own controls. With no options,"petsc"gives the same results as"direct", and SLEPc the same modes and Q as ARPACK, the default eigen solver on one process (across MPI ranks the default is SLEPc). You build them from source (Solve with PETSc and SLEPc).device="cuda": the direct solver on one NVIDIA GPU through cuDSS, experimental (Run the direct solver on an NVIDIA GPU).Thermal and DC conduction problems solve on
"direct"by default and accept"bddc_gmres"and"petsc". One factorization serves a whole transient run. They do not run on the GPU solver or across MPI ranks: both raise.Across MPI ranks: driven uniform sweeps, electrostatic and eigenmode solves, and periodic cells on one axis run split across the ranks of one job, with their gradients (except gradients through a mode’s field), on Open MPI and Linux x86_64. Everything else raises
gfem.DistributedUnsupportedErrorthere; the full table is in Run a distributed solve.
How large a model each solver has finished, and in what time: Performance data.
What you can differentiate#
Problem |
Permittivity |
Conductivity |
||
|---|---|---|---|---|
Driven S-parameters, uniform and adaptive sweep |
FD-verified isotropic and principal values · direct solver, BDDC + GMRES · uniform and adaptive sweep · lumped and wave ports · at wave port faces too |
FD-verified isotropic and principal values · direct solver, BDDC + GMRES · uniform and adaptive sweep · lumped and wave ports · at wave port faces too |
FD-verified direct solver, BDDC + GMRES · uniform and adaptive sweep · lumped and wave ports · at wave port faces too |
FD-verified direct solver, BDDC + GMRES · uniform and adaptive sweep · lumped and wave ports · at wave port faces too |
Eigenmode frequency and Q |
FD-verified isotropic and principal values · direct solver, BDDC + GMRES · wave ports |
FD-verified isotropic and principal values · direct solver, BDDC + GMRES |
FD-verified direct solver, BDDC + GMRES |
FD-verified direct solver, BDDC + GMRES · wave ports |
Electrostatic capacitance |
FD-verified isotropic and principal values · direct solver, BDDC + GMRES |
FD-verified direct solver, BDDC + GMRES |
||
Port mode problem effective index, impedance and field |
FD-verified isotropic and principal values · direct solver |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
Piezoelectric admittance and clamped capacitance, 2D |
FD-verified principal values only · direct solver |
FD-verified direct solver |
||
Driven, plain periodic S-parameters |
FD-verified direct solver, BDDC + GMRES · uniform and adaptive sweep · lumped and floquet ports |
FD-verified, lumped ports direct solver · uniform sweep · lumped ports |
FD-verified, lumped ports direct solver · uniform sweep · lumped ports |
FD-verified direct solver · uniform and adaptive sweep · lumped and floquet ports |
Driven, Bloch S-parameters at a Bloch wave vector |
FD-verified direct solver, BDDC + GMRES · uniform sweep · lumped and floquet ports |
FD-verified, lumped ports direct solver, BDDC + GMRES · uniform sweep · lumped ports |
FD-verified, lumped ports direct solver, BDDC + GMRES · uniform sweep · lumped ports |
FD-verified direct solver, BDDC + GMRES · uniform sweep · lumped and floquet ports |
Eigenmode, plain periodic frequency and Q |
FD-verified direct solver, BDDC + GMRES |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
Eigenmode, Bloch band frequencies and Q |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
Eigenmode, participations participation ratios and port Q |
FD-verified isotropic and principal values · direct solver |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
Eigenmode, mode field the normalized field at points and interface participation |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
|
Electric energy energy per region of a driven or mode field |
FD-verified isotropic and principal values · direct solver · uniform sweep |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
Dissipated power loss per region and sheet of a driven field |
FD-verified direct solver |
FD-verified direct solver, BDDC + GMRES |
FD-verified direct solver |
|
Electromagnetic heating temperature from a driven result’s loss |
FD-verified direct solver |
FD-verified direct solver |
FD-verified direct solver |
|
Driven, incident field kept fields and cross sections |
FD-verified direct solver · uniform sweep |
FD-verified direct solver · uniform sweep |
FD-verified direct solver · uniform sweep |
|
Driven, electric dipole emitted power and port waves (also by reciprocity) |
FD-verified direct solver · uniform and adaptive sweep · wave ports · at wave port faces too |
FD-verified direct solver · uniform sweep · wave ports |
FD-verified direct solver · uniform sweep · wave ports |
FD-verified direct solver · uniform sweep · wave ports |
Driven, magnetic dipole emitted power and port waves |
FD-verified direct solver · uniform sweep · wave ports |
FD-verified direct solver · uniform sweep · wave ports |
FD-verified direct solver · uniform sweep · wave ports |
|
Steady thermal temperature, rise, heat, power and heat flow |
||||
Transient thermal traces (heat out too) and kept temperatures, TR-BDF2 and theta |
||||
DC conduction conductance, dissipation and potentials |
FD-verified direct solver, BDDC + GMRES |
|||
Thermo-optic shift phase per length of a section |
||||
Route phase phase along routes through a 3D rise |
Also FD-verified, with no column above: Driven with respect to the permeability and the loss tangent (isotropic and principal values, direct solver, uniform sweep); Driven with respect to the lumped values (direct solver, BDDC + GMRES, uniform and adaptive sweep); Driven with respect to the permittivity-law parameters (direct solver, uniform and adaptive sweep); Driven with respect to the density of a metal-dielectric blend (direct solver, uniform sweep); Eigenmode with respect to the permeability and the loss tangent (direct solver); Eigenmode with respect to the lumped values (direct solver, BDDC + GMRES); Eigenmode with respect to the permittivity-law parameters (direct solver); Electrostatic with respect to the permittivity-law parameters (direct solver); Port mode problem with respect to the permeability and the loss tangent (direct solver); Port mode problem with respect to the lumped values (direct solver); Port mode problem with respect to the permittivity-law parameters (direct solver); Driven, plain periodic with respect to the permittivity-law parameters (direct solver, uniform sweep); Eigenmode, participations with respect to the lumped values (direct solver); Eigenmode, mode field with respect to the lumped values (direct solver); Electric energy with respect to the loss tangent (direct solver); Electric energy with respect to the permittivity-law parameters (direct solver); Dissipated power with respect to the loss tangent (principal values only, direct solver); Dissipated power with respect to the lumped values (direct solver); Dissipated power with respect to the permittivity-law parameters (direct solver); Dissipated power with respect to the density of a metal-dielectric blend (direct solver); Electromagnetic heating with respect to the lumped values (direct solver); Electromagnetic heating with respect to the thermal conductivity (direct solver); Electromagnetic heating with respect to the incident powers and phases (direct solver); Steady thermal with respect to the thermal conductivity (direct solver, BDDC + GMRES); Steady thermal with respect to the heat-source amount and waveform scales (direct solver); Transient thermal with respect to the thermal conductivity and the mass density and the specific heat (direct solver, BDDC + GMRES); Transient thermal with respect to the heat-source amount and waveform scales (direct solver, BDDC + GMRES).
FD-verified: supported; the gradient is checked against finite differences.
Exact zero: the result does not depend on this input;
jax.gradreturns zero, correctly.Raises: asking for this gradient raises
gfem.NonDifferentiableError(or the error named) instead of returning a wrong value.
The thermal rows differentiate the temperature, the traces, the heat flow, the conductance and the phase with respect to per-element thermal and electrical conductivity, the thermo-optic coefficient, the boundary values (a fixed temperature, a convection’s coefficient and ambient, a heat flux), a transient’s mass density and specific heat, the heat sources and the drive (Differentiate a heater’s phase). The heat rows differentiate the dissipated power and the temperature it heats with respect to the driven solve’s materials, sheets and drive (Heat a device with its electromagnetic loss).
The electro-optic shift differentiates with respect to its tensor, the static permittivity of every element, the drive and the electrostatic mesh’s nodes (an electrode gap through a shape morph), each checked against finite differences; with respect to the optical model’s permittivity or nodes it raises, because the shift holds the mode constant (a port mode on its own differentiates) (Differentiate an electro-optic phase).
A SAX component’s S differentiates as the driven problem’s, with respect to
every input its model function builds from its settings, so one jax.grad of
a SAX circuit reaches gfem’s inputs and SAX’s analytic models together. With
respect to the circuit’s wavelength or frequency it is the derivative of the
band’s interpolation (Differentiate a SAX circuit with gfem blocks).
The piezoelectric problem differentiates its admittance per length, its
clamped capacitance and readings of its fields with respect to the stiffness,
piezoelectric tensor, permittivity, mass density and mechanical quality
factor of every element, and the mesh’s nodes through a node map of your own
(gfem.Mesh.with_nodes()), each checked against finite differences;
its frequencies, terminals, clamped lines and damping frame raise
(Differentiate a transducer’s admittance).
How each mark is checked: How gfem is checked.
Gradients that raise#
Off the matrix, asking for these gradients raises the named error instead of returning a wrong value:
Any result, with respect to a perfectly matched layer’s target reflection (a fixed value of the layer) raises
NonDifferentiableErrorAny result, with respect to a perfectly matched layer’s reference frequency (a fixed value of the layer) raises
NonDifferentiableErrorAny result, with respect to a lumped port’s resistance (its reference impedance) raises
NonDifferentiableErrorA far field (
far_field) whose layer just outside its side holds a design region raisesValueErrorA beam coupling (
beam_coupling) whose layer just outside its side holds a design region raisesValueErrorA beam coupling (
beam_coupling) into agfem.IncidentFieldbeam once node coordinates of its layer have moved raisesValueErrorA beam coupling (
beam_coupling), with respect to the parameters of itsgfem.GaussianBeam(waist, focus, angles, polarization) raisesNonDifferentiableErrorAny result, with respect to a Floquet port’s de-embedding offset raises
NonDifferentiableErrorModel.bloch_wave_vector, with respect to the incidence angles (the incidence of a Floquet port is a constant of the solve) raisesNonDifferentiableErrorDriven S-parameters at a Bloch
wave_vector, with respect to the parameters of a permittivity law raisesNonDifferentiableErrorAny result, with respect to a material’s principal axes raises
NonDifferentiableErrorAny result, with respect to the values of an anisotropic
MaterialraisesNonDifferentiableErrorAny result, with respect to node coordinates, when an
Absorbingsurface borders an anisotropic material raisesNonDifferentiableErrorDriven S-parameters, with respect to node coordinates on a lumped or Floquet port surface raises
PortGeometryErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Eigenmode results, with respect to node coordinates on a port surface raises
PortGeometryErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)A line port’s
PortMode, with respect to the parameters of a permittivity law in a region at the port (the material field values differentiate) raisesNonDifferentiableErrorThe
residualof a wave port’s mode in a driven result, with respect to a design a wave port’s mode reads (the backward error of the mode solve is a diagnostic) raisesNonDifferentiableErrorDriven results at a Bloch
wave_vector, with respect to a design a wave port’s mode reads raisesNonDifferentiableErrorDriven results on a fixed-angle sweep, with respect to a design a wave port’s mode reads raises
NonDifferentiableErrorEigenmode results, with respect to the material of a region with elements on a wave port’s face raises
PortGeometryErrorEigenmode results, with respect to the parameters of a permittivity law in a region with elements on a wave port’s face raises
PortGeometryErrorEigenmode results, with respect to the resistance, inductance or capacitance of an
Impedancethat shares an edge with a wave port’s face raisesPortGeometryErrorEigenmode results with wave ports, with respect to node coordinates on a wave port’s face raises
PortGeometryErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Driven(sweep="adaptive")withoutsamples, insidejax.grad,jax.jitorjax.vmapraisesNotImplementedErrorForward mode:
jax.jvpof a solve raisesTypeErrorA field value at points (
Field.at), with respect to node coordinates raisesNonDifferentiableErrorThe electric energy of a field per region (
electric_energy) of a field of an adaptive sweep, with respect to anything the field depends on raisesNonDifferentiableErrorCross sections (
cross_sections), with respect to a material field with elements in the truncation layer (the elements touching the perfectly matched layer or an absorbing face) raisesNonDifferentiableErrorThe power through a surface (
power_flow), with respect to a material field with elements in the element layer just outside its side raisesNonDifferentiableErrorCross sections (
cross_sections), with respect to node coordinates (the incident-field solve refuses them first) raisesNonDifferentiableErrorMultipoles (
multipoles), with respect to node coordinates through a solve (the incident-field solve refuses them first) raisesNonDifferentiableErrorMultipoles (
multipoles), with respect to node coordinates at fixed coefficients raisesNonDifferentiableErrorMultipoles (
multipoles), with respect to a material field with elements in the truncation layer (the elements touching the perfectly matched layer or an absorbing face) raisesNonDifferentiableErrorMultipoles (
multipoles), with respect to the multipole origin raisesNonDifferentiableErrorMultipoles (
multipoles), with respect to the intensity of agfem.IncidentFieldraisesNonDifferentiableErrorCurrent moments (
current_moments) of a traced result or model (read the exact moments withmultipoles) raisesNonDifferentiableErrorThe heat through a surface (
heat_flow,heat_flow_per_length), with respect to node coordinates raisesNonDifferentiableErrorThe power through a surface (
power_flow) of a field of an adaptive sweep, with respect to anything the field depends on raisesNonDifferentiableErrorThe heat of a driven result (
electromagnetic_heating) of an adaptive sweep, with respect to anything its fields depend on raisesNonDifferentiableErrorAny result, with respect to a
Conductor’s conductivity or thickness (fixed values of the sheet: its fill, or anImpedanceresistance, is the design) raisesNonDifferentiableErrorThe dissipated power per region and sheet (
dissipated_power), with respect to node coordinates raisesNonDifferentiableErrorThe dissipated power per region and sheet (
dissipated_power) of a field of an adaptive sweep, with respect to anything the field depends on raisesNonDifferentiableErrorThe dissipated power per region and sheet (
dissipated_power), with respect to the field’s frequency (a fixed input of the driven solve) raisesNonDifferentiableErrorThe heat of a driven result (
electromagnetic_heating), with respect to its frequency (a fixed input of the driven solve) raisesNonDifferentiableErrorDriven S-parameters, with respect to the Bloch wave vector raises
NonDifferentiableErrorDriven S-parameters of a fixed-angle sweep, with respect to the reference frequency of its wave vector (
wave_vector_frequency) raisesNonDifferentiableErrorA node move that breaks a
Periodicpair (the two surfaces no longer match) raisesValueErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)boundary_morphwith a surface of aPeriodicpair as the moving surface raisesValueErrorDriven(sweep="adaptive")with a Blochwave_vectorraisesNotImplementedErrorDriven S-parameters, with respect to the material of the half-space behind a Floquet port (it fixes the diffraction orders) raises
NonDifferentiableErrorDriven S-parameters, with respect to node coordinates on a Floquet port’s surface raises
PortGeometryErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)gfem.diffraction.propagate, with respect to the propagation distance or the padding (the transfer function is built once, outside the trace) raisesNonDifferentiableErrorDriven(sweep="adaptive")on a model with Floquet ports raisesNotImplementedErrorDrivenwith Floquet ports onlinear_solver="petsc"raisesNotImplementedErrorEigenmodeon a model with Floquet ports raisesNotImplementedErrorgfem.diffraction.cell_response, with respect to the cell’s own design or its sample parameters (a cell response tabulates fixed cells; differentiating it in the design would need second derivatives of the solve) raisesNonDifferentiableErrorgfem.diffractionefficiencies, power balances, Jones matrices and aperture fields, with respect to the incident polarization (a constant of the measurement; to optimize it, combine the columns of a Jones matrix with your own vector) raisesNonDifferentiableErrorgfem.diffraction.angle_sweep, with respect to the incidence angles (each incidence is a constant of its solve) raisesNonDifferentiableErrorEigenmode results, with respect to the Bloch wave vector raises
NonDifferentiableErrorEigenmodewith a Blochwave_vectoronlinear_solver="bddc_gmres"raisesValueErrorThe band group velocity of Bloch eigenmodes (
EigenmodeResult.v_g,BandDiagram.v_g), with respect to anything raisesNonDifferentiableErrorband_diagraminsidejax.jitorjax.vmap(it runs underjax.grad) raisesNonDifferentiableErrorband_diagram, with respect to the wave vectors or the target raisesNonDifferentiableErrorThe backward error of eigenmodes (
EigenmodeResult.error), with respect to anything raisesNonDifferentiableErrorEigenmode participations, port Q and mode fields on
linear_solver="bddc_gmres"raisesNonDifferentiableErrorEigenmode participations, port Q and mode fields on
linear_solver="petsc"raisesNonDifferentiableErrorEigenmode participations, port Q and mode fields on a GPU (
device="cuda") raisesNonDifferentiableErrorEigenmode participations, port Q and mode fields solved with
eigen_toleranceabove 1e-10 raisesNonDifferentiableErrorEigenmode participations, port Q and mode fields of a periodic model raises
NonDifferentiableErrorEigenmode participations, port Q and mode fields at a Bloch wave vector raises
NonDifferentiableErrorEigenmode participations, port Q and mode fields, with respect to node coordinates on a port surface raises
PortGeometryErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Eigenmode participations, port Q and mode fields of one mode of a degenerate cluster, or a sum over it raises
DegenerateModeErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Eigenmode participations, port Q and mode fields of a mode whose cluster
n_modescuts raisesDegenerateModeErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Eigenmode participations, port Q and mode fields of a mode within a relative gap of 1e-4 of another raises
DegenerateModeErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Port Q of a mode that does not load the port (differentiate
1 / q_port) raisesNonDifferentiableErrorwhile the gradient is computed, inside ajax.errors.JaxRuntimeError(how to catch it)Any result, with respect to the parameters of a permittivity law at an end of a metal-dielectric blend raises
NonDifferentiableErrorEigenmode principal participation, with respect to a lumped port’s or an
Impedance’s values raisesNonDifferentiableErrorEigenmode participations, port Q and mode fields, with respect to the parameters of a permittivity law (the frequency and Q differentiate) raises
NonDifferentiableErrorEigenmode with an
Absorbingboundary on a region with a permittivity law (raised by the solve) raisesNotImplementedErrorEigenmode of a periodic model, with respect to the parameters of a permittivity law raises
NonDifferentiableErrorTransientThermal, with respect to itsduration(a fixed value of the time grid; raised when the problem is built) raisesNonDifferentiableErrorTransientThermal, with respect to itssteps(a fixed value of the time grid; raised when the problem is built) raisesNonDifferentiableErrorTransientThermal, with respect to its waveform start times (a fixed value of the time grid; raised when the problem is built) raisesNonDifferentiableErrorTransientThermal, with respect to itsinitial_temperature(a fixed value of the time grid; raised when the problem is built) raisesNonDifferentiableErrorrise_timeof a trace (a crossing time found by search; differentiate the trace’s values) raisesNonDifferentiableErrortime_constantof a trace (a crossing time found by search; differentiate the trace’s values) raisesNonDifferentiableErrorNetworkParameters.fit_rational, with respect to S, its reference impedance or the fit’s weights (the time responses of S differentiate) raisesNonDifferentiableErrorthermo_optic_shift, with respect to the optical model’s permittivity, loss tangent, permeability or conductivity (the mode is held constant; the rise and the thermo-optic coefficient differentiate) raisesNonDifferentiableErrorthermo_optic_shift, with respect to the optical model’s node coordinates raisesNonDifferentiableErrorroute_phase, with respect to the window’s permittivity, loss tangent, permeability or conductivity (the mode is held constant; the rise and the thermo-optic coefficient differentiate) raisesNonDifferentiableErrorroute_phase, with respect to the window’s node coordinates raisesNonDifferentiableErrorThe backward error of a port mode (
PortModeResult.residual), with respect to anything (a diagnostic) raisesNonDifferentiableErrorA port mode’s group index and dispersion (
PortModeResult.n_g,beta_2,beta_3andD), with respect to anything (gamma,n_effandZ_PVdifferentiate) raisesNonDifferentiableErrorA port mode’s field at points (
PortModeField.at), with respect to node coordinates (gamma,n_effandZ_PVdifferentiate) raisesNonDifferentiableErrorcharacteristic_impedanceof a port mode insidejax.grad(Z_PVon the result differentiates) raisesNonDifferentiableErrorelectro_optic_shift, with respect to the optical model’s permittivity, loss tangent, permeability or conductivity (the shift holds the mode constant; the tensor, the static permittivity, the drive and the electrode gap differentiate) raisesNonDifferentiableError
Limits#
Low frequency: a direct driven solve on the CPU in one process keeps its digits below the low-frequency floor, \(k_0 h_\mathrm{min} = 10^{-6}\) (\(f h_\mathrm{min} \approx\) 48 Hz·m, with \(h_\mathrm{min}\) the shortest edge: 48 MHz with 1 µm elements, 5 GHz with 10 nm elements), through the tree-cotree gauge, on by default (
SolverOptions.gauge). The wave ports’ mode problem is not gauged and keeps its own floor: below it, a model with wave ports warns withgfem.LowFrequencyWarning, and lumped ports keep their digits. Other driven solves ("bddc_gmres","pmg_gmres","petsc", the GPU, several MPI ranks, periodic and Floquet models, orgauge="none") are ungauged: below the floor their fields, gradients and, with an exact factorization, the capacitive part of S lose digits, and they warn. For capacitance at low frequency, solvegfem.Electrostatic; the details are undergfem.Driven. An eigenmode solve whose target or lowest mode is below the floor warns too: its frequencies, fields and participations lose the same digits, and the reportederrordoes not show it.Gyrotropic materials: non-symmetric (non-reciprocal) tensors, such as a magnetized ferrite, are not supported. Neither is loss whose principal axes differ from the permittivity’s. Both raise
ValueError.Anisotropic materials at wave ports: a port’s cross-section may contain anisotropic materials when every tensor has a principal axis along the port normal. Elsewhere in the model the principal axes may point in any direction: a model with tilted principal axes and its rigidly rotated copy give the same S, eigenfrequency and capacitance.
Second-order absorbing boundaries raise next to an anisotropic material; use order 1, which is exact at normal incidence for any anisotropic material.
Periodic models: a Bloch wave vector needs the direct solver for eigenmode problems, and the direct or BDDC + GMRES solver for driven problems. PETSc and cuDSS refuse it, as does an adaptive sweep. Electrostatic problems refuse any periodic pair, and a wave port may not touch one. An absorbing boundary reflects waves that meet it obliquely, and a driven solve warns (
gfem.ObliqueAbsorberWarning); a Floquet port absorbs them, or a perfectly matched layer below the cell. A band diagram runs on one process, underjax.gradbut not insidejax.jitorjax.vmap; design gradients reach its band frequencies, notv_gor the wave vectors. Details: Solve a periodic cell.Floquet ports: the half-space behind the face is homogeneous, isotropic and lossless, and the face needs two periodic pairs. Only the uniform driven sweep on the direct or BDDC + GMRES solver; every other path raises. Only orders that propagate over the whole sweep can be excited. No gradient with respect to the incidence, the half-space or the nodes of a Floquet surface. In the gradient matrix, a model with Floquet ports takes the rows of the periodic driven problems (plain and Bloch), with S read from its Floquet ports. Details: Shine a plane wave on a periodic cell.
Periodic surfaces: no gradient with respect to the incidence angle; a power balance needs a port for every propagating order and polarization; a cell response has one parameter at one incidence; aperture fields assume normal incidence, a rectangular lattice and cells that do not diffract, and propagate scalar tangential components at fixed distances. Details: Efficiencies, power balance and polarization of a periodic cell, From a cell response to a metasurface.
Perfectly matched layers: no error estimates or mesh refinement for driven and eigenmode problems (electrostatic refinement runs). Box shells around the interior box only, one thickness per side. Each layer region’s background is a constant
Material, isotropic or on axis-aligned principal axes. NoAbsorbingface,ImpedanceorConductorsheet in or on the layer. Lumped ports and Floquet surfaces keep clear of it, and a wave port may cut a side layer but not one stretched along its normal (driven solves only). No stretch along a periodic axis. No"bddc_gmres";"pmg_gmres"solves the layer exactly inside its iterations. The fields inside the layer are not physical; energies, participations and port power count the physical regions. Details: Absorb outgoing waves with a perfectly matched layer.Free space: 3D only. An incident field needs a perfectly matched layer or absorbing faces, scatterers clear of them where it is not negligible, exterior walls it satisfies and ports outside it; it is refused on periodic models, on the adaptive sweep and by mesh refinement. The incidence layer and a Gaussian beam’s medium are lossless; a beam travels in one material, not a stack. A stack’s layers are constant, isotropic materials whose planes no tetrahedron crosses. A dipole sits inside one lossless, isotropic material (not a
MaterialField), off interfaces, boundary faces, ports and the layer; node gradients take electric dipoles only.source_fields=Falsetakes dipoles only and needs a port with a defined wave; it gives no emitted power, Purcell factor, kept field or far field of them, and its adaptive gradients are exact at the samples and to the sweep’s field error between, with one full-size adjoint per port at each frequency carrying a cotangent. Cross sections need a lossless background and a truncation layer of background only; the far field needs a far-field layer in one lossless, isotropic exterior medium, and no layered exterior. A result or job holding anIncidentFieldcannot be saved, and the solve cache passes it by. Gradients flow to material fields; node coordinates are not differentiable under an incident field.Multipoles: incident-field columns, 3D, a homogeneous lossless background and the whole scatterer (no ground plane, mirror half or slab). The induced-current moments take volume currents only (no perfect conductor, sheet, lumped port or magnetic contrast) and are not differentiable; the multipoles are not differentiable by node coordinates. Details: Decompose scattering into multipoles. Details: Light a scatterer with an incident field, Emit from a point dipole: emitted power, Purcell and beta factors, Read a far field: patterns, directivity, gain and radar cross section.
Unrequested port modes: a propagating mode that no wave port on its surface requests is partly reflected at the port, not converted; request it to see where its power goes (
gfem.SkippedPortModeWarningflags a mode left out below a requested one). An eigenmode solve flags a mode such a family carries, and a mode trapped against the port, withgfem.UnrequestedPortModeWarning; its Q is the port’s, not the device’s.Eigenmodes with wave ports: one process, no Bloch wave vector, no port face cutting a perfectly matched layer, no quantity estimates (field-estimator refinement runs), and no absorbing edge beside a permittivity law in a port’s cross-section. A target below a requested port mode’s cutoff raises
gfem.PortModeError, and a root below a cutoff that does not decay in time is dropped withgfem.AntiBoundRootWarning. The solve lists the resonances of a strip aroundtarget(Q above about 2); a resonance of lower Q is out of reach, even when it lies nearesttarget: use a driven sweep. Underjax.grad, a design touching a wave port face raisesgfem.PortGeometryError; a driven solve differentiates it. The wave ports’ \(\sum_p 1/q_p\) matches \(1/Q\) of an otherwise lossless model to \(O(1/Q^2)\). Details: Modes and ports.Lossy port lines: wave-port S reads each mode by the biorthogonal projection, so a lossy port line is matched to its own mode and the modes of a lossy shared port surface separate. With a
voltage_pathits reference impedance is the mode’s complex \(Z_{PV}\) (pseudo-waves); give every wave port avoltage_path, or none, for a symmetric S. With ports of one kind, \(S\) is symmetric to round-off when the port faces are meshed alike; otherwise it is symmetric to the discretization error of the two ports’ modes, since \(S_{12}/S_{21}\) is the ratio of the two discrete modes’ normalizations (\(\kappa^2/N\) each), about \(10^{-5}\) on a coarse lossy microstrip and independent of the device.Designs at wave ports: a design may reach a wave port face: the materials of its elements (laws and material fields included), a sheet’s fill or an
Impedanceon its edge, and its nodes (gfem.shape.boundary_morph(..., sliding_ports=...)), on every driven path except a Bloch wave vector and a fixed-angle sweep. The port’s mode follows the design, so S stays in the pseudo-waves of the moved mode: renormalize S where a port meets a fixed external line. Agfem.PortModeresult’s \(\gamma\),n_eff, \(Z_{PV}\) and field differentiate the same way. An eigenmode solve raisesgfem.PortGeometryErrorfor such a design. A voltage path is a fixed set of points: a design that moves a conductor at its end, or an interface along it, gives \(Z_{PV}\) a kink. Details: Differentiate port modes and designs at a port.Group index and dispersion: on
PortModeresults only (Noneon a driven solve’s port modes), and not differentiable: underjax.gradthey raisegfem.NonDifferentiableError, where the same result’s \(\gamma\) andn_effdifferentiate. Their error is the mesh’s and the section’s truncation: \(\beta_2\) needs far more cladding around a guide than \(n_\mathrm{eff}\), so converge it in the clearance (Find the group index and dispersion of a waveguide).2D models: normal incidence and one polarization only. Eigenmode, electrostatic and thermal problems, lumped and Floquet ports, periodic pairs, conductor and impedance surfaces, sheet designs, anisotropic materials, PMLs, the adaptive sweep, the iterative and GPU solvers, several processes, measurements other than
Field.at, mesh refinement and node gradients raiseNotImplementedErrorand name the alternative, most often the slab model; a piezoelectric problem takes anisotropic materials, and node gradients through a node map of your own (Find a transducer’s admittance and reflection). In Hz a design blend takes constant permittivities only. Details: Solve a structure that does not vary along one axis.Dispersive materials: a permittivity law is isotropic, and
mu_rdoes not disperse; give an anisotropic or magnetic material constant values per band. A metal in a wave port’s cross-section raises: keep it off the port faces or use lumped ports. A blend with a law end solves on the driven uniform sweep only. An eigenmode target or mode in a law region’s unresolved band raises; move the target or refine that region. A library or fitted law is accurate within its fitted range; a solve outside it warns. Details: Frequency-dependent materials and their gradients.Mode-field gradients: participations, port Q and the mode field differentiate for isolated modes of non-periodic models, on the direct solver, on the CPU, in one process (Differentiate eigenfrequencies, Q and participation ratios). Elsewhere only the eigenfrequencies differentiate.
Quantum metrics: one junction per model; the junction’s cosine on the solved linear modes, in the transmon regime. They are checked against identities, finite differences and published outputs, not against a measured device.
Thermal problems: linear heat conduction with constant, isotropic properties: no temperature-dependent conductivity, no radiation, no thermal contact resistance, and the heat does not change the current or the electromagnetic loss. Electromagnetic heat comes from electric and sheet loss only: no magnetic loss, no eigenmode, port mode or 2D model. A transient runs on a uniform time grid with sources switched at grid times. A cross-section is a slice of an infinitely long device. The thermo-optic shift and the route phase are first order in the rise, with the mode held constant, and refuse a lossy optical section. Mesh refinement and error estimates do not run on thermal problems, and the rise time and time constant have no gradient. Details: Heat a device with a current and read its temperature, Heat a device with its electromagnetic loss, Find the phase a heater puts on a waveguide, Follow a temperature over time, Differentiate a heater’s phase.
Electro-optic shift: a cross-section at DC, first order in the static field with the mode held constant. It refuses a lossy optical section, a 2D model and a potential split across ranks. The optical model does not see the electrodes, so their absorption is absent. No gradient goes through the shift’s mode: the ridge’s shape or width takes a difference over remeshes. Details: Find the phase a voltage puts on a waveguide, Differentiate an electro-optic phase.
Piezoelectric problems: 2D sections only (a tetrahedral or slab mesh raises); one process and the direct solver (sparse Cholesky); no periodic cells, no PML (damping frames instead), and
gfem.Absorbingon a solid’s edge raises; dielectric loss is not read; frequencies, terminals, clamped lines and damping frames are not differentiable; node gradients come through a node map of your own (no 2D boundary morph). Details: Find a transducer’s admittance and reflection.Mechanical eigenmodes: 2D sections only; one process and the direct solver;
gfem.Absorbingon a solid’s edge raises (use a damping frame); gradients ofomegaand the fields only (group_velocityanderrorraisegfem.NonDifferentiableError, and so does a mode in a cluster). Details: Find the mechanical modes of a film or a rib.Layer patterns: width and spacing only (no minimum area), and a pre-check, not foundry sign-off; one flat GDS cell; layer grids only (no free-form 3D designs); length-scale constraints validated up to a rule of \(1.25R\) and a pitch of \(R/3\), for a filter radius \(R\).
SAX circuits: a component answers only inside its band, interpolated between its solved frequencies; every exposed wave port needs a polarity reference, or for RF a voltage path; RF components need a 3D model and one reference impedance for the whole circuit; build the circuit outside
jax.jit; no forward-mode derivatives. Details: Differentiate a SAX circuit with gfem blocks.
Platforms#
Linux x86_64 (glibc >= 2.28), macOS arm64 and Windows x86_64, Python >= 3.12.
The cuDSS GPU solver installs on Linux x86_64 and Windows x86_64. Importing
gfem turns on JAX double precision (jax_enable_x64), which every gfem solve
requires. See Get started.
Licence#
MIT. gfem depends on NGSolve (LGPL-2.1), whose PyPI wheels also contain GPL-2.0+ SuiteSparse code; see Licence.