Choosing the mesh size#

Draft Every number on this page comes from documentation/figure_notebooks/guide_mesh_size.ipynb (solver commit 72fb8c6: the ports of harmolab.utils.ports, with the exact integration of the gap of commit 52b5eb6), which runs the solver on the meshes described. Awaiting review.

How fine the mesh must be depends on what varies where: the current along the antenna, the current across a wide conductor, the field in the feed gap, and the coupling between conductors that are close together. This page gives rules for each, measured with the solver on strip antennas, and two gmsh recipes. The quantity watched is the input impedance \(Z_\mathrm{in}\), the most mesh-sensitive result of a radiation simulation; patterns and directivity converge faster.

The rules#

Rule

Why (measured below)

Make the gap at least as wide as the conductor

The enhanced gap feeds a cube of side \(W\) around the feed point. On a strip wider than \(W\), only the part of the gap inside the cube is fed: with a 30 mm gap on a 40 mm strip, \(R_\mathrm{in}\) ranged from 140 Ω to 1.2 Ω with the number of cells across, instead of 79 Ω. The solver warns (GapSourceWarning).

Preferably, make the edges of the feed gap mesh lines

With gmsh, draw the gap as its own surface and glue it with fragment. Since commit 52b5eb6 the solver integrates the gap field exactly over the triangles the gap edges cut, and a gmsh dipole gives the same \(R_\mathrm{in}\) either way (within 0.25 Ω); before, it came out anywhere between 63 and 182 Ω. An aligned gap still keeps the excitation exactly where it is drawn.

Put at least 3 cells in the gap

The rule of mesh_and_gap_parameters. With aligned gap edges, 3, 6 or 12 cells in the gap give the same \(Z_\mathrm{in}\) (within 0.2 Ω).

Along the antenna, about λ/20 for a first look, λ/40 to λ/60 for numbers

The input impedance of a half-wave dipole is within 3.7 % of the finest mesh at λ/20, 1.7 % at λ/40, 0.8 % at λ/60. The difference roughly halves when the cell length halves.

Across a wide conductor, 4 cells graded towards the edges

On a 0.04 λ wide strip, 1 cell is already within 1.5 Ω of 8 cells, but 2 uniform cells are 6 Ω off; 4 graded cells are within 1.1 Ω. Conductor losses need the edge grading more (see Lossy conductors).

Near a conductor at distance \(s\), cells of about \(s/3\)

With a parallel strip 5 mm away, the input impedance differs by 9 % from the finest mesh with cells as long as the spacing, and by 2 % with cells of \(0.3\,s\).

Refine locally, not everywhere

Fine cells around the feed and λ/10 elsewhere gave \(R_\mathrm{in}\) within 2.4 Ω of the finest uniform mesh with 44 unknowns instead of 297.

Below λ/100, ask why

The cost grows quickly and the matrix becomes less well conditioned (Numerical limits and conditioning); the results above do not need it.

Check by halving

Run once more with all cell sizes halved. With the slow, first-order convergence measured below, the change is about the remaining error of the finer run, and half that of the coarser one.

These figures are for strip antennas at their first resonance. The rules carry over to other shapes, but the numbers will not be the same: check with the last rule.

What was measured#

Six panels. (a) error against cells per wavelength, falling from 12 percent at lambda over 8 to 0.4 percent at lambda over 80. (b) resistance and reactance against cells across a wide strip, nearly flat. (c) the same with a gap narrower than the strip, where the resistance goes from 140 ohms with 1 or 2 cells to 31 and 1.2 ohms with 4 and 8, and with a wider gap, flat near 79 ohms. (d) error against cell length over spacing for a strip alone and with a parallel strip, the coupled case converging more slowly. (e) and (f) resistance and reactance of a dipole meshed by gmsh: with the former one-point rule the resistance is erratic when the gap edges are not mesh lines; with exact integration, the aligned and non-aligned meshes agree and follow the structured reference.

Figure 17 Input impedance of strip antennas against the mesh. (a) Half-wave dipole (300 MHz, 0.47 m × 10 mm, gap 30 mm in 3 cells), cell length elsewhere from λ/8 to λ/80, relative to λ/120. (b) A 40 mm wide strip, 1 to 8 cells across, fed by a delta gap over its whole cut (the model of DeltaGapCut). (c) The same strip with the enhanced gap source, gap 30 mm (narrower than the strip) or 50 mm (wider). (d) A strip alone and with a parallel strip 5 mm away (1 GHz), relative to the finest mesh (\(h = 0.22\,s\)). (e), (f) The dipole of First simulation (gap 50 mm) meshed by gmsh and solved with radiation_algorithm: gap edges cutting through triangles (exact integration, and the former one-point rule for comparison) or aligned with mesh lines, and the structured mesh as reference. Generated by documentation/figure_notebooks/guide_mesh_size.ipynb on solver commit 72fb8c6; all values in mesh_size.json. Click to enlarge.#

Along the antenna#

The current of a dipole varies along its length on the scale of the wavelength. On the structured half-wave dipole of panel (a), with the gap unchanged:

cells per wavelength

10

20

40

60

80

120 (reference)

\(Z_\mathrm{in}\) (Ω)

69.9 − 2.9j

71.1 − 0.9j

71.8 + 0.4j

72.1 + 1.0j

72.2 + 1.2j

72.3 + 1.5j

difference

6.9 %

3.7 %

1.7 %

0.8 %

0.4 %

The resistance settles first; the reactance, which sets the resonant frequency, keeps moving by a few ohms. The convergence is slow, roughly first order: halving the cells halves the difference. The reference is therefore not exact either: going from λ/60 to λ/120 still changed \(Z_\mathrm{in}\) by 0.8 %, about its own remaining error, so the differences in the table understate the true errors by about that much. This is also why halving the cells is a usable check.

Across a wide conductor#

The current on a strip is largest at its edges. For the input impedance of a 40 mm strip fed over its whole width (panel b), the number of cells across matters little: 80.3 + 3.8j Ω with 1 cell, 81.0 + 2.5j Ω with 8 cells graded towards the edges (edge_grading="cosine" in harmolab.optim.geometries.planar). 2 uniform cells are the worst case (82.9 + 8.0j Ω). Use 4 cells, graded. Losses are a different matter: the loss in the metal concentrates at the edges and keeps changing as the edge cells shrink, which is why the reduced multiport model calibrates its loss factor for one fixed rule, 4 graded cells (Reduced multiport model and load optimisation).

The feed gap#

The enhanced gap source (EnhancedGap, Excitations and input impedance) applies the field \(V/W\) in a cube of side \(W\) centred on the feed point, integrated exactly over the part of each triangle inside it. Two consequences, measured:

  • On a conductor wider than \(W\), only the part of the gap inside the cube is fed. Panel (c): on a 40 mm strip, a 30 mm gap gives 139.9 + 19.2j, 138.9 + 33.2j, 30.9 + 69.9j and 1.2 + 18.9j Ω with 1, 2, 4 and 8 cells across; a 50 mm gap gives 78.5 + 12.5j to 79.6 + 16.9j Ω whatever the number of cells. With one cell, each triangle of the gap spans the strip and is fed in proportion to its part inside the cube; with more, the cells near the edges of the strip are fed in part or not at all. GapSourceWarning is emitted in all four cases (Ports).

  • When the gap edges cut through triangles. Before commit 52b5eb6, a triangle was fed entirely or not at all according to where its centroid fell, so the fed length, and with it the applied voltage, changed from one mesh to the next. The solver now integrates the gap field over the part of each triangle inside the cube (Eq. (23) of Excitations and input impedance). Panels (e) and (f), the same dipole meshed by gmsh:

    element size

    λ/20

    λ/30

    λ/60

    λ/120

    gap edges cut through triangles, former one-point rule (Ω)

    80.0 − 2.8j

    181.8 − 2.7j

    76.8 + 4.3j

    63.5 + 4.8j

    gap edges cut through triangles, exact integration (Ω)

    71.4 − 1.9j

    71.8 − 0.6j

    72.7 + 4.1j

    73.0 + 5.4j

    gap drawn as its own surface (Ω)

    71.6 − 0.9j

    71.9 − 0.3j

    72.7 + 4.1j

    73.0 + 5.5j

    The former rule, removed from the solver, is re-implemented in the notebook (centroid_rule_voltage, as in test/test_gap_source_partial.py) and evaluated on the same meshes and matrices; it gives back the values measured with the solver of that time. With exact integration the two gmsh meshes agree within 0.25 Ω in resistance and 1 Ω in reactance, and the differences vanish as the mesh is refined. With an aligned gap both rules give the same values (the last row), and the number of cells in the gap no longer matters: 3, 6 and 12 cells gave 72.40 + 1.75j, 72.39 + 1.55j and 72.39 + 1.56j Ω on the structured mesh.

check_simulation_stability checks the ratio of the gap width to the element size, not where the gap edges fall nor whether the conductor is wider than the gap; the warning above covers the latter.

Conductors close together#

A conductor at distance \(s\) changes the current on its neighbour over lengths of order \(s\). Panel (d): a strip with a parallel strip 5 mm away (λ/60) converges more slowly than the same strip alone, and not monotonically. With cells as long as the spacing the input impedance differs by 9 % from the finest mesh tried, against 3 % for the strip alone; with cells of \(0.3\,s\), 2 % against 0.5 %. The finest mesh (\(h = 0.22\,s\)) is the reference, so these differences understate the true error. Strongly coupled configurations with a small input resistance (here 4.7 Ω) are the most sensitive.

gmsh recipes#

Both are taken from the notebook above, where they are run on the dipole of First simulation (WID4, LEN4, GAP4 are its width, length and gap).

The gap as its own surface. Draw the strip and the gap region, and glue them with fragment: the gap edges become mesh lines.

strip = gmsh.model.occ.addRectangle(-WID4 / 2, -LEN4 / 2, 0, WID4, LEN4)
gap = gmsh.model.occ.addRectangle(-WID4 / 2, -GAP4 / 2, 0, WID4, GAP4)
gmsh.model.occ.fragment([(2, strip)], [(2, gap)])
gmsh.model.occ.synchronize()

The mesh then has several surfaces, and the 4th row of t carries their gmsh tags. radiation_algorithm uses all of them. scattering_algorithm keeps only the triangles labelled 1 (see Scattering: illuminating a structure).

Fine cells around the feed only. A gmsh Ball size field sets the element size inside a sphere around the feed point; generate_and_save_mesh sets the size everywhere else:

ball = gmsh.model.mesh.field.add("Ball")
for key, value in (("XCenter", 0.0), ("YCenter", 0.0), ("ZCenter", 0.0), ("Radius", GAP4),
                   ("VIn", fine_near_gap), ("VOut", size)):
    gmsh.model.mesh.field.setNumber(ball, key, value)
gmsh.model.mesh.field.setAsBackgroundMesh(ball)
generate_and_save_mesh(path, size)

With the gap aligned, λ/10 elsewhere and \(W/3\) near the feed, the dipole has 44 unknowns and \(Z_\mathrm{in}\) = 70.6 − 5.2j Ω; λ/20 elsewhere, 60 unknowns, 71.0 − 3.7j Ω; uniform λ/120, 297 unknowns, 73.0 + 5.5j Ω. The resistance agrees within 2.4 Ω. The reactance differs by up to 10 Ω between these gmsh meshes: it depends on how the triangles are laid across the 10 mm width, which a single size does not control.

The solver also has an adaptive refinement loop that refines where the solution asks for it (Experimental, harmolab/utils/refinement/h_refinement_loop.py); see Geometry and meshing.

The helpers#

gmsh_function.mesh_and_gap_parameters(frequency, resolution=20, gap_fraction=0.15, n_edges_min=3) returns an element size of λ/resolution and a gap of gap_fraction × λ, and makes the element smaller if fewer than n_edges_min elements would fit in the gap. It does not make the gap edges mesh lines (draw the gap as above) and does not know the width of the conductor (keep \(W\) at least as wide). check_simulation_stability checks, after a run, the input resistance range, the gap to element ratio and the element size against λ/10 and λ/100.

Next#

Geometry and meshing

Drawing antennas with gmsh

Geometry and meshing
Excitations

How the gap source is built

Excitations and input impedance
Numerical limits

Cost and conditioning of fine meshes

Numerical limits and conditioning