freegsnke.machine_update module

Defines a machine with limiter support, extending freegsnke.machine.Machine.

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.machine_update.Machine(coils: list[tuple[str, object]], wall: Wall | None = None, limiter: Wall | None = None)[source]

Bases: Machine

Machine with a limiter and in-place machine-description updates.

Same as freegsnke.machine.Machine, but it can have an additional freegsnke.machine.Wall object which specifies the limiter’s properties.

__init__(coils: list[tuple[str, object]], wall: Wall | None = None, limiter: Wall | None = None) → None[source]

Instantiate the Machine, same as freegsnke.machine.Machine.

Parameters:
  • coils (list of (str, object)) – List of (label, coil) pairs, where each coil is a Coil or Circuit.

  • wall (freegsnke.machine.Wall, optional) – It is only used to display the wall in plots.

  • limiter (freegsnke.machine.Wall, optional) – This is the limiter. Used to define limiter plasma configurations.

add_active_coil(coil_name: str, active_coil_data: dict, *, strict_overlap_check: bool = False) → Machine[source]

Add one new active coil/circuit in place from direct machine-description data.

Parameters:
  • coil_name (str) – Label for the new active coil/circuit.

  • active_coil_data (dict) – Machine-description entry for the new active coil/circuit.

  • strict_overlap_check (bool, optional) – If True, reject overlaps with ValueError. By default, warn and continue. Invalid geometry always raises.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

Only the new coil’s R/M entries are calculated; existing entries are reused. The new coil is inserted immediately before any passive structures, so coils_list[:n_active_coils] stays exactly the active coils. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.add_active_coil() instead so equilibrium Greens functions are extended. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions, whose dimensionality will itself have changed.

add_passive_structure(passive_data: dict, name: str | None = None, refine_mode: str = 'G', *, strict_overlap_check: bool = False) → Machine[source]

Add one new passive structure in place from direct machine-description data.

Parameters:
  • passive_data (dict) – Machine-description entry for the new passive structure.

  • name (str, optional) – Label for the new passive structure. If omitted, passive_data["name"] is used, and if that is also absent a default of the form f"passive_{self.n_passive_coils}" is used.

  • refine_mode (str, optional) – Refinement mode for extended (polygonal) passive structures. Defaults to "G".

  • strict_overlap_check (bool, optional) – If True, reject overlaps with ValueError. By default, warn and continue. Invalid geometry always raises.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

Only the new passive structure’s R/M entries are calculated; existing entries are reused. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.add_passive_structure() instead so equilibrium Greens functions are extended. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions, whose dimensionality will itself have changed.

remove_active_coil(coil_name: str) → Machine[source]

Remove one active coil/circuit in place.

Parameters:

coil_name (str) – Existing active coil/circuit label to remove.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

Only the removed coil’s R/M entries are dropped; existing entries are reused. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.remove_active_coil() instead so equilibrium Greens functions are shrunk. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions, whose dimensionality will itself have changed.

remove_passive_structure(name: str) → Machine[source]

Remove one passive structure in place.

Parameters:

name (str) – Existing passive-structure label to remove.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

Only the removed passive structure’s R/M entries are dropped; existing entries are reused. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.remove_passive_structure() instead so equilibrium Greens functions are shrunk. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions, whose dimensionality will itself have changed.

set_machine_description(active_coils_data: dict | None = None, passive_coils_data: list | None = None, limiter_data: list | None = None, wall_data: list | None = None, magnetic_probe_data: dict | None = None, active_coils_path: str | None = None, passive_coils_path: str | None = None, limiter_path: str | None = None, wall_path: str | None = None, magnetic_probe_path: str | None = None, refine_mode: str = 'G', preserve_currents: bool = True, *, strict_overlap_check: bool = False) → Machine[source]

Update this machine in place from direct data dictionaries or pickle paths.

This accepts the same machine description inputs as freegsnke.build_machine.tokamak(), but applies the new geometry to the existing object and refreshes derived FreeGSNKE machine attributes.

Parameters:
  • active_coils_data (dict, optional) – Dictionary containing the active coil description.

  • passive_coils_data (list, optional) – List containing passive structure descriptions. If omitted, no passive structures are added.

  • limiter_data (list, optional) – List of limiter boundary points.

  • wall_data (list, optional) – List of wall boundary points. If omitted, the limiter is used as the wall.

  • magnetic_probe_data (dict, optional) – Dictionary containing magnetic probe descriptions.

  • active_coils_path (str, optional) – Path to a pickle file containing the active coil description.

  • passive_coils_path (str, optional) – Path to a pickle file containing passive structure descriptions.

  • limiter_path (str, optional) – Path to a pickle file containing limiter boundary points.

  • wall_path (str, optional) – Path to a pickle file containing wall boundary points.

  • magnetic_probe_path (str, optional) – Path to a pickle file containing magnetic probe descriptions.

  • refine_mode (str, optional) – Refinement mode for extended passive structures. Defaults to "G".

  • preserve_currents (bool, optional) – If True, currents for labels that are present in both the old and new machine descriptions are copied onto the updated coil objects.

  • strict_overlap_check (bool, optional) – If True, reject overlaps with ValueError. By default, warn and continue. Invalid geometry always raises.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

This method updates only machine-level state. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.update_machine_description() instead so equilibrium Greens functions and limiter masks are refreshed. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions.

update_active_coil(coil_name: str, active_coil_data: dict, preserve_current: bool = True, *, strict_overlap_check: bool = False) → Machine[source]

Update one active coil/circuit in place from direct machine-description data.

Parameters:
  • coil_name (str) – Existing active coil/circuit label to replace.

  • active_coil_data (dict) – Machine-description entry for coil_name. This is the same data structure stored under the coil label in the active-coils pickle or direct active-coils dictionary.

  • preserve_current (bool, optional) – If True, the old current on coil_name is copied onto the replacement coil/circuit. Defaults to True.

  • strict_overlap_check (bool, optional) – If True, reject overlaps with ValueError. By default, warn and continue. Invalid geometry always raises.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

Only the named active coil/circuit and the R/M entries that depend on it are recalculated. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.update_active_coil() instead so equilibrium Greens functions are refreshed. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions.

update_passive_structure(name: str, passive_data: dict, preserve_current: bool = True, refine_mode: str = 'G', *, strict_overlap_check: bool = False) → Machine[source]

Update one passive structure in place from direct machine-description data.

Parameters:
  • name (str) – Existing passive-structure label to replace.

  • passive_data (dict) – Machine-description entry for name. This is the same data structure stored (per-item) in the passive-coils pickle or direct passive-coils list.

  • preserve_current (bool, optional) – If True, the old current on name is copied onto the replacement passive structure. Defaults to True.

  • refine_mode (str, optional) – Refinement mode for extended (polygonal) passive structures. Defaults to "G".

  • strict_overlap_check (bool, optional) – If True, reject overlaps with ValueError. By default, warn and continue. Invalid geometry always raises.

Returns:

This machine object, updated in place.

Return type:

Machine

Notes

Only the named passive structure and the R/M entries that depend on it are recalculated. If this machine is already attached to an equilibrium, use freegsnke.equilibrium_update.Equilibrium.update_passive_structure() instead so equilibrium Greens functions are refreshed. Existing nonlinear solver objects should be reinstantiated after a geometry change because they cache machine-dependent matrices and mode decompositions.