Numerical integration and singularities#

Draft Written from harmolab/utils/impedance/impmet.py and harmolab/utils/quadrature/ at commit 1b6a6e2; module paths updated at commit 72fb8c6. Awaiting review.

Every entry of the impedance matrix is a sum of double surface integrals over pairs of triangles (see Eq. (15)). Their kernel \(e^{-jkR}/R\) becomes infinite when the two points meet, which happens only when the two triangles touch. The solver therefore sorts the pairs and integrates each kind with a dedicated scheme.

The idea#

For two distant triangles the integrand is smooth and a few quadrature points per triangle give an accurate result. When the triangles share an edge, a vertex, or are the same triangle, \(R\) goes to zero somewhere and a plain rule either loses accuracy or divides by zero. Those pairs are few (about 10 % on the mesh of Figure 5), so they can afford more careful, more expensive treatments without slowing the fill much.

Four kinds of triangle pairs#

singularity_classifier.classify_triangle_pair compares the vertex indices of the test and source triangles:

Category

Shared vertices

Treatment in impmet

FAR

none

the same Gauss rule on both triangles (default degree 6, 12 points)

VERTEX

one

Gauss rule of degree 16 (81 points) on both triangles, \(1/R\) part of the charge term in closed form on the source triangle

EDGE

two

same as VERTEX

SELF

three (same triangle)

Gauss rule on the test triangle (degree 6); around each of its nodes, Duffy transform on the source triangle (order 7, 147 nodes)

Left, a plate mesh where one triangle is dark, its three edge neighbours blue and the triangles sharing only a vertex amber. Right, three copies of that triangle showing 12 quadrature points, 81 quadrature points, and the 147 Duffy nodes gathered around one point.

Figure 5 (a) A 120 mm × 80 mm plate (114 triangles, 157 RWG functions) and the category of every triangle with respect to one test triangle. Over all the sub-pairs that enter \(Z\), 89.7 % are FAR, 6.9 % VERTEX, 2.5 % EDGE and 0.9 % SELF. (b)–(d) The nodes used on that triangle by each scheme, with the solver’s default orders. Marker size is proportional to the weight. In (d), the Duffy nodes (dots) are those used for one outer node (filled circle): the source triangle is split into three sub-triangles meeting at that node (dashed). Generated by documentation/figure_notebooks/theory_numerical_integration.ipynb on solver commit 72fb8c6, with the default orders read from impmet.impedance_matrix_z. Click to enlarge.#

Gauss rules on triangles#

A rule of degree \(d\) integrates exactly every polynomial of total degree \(\le d\) on the triangle. The nodes are given in barycentric coordinates and the weights sum to ½, so that for a triangle of area \(A\)

(17)#\[\int_T g\,dS \;\approx\; 2A\sum_{q=1}^{N_q} w_q\, g(\mathbf r_q).\]

gauss_dunavant.dunavant_rule(degree) offers the degrees below. Degrees 1 to 6 are the symmetric rules of Dunavant[1]. Degrees 7 and above are not Dunavant rules: they are Gauss–Legendre product rules mapped onto the triangle, because, as the module explains, the published symmetric coefficients above degree 6 could not be transcribed to full double precision.

Degree

Points

Type

1, 3, 4, 5

1, 4, 6, 7

symmetric Dunavant rules

6 (FAR, SELF outer)

12

symmetric Dunavant rule

7, 11

25, 49

Gauss–Legendre product rules

16 (EDGE/VERTEX)

81

Gauss–Legendre product rule

20, 24

121, 169

Gauss–Legendre product rules

FAR pairs#

The integrand of Eq. (15) is smooth and the default degree-6 rule is applied on both triangles. Because the same rule is used on both sides, exchanging the test and source triangles gives exactly the same number: FAR entries are symmetric to machine precision.

SELF pairs: the Duffy transform#

When the test and source triangles are the same, every test node \(\mathbf r_p\) lies inside the source triangle and \(1/|\mathbf r_p - \mathbf r'|\) is infinite at \(\mathbf r' = \mathbf r_p\). The solver keeps a Gauss rule on the test triangle and, for each of its nodes, integrates over the source triangle with the Duffy transform [2]:

  1. the source triangle is split into three sub-triangles that share the singular point as a vertex (dashed lines in Figure 5 d);

  2. on each sub-triangle \((\mathbf q_0, \mathbf q_1, \mathbf q_2)\), with the singular point at \(\mathbf q_0\), the coordinates are “collapsed”:

(18)#\[\mathbf r'(u,v) = \mathbf q_0 + u(\mathbf q_1 - \mathbf q_0) + uv(\mathbf q_2 - \mathbf q_1), \qquad dS' = 2A_{\mathrm{sub}}\,u\,du\,dv, \qquad (u,v)\in[0,1]^2 .\]

Since \(|\mathbf r' - \mathbf q_0| = O(u)\), the factor \(u\) of the area element cancels the \(1/R\) singularity: the transformed integrand is bounded, and an ordinary Gauss–Legendre rule in \(u\) and \(v\) converges. The solver uses 7 points per direction (duffy_order = 7), that is 3 × 49 = 147 nodes per outer node.

A detail that matters. The Duffy nodes come with weights summing to the physical area \(A\), while the rules of Eq. (17) sum to ½. The SELF branch mixes the two, so it rescales the Duffy weights by \(1/(2A)\) (impmet._duffy_weight_scale). Its docstring explains what happened when that factor was missing: the SELF contributions were scaled by \(2A\), i.e. almost removed, and \(R = \mathrm{Re}\,Z\) lost its positive semi-definiteness. test_impedance_quadrature_normalisation.py now checks the invariant that would have caught it: scaling the geometry by \(s\) and the frequency by \(1/s\) must leave the spectrum of \(R\) unchanged.

EDGE and VERTEX pairs: the singularity in closed form#

When the triangles share an edge or a vertex, the Gauss nodes never coincide, but they come close to each other along the shared part and \(1/R\) varies too fast for a moderate rule. The solver handles the dominant term, the charge term (larger than the current term by about \(4/(kh)^2\)), by splitting its kernel:

(19)#\[\frac{e^{-jkR}}{R} = \underbrace{\frac{e^{-jkR} - 1}{R}}_{\text{bounded, }\to\,-jk} \;+\; \underbrace{\frac{1}{R}}_{\text{singular}} .\]

The bounded part is integrated with the degree-16 rule on both triangles. The singular part is integrated over the source triangle in closed form, with the formula of Wilton et al.[3], and the result is integrated over the test triangle with the same rule. For an observation point \(\mathbf r_0\) at signed height \(h\) above the plane of the source triangle:

(20)#\[\begin{split}\begin{aligned} \int_T \frac{dS'}{|\mathbf r_0 - \mathbf r'|} = \sum_{i=1}^{3}\Bigg[\, & P_i^0 \ln\frac{R_i^+ + l_i^+}{R_i^- + l_i^-}\\ & - |h|\left(\arctan\frac{P_i^0\, l_i^+}{(R_i^0)^2 + |h|R_i^+} - \arctan\frac{P_i^0\, l_i^-}{(R_i^0)^2 + |h|R_i^-}\right)\Bigg], \end{aligned}\end{split}\]

where, for edge \(i\) going from vertex \(\mathbf A\) to vertex \(\mathbf B\): \(P_i^0\) is the signed distance from the projection of \(\mathbf r_0\) to the line of the edge, \(l_i^\mp\) the signed positions of \(\mathbf A\) and \(\mathbf B\) along it, \(R_i^\mp = |\mathbf A - \mathbf r_0|\), \(|\mathbf B - \mathbf r_0|\), and \((R_i^0)^2 = (P_i^0)^2 + h^2\). Because \(P_i^0\) is signed, the formula holds whether the projection falls inside the triangle or not. That is what EDGE and VERTEX pairs need, and what a Duffy subdivision cannot give: it only tiles the triangle when the point is inside it.

The \(|h|\) term vanishes for coplanar triangles but not at a junction between two surfaces. The module analytic_singular records what dropping it costs: on a 40 mm cell, 34 % error at a 90° junction. test/test_impedance_non_coplanar.py keeps a permanent three-dimensional case. The current term keeps the plain degree-16 rule: it is smaller by \((kh)^2/4\), so its residual error is negligible.

How accurate is each scheme?#

Figure 6 isolates the static kernel \(1/R\), the part that each special scheme exists for, on an EDGE pair and a SELF pair of the mesh above, and compares it with a reference accurate to about \(10^{-6}\).

Two log-log plots of relative error against number of quadrature points. Left, for an edge pair, plain Gauss stalls near 0.4 percent while the closed-form inner integral keeps converging to about 3e-5. Right, for a self pair, Duffy stalls near 1e-3 with a spike at 49 points while the closed-form inner integral keeps converging.

Figure 6 Relative error on \(\iint dS'\,dS/R\) against the number of points of the rule on the test triangle. (a) EDGE pair: with the same Gauss rule on both triangles the error stalls (0.44 % at the solver’s degree 16); with the inner integral in closed form it is 0.014 % at that degree and keeps decreasing. (b) SELF pair: at the solver’s default (degree 6, Duffy order 7) the error is 0.36 %. Raising only the outer degree does not help: with Duffy at fixed order the error stalls near \(10^{-3}\) and jumps at degree 11, where outer nodes come close to the edges and the Duffy sub-triangles degenerate. The closed form (blue) is what replacing the inner Duffy integral would give. The reference splits the test triangle into 256 sub-triangles with the inner integral in closed form; its own accuracy, measured against 64 sub-triangles, is about \(10^{-6}\). Generated by documentation/figure_notebooks/theory_numerical_integration.ipynb on solver commit 72fb8c6; numbers in numerical_integration.json. Click to enlarge.#

The same behaviour is documented in the code for complete matrix entries, measured during development (comments in impmet.py):

  • EDGE pairs: closed-form extraction took the error from +1.15 % (plain Gauss, degree 11) to −0.008 %;

  • SELF pairs: 0.22 % at outer degree 6 on a 40 mm cell. Raising the outer degree alone makes the Duffy integral non-monotone (2.05 %, 0.008 %, 0.275 %, 0.005 % at Duffy orders 7, 10, 14, 25 with an outer degree 11), so self_outer_order and duffy_order must be raised together or not at all. The code comment names the way to lift this ceiling: replace the inner Duffy integral by the closed form, as the EDGE/VERTEX branch already does.

Reciprocity as a health check#

Only FAR pairs use the same rule on both sides; SELF and EDGE/VERTEX are numerical on the test triangle and analytic (or Duffy) on the source. So a matrix filled with fill_mode="full" is not exactly symmetric, and \(\max|Z - Z^\mathsf T|/\max|Z|\) measures the quadrature error of the singular branches. The docstring of NEAR_ORDER_DEFAULT gives that residual on the CubeSat mesh at 440 MHz (\(N = 760\)):

EDGE/VERTEX degree

6

7

11

16

20

24

\(\max|Z - Z^\mathsf T|/\max|Z|\)

5.2e-3

3.9e-3

1.3e-3

5.2e-4

2.5e-4

1.3e-4

Degree 16 is the lowest that brings it under \(10^{-3}\), the tolerance RECIPROCITY_TOL of harmolab/cma/z_matrix_diagnostics.py. On that mesh the extra cost was measured as negligible (13.3 s against 13.0 s for the GPU fill), because EDGE/VERTEX pairs are few. The production default "full_sym" then symmetrises the matrix (see Method of Moments and the impedance matrix).

In this solver#

Theory vs. implementation

The parameters of the scheme, where they live and how to change them.

Argument of impmet.impedance_matrix_z

Default

Meaning

quad_order

6

degree of the rule on both triangles of FAR pairs

near_order

None → max(quad_order, 16)

degree on both triangles of EDGE/VERTEX pairs (NEAR_ORDER_DEFAULT = 16)

self_outer_order

None → quad_order

degree on the test triangle of SELF pairs

duffy_order

7

Gauss–Legendre points per direction of the Duffy integral (3 sub-triangles)

fill_mode

"full_sym"

see Method of Moments and the impedance matrix

only_categories

None

diagnostic: keep only some categories, to attribute an error to one scheme

rwg3.calculate_z_matrice and the high-level algorithms use these defaults; changing an order means calling the impmet assemblers directly. The same arguments exist on impedance_matrix_z_sweep and impedance_matrix_z_sweep_gpu, which must stay consistent with impedance_matrix_z (their regression tests check it). The script harmolab/antenna_simulation/numerical_studies/outer_order_study.py (python -m harmolab.antenna_simulation.numerical_studies.outer_order_study) reproduces the convergence measurements behind the defaults.

Modules. quadrature/singularity_classifier.py (categories), quadrature/gauss_dunavant.py (rules and mapping), quadrature/duffy.py (Duffy nodes), quadrature/analytic_singular.py (Eq. (20), scalar and batched versions).

Tests. harmolab/utils/quadrature/tests/: test_gauss_dunavant.py, test_duffy.py, test_analytic_singular.py, test_singularity_classifier.py, test_impedance_outer_order.py, test_impedance_quadrature_normalisation.py; and test/test_impedance_non_coplanar.py.

Assumptions and limits#

  • SELF ceiling. With Duffy at order 7 the SELF integrals stay around \(10^{-3}\) relative accuracy; raising only one of the two orders can make it worse.

  • Current term near singular pairs is integrated with the plain degree-16 rule (no extraction). The code comment justifies it by the factor \((kh)^2/4\), which holds only while the cells stay small compared with the wavelength.

  • Flat triangles only. The closed form Eq. (20) and the rules assume planar triangles, which is what the mesh provides.

  • The categories are decided from vertex indices: two triangles that touch geometrically but do not share vertex indices (duplicated nodes) are treated as FAR.

Continue#

Method of Moments and \(Z\)

The formula these integrals belong to, and how the system is solved.

Method of Moments and the impedance matrix
Next: excitations

How the gap source and the plane wave build the vector \(V\)

Excitations and input impedance
API of harmolab.rwg

calculate_z_matrice and the other entry points.

harmolab.rwg — RWG pipeline

References#