freegsnke.machine_config module

Checks and/or calculates resistance and inductances matrices based on a provided machine description.

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.machine_config.append_tokamak_R_and_M_entries(tokamak: object, new_labels: list[str]) → None[source]

Extend the existing resistance (R) and inductance (M) matrices with entries for coil labels that have just been appended to the machine.

Parameters:
  • tokamak (Machine) – The tokamak object. tokamak.coils_list and tokamak.coils_dict must already include new_labels, appended in order at the end of coils_list, and tokamak.coil_resist/tokamak.coil_self_ind must already exist for every other (pre-existing) label.

  • new_labels (list of str) – Labels of the newly appended coils, in the order they were appended.

Notes

tokamak.coil_resist and tokamak.coil_self_ind are replaced in place with the extended matrices.

freegsnke.machine_config.build_tokamak_R_and_M(tokamak: object, rebuild: bool = False, changed_coils: list[str] | None = None) → None[source]

Build the resistance (R) and inductance (M) matrices for the machine within the tokamak object. This will construct R and M for the active coils (and any passive structures).

If already present, they will not be re-calculated.

Notes

  • The mutual inductance between coils is 2pi * (sum of all Greens(R_i, Z_i, R_j, Z_j) terms weighted by the polarities and multipliers of the filaments).

  • This sum is valid for active coils, where each filament carries the nominal current. It is not valid as such for refined passive structures, where each filament carries a factor 1/n_filaments of the total current and a mean of the Greens functions (rather than the sum) is needed; this is accounted for through the multiplier.

  • The resistance is 2pi * (resistivity/area) * (number of loops * mean radius). The multiplier is used because refined passives have a number of loops equal to 1.

Parameters:
  • tokamak (Machine) – The tokamak object; coil_resist and coil_self_ind are set (or updated) in place.

  • rebuild (bool, optional) – Recalculate and replace existing resistance and inductance matrices even when tokamak.coil_resist or tokamak.coil_self_ind already exist. This should be set when the machine geometry has been updated in place.

  • changed_coils (list of str, optional) – Coil/circuit labels whose geometry or metadata changed. When existing matrices are available and the coil ordering has not changed, only the resistance entries and mutual-inductance rows/columns involving these labels are recalculated.

freegsnke.machine_config.insert_tokamak_R_and_M_entries(tokamak: object, index: int, new_labels: list[str]) → None[source]

Insert resistance (R) and inductance (M) matrix entries for coil labels that have just been inserted into the machine at a given position, shifting any existing entries at or after that position along.

Unlike append_tokamak_R_and_M_entries(), this supports inserting new coils before existing ones (e.g. a new active coil, which must be inserted immediately before the first passive structure to keep the active/passive partition of tokamak.coils_list contiguous).

Parameters:
  • tokamak (Machine) – The tokamak object. tokamak.coils_list and tokamak.coils_dict must already include new_labels, inserted in order starting at index, and tokamak.coil_resist/tokamak.coil_self_ind must already exist for every other (pre-existing) label.

  • index (int) – Position at which new_labels were inserted into tokamak.coils_list.

  • new_labels (list of str) – Labels of the newly inserted coils, in the order they were inserted.

Notes

tokamak.coil_resist and tokamak.coil_self_ind are replaced in place with the extended matrices.

freegsnke.machine_config.remove_tokamak_R_and_M_entry(tokamak: object, index: int) → None[source]

Remove the resistance (R) and inductance (M) matrix entries at a given coil position.

Parameters:
  • tokamak (Machine) – The tokamak object, with coil_resist/coil_self_ind already built for the machine prior to removal.

  • index (int) – Position (row/column) to remove from the existing matrices. This should be the coil’s index before it is removed from tokamak.coils_list.

Notes

tokamak.coil_resist and tokamak.coil_self_ind are replaced in place with the shrunk matrices.

freegsnke.machine_config.self_ind_circular_loop(R: float | ndarray, dR: float | ndarray) → float | ndarray[source]

Calculate the self inductance of a circular loop with radius R and width dR.

Parameters:
  • R (float or np.ndarray) – Radial position of the loop [m].

  • dR (float or np.ndarray) – Radial width of the filament [m].

Returns:

Self inductance in H.

Return type:

float or np.ndarray