Ports#
Draft Written from harmolab/utils/ports/ (specs.py, core.py, delta_gap.py, enhanced_gap.py) and its tests at commit 72fb8c6; every number comes from documentation/figure_notebooks/theory_ports.ipynb (ports.json). Awaiting review.
A port is where and how an antenna is fed: a voltage applied across a gap, and the current that crosses it. The solver has three port models, an enhanced gap of finite width and two delta gaps, and treats all of them with the same few formulas, because each one is a real vector on the RWG edges. This page derives that common framework, describes the three models and their checks, and explains why a port is given by its geometry and placed on the mesh by the solver. How to choose and use them is on Ports: feeding an antenna; the field model of the gap itself is on Excitations and input impedance.
One framework: a real vector per port#
Let \(\mathbf b_p \in \mathbb R^N\) be the vector of port \(p\) on the \(N\) RWG edges, and \(B = [\mathbf b_1 \cdots \mathbf b_P]\) (\(N\times P\)) for \(P\) ports. With \(v_p\) the complex voltage of port \(p\) (peak value, \(v_p = |v_p|\,e^{j\varphi_p}\)):
with \(P_p = \mathrm{Re}\,S_p\) the active power delivered by port \(p\) and \(Q_p = \mathrm{Im}\,S_p\) the reactive power. When several ports are driven together, \(Z_{\mathrm{in},p}\) is the active impedance of port \(p\), the other ports being driven too.
Why the same vector gives both \(V\) and \(i_p\). For a delta gap on a set of edges \(S_p\) crossed in
the direction \(\hat{\mathbf u}_p\) (docstring of core.py):
the RWG function \(\mathbf f_n\) carries the current \(\ell_n I_n\) across its edge, from \(T_n^+\) to \(T_n^-\) (RWG basis functions), so the current across the port, counted along \(\hat{\mathbf u}_p\), is \(i_p = \sum_{n\in S_p} s_n \ell_n I_n\) with \(s_n = \mathrm{sign}\big((\mathbf c_n^- - \mathbf c_n^+)\cdot\hat{\mathbf u}_p\big)\), the sign of the edge against the port direction (\(\mathbf c_n^\pm\): centroids of \(T_n^\pm\));
a voltage \(v_p\) across the cut, \(\mathbf E^i = v_p\,\delta(n)\,\hat{\mathbf u}_p\), tested with \(\mathbf f_m\), gives \(V_m = s_m \ell_m v_p\), Makarov’s \(V_m = \ell_m V\) generalised to several edges and to either orientation.
Both are \(\mathbf b_p\) with \((\mathbf b_p)_n = s_n\ell_n\) on the edges of the cut and 0 elsewhere. A
lumped load \(Z_L\) on a one-edge port is \(Z \leftarrow Z + Z_L\,\mathbf b_p\mathbf b_p^\mathsf T\), which
is exactly \(Z_{mm} \leftarrow Z_{mm} + \ell_m^2 Z_L\) of rwg3.calculate_z_matrice_lumped_elements.
For the enhanced gap, eq. (7) of Ding et al.[1], integrated exactly (Eq. (23)), is linear in the gap voltage: \(V = \mathbf b_p v_p\) with \(\mathbf b_p\) given by Eq. (23) for \(V = 1\). Its current is defined in the same way, \(i_p = \mathbf b_p^\mathsf T I\), so that the two following identities hold for every model.
The input impedance equals the power definition#
Before the port refactoring, rwg4.compute_port_results defined the input impedance of a gap from
the complex power delivered on its own edges, Eq. (24) of Excitations and input impedance:
\(S_p = \tfrac12\sum_{m\in S_p} V_m I_m^*\) and \(Z = |v_p|^2/(2S_p^*)\). If the ports do not overlap,
\(V_m = (\mathbf b_p)_m v_p\) on the edges of port \(p\), and \(\mathbf b_p\) is real, so
The two definitions are the same number. The notebook checks it on a strip fed by an enhanced gap and a delta-gap cut together (1 V and 0.5 V at 0.7 rad): relative differences of \(4.8\times10^{-17}\) and \(9.1\times10^{-17}\).
Energy identity#
The total input power of the system is \(\tfrac12\mathrm{Re}\{V^\mathsf T I^*\}\). Since \(V = Bv\) and \(B\) is real,
The port powers add up to the input power; on the same two-port case the relative difference is \(1.9\times10^{-16}\). Forbidding overlaps is what makes each \(P_p\) also the power delivered on the port’s own edges, as in Eq. (26): on an edge shared by two ports, \(V_m\) would be the sum of both voltages and neither port would be an independent terminal.
The three models#
Figure 9 The three models on a 60 × 12 mm strip meshed by gmsh (4 mm elements, 132 triangles, 179 RWG
edges), the line \(x = 0\) being a mesh line. (a) DeltaGapEdge: one edge, \(b = +\ell = +4.00\) mm.
(b) DeltaGapCut: the three edges of the cut, each \(+4.00\) mm; the arrows go from the centroid of
\(T^+\) to that of \(T^-\), and their sign against the direction \(\mathbf u\) is \(s = +1\) on all three.
(c) EnhancedGap with \(W\) = 15 mm: the cube (dashed, seen from above) spans the strip, its sides at
\(x = \pm 7.5\) mm cut through triangles, and the part of each triangle inside it is fed (shaded); 65
edges receive a weight, from \(-0.43\) to \(+0.60\) mm (colour).
Generated by documentation/figure_notebooks/theory_ports.ipynb on solver commit 72fb8c6; values in ports.json. Click to enlarge.#
DeltaGapEdge: one RWG edge#
The delta gap of Makarov[2], on a single “feeding edge”. Among the edges whose unit
vector \(\hat{\mathbf e}_n\) is perpendicular to direction (\(|\hat{\mathbf e}_n\cdot\hat{\mathbf u}| <\)
orientation_tol, \(10^{-3}\) by default), port_from_edge takes the one whose midpoint is closest to
point: the rule of the lumped loads of rwg3, with the same tie-breaking, so a load and a port
given the same point and direction sit on the same edge. \(\mathbf b_p\) has one non-zero entry,
\(s\,\ell\).
On a strip one cell wide, the cut across it is a single edge, and DeltaGapEdge is the same port
as DeltaGapCut (on the 10 mm dipole at λ/60, both give 71.779 − 0.907j Ω). On a conductor several
cells wide it feeds one edge of the cut only, and the neighbouring edges of the same cut, which
are metal, short the source: see Figure 18 and Figure 19
on Ports: feeding an antenna. Nothing warns about it.
DeltaGapCut: every edge of a cut#
port_from_cut collects every RWG edge whose two end points lie within tol (\(10^{-9}\) m by
default) of the segment from p_start to p_end, and orients each one with \(s_n\) against
direction. It refuses the port, with a message saying what to change, when:
no edge lies on the segment (the cut must follow a line of mesh vertices, inside the mesh: boundary edges carry no RWG function);
directionis parallel to the cut, or gives a zero sign on an edge;the sign from
directiondiffers from the sign from its component perpendicular to the cut on some edge (direction too oblique);the edges found do not cover the segment: \(\big|\sum_n \ell_n - |\mathbf p_\mathrm{end} - \mathbf p_\mathrm{start}|\big| >\)
tol(cut longer than the conductor, partly off mesh edges, or crossing a junction whose duplicated edges would be counted twice).
A delta gap has no width: the whole voltage drops across a line. This is the model of the reduced multiport and optimisation module (Reduced multiport model and load optimisation).
EnhancedGap: a field of finite width#
The enhanced gap source of Ding et al.[1], described on Excitations and input impedance: a uniform field
\(v/W\) along axis ('x', 'y' or 'z') in a cube of side \(W\) = gap_width centred on
feed_point, integrated exactly over the part of each triangle inside the cube. Every RWG function
with a triangle in the cube belongs to the port, with the weight Eq. (23); a weight can
be 0 (for instance when \(\boldsymbol\rho\cdot\hat{\mathbf e} = 0\)), the edge still belongs to the port.
enhanced_gap_port raises GapSourceError when no edge is in the cube, and emits
GapSourceWarning when the conductor crosses the gap outside the cube (below).
A port is geometry; the solver places it on the mesh#
The high-level solvers (radiation_algorithm, frequency_sweep, run_radiation_refinement) build
the RWG mesh themselves from path.msh, and calculate_current_radiation reads the one they saved. A
port given as a list of edge indices could not be written before that mesh exists, and would stop
meaning anything once the mesh changes. So a port is given as a specification, geometry only (specs.py):
Specification |
Fields |
Placed by |
|---|---|---|
|
|
|
|
|
|
|
|
|
The specifications are frozen dataclasses of plain numbers, checked when they are created (a
non-empty name, finite 3-vectors, a positive gap_width, an axis among 'x', 'y', 'z'). They do
not depend on the mesh; .resolve(points, triangles, edges, vecteurs_rho) places one on a mesh, and
resolve_ports places a list and checks that the names are unique and that no two ports share an
edge. radiation_algorithm checks the ports and the voltages (check_ports_and_voltages) before any
mesh work, and places the ports right after the RWG data are built, before the impedance matrix
is assembled: a port that finds no edge fails in a fraction of a second, not after the most expensive
step.
The same specification lands on different edges of different meshes. An EnhancedGap of 20 mm on the
10 mm dipole feeds 12 of 48 edges at λ/20, 12 of 148 at λ/60 and 22 of 288 at λ/120, with different
indices each time; a DeltaGapCut across a 40 mm strip is the edges 44, 47, 50, 53 of 106 on one
mesh, 154, 157, 160, 163 of 326 on another, eight edges of 1326 on a third. This is why a project
stores the geometry of its ports, never edge indices: indices kept from one mesh would silently feed
other edges of the next one (the solver can only check that they are within range).
Limits and errors#
Figure 10 An enhanced gap narrower than the conductor. 40 mm strip, 300 MHz, λ/60 along. (a) With
\(W\) = 30 mm and 4 cells across, the cube (dashed) covers only the middle of the gap cross-section;
the hatched parts of the gap are not fed. (b) Input impedance against the number of cells across.
With \(W\) = 30 mm: 139.9 + 19.3j, 135.1 + 40.6j, 30.5 + 69.6j and 1.4 + 19.9j Ω for 1, 2, 4 and 8
cells, and GapSourceWarning every time (circled). With \(W\) = 50 mm, wider than the strip:
78.6 + 12.5j to 79.7 + 16.9j Ω, no warning.
Generated by documentation/figure_notebooks/theory_ports.ipynb on solver commit 72fb8c6; values in ports.json. Click to enlarge.#
The enhanced gap must be at least as wide as the conductor. Inside the cube the field is applied; the rest of the gap cross-section is not fed. When a cell spans the whole width, it is fed in proportion to its part inside the cube, so the applied voltage, and \(Z_\mathrm{in}\) with it, is wrong by a factor that depends on the mesh (Figure 10; on the one-cell strip of Ding et al., \(Z_\mathrm{in}\) grows as \((w/W)^2\), see Excitations and input impedance).
enhanced_gap_portthen warns:GapSourceWarning: Port 'feed': the conductor crosses the gap outside the gap window (gap_width=0.03 m, a cube centred on feed_point=[0. 0. 0.]): 4 triangle(s) in the gap reach beyond it across the conductor and are not fed, so only part of the gap cross-section is excited and the input impedance is wrong. Make gap_width at least as wide as the conductor at the feed.
Surfaces perpendicular to the excitation axis (a ground plane under a monopole fed along its axis) carry no current across the gap and are not flagged.
Axes. The enhanced gap is along
'x','y'or'z'only. The delta gaps take anydirection, provided it crosses the cut.gap_widthis required, port by port. It has no default any more (it was 0.05 m inradiation_algorithmandfrequency_sweep, 1 mm inrun_radiation_refinement).No overlap, unique names, one voltage per port.
DeltaGapEdgeon a conductor several cells wide feeds one edge of the cut and is shorted by the others, without a warning (see above).Edges of weight zero. A triangle that only touches a face of the cube can come out of the clipping with an area fraction of order \(10^{-17}\) (rounding). Its edges are then counted in the port with a weight of order \(10^{-34}\) m or exactly 0: this changes neither \(V\) nor \(Z_\mathrm{in}\), but adds edges to
edge_indices(two of the seven edges of the case of Figure 7).
Errors. Every port error is a PortDefinitionError, a ValueError; GapSourceError (no edge
in the cube) is a subclass of it, so one except PortDefinitionError catches all of them.
GapSourceWarning is a UserWarning. The messages say what to change. Recorded by the notebook on
the 10 mm dipole (λ/60, 2 cells across):
Mistake |
Message |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
an |
|
two ports named |
|
one voltage for two ports |
|
In this solver#
Theory vs. implementation
Where each part of this page lives.
Function or class |
Role |
|---|---|
|
the only import point of the port models ( |
|
specifications, placement on the mesh, early checks |
|
Eq. (25) for ports of any model, mixed or not |
|
the two delta gaps |
|
the enhanced gap source |
|
places the ports (or takes ports already placed), solves, returns |
PortResult holds name, voltage, current (\(i_p\)), impedance, power and reactive_power.
Tests. test/test_ports_unified.py (superposition, Eq. (26) and
Eq. (27) for any current, mixed models, overlaps refused), test/test_ports_specs.py
(specifications, resolution, early checks), test/test_ports_package.py (the former modules and feed
arguments are gone), test/test_gap_source.py and test/test_gap_source_partial.py (the cube window,
the exact integration against a Monte-Carlo integration, the warning), test/test_frequency_sweep.py
(the solvers take ports and voltages; a port without edge fails before the assembly).
Continue#
Choosing a model, the call, migrating old code
The field of the enhanced gap, validation against Ding et al.
Ports as terminals of a reduced model