freegsnke.passive_structure module

Implements the FreeGSNKE object used to deal with extended vessel structures. Current is distributed uniformly over each extended structure.

Copyright 2025 UKAEA, UKRI-STFC, and The Authors, as per the COPYRIGHT and README files.

This file is part of FreeGSNKE.

FreeGSNKE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FreeGSNKE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>.

class freegsnke.passive_structure.PassiveStructure(R: ndarray, Z: ndarray, min_refine_per_area: float, min_refine_per_length: float, refine_mode: str = 'G')[source]

Bases: Coil

Passive structure with current distributed uniformly over a polygon.

Inherits from freegsnke.coil.Coil. Rather than listing a large number of filaments, it averages the relevant Green’s functions over refining filaments so that current is distributed uniformly over the structure.

__init__(R: ndarray, Z: ndarray, min_refine_per_area: float, min_refine_per_length: float, refine_mode: str = 'G') → None[source]

Instantiate the object and build the refinement of the polygonal shape.

Parameters:
  • R (np.ndarray) – Radial vertex coordinates (m) defining the passive structure polygon.

  • Z (np.ndarray) – Vertical vertex coordinates (m) defining the passive structure polygon.

  • min_refine_per_area (float) – Minimum number of refining filaments per unit area (m^-2).

  • min_refine_per_length (float) – Minimum number of refining filaments per unit length (m^-1), where the length is the diagonal of the polygon bounding box.

  • refine_mode (str, optional) – Refinement mode for passive structures input as polygons, by default “G” for grid. Use “LH” for an alternative mode using a Latin Hypercube implementation.

build_control_br(R: ndarray, Z: ndarray) → None[source]

Compute and cache the Green’s function for the radial magnetic field (Br) of the refining filaments on a specified R-Z grid.

The result is obtained by evaluating the contribution from each filament (via GreensBr) and averaging across all filaments.

Parameters:
  • R (np.ndarray) – 2D array defining the radial coordinate grid (e.g. equilibrium R grid).

  • Z (np.ndarray) – 2D array defining the vertical coordinate grid (e.g. equilibrium Z grid).

Notes

  • Each filament is evaluated over the full grid using broadcasting.

  • Filament contributions are averaged to produce the total response.

  • The result is cached in self.greens[key][“Br”], where key is given by create_RZ_key(R, Z).

build_control_bz(R: ndarray, Z: ndarray) → None[source]

Compute and cache the Green’s function for the vertical magnetic field (Bz) of the refining filaments on a specified R-Z grid.

The result is obtained by evaluating the contribution from each filament (via GreensBz) and averaging across all filaments.

Parameters:
  • R (np.ndarray) – 2D array defining the radial coordinate grid (e.g. equilibrium R grid).

  • Z (np.ndarray) – 2D array defining the vertical coordinate grid (e.g. equilibrium Z grid).

Notes

  • Each filament is evaluated over the full grid using broadcasting.

  • Filament contributions are averaged to produce the total response.

  • The result is cached in self.greens[key][“Bz”], where key is given by create_RZ_key(R, Z).

build_control_psi(R: ndarray, Z: ndarray) → None[source]

Compute and cache the Green’s function for the poloidal flux (psi) of the refining filaments on a specified R-Z grid.

The result is obtained by evaluating the contribution from each filament (via Greens) and averaging across all filaments.

Parameters:
  • R (np.ndarray) – 2D array defining the radial coordinate grid (e.g. equilibrium R grid).

  • Z (np.ndarray) – 2D array defining the vertical coordinate grid (e.g. equilibrium Z grid).

Notes

  • Each filament is evaluated over the full grid using broadcasting.

  • Filament contributions are averaged to produce the total response.

  • The result is cached in self.greens[key][“psi”], where key is given by create_RZ_key(R, Z).

build_refining_filaments() → ndarray[source]

Construct the set of refining filaments used to represent the structure.

Returns:

Filament (R, Z) coordinates, shape (N, 2), generated by the refinement procedure.

Return type:

np.ndarray

Notes

  • The filaments are generated from the polygon defined by self.Rpolygon and self.Zpolygon.

  • The refinement density is controlled by self.n_refine.

  • The refinement strategy is determined by self.refine_mode.

  • The function generate_refinement also returns an area estimate, which is currently ignored.

controlBr(R: ndarray, Z: ndarray) → ndarray[source]

Return the radial magnetic field Br on the grid (R, Z) due to a unit current.

The value is retrieved from the cached Green’s function table if available; otherwise it is computed with build_control_br and stored.

Parameters:
  • R (np.ndarray) – 2D radial coordinate grid (m), used to build the cache key.

  • Z (np.ndarray) – 2D vertical coordinate grid (m), used to build the cache key.

Returns:

Green’s function values on the grid for a unit current.

Return type:

np.ndarray

controlBz(R: ndarray, Z: ndarray) → ndarray[source]

Return the vertical magnetic field Bz on the grid (R, Z) due to a unit current.

The value is retrieved from the cached Green’s function table if available; otherwise it is computed with build_control_bz and stored.

Parameters:
  • R (np.ndarray) – 2D radial coordinate grid (m), used to build the cache key.

  • Z (np.ndarray) – 2D vertical coordinate grid (m), used to build the cache key.

Returns:

Green’s function values on the grid for a unit current.

Return type:

np.ndarray

controlPsi(R: ndarray, Z: ndarray) → ndarray[source]

Return the poloidal flux psi on the grid (R, Z) due to a unit current.

The value is retrieved from the cached Green’s function table if available; otherwise it is computed with build_control_psi and stored.

Parameters:
  • R (np.ndarray) – 2D radial coordinate grid (m), used to build the cache key.

  • Z (np.ndarray) – 2D vertical coordinate grid (m), used to build the cache key.

Returns:

Green’s function values on the grid for a unit current.

Return type:

np.ndarray

copy() → PassiveStructure[source]

Create a shallow copy without reinitialising geometry or Green’s functions.

This method avoids calling the constructor for performance reasons and instead manually copies the attributes that define the geometry and the cached electromagnetic response.

Returns:

A new instance of the same class with duplicated state.

Return type:

PassiveStructure

Notes

  • Geometry-related arrays (e.g. R, Z, vertices, filaments) are shared by reference and are assumed to be immutable.

  • The greens dictionary is shallow-copied:
    • Safe usage: replacing entries (e.g. greens[“psi”] = new_array)

    • Unsafe usage: in-place modification (e.g. greens[“psi”][:] = …)

  • This copy is therefore not fully independent and should be used only when immutability assumptions hold.

  • The attribute control is currently assigned from self.turns (this may be intentional or a likely typo depending on design intent).

create_RZ_key(R: ndarray, Z: ndarray) → tuple[float, float, float, float, int][source]

Create a hashable key identifying a specific R-Z grid for caching Green’s functions.

The key is based on the grid bounds and size, and is used to ensure that Green’s function evaluations are reused only when the underlying spatial grid is identical.

Parameters:
  • R (np.ndarray) – Radial coordinate grid (typically eq.R).

  • Z (np.ndarray) – Vertical coordinate grid (typically eq.Z).

Returns:

A hashable identifier of the form (R_min, R_max, Z_min, Z_max, N), where N = total number of grid points in R.

Return type:

tuple

plot(axis: object | None = None, show: bool = False) → object[source]

Plot the passive structure polygon on a Matplotlib axis.

This method constructs a matplotlib.patches.Polygon from the stored vertex coordinates and adds it to the provided axis. If no axis is supplied, a new Matplotlib figure and axis are created.

Parameters:
  • axis (matplotlib.axes.Axes, optional) – Existing Matplotlib axis to plot onto. If None, a new figure and axis are created.

  • show (bool, optional) – Unused. Present for API compatibility; does not affect behaviour.

Returns:

Axis containing the plotted polygon.

Return type:

matplotlib.axes.Axes

Notes

  • The polygon is also stored as self.polygon for later access.

  • The polygon is rendered with fixed styling (grey fill, black edge).

  • This method does not call plt.show() even if show=True.