Method of Moments and the impedance matrix#
Draft Written from harmolab/utils/impedance/impmet.py, harmolab/rwg/rwg3.py and harmolab/rwg/rwg4.py at commit 1b6a6e2; right-hand side and module paths updated at commit 72fb8c6. Awaiting review.
How the integral equation of From Maxwell’s equations to the EFIE becomes a linear system \(Z\,I = V\) of size \(N\times N\), what each entry of \(Z\) contains, and how the solver fills and solves it.
The idea#
The EFIE must hold at every point of the surface, for an unknown current that is a function. The Method of Moments trades both for finite objects [1]:
the current is written as a combination of \(N\) known functions, with \(N\) unknown coefficients;
instead of imposing the equation at every point, it is imposed “on average” against \(N\) testing functions, one equation per testing function.
That gives \(N\) linear equations for \(N\) unknowns. With the same RWG functions for expansion and testing, the scheme is called Galerkin, and it is what the solver does.
From the EFIE to \(Z\,I = V\)#
Expand the current in RWG functions, \(\mathbf J = \sum_n I_n \mathbf f_n\) (see RWG basis functions), and take the inner product of the EFIE Eq. (8) with each \(\mathbf f_m\):
The gradient is moved from \(\Phi\) onto the testing function by integration by parts, \(\langle \mathbf f_m, \nabla\Phi\rangle = -\langle \nabla_s\cdot\mathbf f_m, \Phi\rangle\). There is no boundary term because \(\mathbf f_m\) has no normal component on the outer edges of its two triangles. Only first derivatives of the RWG functions remain, which are the constants \(\pm\ell_m/A_m^\pm\). The result is
with \(G = e^{-jkR}/(4\pi R)\). The first term of Eq. (13) comes from the vector potential (the current), the second from the scalar potential (the charge).
What the solver computes#
Each RWG function lives on two triangles, so each \(Z_{mn}\) is a sum of four double integrals, one per pair \((T_m^t, T_n^s)\) with \(t, s \in \{+,-\}\). On \(T^\pm\), the solver writes \(\mathbf f = \pm\frac{\ell}{2A^\pm}(\mathbf r - \mathbf v^\pm)\) and \(\nabla_s\cdot\mathbf f = \pm\ell/A^\pm\), and integrates over each triangle with a quadrature rule whose weights sum to ½ (the area of the reference triangle), so that \(\int_T g\,dS \approx 2A\sum_p w_p\,g(\mathbf r_p)\). The factors \(2A\) then cancel the \(\ell/(2A)\) of the RWG normalisation, and Eq. (13) becomes
where \(s_\pm = \pm1\), \(\boldsymbol\rho_t(\mathbf r) = \mathbf r - \mathbf v_m^t\) is measured from the
free vertex of the test triangle, \(\mathbf r_p\) and \(\mathbf r_q\) are the quadrature nodes on the test
and source triangles and \(R_{pq} = |\mathbf r_p - \mathbf r_q|\). The factor 4 of the charge term is
\((\ell/A)^2(2A)^2/\ell^2\). This is the formula of the docstring of
impmet.impedance_matrix_z; in the code the two brackets are pref_A * rho_dot and
4.0 * pref_Phi.
Eq. (15) is used as written only for pairs of triangles that do not touch (FAR pairs). When the two triangles touch, \(1/R\) is singular and the same rule on both sides is inaccurate or fails: the SELF, EDGE and VERTEX pairs are integrated differently, see Numerical integration and singularities.
Symmetry and fill modes#
Because \(G(\mathbf r,\mathbf r') = G(\mathbf r',\mathbf r)\) and the same functions are used for expansion and testing, the exact matrix is complex symmetric: \(Z_{mn} = Z_{nm}\) (not Hermitian). Its real and imaginary parts \(R = \mathrm{Re}\,Z\) and \(X = \mathrm{Im}\,Z\) are real symmetric matrices. This is reciprocity, and characteristic modes rely on it (see Characteristic modes).
The assembled matrix is symmetric only up to quadrature error, because the singular pairs are not
integrated the same way on the test and source sides. The argument fill_mode of the assemblers
decides what to do about it:
|
What is computed |
Use |
|---|---|---|
|
every \((m,n)\) entry, then \(Z \leftarrow (Z + Z^\mathsf{T})/2\) |
production. Exactly symmetric, and the charge term stays exactly neutral on loop currents. |
|
entries \(m \le n\) only, lower half copied |
comparison only. Half the cost, but not charge-neutral. |
|
every entry, no symmetrisation |
diagnostic: \(\max|Z - Z^\mathsf T|/\max|Z|\) measures the quadrature error. |
The reason for "full_sym" is documented in impmet._mirror_upper_triangle. The charge term has the
structure \(Z_\Phi = D^\mathsf{T} K D\), where \(D\) maps edge currents to triangle charges, so it
vanishes exactly on any current that deposits no charge (a loop), whatever the quadrature,
provided every entry uses the same triangle kernel \(K\). Mirroring breaks that structure. On a
20 mm loop the developers measured \(|u^\mathsf{H} Z_\Phi u| / |u^\mathsf{H} Z_A u| = 0.10\) with the
mirrored fill against \(5\times10^{-13}\) with the full fill, and the loop reactance did not converge
with mesh refinement. Symmetrising the full fill keeps the structure, since
\((D^\mathsf T K D + D^\mathsf T K^\mathsf T D)/2 = D^\mathsf T\,\tfrac{K+K^\mathsf T}{2}\,D\).
The right-hand side#
\(V_m\) in Eq. (14) is the incident field tested by \(\mathbf f_m\). The solver evaluates it with one point per triangle, the centroid, where \(\mathbf f_m(\mathbf r_m^{c\pm}) = \ell_m\boldsymbol\rho_m^{c\pm}/(2A_m^\pm)\) and the factor \(A_m^\pm\) of the one-point rule cancels:
plane wave (
rwg4.calculate_current_scattering): Eq. (16) with the plane wave of From Maxwell’s equations to the EFIE;enhanced gap source (
harmolab.utils.ports.EnhancedGap): the field \(V/W\) of the gap is constant and \(\mathbf f_m\) linear, so the integral over the part of each triangle inside the gap window is computed exactly, with one point at the centroid of that part; for a triangle entirely inside, this is Eq. (16);delta gaps (
DeltaGapEdge,DeltaGapCut): \(V_m = \pm\ell_m V\) on the edges of the port, 0 elsewhere.
All are detailed in Excitations and input impedance and Ports. Two modifications of \(Z\) also belong to the system solved:
a lumped impedance \(\Delta Z\) on edge \(m\) adds \(\ell_m^2\,\Delta Z\) to \(Z_{mm}\)
(rwg3.calculate_z_matrice_lumped_elements), and a lossy conductor replaces \(Z\) by \(Z + Z_s\mathsf G\)
(see Lossy conductors).
Solving the system#
rwg4.calculate_current_radiation and calculate_current_scattering call numpy.linalg.solve: a
dense LU factorisation with partial pivoting (LAPACK). The matrix is never inverted.
Step |
Cost |
Notes |
|---|---|---|
Fill of \(Z\) |
\(O(N^2)\) entries, each 4 double integrals |
the dominant cost for most meshes; CPU or GPU (see GPU acceleration) |
Storage of \(Z\) |
\(16\,N^2\) bytes (complex128) |
\(N = 760\): 9.2 MB; \(N = 5\,000\): 400 MB; \(N = 10\,000\): 1.6 GB |
LU solve |
\(O(N^3)\) operations |
one factorisation per frequency |
A frequency sweep keeps one matrix per frequency (calculate_z_matrice_sweep returns an array
\(N_f\times N\times N\)), so its memory grows with the number of frequencies.
Conditioning#
Two properties of \(Z\) matter in practice.
The charge term dominates at small cell size. Relative to the current term, the charge term of Eq. (13) is larger by about \(4/(kh)^2\) for a cell of size \(h\) (comment in
impedance/impmet.py). As the frequency drops or the mesh is refined, the two terms separate by orders of magnitude and \(Z\) becomes ill-conditioned. This is the low-frequency breakdown of the EFIE, cured by splitting the current into loop and star (or tree) parts [2]. The solver has no such decomposition. Its meshing helpergmsh_function.mesh_and_gap_parameterswarns when the cell falls below \(\lambda/100\).\(R = \mathrm{Re}\,Z\) is only positive semi-definite. The radiated power \(\tfrac12 I^\mathsf{H} R\, I\) is never negative, but many current distributions radiate almost nothing, so \(R\) has many tiny eigenvalues on an electrically small structure. This does not affect \(Z\,I = V\), but it is central to characteristic modes, which solve a problem in \(R\) (see Characteristic modes).
In this solver#
Theory vs. implementation
What the code implements, its entry points and the parameters you can change.
Function |
Role |
|---|---|
|
sets the constants, chooses CPU or GPU, returns \(\omega, \mu, \varepsilon, c, \eta\) and \(Z\) |
|
same for many frequencies in one pass (shared geometry precomputation) |
|
\(Z\) plus lumped R, L, C loads |
|
the three assemblers. They implement the same scheme and their regression tests cross-check them to \(10^{-10}\) |
|
build \(V\) (for radiation \(V = B\,v\), from the ports, see Ports) and solve \(Z\,I = V\) |
Parameters. fill_mode and use_gpu are exposed by the rwg3 functions. The quadrature orders
(quad_order, near_order, self_outer_order, duffy_order) are arguments of the impmet
assemblers only: calculate_z_matrice always uses their defaults. See Numerical integration and singularities.
Tests. harmolab/utils/quadrature/tests/test_impedance_matrix_regression.py,
test_impedance_sweep_regression.py, test_impedance_sweep_gpu_regression.py,
test_impedance_fill_mode.py, test_impedance_quadrature_normalisation.py, and
test/test_rwg3_gpu_dispatch.py.
Assumptions and limits#
Dense matrix and dense LU: memory \(O(N^2)\), time \(O(N^3)\). No fast method (multilevel fast multipole, compression) is implemented.
No loop–star or loop–tree decomposition: avoid cells much smaller than needed, especially at low frequency.
The plane-wave right-hand side uses one point per triangle (centroid); the enhanced gap source is integrated exactly (its field is constant); the matrix uses full quadrature.
Quadrature orders are not exposed by the high-level functions.
Continue#
How the singular pairs of triangles are integrated, and how accurate it is.
The functions \(\mathbf f_n\) used for expansion and testing.
How the vector \(V\) is built for a gap source and for a plane wave