harmolab.utils.ports — ports#

Tous les modèles de port du solveur, importés d’un seul endroit : from harmolab.utils.ports import .... Théorie : Ports ; utilisation : Ports : alimenter une antenne.

Paquet#

Ports of an RWG mesh: where and how an antenna is fed.

One import point for every port model of the solver:

    from harmolab.utils.ports import EnhancedGap, DeltaGapCut, DeltaGapEdge, ...

specs         -- port specifications, geometry only (what the high-level solvers
                 take and what a project stores): EnhancedGap, DeltaGapCut,
                 DeltaGapEdge; resolve_ports places them on a mesh
core          -- Port (delta gap: RWG edges + signs), PortLike, incidence_matrix,
                 excitation_vector, port_results / PortResult, PortDefinitionError
delta_gap     -- delta-gap ports on a cut of mesh edges: port_from_cut, port_from_edge
enhanced_gap  -- enhanced gap source of Ding et al. 2013: enhanced_gap_port /
                 EnhancedGapPort, GapSourceError, GapSourceWarning

Every port is a real vector b_p on the RWG edges: V = B v, i = B^T I,
Z_in = v / i, whatever the model (see core.py).

    from harmolab.src.radiation_algorithm.radiation_algorithm import radiation_algorithm
    ports = [EnhancedGap("feed", feed_point=(0, 0, 0), axis="x", gap_width=1e-3)]
    result = radiation_algorithm(path, 2.4e9, ports, voltages=[1.0])
    result.ports[0].impedance

This is the only path to the ports: the former modules harmolab.optim.ports and
harmolab.utils.gap_source, the re-export by harmolab.optim, the feed arguments
(feed_point, voltage_amplitude, excitation_unit_vector, gap_width,
voltage_phase), multiple_gap_sources and rwg4.compute_port_results were removed.

specs — spécifications de ports#

Port specifications: where a port is, described by geometry only.

A specification does not depend on the mesh. It is what the high-level solvers take (radiation_algorithm, frequency_sweep, calculate_current_radiation) and what a project will store: those solvers build the mesh themselves, so the port can only be placed on the RWG edges once the mesh exists. .resolve(…) does that, with every check of delta_gap / enhanced_gap.

EnhancedGap(« feed », feed_point=(0, 0, 0), axis= »x », gap_width=1e-3) Ding et al. 2013 DeltaGapCut(« feed », p_start=(0, -w/2, 0), p_end=(0, w/2, 0), direction=(1, 0, 0)) DeltaGapEdge(« feed », point=(0, 0, 0), direction=(1, 0, 0)) one RWG edge

All lengths in metres. The excitation (one complex voltage per port) is given separately: a port says where and how, the voltage says how much.

class harmolab.utils.ports.specs.EnhancedGap(name: str, feed_point: tuple, axis: str, gap_width: float)[source]#

Bases : object

Enhanced gap source (Ding et al. 2013): uniform field V/W in a cube of side gap_width centred on feed_point, along axis. Resolves to EnhancedGapPort.

name: str#
feed_point: tuple#
axis: str#
gap_width: float#
property location: ndarray#

Point shown as the feed in plots (m).

resolve(points, triangles, edges, vecteurs_rho)[source]#
class harmolab.utils.ports.specs.DeltaGapCut(name: str, p_start: tuple, p_end: tuple, direction: tuple, tol: float = 1e-09)[source]#

Bases : object

Delta gap across the cut [p_start, p_end] made of RWG edges, current positive along direction. Resolves to Port (port_from_cut).

name: str#
p_start: tuple#
p_end: tuple#
direction: tuple#
tol: float = 1e-09#
property location: ndarray#

Middle of the cut (m).

resolve(points, triangles, edges, vecteurs_rho=None)[source]#
class harmolab.utils.ports.specs.DeltaGapEdge(name: str, point: tuple, direction: tuple, orientation_tol: float = 0.001)[source]#

Bases : object

Delta gap on the single RWG edge nearest to point that lies across direction (rule of the lumped loads). Resolves to Port (port_from_edge).

name: str#
point: tuple#
direction: tuple#
orientation_tol: float = 0.001#
property location: ndarray#
resolve(points, triangles, edges, vecteurs_rho=None)[source]#
harmolab.utils.ports.specs.check_ports_and_voltages(specs: Sequence, voltages) → tuple[list, ndarray][source]#

Cheap checks done before any mesh work: at least one port, every item a port specification, unique names, one complex voltage per port. Returns (list of specs, complex voltages).

harmolab.utils.ports.specs.resolve_ports(specs: Sequence[EnhancedGap | DeltaGapCut | DeltaGapEdge], points, triangles, edges, vecteurs_rho) → list[PortLike][source]#

Place every port on the RWG mesh. Raises PortDefinitionError (or its subclass GapSourceError) with a message saying what to fix if a port finds no edge, has a bad direction, or two ports share an edge.

core — Port, matrice d’incidence, résultats des ports#

Ports of an RWG mesh: the Port object and the incidence matrix.

A port p is a set of RWG edges S_p that together form a cut across a strip, plus a unit vector u_p giving the positive current direction across that cut. Its incidence vector a_p in R^N is

(a_p)_n = s_n * l_n if n in S_p, 0 otherwise, s_n = sign( (c_n^- - c_n^+) . u_p ),

where l_n is the edge length and c_n^+/- the centroids of the triangles T_n^+/-.

Why this is the right vector (conventions checked in harmolab.utils.impedance.impmet):

  • The RWG function f_n carries current from T_n^+ to T_n^- across edge n, and its normal component on the edge is 1, so the total current crossing edge n in the T^+ -> T^- direction is l_n * I_n. Hence the current across the port, counted positive along u_p, is

    i_p = a_p^T I.

  • A delta-gap voltage v_p across the cut, i.e. E_inc = v_p delta(n) u_p, tested with f_m gives <f_m, E_inc> = s_m l_m v_p (Makarov’s V_m = l_m V generalised to several edges and to either edge orientation), so

    V = a_p v_p.

  • A lumped load Z_L on a single-edge port is therefore Z += Z_L a_p a_p^T, i.e. Z_mm += l_m^2 Z_L – exactly rwg3.calculate_z_matrice_lumped_elements.

With P ports, A = [a_1 … a_P] (N x P): V = A v, i = A^T I.

The functions that build a Port from a geometry are in delta_gap.py.

Every port model, one formula#

The enhanced gap source (enhanced_gap.py) is also described by a real vector b_p on the RWG edges: eq. (7) of Ding et al. is linear in the gap voltage, so V = b_p v_p. Any object with name, edge_indices and incidence_vector(edges) is a port (PortLike), and for all of them

V = B v, i_p = b_p^T I, Z_in,p = v_p / i_p, S_p = 1/2 v_p i_p*.

For an enhanced gap with non-overlapping ports, Z_in,p = v_p / i_p equals the impedance derived from the complex power 1/2 sum V_n I_n* over the feeding edges (b_p is real), the definition of the former rwg4.compute_port_results: the two agree. i_p itself is the physical current b_p^T I (the former “gap_current” carried an extra phase factor e^{-j phase}).

exception harmolab.utils.ports.core.PortDefinitionError[source]#

Bases : ValueError

Raised when a port cannot be defined unambiguously on the RWG mesh.

class harmolab.utils.ports.core.PortLike(*args, **kwargs)[source]#

Bases : Protocol

What every port model provides (Port, EnhancedGapPort).

name: str#
edge_indices: ndarray#
incidence_vector(edges) → ndarray[source]#

Real vector b_p, shape (N,): V = b_p v_p, i_p = b_p^T I.

class harmolab.utils.ports.core.Port(name: str, edge_indices: ndarray, signs: ndarray, direction: ndarray)[source]#

Bases : object

One port: a cut made of RWG edges with a positive current direction.

Attributes
----------
name         : str               label used in results
edge_indices : (n_p,) int        RWG edges forming the cut
signs        : (n_p,) float      s_n = +1/-1, orientation of each edge w.r.t. `direction`
direction    : (3,) float        unit vector u_p, positive current direction across the cut

The arrays are stored as read-only copies so a Port can be shared safely.
name: str#
edge_indices: ndarray#
signs: ndarray#
direction: ndarray#
property n_edges: int#
width(edges) → float[source]#

Total length of the cut, sum_{n in S_p} l_n (m).

incidence_vector(edges) → ndarray[source]#

a_p, shape (N,): (a_p)_n = s_n l_n for n in S_p, 0 elsewhere.

Delta-gap excitation V = a_p v_p ; port current i_p = a_p^T I.

harmolab.utils.ports.core.incidence_matrix(ports: Sequence[PortLike], edges) → ndarray[source]#

A = [a_1 … a_P], shape (N, P), for ports of any model (they may be mixed).

Raises PortDefinitionError if the list is empty, if two ports share a name, or if two ports share an edge (the ports would not be independent terminals: V = A v would add both voltages on the shared edge).

harmolab.utils.ports.core.excitation_vector(ports: Sequence[PortLike], edges, voltages) → ndarray[source]#

V = B v, shape (N,), complex: the right-hand side for port voltages v.

voltagesone complex value per port, v_p = amplitude * exp(1j * phase)

(phase in radians), in volts.

The ports are checked as in incidence_matrix (unique names, no shared edge).

class harmolab.utils.ports.core.PortResult(name: str, voltage: complex, current: complex, impedance: complex, power: float, reactive_power: float)[source]#

Bases : object

What a solved current I gives at one port.

voltage : v_p, the source voltage (V) current : i_p = b_p^T I, the current across the port (A) impedance : Z_in = v_p / i_p (Ohm); inf if i_p = 0 power : P = 1/2 Re(v_p i_p*), active power delivered by the port (W) reactive_power : Q = 1/2 Im(v_p i_p*) (var)

name: str#
voltage: complex#
current: complex#
impedance: complex#
power: float#
reactive_power: float#
harmolab.utils.ports.core.port_results(ports: Sequence[PortLike], edges, current, voltages) → list[PortResult][source]#

Per-port voltage, current, input impedance and power, for any port model.

current : (N,) complex, the solution I of Z I = V voltages : one complex value per port, the v_p used to build V

With several ports driven together, Z_in,p is the active impedance of port p (the others driven too).

delta_gap — delta-gaps sur les arêtes du maillage#

Delta-gap ports: a voltage applied across a cut made of RWG edges.

Two ways to build a Port (core.py) from a geometry:

  • port_from_cut – every RWG edge lying on a segment across the conductor;

  • port_from_edge – a single edge, with the rule of

    rwg3.calculate_z_matrice_lumped_elements.

The excitation is V = a_p v_p and the port current i_p = a_p^T I, with the incidence vector a_p explained in core.py.

harmolab.utils.ports.delta_gap.port_from_cut(points, triangles, edges, p_start, p_end, direction, name, tol=1e-09) → Port[source]#
Port made of all RWG edges lying ON the segment [p_start, p_end].

An edge is selected when both its endpoints are within `tol` (metres) of
the segment. Its sign is s_n = sign((c_n^- - c_n^+) . u), u = direction/|direction|.

Raises PortDefinitionError, with a message saying what to change, if
  * no edge lies on the segment (cut off the mesh, or not on mesh lines);
  * `direction` runs along the cut instead of across it, or gives a zero
    sign on some edge (no component across that edge);
  * the sign from `direction` disagrees with the sign from its component
    perpendicular to the cut on some edge (direction too oblique to define
    an orientation unambiguously);
  * the selected edges do not cover the segment:
    | sum_n l_n - |p_end - p_start| | > tol  (cut partly off the conductor,
    or crossing a T-junction whose duplicated edges would be counted twice).
harmolab.utils.ports.delta_gap.port_from_edge(points, triangles, edges, point, direction, name, orientation_tol=0.001) → Port[source]#
Single-edge port, selected with the same rule as
rwg3.calculate_z_matrice_lumped_elements: among the edges whose unit vector
e_n = (P1 - P2)/l_n satisfies |e_n . u| < orientation_tol (edge perpendicular
to the current direction), take the one whose midpoint is closest to `point`.

The direction is normalised first; for a unit `direction` (the normal use of
LoadDir) the selected edge is the one rwg3 picks. The sign is
s = sign((c^- - c^+) . u), as for port_from_cut.

Raises PortDefinitionError if no edge is perpendicular to `direction`, or if
the selected edge's sign is 0.

enhanced_gap — source à gap amélioré#

Enhanced gap source (Ding et al., 2013, eq. 7): a uniform field V/W over a
gap of width W around a feed point, feeding every RWG function that has a
triangle in the gap.

enhanced_gap_port(...) -> EnhancedGapPort gives the port as a real vector b_p
on the RWG edges, like the delta-gap Port (core.py): V = b_p v_p and the port
current i_p = b_p^T I. Eq. (7) is linear in the gap voltage, which is why one
vector describes the port. The high-level solvers take the specification
EnhancedGap (specs.py), resolved with this function once the mesh exists.

Partial triangles (exact integration)
-------------------------------------
E^i = (V/W) e_hat inside the window, so eq. (7) is
    V_m = (V/W) e_hat . integral over (T_m^+- inside the window) of f_m dS.
f_m is linear on each triangle, so the integral over the clipped part of a
triangle (area A_c, centroid r_cc) is exact with one point:
    integral = (l_m / 2A) A_c (r_cc - v^+)      on T^+,
               (l_m / 2A) A_c (v^- - r_cc)      on T^-.
For a triangle entirely inside, A_c = A and r_cc is its centroid: the
centroid rule of the paper. The two differ only on triangles cut by the edge
of the window. The centroid rule (removed with multiple_gap_sources) fed such
a triangle wholly or not at all depending on where its centroid fell, so the
applied voltage jumped from one mesh to the next: on a gmsh dipole whose gap
edges were not mesh lines, the input resistance ranged from 63 to 182 Ohm
instead of 72 Ohm (documentation, user guide "Choosing the mesh size").

Gap localisation (a cube, not a band)
-------------------------------------
The gap window is a cube of side `gap_width` centred on the feed point,
tested on all three coordinates -- not just the excitation axis. For a simple
1D wire/strip (the case eq. 7 was derived for), the structure's cross-section
is already far smaller than gap_width, so this is equivalent to testing the
excitation axis alone. It stops being equivalent at a junction between
differently oriented surfaces sharing the feed point (e.g. a monopole blade
standing on a ground plane): testing only the excitation-axis coordinate
would then also catch far-away triangles that merely share that coordinate
with the feed point (a whole band of the ground plane), spuriously exciting
geometry unrelated to the feed. The cube keeps the excitation local.
exception harmolab.utils.ports.enhanced_gap.GapSourceError[source]#

Bases : PortDefinitionError

Raised when a gap-source excitation finds no RWG edge to feed.

A PortDefinitionError (hence a ValueError): one exception type covers every port model.

exception harmolab.utils.ports.enhanced_gap.GapSourceWarning[source]#

Bases : UserWarning

Emitted when the conductor crosses the gap outside the gap window (part of it is not fed).

class harmolab.utils.ports.enhanced_gap.EnhancedGapPort(name: str, edge_indices: ndarray, weights: ndarray, feed_point: ndarray, axis: str, gap_width: float)[source]#

Bases : object

One enhanced gap source, as a port: the real vector b_p on the RWG edges.

Attributes
----------
name         : str          label used in results
edge_indices : (n_p,) int   RWG edges with a triangle in the gap (the "feeding edges")
weights      : (n_p,) float b_p on those edges:  l_m / (2W) [chi+ (rho+ . e + shift+)
                                                 + chi- (rho- . e + shift-)]
feed_point   : (3,) float   centre of the gap cube (m)
axis         : 'x' | 'y' | 'z'  excitation direction e_hat
gap_width    : float        W, side of the gap cube (m)

V = b_p v_p (eq. 7 for a gap voltage v_p) and i_p = b_p^T I. A weight may
be 0 on a feeding edge (rho . e = 0 there); the edge still belongs to the
port (it has a triangle in the gap).
name: str#
edge_indices: ndarray#
weights: ndarray#
feed_point: ndarray#
axis: str#
gap_width: float#
property n_edges: int#
incidence_vector(edges) → ndarray[source]#

b_p, shape (N,): the weights on the feeding edges, 0 elsewhere.

harmolab.utils.ports.enhanced_gap.enhanced_gap_port(points, triangles, edges, vecteurs_rho, feed_point, axis, gap_width, name) → EnhancedGapPort[source]#

Enhanced gap source at feed_point as a port (see EnhancedGapPort).

Cube of side gap_width centred on feed_point, eq. (7) integrated exactly over the part of each triangle inside it. For a gap voltage v the excitation is V = v * port.incidence_vector(edges).

Raises PortDefinitionError for an invalid axis, gap_width or feed_point, and GapSourceError (a PortDefinitionError) if no RWG edge is in the gap. Emits GapSourceWarning when the conductor crosses the gap outside the cube.