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}\)):

(25)#\[V = B\,v = \sum_p \mathbf b_p\, v_p, \qquad i_p = \mathbf b_p^\mathsf T I, \qquad Z_{\mathrm{in},p} = \frac{v_p}{i_p}, \qquad S_p = \tfrac12\, v_p\, i_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

(26)#\[S_p = \tfrac12\, v_p \sum_{m\in S_p} (\mathbf b_p)_m I_m^* = \tfrac12\, v_p\, \big(\mathbf b_p^\mathsf T I\big)^* = \tfrac12\, v_p\, i_p^*, \qquad \frac{|v_p|^2}{2\,S_p^*} = \frac{|v_p|^2}{v_p^*\, i_p} = \frac{v_p}{i_p}.\]

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,

(27)#\[\tfrac12\, V^\mathsf T I^* = \tfrac12\, v^\mathsf T B^\mathsf T I^* = \tfrac12 \sum_p v_p\, i_p^* \quad\Longrightarrow\quad \sum_p P_p = \tfrac12\,\mathrm{Re}\{V^\mathsf T I^*\}.\]

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#

Three views of the same small strip mesh. (a) one vertical edge at x = 0 drawn in blue, with an arrow and the sign +1. (b) the three edges of the vertical line x = 0 in blue, each with an arrow and the sign +1, and an arrow labelled direction u. (c) a dashed square of 15 mm around the centre, the part of the triangles inside it shaded, and about sixty edges coloured from orange (negative) to blue (positive) by their weight.

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);

  • direction is parallel to the cut, or gives a zero sign on an edge;

  • the sign from direction differs 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

EnhancedGap

name, feed_point, axis, gap_width

enhanced_gap_port → EnhancedGapPort

DeltaGapCut

name, p_start, p_end, direction, tol=1e-9

port_from_cut → Port

DeltaGapEdge

name, point, direction, orientation_tol=1e-3

port_from_edge → Port

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#

(a) Close-up of a 40 mm strip with 4 cells across; a dashed 30 mm square around the feed is shaded inside, the parts of the gap band above and below it are hatched. (b) Input resistance and reactance against cells across the width: with a 30 mm gap they vary wildly, from 140 ohms to 1.4 ohms, all points circled as warned; with a 50 mm gap they stay near 79 ohms.

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_port then 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 any direction, provided it crosses the cut.

  • gap_width is required, port by port. It has no default any more (it was 0.05 m in radiation_algorithm and frequency_sweep, 1 mm in run_radiation_refinement).

  • No overlap, unique names, one voltage per port.

  • DeltaGapEdge on 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

EnhancedGap(..., axis="w", ...)

PortDefinitionError: Port 'feed': axis must be 'x', 'y' or 'z', got 'w'. (at creation)

EnhancedGap 0.5 m away from the strip

GapSourceError: Port 'feed' (feed_point=[0.  0.5 0. ], axis='x', gap_width=0.02): no RWG edge found within the gap. Check that feed_point lies on (or very near) the mesh, that gap_width is large enough to reach at least one triangle on every side of the feed you intend to excite, and that the axis matches the actual direction current should flow at this feed [...]

DeltaGapCut at \(x\) = 3 mm, between two lines of vertices

PortDefinitionError: Port 'feed': no RWG edge lies on the segment [ 0.003 -0.005  0.   ] -> [0.003 0.005 0.   ] (tol = 1e-09 m). The cut must follow mesh edges: place it on a line of mesh vertices across the conductor (and inside the mesh, not on its boundary -- boundary edges carry no RWG function), or increase tol if the coordinates are only approximately aligned.

DeltaGapCut with direction along the cut

PortDefinitionError: Port 'feed': direction [0. 1. 0.] is parallel to the cut [...]. The direction is the current flow ACROSS the port: for a transverse cut of a strip it must point along the strip.

DeltaGapCut 16 mm long on the 10 mm strip

PortDefinitionError: Port 'feed': the 2 edge(s) found on the cut have total length 0.01 m but the cut is 0.016 m long. Either the cut extends beyond the conductor (shorten it to the conductor's width), part of it does not lie on mesh edges, or it crosses a junction whose duplicated edges are counted twice.

DeltaGapEdge with direction normal to the strip

PortDefinitionError: Port 'feed': direction [0. 0. 1.] does not cross edge(s) [73] (sign of (c^- - c^+).direction is 0). The direction must point ACROSS the cut, tangent to the conductor [...]

an EnhancedGap and a DeltaGapCut at the same place

PortDefinitionError: Ports 'gap' and 'cut' share edge 70. Two ports cannot overlap: move one cut to another line of edges.

two ports named "gap"

PortDefinitionError: Port names must be unique; duplicated: ['gap'].

one voltage for two ports

PortDefinitionError: 2 port(s) but 1 voltage(s): give one complex voltage per port (amplitude * np.exp(1j * phase), phase in radians), in the order of the ports.

In this solver#

Theory vs. implementation

Where each part of this page lives.

Function or class

Role

harmolab.utils.ports

the only import point of the port models (from harmolab.utils.ports import ...)

EnhancedGap, DeltaGapCut, DeltaGapEdge, resolve_ports, check_ports_and_voltages (specs.py)

specifications, placement on the mesh, early checks

Port, incidence_matrix, excitation_vector, port_results, PortResult, PortDefinitionError (core.py)

Eq. (25) for ports of any model, mixed or not

port_from_cut, port_from_edge (delta_gap.py)

the two delta gaps

enhanced_gap_port, EnhancedGapPort, GapSourceError, GapSourceWarning (enhanced_gap.py)

the enhanced gap source

rwg4.calculate_current_radiation(path, ports, voltages, ...)

places the ports (or takes ports already placed), solves, returns (frequency, V, I, [PortResult])

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#

Use it: ports

Choosing a model, the call, migrating old code

Ports: feeding an antenna
Excitations

The field of the enhanced gap, validation against Ding et al.

Excitations and input impedance
Reduced multiport

Ports as terminals of a reduced model

Reduced multiport model and load optimisation

References#