Skip to main content

Python package for running and analysing gyrokinetic simulations

Project description

Documentation Status Tests Available on pypi Formatted with black Code coverage DOI

Pyrokinetics

This project aims to standardise gyrokinetic analysis.

A general pyro object can be loaded either from simulation/experimental data or from an existing gyrokinetics file.

In general pyrokinetics can do the following

  • Read data in from:
    • Gyrokinetic input files
    • Simulations outputs
  • Write input files for various GK codes
  • Generate N-D pyro object for scans
  • Read in gyrokinetic outputs
  • Standardise analysis of gk outputs

At a minimum pyrokinetics needs the local geometry and species data. Example scripts can be found in the examples folder

Documentation

Documentation can be found at readthedocs.

Installation

Pyrokinetics requires a minimum Python version of 3.9. It may be necessary to upgrade pip to install:

$ pip install --upgrade pip

To install the latest release:

$ pip install pyrokinetics

Otherwise, to install from source:

$ git clone https://github.com/pyro-kinetics/pyrokinetics.git
$ cd pyrokinetics
$ pip install .

If you are planning on developing pyrokinetics use the following instead to install:

$ pip install -e .[docs,tests]

Note that currently the installation of pyrokinetics requires an available Fortran compiler

Testing

To run the tests:

$ pip install -e .[tests]
$ pytest --cov .

Basic Usage

The simplest action in Pyrokinetics is to convert a gyrokinetics input file for code 'X' into an equivalent input file for code 'Y'. The easiest way to achieve this is to use a Pyro object, which manages the various other classes in the API. For example, to convert a GS2 input file to a CGYRO input file:

>>> from pyrokinetics import Pyro
>>> pyro = Pyro(gk_file="my_gs2_file.in") # file type is automatically inferred
>>> pyro.write_gk_file("input.cgyro", gk_code="CGYRO")

There are many other features in Pyrokinetics, such as methods for building gyrokinetics input files using global plasma equilibria and/or kinetics profiles. There are also methods for analysing and comparing the results from gyrokinetics code runs. Please read the docs for more information.

Command Line Interface

After installing, simple pyrokinetics operations can be performed on the command line using either of the following methods:

$ python3 -m pyrokinetics {args...}
$ pyro {args...}

For example, to convert a GS2 input file to CGYRO:

$ pyro convert CGYRO "my_gs2_file.in" -o "input.cgyro"

You can get help on how to use the command line interface or any of its subcommands by providing -h or --help:

$ pyro --help
$ pyro convert --help

Docker

Pyrokinetics provides a Dockerfile from which you can build and run Docker containers. To do so, you must have Docker installed on your system. To build a local container:

$ docker build . -t pyrokinetics

It can then be run using:

$ docker run -it --rm -v ./path/to/local:/mymount pyrokinetics

where:

  • -it runs an interactive shell.
  • --rm deletes the Docker instance after use.
  • -v ./path/to/local:/mymount mounts the local directory ./path/to/local to the directory /mymount within the Docker container.

The container runs an IPython interpreter, with Pyrokinetics already installed. Note that you will need to import Pyrokinetics before it can be used.

Code structure

Pyro object comprised of

  • Equilibrium
    • LocalGeometry
      • Miller
      • Fourier (to be added)
  • Kinetics
    • LocalSpecies
  • Numerics
  • GKCodes
  • GKOutput
    • For nonlinear simulations
      • Fields (field, kx, ky, theta, time)
      • Fluxes (field, species, moment, ky, theta, time)
    • For linear simulations
      • Fields (field, kx, ky, theta, time)
      • Fluxes (field, species, moment, ky, theta, time)
      • Eigenfunctions (field, ky, theta, time)
      • Eigenvalues - growth rate and mode freq (ky, time)

There also exists the PyroScan object which allows you to make a N-D parameter scan of Pyro objects

Supports sources of Equilibrium data

pyrokinetics currently supports

Future formats to be added are

  • CHEASE

Supported sources of Kinetic data

Sources of kinetic profile data currently supported are

  • SCENE
  • JETTO
  • TRANSP

Future codes to be add

  • SimDB
  • OMFIT

Supported GK codes

The following gk codes are supported in pyrokinetics

  • CGYRO
  • GS2
  • GENE
  • TGLF

Codes to be added in the future

  • Stella
  • GX

Note on units

The pyro object uses standardised reference values to normalise the results. It will automatically handle converting to a GK codes standard units.

Note any scans/parameter changes made will be in standard pyro units so please account for this.

Reference values

  • $T_{ref} = T_e$ Electron temperature at flux surface
  • $n_{ref} = n_e$ Electron density at flux surface
  • $m_{ref} = m_D$ Deuterium mass
  • $v_{ref} = c_s = \sqrt{T_e/m_D}$ Ion sound speed at flux surface
  • $B_{ref} = B_0$ Toroidal field at centre of the flux surface
  • $L_{ref} = a$ Minor radius of the last closed flux surface
  • $t_{ref} = a/c_s$ Ion sound time at flux surface
  • $\rho_{ref} = \frac{c_s}{eB_0/m_D}$ Ion Larmor radius at flux surface

It is possible to change the reference units but proceed with caution

Used By

This project is used by the following institutions

  • CCFE
  • University of York

Copyright owned by UKAEA. Pyrokinetics is licensed under LGPL-3.0, and is free to use, modify, and distribute.

Project details


Download files

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

Source Distribution

pyrokinetics-0.7.0.tar.gz (21.1 MB view details)

Uploaded Source

Built Distribution

pyrokinetics-0.7.0-py3-none-any.whl (16.9 MB view details)

Uploaded Python 3

File details

Details for the file pyrokinetics-0.7.0.tar.gz.

File metadata

  • Download URL: pyrokinetics-0.7.0.tar.gz
  • Upload date:
  • Size: 21.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for pyrokinetics-0.7.0.tar.gz
Algorithm Hash digest
SHA256 1fcda982b1ed62894b0ac103a1fe07c5f6c70a186d23e6385b3ebf3a07014ac2
MD5 15d2a8ee20facb18c92605bbf83b065e
BLAKE2b-256 eaf385bc9e5a5c6891cf5bb609694af09406d0b44a1a0f8b584349f65db1c0ab

See more details on using hashes here.

File details

Details for the file pyrokinetics-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: pyrokinetics-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for pyrokinetics-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 074d480598ddb8e7ddbc8d02b012b8bacf06cf96d36a679da0a4bb251ece540d
MD5 7649e0d736d525f52cc3ba5d1175a83c
BLAKE2b-256 0568aba36b321c1b40177453ce74d842b848d32690f3b20b4b564b6d28623fb8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page