Skip to content

Conductors

A Conductor connects two nodes of the network (electrodes or junctions) or two points: a PEN conductor of a low-voltage network, a cable screen, a bare bonding wire, an overhead earth wire or a measurement lead. Unlike an electrode it is not an equipotential body: it has a series impedance, and depending on its settings it carries inductance and leaks current into the soil along its length.

Mathematical and physical context

A conductor of length \(\ell\), wire radius \(a\), material resistivity \(\rho_\text{mat}\) and cross section \(A\) is a branch of the nodal system with

\[ Z_b(\omega) = R + j\omega L_\text{Neumann} + \Delta Z_\text{earth}(\omega), \qquad R = \rho_\text{mat}\,\ell / A , \]

where \(L_\text{Neumann}\) (self and mutual, from the segment geometry) and the earth-return correction \(\Delta Z_\text{earth}\) (Carson or Sommerfeld) are assembled in Coupling when the conductor sets inductance_model="neumann". The settings that decide the model:

Field Values Meaning
cross_section None (default) ideal connection: both end nodes form one galvanic cluster
float (m²) or "from_radius" (\(\pi a^2\)) finite resistance \(R = \rho_\text{mat}\ell/A\)
lumped_series_resistance_ohm Ω replaces the geometric \(R\)
discretize_segment_length m distributed conductor: a chain of branches with this segment length (needs a finite resistance)
coupling_to_soil "isolated" (default), "galvanic" insulated cable, or bare wire that leaks along its length like an electrode
inductance_model None (default), "neumann" resistive branch only, or Neumann inductance with the engine's earth-return model (Engine.earth_inductive_model)
resistance_model "dc" (default), "skin" \(R\) at every frequency, or the exact internal impedance of a solid round wire (Bessel functions)

Units. Lengths and radii in m, cross_section in m² (95 mm² is 95e-6), resistivity in Ω·m (copper 1.68e-8, the default). A cross section above MAX_PLAUSIBLE_CROSS_SECTION (10⁻² m²) warns with CrossSectionUnitWarning, because a value given in mm² would otherwise be a silent near-ideal short.

Skin effect. With resistance_model="skin" the internal impedance per unit length is

\[ Z'_\text{int} = \frac{k\,\rho_\text{mat}}{2\pi a}\,\frac{I_0(ka)}{I_1(ka)}, \qquad k = \sqrt{j\omega\mu_0/\rho_\text{mat}} \]

(Schelkunoff 1934), which tends to \(\rho_\text{mat}/(\pi a^2) + j\omega\mu_0/(8\pi)\) at low frequency. Below 1 kHz the effect matters only for thick conductors: the skin depth of copper at 1 kHz is about 2 mm.

Example

import groundfield as gf

world = gf.create_world(soil=gf.TwoLayerSoil(rho_1=100.0, rho_2=500.0, h_1=1.0))
gf.create_electrode(world, "ring", name="g1", center=(0.0, 0.0, 0.8), radius=3.0)
gf.create_electrode(world, "ring", name="g2", center=(40.0, 0.0, 0.8), radius=3.0)

pen = gf.create_conductor(
    world, name="pen_1", start="g1", end="g2",
    conductor_type="pen",
    cross_section=95e-6,             # 95 mm² in m²
    discretize_segment_length=2.0,   # distributed: about 20 inductive segments
    inductance_model="neumann",      # with the engine's earth-return model
)
assert abs(pen.length - 40.0) < 1e-12   # m, from (3, 0, 0.8) on g1 to (43, 0, 0.8) on g2
assert abs(pen.series_resistance - 1.68e-8 * 40.0 / 95e-6) < 1e-15   # 7.1 mΩ

The conductor object is geometry and material only; the earth-return model is chosen on the engine (earth_inductive_model, default "sommerfeld"), so the same world can be solved with different earth-return models. The theory is on the earth return page.

find_close_wires and find_close_conductors report pairs of wires that are closer than the thin-wire model allows (interpenetrating, crossing or very close); diagnose runs them before a solve.

API reference

conductors

Conductors, PEN, and cable shields.

Subpackage for all current-carrying elements above and inside the soil that are not electrodes themselves but still take part in the current distribution:

  • overhead lines (phase conductor, earth wire),
  • cables (phase + shield, concentric or three-core),
  • PEN conductors in TN low-voltage networks,
  • auxiliary electrodes for grounding measurements.
Contents

Conductor Single conductor segment with end-point coordinates and a type tag ("pen", "cable_shield", "bare_copper", "overhead", "generic"), its series resistance and — with resistance_model="skin" — its frequency-dependent internal impedance. ConductorType, ResistanceModel Literal unions of the supported type tags and resistance models. CrossSectionUnitWarning Raised for cross sections that look like mm² entered as m². solid_round_internal_impedance Exact internal impedance per unit length of a solid round wire (skin effect). find_close_wires, find_close_conductors, WireProximity Detection of close, interpenetrating and crossing wire pairs.

Notes

Carson corrections for the earth-return path are not computed here; they enter via groundfield.coupling. This keeps the conductor model purely geometric and material-based, so it can be combined with different earth-return models.

ConductorType module-attribute

ConductorType = Literal['pen', 'cable_shield', 'bare_copper', 'overhead', 'generic']

Kind of a conductor (Conductor.conductor_type).

  • "pen": PEN conductor of a low-voltage network;
  • "cable_shield": cable shield, a thin-walled tube around its core (user decisions Q32 / Q33);
  • "bare_copper": bare copper wire;
  • "overhead": overhead line or earth wire;
  • "generic": fallback.

MAX_PLAUSIBLE_CROSS_SECTION module-attribute

MAX_PLAUSIBLE_CROSS_SECTION = 0.01

Largest cross section in m² accepted without a warning (100 cm²).

Real conductors stay far below it; a value in mm² does not.

ResistanceModel module-attribute

ResistanceModel = Literal['dc', 'skin']

Series-resistance model of a conductor (Conductor.resistance_model).

  • "dc": rho * L / A at every frequency (the default);
  • "skin": the exact internal impedance of a solid round wire (Bessel solution).

Conductor

Bases: BaseModel

Wire segment between two points.

Attributes:

Name Type Description
name str

Unique name within the World.

start, end

Start and end point (x, y, z) in metres. z > 0 puts the conductor inside the soil, z < 0 above ground.

start_electrode, end_electrode

Optional name of the electrode anchored at start / end. If both are set, the solver inserts this conductor as a branch in the nodal analysis: ideal (cross_section=None) → hard cluster constraint, finite section → branch with \(R_\text{ser} = \rho L / A\).

conductor_type ConductorType

Type tag from ConductorType. "cable_shield" marks the shield of a concentric cable, a thin-walled tube (user decisions Q32 and Q33 of 2026.11): with inductance_model="neumann" a thinner conductor drawn on its axis, inside it, is its core and couples to it at the shield radius (the geometric mean distance of a point inside a tube), and its self inductance carries no internal inductance of a solid wire. Two conductors of other types on one axis are separate conductors that touch. The other tags only select plot styles.

wire_radius float

Wire radius in metres. Default 5 mm. Used for the geometric thin-wire approximation in the segment self-action and as a fallback for cross_section when the latter is given as "from_radius".

resistivity float

Material resistivity in \(\Omega\,\mathrm{m}\). Default: copper (1.68e-8).

cross_section float | Literal['from_radius'] | None

Conductor cross section in \(\mathrm{m}^2\). None (default) means ideal galvanic short — the conductor is a zero-impedance bridge. A finite value enables the nodal-analysis branch model with \(R_\text{ser} = \rho_\text{mat}\, L / A\). The string "from_radius" is a convenience shortcut for \(A = \pi r_\text{wire}^2\).

effective_cross_section property

effective_cross_section: float | None

Resolved cross section in \(\mathrm{m}^2\) or None.

Returns:

Type Description
float or None

None when cross_section is None (ideal-galvanic mode). Otherwise the explicit cross section in m² ("from_radius" resolved to \(\pi\, r_\text{wire}^2\)).

is_distributed property

is_distributed: bool

True iff the conductor is split into sub-segments.

A distributed conductor has a finite discretize_segment_length — the solver builds one longitudinal segment per sub-piece. False keeps the conductor lumped (single branch between the two end electrodes).

is_shield property

is_shield: bool

Whether the conductor is a cable shield ("cable_shield").

A shield is a thin-walled tube: no internal inductance of a solid wire, and a thinner conductor on its axis is its core (user decisions Q32 and Q33 of 2026.11).

length property

length: float

Euclidean length of the conductor in m.

n_segments property

n_segments: int

Number of segments produced by the discretiser.

Returns 1 for a lumped conductor. Otherwise \(n = \lceil L / \Delta s \rceil\) with \(L\) the Euclidean length and $\Delta s = $ discretize_segment_length, with the round-off allowance of the electrode wires (_segment_count()): a conductor that exceeds a whole number of pieces only through the round-off of its end points gets no extra piece. Up to the calendar release the count had no allowance, so a 60 m counterpoise in 10 m pieces got 7 instead of 6 at projected (UTM) coordinates, where its computed length is 60.0000000012 m.

series_resistance property

series_resistance: float

Series DC resistance \(R_\text{ser}\) in Ω.

Resolution order:

  1. If lumped_series_resistance_ohm is set (ADR-0012 V1 concrete-shell path or any user-supplied lumped override), return that value verbatim.
  2. Otherwise compute the geometric formula \(R = \rho_\text{mat}\, L / A\) from resistivity, length and effective_cross_section.
  3. If cross_section is None, the conductor is in the ideal-galvanic-short branch and the series resistance is 0.0.

Returns:

Type Description
float

Total series resistance in Ω consumed by the solver's distributed-conductor model (ADR-0003).

internal_impedance_per_length

internal_impedance_per_length(frequency: float | ndarray) -> complex | np.ndarray

Internal series impedance per unit length in Ω/m.

The conductor's own longitudinal impedance \(Z'_\text{int} = R'(f) + j\omega L'_\text{int}(f)\), excluding the external (thin-wire / earth-return) inductance of groundfield.coupling.

  • resistance_model="dc": \(R' = R_\text{ser}/L\) and the uniform-current internal inductance \(\mu_0/(8\pi)\) — the convention of groundfield.coupling.inductance.thin_wire_self_inductance() with include_internal=True; a "cable_shield" (a thin-walled tube) has none (user decision Q33). An ideal conductor has \(R' = 0\).
  • resistance_model="skin": the exact solid-round Bessel solution for the radius \(\sqrt{A/\pi}\) of the conducting cross section (solid_round_internal_impedance()).

Parameters:

Name Type Description Default
frequency float | ndarray

Frequency in Hz (scalar or array, >= 0).

required

Returns:

Type Description
complex or ndarray

Internal impedance per unit length in Ω/m.

Source code in src/groundfield/conductors/conductor.py
def internal_impedance_per_length(
    self, frequency: float | np.ndarray
) -> complex | np.ndarray:
    r"""Internal series impedance per unit length in Ω/m.

    The conductor's own longitudinal impedance $Z'_\text{int} =
    R'(f) + j\omega L'_\text{int}(f)$, excluding the external
    (thin-wire / earth-return) inductance of
    :mod:`groundfield.coupling`.

    - ``resistance_model="dc"``: $R' = R_\text{ser}/L$ and the
      uniform-current internal inductance $\mu_0/(8\pi)$ — the
      convention of
      :func:`groundfield.coupling.inductance.thin_wire_self_inductance`
      with ``include_internal=True``; a ``"cable_shield"`` (a
      thin-walled tube) has none (user decision Q33). An ideal
      conductor has $R' = 0$.
    - ``resistance_model="skin"``: the exact solid-round Bessel
      solution for the radius $\sqrt{A/\pi}$ of the conducting
      cross section
      (:func:`~groundfield.conductors.skin.solid_round_internal_impedance`).

    Parameters
    ----------
    frequency
        Frequency in Hz (scalar or array, ``>= 0``).

    Returns
    -------
    complex or np.ndarray
        Internal impedance per unit length in Ω/m.
    """
    f = np.asarray(frequency, dtype=float)
    if np.any(f < 0.0) or not np.all(np.isfinite(f)):
        raise ValueError("frequency must be finite and >= 0")
    if self.resistance_model == "skin":
        area = self.effective_cross_section
        assert area is not None  # guaranteed by the validator
        return solid_round_internal_impedance(
            frequency,
            radius=math.sqrt(area / math.pi),
            resistivity=self.resistivity,
        )
    length = self.length
    r_per_m = self.series_resistance / length if length > 0.0 else 0.0
    l_int = 0.0 if self.is_shield else _MU_0 / (8.0 * math.pi)
    z = r_per_m + 1j * 2.0 * math.pi * f * l_int
    if np.ndim(frequency) == 0:
        return complex(z)
    return z

is_ideal

is_ideal(threshold: float = _IDEAL_RESISTANCE_THRESHOLD) -> bool

Return True when the conductor acts as a galvanic short.

Parameters:

Name Type Description Default
threshold float

Resistance threshold in Ω. Conductors at or below this value are treated as ideal by the solver. Default 1e-6 Ω.

_IDEAL_RESISTANCE_THRESHOLD
Source code in src/groundfield/conductors/conductor.py
def is_ideal(self, threshold: float = _IDEAL_RESISTANCE_THRESHOLD) -> bool:
    """Return ``True`` when the conductor acts as a galvanic short.

    Parameters
    ----------
    threshold
        Resistance threshold in Ω. Conductors at or below this
        value are treated as ideal by the solver. Default
        ``1e-6 Ω``.
    """
    if self.cross_section is None:
        return True
    return self.series_resistance <= threshold

skin_correction_per_length

skin_correction_per_length(frequency: float | ndarray) -> complex | np.ndarray

Skin-effect correction to the DC convention, in Ω/m.

\(\Delta Z' = Z'_\text{int}(f) - [R'_\text{dc} + j\omega\mu_0/(8\pi)]\): what a solver that assembles \(R_\text{dc}\) and the DC internal inductance (include_internal=True) has to add per metre of branch length. Zero for resistance_model="dc".

Parameters:

Name Type Description Default
frequency float | ndarray

Frequency in Hz (scalar or array, >= 0).

required

Returns:

Type Description
complex or ndarray

Correction per unit length in Ω/m.

Source code in src/groundfield/conductors/conductor.py
def skin_correction_per_length(
    self, frequency: float | np.ndarray
) -> complex | np.ndarray:
    r"""Skin-effect correction to the DC convention, in Ω/m.

    $\Delta Z' = Z'_\text{int}(f) - [R'_\text{dc} + j\omega\mu_0/(8\pi)]$:
    what a solver that assembles $R_\text{dc}$ and the DC internal
    inductance (``include_internal=True``) has to add per metre of
    branch length. Zero for ``resistance_model="dc"``.

    Parameters
    ----------
    frequency
        Frequency in Hz (scalar or array, ``>= 0``).

    Returns
    -------
    complex or np.ndarray
        Correction per unit length in Ω/m.
    """
    f = np.asarray(frequency, dtype=float)
    if np.any(f < 0.0) or not np.all(np.isfinite(f)):
        raise ValueError("frequency must be finite and >= 0")
    if self.resistance_model == "dc":
        return 0j if np.ndim(frequency) == 0 else np.zeros(f.shape, dtype=complex)
    area = self.effective_cross_section
    assert area is not None
    z = self.internal_impedance_per_length(frequency)
    z_dc = self.resistivity / area + 1j * 2.0 * math.pi * f * _MU_0 / (
        8.0 * math.pi
    )
    if np.ndim(frequency) == 0:
        return complex(z - z_dc)
    return z - z_dc

CrossSectionUnitWarning

Bases: UserWarning

A conductor cross section is implausibly large for m².

Conductor.cross_section is in m². A value above MAX_PLAUSIBLE_CROSS_SECTION almost always means the value was given in mm² (50 instead of 50e-6), which turns the conductor into an ideal short (series resistance in the nΩ range). Silence with warnings.simplefilter("ignore", CrossSectionUnitWarning) when a huge cross section is intended (e.g. a deliberate near-ideal bond).

WireProximity dataclass

WireProximity(kind: ProximityKind, name_a: str, name_b: str, index_a: int, index_b: int, distance: float, clearance: float, point_a: tuple[float, float, float], point_b: tuple[float, float, float])

One pair of wire segments that are too close.

Attributes:

Name Type Description
kind ProximityKind

"crossing", "touching", "interpenetrating", "close" or "junction" (see the module docstring).

name_a str

Owner name of the first segment (e.g. a conductor name).

name_b str

Owner name of the second segment.

index_a int

Index of the first segment in the input arrays.

index_b int

Index of the second segment in the input arrays.

distance float

Minimum axis-to-axis distance \(d\) in m.

clearance float

Surface-to-surface distance \(d - (a_a + a_b)\) in m; negative when the wires interpenetrate.

point_a tuple[float, float, float]

Closest point on the axis of the first segment, (x, y, z) in m.

point_b tuple[float, float, float]

Closest point on the axis of the second segment, (x, y, z) in m.

find_close_conductors

find_close_conductors(conductors: Iterable[Conductor], *, rel_threshold: float = 5.0, abs_threshold: float = 0.0, include_junctions: bool = False) -> list[WireProximity]

find_close_wires() for Conductor objects.

Every conductor is one straight wire from start to end with its wire_radius; pairs are reported by conductor name.

Parameters:

Name Type Description Default
conductors Iterable[Conductor]

Conductors, e.g. world.conductors.

required
rel_threshold float 5.0
abs_threshold float 5.0
include_junctions float 5.0

Returns:

Type Description
list of WireProximity

Close / interpenetrating / crossing conductor pairs, worst first.

Source code in src/groundfield/conductors/proximity.py
def find_close_conductors(
    conductors: Iterable[Conductor],
    *,
    rel_threshold: float = 5.0,
    abs_threshold: float = 0.0,
    include_junctions: bool = False,
) -> list[WireProximity]:
    """:func:`find_close_wires` for :class:`~groundfield.conductors.Conductor` objects.

    Every conductor is one straight wire from ``start`` to ``end`` with
    its ``wire_radius``; pairs are reported by conductor name.

    Parameters
    ----------
    conductors
        Conductors, e.g. ``world.conductors``.
    rel_threshold, abs_threshold, include_junctions
        See :func:`find_close_wires`.

    Returns
    -------
    list of WireProximity
        Close / interpenetrating / crossing conductor pairs, worst
        first.
    """
    conds = list(conductors)
    if len(conds) < 2:
        return []
    ep = np.array([[c.start, c.end] for c in conds], dtype=float)
    radii = np.array([c.wire_radius for c in conds], dtype=float)
    names = [c.name for c in conds]
    return find_close_wires(
        ep,
        radii,
        names,
        rel_threshold=rel_threshold,
        abs_threshold=abs_threshold,
        include_junctions=include_junctions,
    )

find_close_wires

find_close_wires(endpoints: ndarray, radii: Sequence[float] | ndarray, names: Sequence[str], *, rel_threshold: float = 5.0, abs_threshold: float = 0.0, include_junctions: bool = False) -> list[WireProximity]

Find segment pairs of different owners that are too close.

Parameters:

Name Type Description Default
endpoints ndarray

Segment end points, shape (K, 2, 3), in m.

required
radii Sequence[float] | ndarray

Wire radius of every segment in m, shape (K,).

required
names Sequence[str]

Owner name of every segment (conductor or electrode name), length K. Segments of one owner are never paired.

required
rel_threshold float

A pair is reported when its axis distance is below rel_threshold * (a_i + a_j) (default 5: e.g. 8 cm for two 8 mm rods, where the point-source kernel is already +24 % off).

5.0
abs_threshold float

Additional absolute threshold in m (default 0); the larger of the two applies.

0.0
include_junctions bool

Also report pairs that only meet at a shared end point (default False: such junctions are connections by design).

False

Returns:

Type Description
list of WireProximity

Sorted by ascending clearance (worst first).

Raises:

Type Description
ValueError

If endpoints does not have shape (K, 2, 3), if radii or names does not have one entry per segment, if an end point or radius is not finite or a radius is negative, or if a threshold is negative.

Source code in src/groundfield/conductors/proximity.py
def find_close_wires(
    endpoints: np.ndarray,
    radii: Sequence[float] | np.ndarray,
    names: Sequence[str],
    *,
    rel_threshold: float = 5.0,
    abs_threshold: float = 0.0,
    include_junctions: bool = False,
) -> list[WireProximity]:
    r"""Find segment pairs of different owners that are too close.

    Parameters
    ----------
    endpoints
        Segment end points, shape ``(K, 2, 3)``, in m.
    radii
        Wire radius of every segment in m, shape ``(K,)``.
    names
        Owner name of every segment (conductor or electrode name),
        length ``K``. Segments of one owner are never paired.
    rel_threshold
        A pair is reported when its axis distance is below
        ``rel_threshold * (a_i + a_j)`` (default 5: e.g. 8 cm for two
        8 mm rods, where the point-source kernel is already +24 % off).
    abs_threshold
        Additional absolute threshold in m (default 0); the larger of
        the two applies.
    include_junctions
        Also report pairs that only meet at a shared end point (default
        ``False``: such junctions are connections by design).

    Returns
    -------
    list of WireProximity
        Sorted by ascending clearance (worst first).

    Raises
    ------
    ValueError
        If ``endpoints`` does not have shape ``(K, 2, 3)``, if ``radii`` or
        ``names`` does not have one entry per segment, if an end point or
        radius is not finite or a radius is negative, or if a threshold is
        negative.
    """
    ep = np.asarray(endpoints, dtype=float)
    if ep.ndim != 3 or ep.shape[1:] != (2, 3):
        raise ValueError(f"endpoints must have shape (K, 2, 3), got {ep.shape}")
    K = ep.shape[0]
    rad = np.asarray(radii, dtype=float).reshape(-1)
    if rad.shape != (K,) or len(names) != K:
        raise ValueError("radii and names must have one entry per segment")
    if not np.all(np.isfinite(ep)) or not np.all(np.isfinite(rad)) or np.any(rad < 0):
        raise ValueError("endpoints and radii must be finite, radii >= 0")
    if rel_threshold < 0.0 or abs_threshold < 0.0:
        raise ValueError("thresholds must be non-negative")
    if K < 2:
        return []
    p1 = ep[:, 0]
    p2 = ep[:, 1]
    mid = 0.5 * (p1 + p2)
    half = 0.5 * np.linalg.norm(p2 - p1, axis=1)
    thr = np.maximum(rel_threshold * 2.0 * rad.max(), abs_threshold)
    reach = 2.0 * half.max() + thr
    from scipy.spatial import cKDTree  # lazy: keep `import groundfield` light

    tree = cKDTree(mid)
    pairs = tree.query_pairs(r=float(reach), output_type="ndarray")
    if pairs.size == 0:
        return []
    names_arr = np.asarray(list(names), dtype=object)
    keep = names_arr[pairs[:, 0]] != names_arr[pairs[:, 1]]
    pairs = pairs[keep]
    if pairs.size == 0:
        return []
    i, j = pairs[:, 0], pairs[:, 1]
    # cheap pre-filter: midpoint distance minus both half lengths
    gap = np.linalg.norm(mid[i] - mid[j], axis=1) - half[i] - half[j]
    pair_thr = np.maximum(rel_threshold * (rad[i] + rad[j]), abs_threshold)
    sel = gap <= pair_thr
    i, j, pair_thr = i[sel], j[sel], pair_thr[sel]
    if i.size == 0:
        return []
    dist, s, t = segment_distance(p1[i], p2[i], p1[j], p2[j])
    hit = dist < pair_thr
    scale = np.maximum(np.abs(ep[i]).max(axis=(1, 2)), np.abs(ep[j]).max(axis=(1, 2)))
    inside = dist < _closer_than_touching(rad[i] + rad[j], scale)
    out: list[WireProximity] = []
    for k in np.nonzero(hit)[0]:
        ia, ib = int(i[k]), int(j[k])
        length = max(2.0 * half[ia], 2.0 * half[ib], 1e-12)
        tol = _TOUCH_REL * length
        at_end_a = s[k] <= 1e-9 or s[k] >= 1.0 - 1e-9
        at_end_b = t[k] <= 1e-9 or t[k] >= 1.0 - 1e-9
        if dist[k] <= tol and at_end_a and at_end_b:
            if not include_junctions:
                continue  # shared end point: a junction by design
            kind: ProximityKind = "junction"
        elif dist[k] <= tol:
            kind = "touching" if (at_end_a or at_end_b) else "crossing"
        elif inside[k]:
            kind = "interpenetrating"
        else:
            kind = "close"
        pa = p1[ia] + s[k] * (p2[ia] - p1[ia])
        pb = p1[ib] + t[k] * (p2[ib] - p1[ib])
        out.append(
            WireProximity(
                kind=kind,
                name_a=str(names_arr[ia]),
                name_b=str(names_arr[ib]),
                index_a=ia,
                index_b=ib,
                distance=float(dist[k]),
                clearance=float(dist[k] - rad[ia] - rad[ib]),
                point_a=(float(pa[0]), float(pa[1]), float(pa[2])),
                point_b=(float(pb[0]), float(pb[1]), float(pb[2])),
            )
        )
    out.sort(key=lambda p: p.clearance)
    return out

segment_distance

segment_distance(p1_a: ndarray, p2_a: ndarray, p1_b: ndarray, p2_b: ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray]

Minimum distance between straight segments (vectorised).

Closest points \(p_a(s) = p_{1,a} + s\,d_a\) and \(p_b(t) = p_{1,b} + t\,d_b\) with \(s, t \in [0, 1]\), by the standard clamped two-segment algorithm (Ericson 2005, sec. 5.1.9). Parallel segments and zero-length segments (points) are handled explicitly: the distance of a point to a segment is that of its orthogonal projection, clamped to the segment (audit of review pass 10, F04: a point-like second segment was measured from the start of the first one).

Parameters:

Name Type Description Default
p1_a ndarray

End points, arrays of shape (K, 3) (or (3,)) in m.

required
p2_a ndarray

End points, arrays of shape (K, 3) (or (3,)) in m.

required
p1_b ndarray

End points, arrays of shape (K, 3) (or (3,)) in m.

required
p2_b ndarray

End points, arrays of shape (K, 3) (or (3,)) in m.

required

Returns:

Type Description
distance, s, t : np.ndarray

Distance in m and the segment parameters of the closest points, each of shape (K,).

Source code in src/groundfield/conductors/proximity.py
def segment_distance(
    p1_a: np.ndarray,
    p2_a: np.ndarray,
    p1_b: np.ndarray,
    p2_b: np.ndarray,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
    r"""Minimum distance between straight segments (vectorised).

    Closest points $p_a(s) = p_{1,a} + s\,d_a$ and
    $p_b(t) = p_{1,b} + t\,d_b$ with $s, t \in [0, 1]$, by the standard
    clamped two-segment algorithm (Ericson 2005, sec. 5.1.9). Parallel
    segments and zero-length segments (points) are handled explicitly:
    the distance of a point to a segment is that of its orthogonal
    projection, clamped to the segment (audit of review pass 10, F04:
    a point-like second segment was measured from the start of the
    first one).

    Parameters
    ----------
    p1_a, p2_a, p1_b, p2_b
        End points, arrays of shape ``(K, 3)`` (or ``(3,)``) in m.

    Returns
    -------
    distance, s, t : np.ndarray
        Distance in m and the segment parameters of the closest points,
        each of shape ``(K,)``.
    """
    p1_a = np.atleast_2d(np.asarray(p1_a, dtype=float))
    p2_a = np.atleast_2d(np.asarray(p2_a, dtype=float))
    p1_b = np.atleast_2d(np.asarray(p1_b, dtype=float))
    p2_b = np.atleast_2d(np.asarray(p2_b, dtype=float))
    d1 = p2_a - p1_a
    d2 = p2_b - p1_b
    r = p1_a - p1_b
    a = np.einsum("ij,ij->i", d1, d1)
    e = np.einsum("ij,ij->i", d2, d2)
    f = np.einsum("ij,ij->i", d2, r)
    c = np.einsum("ij,ij->i", d1, r)
    b = np.einsum("ij,ij->i", d1, d2)
    denom = a * e - b * b
    with np.errstate(divide="ignore", invalid="ignore"):
        s = np.where(
            denom > 1e-14 * np.maximum(a * e, 1e-300),
            np.clip((b * f - c * e) / denom, 0.0, 1.0),
            0.0,
        )
        t = (b * s + f) / np.where(e > 0.0, e, 1.0)
        # clamp t and recompute s where needed
        t_lo = t < 0.0
        t_hi = t > 1.0
        t = np.clip(t, 0.0, 1.0)
        s = np.where(t_lo, np.clip(-c / np.where(a > 0.0, a, 1.0), 0.0, 1.0), s)
        s = np.where(t_hi, np.clip((b - c) / np.where(a > 0.0, a, 1.0), 0.0, 1.0), s)
        # Degenerate segments: a point against a segment is the clamped
        # projection; two points are their distance.
        scale = np.maximum(np.maximum(a, e), 1e-300)
        point_a = a <= 1e-24 * scale
        point_b = e <= 1e-24 * scale
        s = np.where(point_b, np.clip(-c / np.where(a > 0.0, a, 1.0), 0.0, 1.0), s)
        t = np.where(point_b, 0.0, t)
        s = np.where(point_a, 0.0, s)
        t = np.where(
            point_a & ~point_b, np.clip(f / np.where(e > 0.0, e, 1.0), 0.0, 1.0), t
        )
    ca = p1_a + s[:, None] * d1
    cb = p1_b + t[:, None] * d2
    dist = np.linalg.norm(ca - cb, axis=1)
    return dist, s, t

solid_round_internal_impedance

solid_round_internal_impedance(frequency: float | ndarray, *, radius: float, resistivity: float) -> complex | np.ndarray

Internal series impedance per unit length of a solid round wire.

Parameters:

Name Type Description Default
frequency float | ndarray

Frequency in Hz (scalar or array, >= 0).

required
radius float

Conductor radius \(a\) in m (the radius of a solid conductor with the same conducting cross section, \(a = \sqrt{A/\pi}\)).

required
resistivity float

Conductor resistivity \(\rho\) in Ω·m.

required

Returns:

Type Description
complex or ndarray

\(Z'_\text{int} = R'(f) + j\omega L'_\text{int}(f)\) in Ω/m; at frequency == 0 the DC resistance \(\rho/(\pi a^2)\).

Raises:

Type Description
ValueError

If radius or resistivity is not positive and finite, or if a frequency is negative or not finite.

Source code in src/groundfield/conductors/skin.py
def solid_round_internal_impedance(
    frequency: float | np.ndarray,
    *,
    radius: float,
    resistivity: float,
) -> complex | np.ndarray:
    r"""Internal series impedance per unit length of a solid round wire.

    Parameters
    ----------
    frequency
        Frequency in Hz (scalar or array, ``>= 0``).
    radius
        Conductor radius $a$ in m (the radius of a solid conductor with
        the same conducting cross section, $a = \sqrt{A/\pi}$).
    resistivity
        Conductor resistivity $\rho$ in Ω·m.

    Returns
    -------
    complex or np.ndarray
        $Z'_\text{int} = R'(f) + j\omega L'_\text{int}(f)$ in Ω/m;
        at ``frequency == 0`` the DC resistance $\rho/(\pi a^2)$.

    Raises
    ------
    ValueError
        If ``radius`` or ``resistivity`` is not positive and finite, or
        if a frequency is negative or not finite.
    """
    if not (radius > 0.0 and math.isfinite(radius)):
        raise ValueError(f"radius must be positive and finite, got {radius}")
    if not (resistivity > 0.0 and math.isfinite(resistivity)):
        raise ValueError(f"resistivity must be positive and finite, got {resistivity}")
    f = np.asarray(frequency, dtype=float)
    if np.any(f < 0.0) or not np.all(np.isfinite(f)):
        raise ValueError("frequency must be finite and >= 0")
    r_dc = resistivity / (math.pi * radius * radius)
    omega = 2.0 * math.pi * f
    k = np.sqrt(1j * omega * MU_0 / resistivity)
    z = k * radius
    out = np.full(f.shape, r_dc, dtype=complex)
    small = np.abs(z) < _SERIES_LIMIT
    if np.any(small):
        z2 = z[small] ** 2
        # Z' = r_dc * (k a / 2) * I0/I1 = r_dc * (1 + z^2/8 - z^4/192 + z^6/3072)
        out[small] = r_dc * (1.0 + z2 / 8.0 - z2 * z2 / 192.0 + z2**3 / 3072.0)
    big = ~small
    if np.any(big):
        # Imported here: ``import groundfield`` must not load scipy.special.
        from scipy.special import ive

        zb = z[big]
        out[big] = (
            k[big] * resistivity / (2.0 * math.pi * radius) * ive(0, zb) / ive(1, zb)
        )
    if np.ndim(frequency) == 0:
        return complex(out[()])
    return out

Conductor options and constants

The literal types of the Conductor settings that the package namespace does not re-export, and the constants of the conductor models.

SoilCoupling module-attribute

SoilCoupling = Literal['isolated', 'galvanic']

Galvanic coupling of a conductor to the soil (Conductor.coupling_to_soil).

  • "isolated": cable or PEN inside an insulating jacket, no leakage;
  • "galvanic": bare copper or exposed shield, leakage along the wire.

InductanceModel module-attribute

InductanceModel = Literal['neumann',]

Inductance model of a conductor (Conductor.inductance_model).

  • "neumann": Neumann double-line integrals plus the earth-return model of the engine (Engine.earth_inductive_model).

ProximityKind module-attribute

ProximityKind = Literal['crossing', 'touching', 'interpenetrating', 'close', 'junction']

Kind of a close wire pair (WireProximity.kind).

  • "crossing": the axes intersect inside both segments;
  • "touching": the end point of one segment lies on the interior of the other (a T-contact the model does not connect);
  • "interpenetrating": the axis distance is below the sum of the radii;
  • "close": the axis distance is below the reporting threshold;
  • "junction": the two segments only share an end point.

The exact criteria are in the module docstring.

MU_0 module-attribute

MU_0 = 4e-07 * math.pi

Vacuum permeability μ0 = 4π · 10⁻⁷ H/m (the conventional value).