Capabilities#

What gfem solves, which results it differentiates, and what it refuses, at v0.1.

What you can solve#

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 the mkl extra 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" and eigen_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.DistributedUnsupportedError there; 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

Sheet fill

Node coordinates

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

exact zero

raises NotImplementedError

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

exact zero

raises NotImplementedError

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

raises NonDifferentiableError

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

raises

Electromagnetic heating temperature from a driven result’s loss

FD-verified direct solver

FD-verified direct solver

FD-verified direct solver

raises

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

raises

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

raises

Steady thermal temperature, rise, heat, power and heat flow

exact zero

exact zero

exact zero

raises NonDifferentiableError

Transient thermal traces (heat out too) and kept temperatures, TR-BDF2 and theta

exact zero

exact zero

exact zero

raises NonDifferentiableError

DC conduction conductance, dissipation and potentials

exact zero

FD-verified direct solver, BDDC + GMRES

exact zero

raises NonDifferentiableError

Thermo-optic shift phase per length of a section

raises

raises

raises

raises

Route phase phase along routes through a 3D rise

raises

raises

raises

raises

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.grad returns 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:

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 with gfem.LowFrequencyWarning, and lumped ports keep their digits. Other driven solves ("bddc_gmres", "pmg_gmres", "petsc", the GPU, several MPI ranks, periodic and Floquet models, or gauge="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, solve gfem.Electrostatic; the details are under gfem.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 reported error does 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, under jax.grad but not inside jax.jit or jax.vmap; design gradients reach its band frequencies, not v_g or 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. No Absorbing face, Impedance or Conductor sheet 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=False takes 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 an IncidentField cannot 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.SkippedPortModeWarning flags 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, with gfem.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 with gfem.AntiBoundRootWarning. The solve lists the resonances of a strip around target (Q above about 2); a resonance of lower Q is out of reach, even when it lies nearest target: use a driven sweep. Under jax.grad, a design touching a wave port face raises gfem.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_path its reference impedance is the mode’s complex \(Z_{PV}\) (pseudo-waves); give every wave port a voltage_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 Impedance on 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. A gfem.PortMode result’s \(\gamma\), n_eff, \(Z_{PV}\) and field differentiate the same way. An eigenmode solve raises gfem.PortGeometryError for 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 PortMode results only (None on a driven solve’s port modes), and not differentiable: under jax.grad they raise gfem.NonDifferentiableError, where the same result’s \(\gamma\) and n_eff differentiate. 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 raise NotImplementedError and 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_r does 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.Absorbing on 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.Absorbing on a solid’s edge raises (use a damping frame); gradients of omega and the fields only (group_velocity and error raise gfem.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.