Skip to content
Snippets Groups Projects
Commit 8b61d9c3 authored by Stefan Possanner's avatar Stefan Possanner
Browse files

Added License, delete old files, update README

parent d066294f
Branches
Tags
1 merge request!2Added License, delete old files, update README
Pipeline #154035 failed
Showing with 45 additions and 284 deletions
......@@ -45,7 +45,7 @@ install_and_test:
# - apt-get -qq insall -y texlive-latex-recommended texlive-fonts-recommended tex-gyre texlive-latex-extra latexmk texlive-lang-cyrillic texlive-lang-greek cm-super texlive-xetex texlive-luatex fonts-freefont-otf xindy graphviz
- python -m venv ipp-env
- source ipp-env/bin/activate
- pip install -U pip build wheel pytest coverage
- pip install -U pip build wheel pytest pytest-cov coverage
# - pip install -r requirements.txt
# Print directory structure, but exclude virtual environment directory.
......@@ -69,7 +69,6 @@ install_and_test:
- coverage run -m pytest
- coverage xml
- coverage report --skip-empty
- coverage erase
# Deploy: run deploy.
- echo "Run deploy:"
......
## Max Planck Institute for Plasma Physics
* Florian Hindenlang
* Stefan Possanner
## TU Munich
* Tin Kei Cheng
Copyright 2023 (c) T.K. Cheng, F. Hindenlang, S. Possanner | Max Planck Institute for Plasma Physics
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# 3D GVEC equilibria in Python
Install:
PyPI install (not yet :-):
```
pip install gvec_to_python
```
Compile kernels (for fast evaluations):
Or from source:
```
git clone git@gitlab.mpcdf.mpg.de:spossann/gvec_to_python.git
cd gvec_to_python
pip install -e .
```
Compile kernels for faster evaluations:
```
compile_gvec_to_python
```
......@@ -22,7 +28,7 @@ In a second step, callables of MHD equilibrium quantities are created as methods
```
from gvec_to_python import GVEC
gvec = GVEC(json_file_out)
gvec = GVEC(json_file_out, mapping='gvec', use_nfp=False, use_pyccel=False)
```
Profiles can be evaluated via
```
......@@ -31,6 +37,8 @@ gvec.profiles.profile(s, name='chi') # poloidal flux profile
gvec.profiles.profile(s, name='iota') # iota profile
gvec.profiles.profile(s, name='pressure') # pressure profile
```
![Profiles](notebooks/profiles.png "Title")
The mapping and metric coefficients are called via
```
gvec.f(s, a1, a2) # mapping
......@@ -41,7 +49,11 @@ gvec.g(s, a1, a2) # metric tensor
gvec.g_inv(s, a1, a2) # inverse metric tensor
```
Here, `s` is the radial coordinate, `a1` is the poloidal angle and `a2` denotes the toroidal angle.
Four different mappings can be invoked by the `mapping.setter`:
![Profiles](notebooks/poloidal.png "Title")
![](notebooks/topview.png)
Five different mappings can be invoked by the `mapping.setter`:
```
# gvec standard coordinates
gvec.mapping = 'gvec'
......@@ -54,7 +66,14 @@ gvec.mapping = 'unit'
# gvec straight-field-line with unit cube as logical domain
gvec.mapping = 'unit_pest'
# gvec without hmap
gvec.mapping = 'wo_hmap'
```
![](notebooks/dtheta.png)
![](notebooks/det_df.png)
The MHD quantities are called via
```
gvec.p0(s, a1, a2) # pressure as 0-form
......@@ -68,8 +87,11 @@ gvec.a1(s, a1, a2) # co-variant vector potential (1-form)
gvec.a2(s, a1, a2) # 2-form vector potential
gvec.a_cart(s, a1, a2) # Cartesian vector potential
```
See the notebook `notebooks/plt_mhd_equil.ipynb` for example plots like this one:
![Poloidal geometry](poloidal_grid.png "Title")
![](notebooks/pressure.png)
![](notebooks/absB.png)
# This script is similar to the pipeline in GitLab CI `.gitlab-ci.yml` file.
# Docs: Make sphinx docs.
echo "Make sphinx docs:"
sphinx-apidoc -f -o ./docs/source ./src/gvec_to_python
sphinx-build -b html ./docs/source ./public
# cd docs/
# make latex
# make latexpdf
# cd ..
# Build:
# echo "Run pyccel:"
# cd src/ && make flags_openmp_mhd= flags_openmp_pic=--openmp && cd ..
echo "Run python build:"
python -m build
ls -lah dist
echo "Install dist:"
pip install -U dist/gvec_to_python-*.whl # --force-reinstall
# Test: run pytest.
echo "Run pytest:"
coverage run -m pytest
coverage xml
coverage report --skip-empty
coverage erase
python test/cleanup.py
# Deploy: run deploy.
echo "Run deploy:"
echo "Release pipeline not implemented."
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
.wy-nav-content {
max-width: 1200px !important;
}
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath(os.path.join('..', '..', 'src')))
import sphinx_rtd_theme
# -- Project information -----------------------------------------------------
project = 'Python Interface for GVEC Equilibria'
copyright = '2021, Max Planck Institute for Plasma Physic'
author = 'Tin Kei CHENG'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.duration', # https://www.sphinx-doc.org/en/master/usage/extensions/duration.html
'sphinx.ext.napoleon', # https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
'sphinx.ext.autodoc', # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
'sphinx.ext.mathjax', # https://www.sphinx-doc.org/en/master/usage/extensions/math.html
'sphinx.ext.viewcode', # https://www.sphinx-doc.org/en/master/usage/extensions/viewcode.html
'sphinx.ext.graphviz', # https://www.sphinx-doc.org/en/master/usage/extensions/graphviz.html
'sphinx.ext.inheritance_diagram', # https://www.sphinx-doc.org/en/master/usage/extensions/inheritance.html
'sphinx_rtd_theme', # https://sphinx-rtd-theme.readthedocs.io/en/stable/index.html
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# These paths are either relative to html_static_path
# or fully qualified paths (eg. https://...)
html_css_files = [
'css/my_theme.css',
]
# -- Options for LaTeX output ------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/builders/index.html#sphinx.builders.latex.LaTeXBuilder
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-latex-output
latex_engine = 'xelatex'
.. Python Interface for GVEC Equilibria documentation master file, created by
sphinx-quickstart on Thu Nov 4 11:55:49 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Python Interface for GVEC Equilibria's documentation!
================================================================
`STRUcture-Preserving HYbrid code (STRUPHY) <https://gitlab.mpcdf.mpg.de/clapp/hylife>`_ is a code base for kinetic-fluid plasma simulations developed at the `Max Planck Institute for Plasma Physics in Garching <https://www.ipp.mpg.de/17301/garching>`_.
In this package we add to STRUPHY several general Python interfaces for reading magneto-hydrodynamic (MHD) equilibrium data for Tokamaks and Stellarators.
In particular, interfaces to the equilibrium code `Galerkin Variational Equilibrium Code (GVEC) <https://gitlab.mpcdf.mpg.de/gvec-group/gvec>`_ (and in the future, to the ``eqdsk`` file format) are provided.
From the data, a flux-aligned coordinate system is created, and the MHD quantities are transformed into differential forms for the use in STRUPHY.
.. toctree::
:maxdepth: 3
:caption: Contents:
modules
..
Below is a comment.
.. inheritance-diagram:: gvec_to_python.GVEC_functions.GVEC
How to use
==========
First and foremost, one need to setup the package.
It can be accomplished as simple as a ``pip install -e ./``.
..
See Section "Build and install" below for detailed instructions.
This code needs to read in a GVEC MHD equilibrium in JSON format.
Therefore, the `.dat` GVEC output data has to be converted into ``.json`` using a utility as demonstrated below.
This only needs to be done once, per GVEC equilibrium.
.. code-block:: python
from gvec_to_python.reader.gvec_reader import GVEC_Reader
# Spline coefficients are not provided by GVEC by default.
read_filepath = 'GVEC/testcases/circ_tok/'
read_filename = 'CIRC_TOK_State_0000_00010000.dat'
save_filepath = 'GVEC/testcases/circ_tok/'
save_filename = 'CIRC_TOK_State_0000_00010000.json'
reader = GVEC_Reader(read_filepath, read_filename, save_filepath, save_filename, with_spl_coef=False)
# Special case with spline coefficients.
read_filepath = 'GVEC/testcases/ellipstell/'
read_filename = 'GVEC_ellipStell_profile_update_State_0000_00010000.dat'
save_filepath = 'GVEC/testcases/ellipstell/'
save_filename = 'GVEC_ellipStell_profile_update_State_0000_00010000.json'
reader = GVEC_Reader(read_filepath, read_filename, save_filepath, save_filename, with_spl_coef=True)
The main features can then be used simply as follows:
.. code-block:: python
:emphasize-lines: 6,24,25,26,27,28
import numpy as np
from gvec_to_python import GVEC, Form, Variable
gvec_data_filepath = 'GVEC/testcases/ellipstell/'
gvec_data_filename = 'GVEC_ellipStell_profile_update_State_0000_00010000.json'
gvec = GVEC(gvec_data_filepath, gvec_data_filename)
# The functions can accept various types of inputs:
# - Individual point in logical coordinates.
(s, u, v) = (0.1, 0.2, 0.3)
# - 1D arrays of a grid.
s_range = np.linspace(0, 1, 11)
u_range = np.linspace(0, 1, 21)
v_range = np.linspace(0, 1, 31)
# - A sparse 3D meshgrid.
s_sparse, u_sparse, v_sparse = np.meshgrid(s_range, u_range, v_range, indexing='ij', sparse=True)
# - A dense 3D meshgrid.
s_dense, u_dense, v_dense = np.meshgrid(s_range, u_range, v_range, indexing='ij', sparse=False)
# Function parameters can either be floats gvec.F(s, u, v),
# or 1D arrays gvec.F(s_range, u_range, v_range),
# or 3D arrays from sparse meshgrid gvec.F(s_sparse, u_sparse, v_sparse),
# or dense meshgrid gvec.F(s_dense, u_dense, v_dense).
(x, y, z) = gvec.F(s, u, v)
jacobian = gvec.DF(s, u, v)
pressure = gvec.get_variable(s, u, v, variable=Variable.PRESSURE, form=Form.ZERO)
pressure = gvec.P(s, u, v) # Alternatively, a shorthand is available.
p_3 = gvec.P_3(s, u, v) # 3-form pressure.
Caveat: The mapping function ``F()`` returns in the shape ``(3, #s, #u, #v)`` so that we can do ``(x, y, z) = gvec.F(s, u, v)``, but the Jacobian function ``DF()`` returns in the shape ``(#s, #u, #v, 3, 3)`` in order to comply with numpy's convention.
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
File deleted
# Ignore everything in this directory
*
# Except this file
!.gitignore
\ No newline at end of file
notebooks/absB.png

87.8 KiB

notebooks/det_df.png

114 KiB

notebooks/dtheta.png

751 KiB

notebooks/poloidal.png

447 KiB

notebooks/pressure.png

128 KiB

notebooks/profiles.png

74.7 KiB

notebooks/topview.png

397 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment