Skip to main content

Free boundary Grad-Shafranov solver for tokamak plasma equilibria

Project description

[![License](]( [![py3comp](](

This Python module calculates plasma equilibria for tokamak fusion experiments, by solving the Grad-Shafranov equation with free boundaries. Given a set of coils, plasma profiles and shape, FreeGS finds the currents in the coils which produce a steady-state solution in force balance.

Note This is a work in progress, and probably contains bugs. There is a feature wishlist in issues, suggestions and contributions welcome!


FreeGS is available on PyPI

$ pip install –user freegs

or clone/download this repository and run setup:

$ git clone $ cd freegs $ python install –user


The manual is in the docs subdirectory, and [hosted here on readthedocs](


The Jupyter notebooks contain examples wuth additional notes

  • MAST-example.ipynb

There are also some Python scripts to run short tests and examples

$ python

This solves a free boundary problem, specifying the desired location of two X-points. Writes the equilibrium to a G-EQDSK file “lsn.geqdsk”

$ python

Reads in the file “lsn.geqdsk”, inferring the coil currents from the plasma boundary and profiles in the G-EQDSK file.

$ python

Calculates a double-null (CDND) equilibrium for MAST from scratch. Writes solution to G-EQDSK file “mast.geqdsk”

$ python

Reads the file “mast.geqdsk”, inferring the coil currents.

$ python

This example solves a fixed boundary problem, in which the square edges of the domain are fixed. The plasma pressure on axis and plasma current are fixed.

$ python

This demonstrates the coil current control code, finding X-points, and marking core region These routines are used inside the free boundary solver


The “freegs” module consists of the following files:

  • - Operators for applying boundary conditions to plasma psi
  • - Routines for controlling coil currents based on constraints
  • - Finds critical points (O- and X-points)
  • - Represents the plasma equilibrium state
  • - Greens functions and operators for the Grad-Shafranov equation
  • - Routines for calculating toroidal current density (profiles)
  • - Represents the coils and power supply circuits
  • - The multigrid solver for the linear elliptic operator
  • - Nonlinear solver, iterating the profiles and constraints
  • - Plotting routines using matplotlib


Copyright 2016-2018 Ben Dudson, University of York. Email:

This program 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.

This program 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 this program. If not, see <>.



0.2.0 12th March 2019
  • Add field line tracer, freegs.fieldtracer
  • Add Equilibrium.Btor toroidal field calculation
  • Add Equilibrium.plasmaVolume
  • Fix rlim, zlim saved into GEQDSK files

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for FreeGS, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size FreeGS-0.3.0-py2.py3-none-any.whl (61.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size FreeGS-0.3.0.tar.gz (45.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page