The Open FUSION Toolkit 26.9
An open-source framework for fusion and plasma science and engineering
Loading...
Searching...
No Matches
MUGToksim Class Reference

Detailed Description

Coupled MUG/TokaMaker (mugtok_td) time-dependent simulation.

Built on top of an existing TokaMaker instance, whose mesh, finite-element representation, and active equilibrium are reused. The poloidal flux (psi) and coil currents live in the TokaMaker equilibrium; the MHD fields (velocity, pressure, F) live in this object.

Public Member Functions

 __del__ (self)
 Free the Fortran-side object (the borrowed equilibrium/mesh are left intact).
 __init__ (self, tokamaker)
 Create a combined MUG/TokaMaker simulation from an existing TokaMaker instance.
 get_field (self, name, cell_centered=False)
 Get the present values of a field at node points.
 plot_field (self, fig, ax, name, colormap=None, scale=1.0, clabel=None, colorbar=True, shared_scale=False, **kwargs)
 Plot a field on the mesh.
 save_to_dict (self, cell_centered=False)
 Collect every field at the current time into a single dictionary.
 setup (self, dt, lin_tol, nl_tol, mhd_dict, incomp=True, allow_toroidal_flow=False)
 Set up the coupled solver.
 step (self, time, dt, coil_currents=None)
 Advance the coupled solution by one timestep.

Public Attributes

 lc = None
 Triangle list [nc,3] for the main order fields (same as TokaMaker.lc).
 pressure_lc = None
 Triangle list [nc_p,3] for the (order-1) pressure field.
 pressure_r = None
 Node coordinates [np_p,3] for the (order-1) pressure field.
 pressure_reg = None
 Per-cell region IDs [nc_p] for the (order-1) pressure mesh.
 r = None
 Node coordinates [np,3] for the main order fields.
 reg = None
 Per-cell region IDs [nc] for the main order fields (same as TokaMaker.reg).

Protected Member Functions

 _get_current (self)
 Current density in the conducting structures, J [A/m^2].
 _get_gradf (self)
 Fetch the projected poloidal gradient of F, (dF/dR, dF/dZ), at node points.
 _get_mug_field (self, field_id)
 Fetch a MUG-owned field (by augmented-vector block index) at node points.
 _load_pmesh (self)
 Load and cache the order-1 (pressure) plotting mesh.
 _zz_doxygen_dummy (self)
 _zz_doxygen_dummy (self)

Protected Attributes

 _mhd_dict = mhd_dict
 Per-region MHD properties as supplied to setup().
 _mhd_flag = None
 Per-region MHD flag [nreg] (1 = MHD region); set by setup().
 _oft_env = tokamaker._oft_env
 OpenFUSIONToolkit environment (See OFT_env).
 _plc = None
 _pr = None
 Cached order-1 (pressure) plotting mesh (loaded on first access).
 _preg = None
 _ptr = ctypes.c_void_p()
 C pointer to the Fortran-side combined simulation object.
 _tokamaker = tokamaker
 Parent TokaMaker object (mesh/equilibrium/coils borrowed from it).

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
tokamaker )

Create a combined MUG/TokaMaker simulation from an existing TokaMaker instance.

Parameters
tokamakerA TokaMaker object with an active equilibrium

◆ __del__()

__del__ ( self)

Free the Fortran-side object (the borrowed equilibrium/mesh are left intact).

Member Function Documentation

◆ _get_current()

_get_current ( self)
protected

Current density in the conducting structures, J [A/m^2].

Poloidal components come from the (projected) grad(F): J_pol = (grad F x phi_hat)/(mu0 R); the toroidal component and the conductor mask come from the TokaMaker equilibrium via calc_conductor_currents(psi).

Returns
Tuple (mask, J) where mask is the per-cell conductor mask and J is a (ndof, 3) array with columns ordered (R, phi, Z).

◆ _get_gradf()

_get_gradf ( self)
protected

Fetch the projected poloidal gradient of F, (dF/dR, dF/dZ), at node points.

◆ _get_mug_field()

_get_mug_field ( self,
field_id )
protected

Fetch a MUG-owned field (by augmented-vector block index) at node points.

◆ _load_pmesh()

_load_pmesh ( self)
protected

Load and cache the order-1 (pressure) plotting mesh.

◆ _zz_doxygen_dummy() [1/2]

_zz_doxygen_dummy ( self)
protected

◆ _zz_doxygen_dummy() [2/2]

_zz_doxygen_dummy ( self)
protected

◆ get_field()

get_field ( self,
name,
cell_centered = False )

Get the present values of a field at node points.

Parameters
nameOne of 'velocity', 'pressure', 'F' (MUG-owned), 'psi', or 'current density'
cell_centeredIf True, return one value per mesh cell (averaged over the cell's vertices) instead of one per node
Returns
A tuple (mask, field) where mask is a per-cell boolean mask to apply at plot time

Returned units by field:

  • 'velocity': [m/s]
  • 'pressure': [Pa] (defined only up to a constant per MHD region; each region shifted so its own min = 0)
  • 'F': [T*m]
  • 'psi': [Wb]
  • 'current density': [A/m^2]

The per-cell masks let each field be plotted only where it is physically defined:

  • 'velocity', 'pressure': True only in the MHD (MUG) regions.
  • 'F', 'psi': True everywhere (defined over the whole mesh).
  • 'current': the conductor mask from the TokaMaker equilibrium.

◆ plot_field()

plot_field ( self,
fig,
ax,
name,
colormap = None,
scale = 1.0,
clabel = None,
colorbar = True,
shared_scale = False,
** kwargs )

Plot a field on the mesh.

Wraps get_field and draws it with tripcolor, applying the field's mask so only the region where it is defined is shaded.

Vector fields are drawn as three separate colour maps, one per component, so ax must hold three axes for those.

Parameters
figFigure the axes belong to (needed for the colorbars)
axAxes to draw on. Scalar fields ('pressure', 'F', 'psi') take a single Axes; vector fields ('velocity', 'current density') take a sequence of three
nameField name, as accepted by get_field
colormapColormap to use. By default 'velocity' and 'current density' use 'seismic' with limits symmetric about zero, since their sign carries direction; every other field uses 'viridis' over its own range.
scaleMultiplier applied to the values before plotting. Set clabel to match: e.g. scale=1.0E-6, clabel=r'$J$ [MA/m$^2$]'.
clabelLabel for the colorbars. None builds one per component from the field name and its base units.
colorbarDraw colorbars (default True)
shared_scaleFor vector fields, put all three components on a common colour scale so the panels are directly comparable, and draw a single colorbar. (default False)

◆ save_to_dict()

save_to_dict ( self,
cell_centered = False )

Collect every field at the current time into a single dictionary.

Parameters
cell_centeredIf True, average each field over its cell vertices to give one value per cell.
Returns
Dictionary keyed by field name ('velocity', 'pressure', 'F', 'psi', 'current density'). Each entry is a sub-dictionary: 'field' values, 'mask' per-cell boolean for where the field is defined, 'units' string for the field's base units.

◆ setup()

setup ( self,
dt,
lin_tol,
nl_tol,
mhd_dict,
incomp = True,
allow_toroidal_flow = False )

Set up the coupled solver.

Parameters
dtTimestep [s]
lin_tolLinear solver tolerance
nl_tolNon-linear solver tolerance
mhd_dictDictionary of regions where the MHD (MUG) solve is active, keyed by region name. Each entry must provide: 'density' mass density [kg/m^3] 'viscosity' dynamic viscosity [Pa-s] e.g. {'CHANNEL': {'density': 9.4E3, 'viscosity': 1.5E-3}} Every named region must also be a TokaMaker conducting region, since that is where its resistivity comes from. May be empty, in which case no region is evolved by MUG.
incompUse incompressible flow (default: True). Compressible flow (incomp=False) is not currently supported and will throw an error.
allow_toroidal_flowAllow toroidal (phi) flow in the MHD regions (default:False)

◆ step()

step ( self,
time,
dt,
coil_currents = None )

Advance the coupled solution by one timestep.

Parameters
timeTime at the start of the step [s]
dtTimestep size [s]
coil_currentsCoil currents as a dict of name->[A] (if None, the equilibrium's present currents are used)
Returns
new time, new dt, # nonlinear iterations, # linear iterations, # retries

Member Data Documentation

◆ _mhd_dict

_mhd_dict = mhd_dict
protected

Per-region MHD properties as supplied to setup().

◆ _mhd_flag

_mhd_flag = None
protected

Per-region MHD flag [nreg] (1 = MHD region); set by setup().

◆ _oft_env

_oft_env = tokamaker._oft_env
protected

OpenFUSIONToolkit environment (See OFT_env).

◆ _plc

_plc = None
protected

◆ _pr

_pr = None
protected

Cached order-1 (pressure) plotting mesh (loaded on first access).

◆ _preg

_preg = None
protected

◆ _ptr

_ptr = ctypes.c_void_p()
protected

C pointer to the Fortran-side combined simulation object.

◆ _tokamaker

_tokamaker = tokamaker
protected

Parent TokaMaker object (mesh/equilibrium/coils borrowed from it).

◆ lc

lc = None

Triangle list [nc,3] for the main order fields (same as TokaMaker.lc).

◆ pressure_lc

pressure_lc = None

Triangle list [nc_p,3] for the (order-1) pressure field.

◆ pressure_r

pressure_r = None

Node coordinates [np_p,3] for the (order-1) pressure field.

◆ pressure_reg

pressure_reg = None

Per-cell region IDs [nc_p] for the (order-1) pressure mesh.

◆ r

r = None

Node coordinates [np,3] for the main order fields.

These are the same tessellated node points as the parent TokaMaker.r, so the order-2 fields (and psi) can be plotted with self.r/self.lc.

◆ reg

reg = None

Per-cell region IDs [nc] for the main order fields (same as TokaMaker.reg).


The documentation for this class was generated from the following file: