freegsnke.refine_passive module

Defines functionality needed for building passive conductive structures.

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/>.

freegsnke.refine_passive.find_area(R: ndarray, Z: ndarray, n_refine: int | None) → tuple[float, Path, ndarray, ndarray, ndarray, float, float][source]

Estimate polygon area and construct a point-in-polygon test path.

This function computes a bounding-box-based Monte Carlo estimate of the area enclosed by a polygon defined by vertices (R, Z). It also constructs a matplotlib.path.Path object for point-in-polygon queries and estimates a centroid-like mean of accepted sample points.

Parameters:
  • R (np.ndarray) – R coordinates of the polygon vertices in m.

  • Z (np.ndarray) – Z coordinates of the polygon vertices in m.

  • n_refine (int) – Target number of refinement points used to control Monte Carlo sampling. If None, 100 is used.

Returns:

  • area (float) – Estimated area of the polygon.

  • path (matplotlib.path.Path) – Path object for point-in-polygon evaluation.

  • vmin (np.ndarray) – Minimum bounds of the vertex coordinates (R_min, Z_min).

  • vmax (np.ndarray) – Maximum bounds of the vertex coordinates (R_max, Z_max).

  • dv (np.ndarray) – Bounding box size (vmax - vmin).

  • meanR (float) – Mean R coordinate of accepted Monte Carlo samples.

  • meanZ (float) – Mean Z coordinate of accepted Monte Carlo samples.

freegsnke.refine_passive.generate_refinement(R: ndarray, Z: ndarray, n_refine: int, refine_mode: str) → tuple[ndarray, float] | None[source]

Generate a refined set of points in (R, Z) space using a selected strategy.

The refinement strategy is selected via refine_mode and delegates to the corresponding refinement routine.

Parameters:
  • R (np.ndarray) – Radial coordinates of the polygon vertices in m.

  • Z (np.ndarray) – Vertical coordinates of the polygon vertices in m.

  • n_refine (int) – Number of refinement points to generate.

  • refine_mode (str) – Refinement strategy selector: - “G” : regular grid refinement - “LH” : Latin Hypercube refinement

Returns:

  • points (np.ndarray) – Refined (R, Z) point set, shape (N, 2), produced by the selected method.

  • area (float) – Estimated area of the polygon.

  • None – Returned instead (after printing a message) if refine_mode is not recognised.

freegsnke.refine_passive.generate_refinement_G(R: ndarray, Z: ndarray, n_refine: int) → tuple[ndarray, float][source]

Generate a structured grid refinement inside a polygon.

This method constructs a regular Cartesian grid over the bounding box of the polygon defined by (R, Z), and retains only the points that lie inside the polygon. The grid resolution is increased iteratively until at least n_refine interior points are obtained.

Parameters:
  • R (np.ndarray) – R coordinates of the polygon vertices in m.

  • Z (np.ndarray) – Z coordinates of the polygon vertices in m.

  • n_refine (int) – Target number of refinement points.

Returns:

  • points (np.ndarray, shape (N, 2)) – Refinement points inside the polygon (N ≥ n_refine).

  • area (float) – Estimated area of the polygon region returned by find_area.

freegsnke.refine_passive.generate_refinement_LH(R: ndarray, Z: ndarray, n_refine: int) → tuple[ndarray, float][source]

Generate refinement points inside a polygon using Latin Hypercube sampling.

This method samples candidate points using a Latin Hypercube strategy, maps them into the bounding box of the polygon defined by (R, Z), and retains only points lying inside the polygon.

Sampling is repeated until at least n_refine valid interior points are obtained (or a maximum of 100 iterations is reached).

Parameters:
  • R (np.ndarray) – R coordinates of the polygon vertices in m.

  • Z (np.ndarray) – Z coordinates of the polygon vertices in m.

  • n_refine (int) – Number of interior refinement points to generate.

Returns:

  • points (np.ndarray, shape (n_refine, 2)) – Generated refinement points inside the polygon.

  • area (float) – Estimated area of the polygon region returned by find_area.