megpy 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
megpy-1.1.0/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
megpy-1.1.0/PKG-INFO ADDED
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.1
2
+ Name: megpy
3
+ Version: 1.1.0
4
+ Summary: MEGPy
5
+ Home-page: https://www.github.com/gsnoep/megpy
6
+ Author: Garud Snoep
7
+ Keywords: fusion simulation toolkit
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+
13
+ # MEGPy: Magnetic Equilibrium Geometry Python
14
+ MEGPy is a package for quick **extraction of (local) equilibrium quantities** and visualisation of 2D magnetic equilibria used in magnetic confinement fusion research.
15
+ It offers both a command line interface (CLI) and Python API.
16
+
17
+ # Getting started
18
+ To get MEGPy clone and install the latest version:
19
+ ```bash
20
+ $ git clone git@github.com:gsnoep/megpy.git
21
+ $ cd megpy
22
+ $ pip install --user -e .
23
+ ```
24
+
25
+ To use MEGPy call the CLI:
26
+ ```bash
27
+ $ python -m megpy <file_path> <parameterization> <x_fs>
28
+ ```
29
+ For details on the CLI options:
30
+ ```bash
31
+ $ python -m megpy -h
32
+ ```
33
+ Or use the Python API, of which some examples can be found in /examples/.
34
+
35
+ Join the repository to contribute or raise issues!
36
+
37
+ # Supported equilibrium formats
38
+ - EQDSK [(g-file)](https://w3.pppl.gov/ntcc/TORAY/G_EQDSK.pdf) from EFIT, ESCO, CHEASE or LIUQE
39
+
40
+ To be added:
41
+ - IMAS equilibrium IDS
42
+
43
+ # Supported flux-surface geometries
44
+ - Miller [(doi)](https://doi.org/10.1063/1.872666)
45
+ - Turnbull-Miller [(doi)](https://doi.org/10.1063/1.873380)
46
+ - Fourier / generalised Miller [(doi)](https://doi.org/10.1088/0741-3335/51/10/105009)
47
+ - Miller eXtended Harmonic (MXH) [(doi)](https://doi.org/10.1088/1361-6587/abc63b)
48
+
49
+ # Citation
50
+ If you use MEGPy in your research, please cite [(bibtex)](https://github.com/gsnoep/megpy/blob/main/citation.bib):
51
+ >G. Snoep, J.T.W. Koenders, C. Bourdelle, J. Citrin and JET contributors, "Improved flux-surface parameterization through constrained nonlinear optimization," _Physics of Plasmas_ **30**, 063906 (2023)
52
+
53
+
54
+ .#&%%%-.
55
+ <===#%%%%%%%%%%.
56
+ ?==%%( )%%%%%
57
+ )%%%%%%%%%%%%\
58
+ )%%%%%%%%%%%..%%%
59
+ )%%%%%%%%&.. .\%.
60
+ %%%%%%%% &\,. ..\%.
61
+ M%%%%%%%...&&%\%%%%%%%%%-
62
+ %%%%%. .\%%%%%%%%%%.
63
+ %%%.. .\%%%%%%%.
64
+ E... .\%%%%%%%-.
65
+ &... )%%%%(%%%.
66
+ G.. .&). )GS\ \%%%%%%-.
67
+ \&)) \&(%^^ \&%%%%%&.
68
+ )%% %% \%%%%%%%&.
69
+ .&& .% \&\\%%%%\\&..
70
+ .%< (\ % \
71
+ .::-P-..-& &&-Y&--.
megpy-1.1.0/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # MEGPy: Magnetic Equilibrium Geometry Python
2
+ MEGPy is a package for quick **extraction of (local) equilibrium quantities** and visualisation of 2D magnetic equilibria used in magnetic confinement fusion research.
3
+ It offers both a command line interface (CLI) and Python API.
4
+
5
+ # Getting started
6
+ To get MEGPy clone and install the latest version:
7
+ ```bash
8
+ $ git clone git@github.com:gsnoep/megpy.git
9
+ $ cd megpy
10
+ $ pip install --user -e .
11
+ ```
12
+
13
+ To use MEGPy call the CLI:
14
+ ```bash
15
+ $ python -m megpy <file_path> <parameterization> <x_fs>
16
+ ```
17
+ For details on the CLI options:
18
+ ```bash
19
+ $ python -m megpy -h
20
+ ```
21
+ Or use the Python API, of which some examples can be found in /examples/.
22
+
23
+ Join the repository to contribute or raise issues!
24
+
25
+ # Supported equilibrium formats
26
+ - EQDSK [(g-file)](https://w3.pppl.gov/ntcc/TORAY/G_EQDSK.pdf) from EFIT, ESCO, CHEASE or LIUQE
27
+
28
+ To be added:
29
+ - IMAS equilibrium IDS
30
+
31
+ # Supported flux-surface geometries
32
+ - Miller [(doi)](https://doi.org/10.1063/1.872666)
33
+ - Turnbull-Miller [(doi)](https://doi.org/10.1063/1.873380)
34
+ - Fourier / generalised Miller [(doi)](https://doi.org/10.1088/0741-3335/51/10/105009)
35
+ - Miller eXtended Harmonic (MXH) [(doi)](https://doi.org/10.1088/1361-6587/abc63b)
36
+
37
+ # Citation
38
+ If you use MEGPy in your research, please cite [(bibtex)](https://github.com/gsnoep/megpy/blob/main/citation.bib):
39
+ >G. Snoep, J.T.W. Koenders, C. Bourdelle, J. Citrin and JET contributors, "Improved flux-surface parameterization through constrained nonlinear optimization," _Physics of Plasmas_ **30**, 063906 (2023)
40
+
41
+
42
+ .#&%%%-.
43
+ <===#%%%%%%%%%%.
44
+ ?==%%( )%%%%%
45
+ )%%%%%%%%%%%%\
46
+ )%%%%%%%%%%%..%%%
47
+ )%%%%%%%%&.. .\%.
48
+ %%%%%%%% &\,. ..\%.
49
+ M%%%%%%%...&&%\%%%%%%%%%-
50
+ %%%%%. .\%%%%%%%%%%.
51
+ %%%.. .\%%%%%%%.
52
+ E... .\%%%%%%%-.
53
+ &... )%%%%(%%%.
54
+ G.. .&). )GS\ \%%%%%%-.
55
+ \&)) \&(%^^ \&%%%%%&.
56
+ )%% %% \%%%%%%%&.
57
+ .&& .% \&\\%%%%\\&..
58
+ .%< (\ % \
59
+ .::-P-..-& &&-Y&--.
@@ -0,0 +1,24 @@
1
+ import sys
2
+ from pkg_resources import (
3
+ DistributionNotFound as _DistributionNotFound,
4
+ get_distribution as _get_distribution,
5
+ )
6
+
7
+ if sys.version_info < (3,7):
8
+ raise Exception("MEGPy does not support Python < 3.7")
9
+
10
+ from .equilibrium import Equilibrium
11
+ from .localequilibrium import LocalEquilibrium
12
+ from .tracer import *
13
+
14
+
15
+ __all__= [
16
+ "Equilibrium",
17
+ "LocalEquilibrium"
18
+ ]
19
+
20
+ try:
21
+ _distribution = _get_distribution("megpy")
22
+ __version__ = _distribution.version
23
+ except _DistributionNotFound:
24
+ __version__ = "unknown"
@@ -0,0 +1,4 @@
1
+ from .cli import parse
2
+
3
+ if __name__ == "__main__":
4
+ parse()
@@ -0,0 +1,92 @@
1
+ import os
2
+ import argparse
3
+
4
+ from .equilibrium import Equilibrium
5
+ from .localequilibrium import LocalEquilibrium
6
+ from .utils import *
7
+
8
+ def is_valid_file(file):
9
+ if not os.path.exists(file):
10
+ raise argparse.ArgumentTypeError('The provided path {} does not lead to an existing EQDSK file, check input!'.format(file))
11
+ else:
12
+ return file
13
+
14
+ def str2bool(v):
15
+ if isinstance(v, bool):
16
+ return v
17
+ if v.lower() in ('yes', 'true', 't', 'y', '1'):
18
+ return True
19
+ elif v.lower() in ('no', 'false', 'f', 'n', '0'):
20
+ return False
21
+ else:
22
+ raise argparse.ArgumentTypeError('Boolean value expected.')
23
+
24
+ def parse():
25
+ parser = argparse.ArgumentParser(description='MEGPy: Extract flux surface shaping parameters (Miller, Turnbull-Miller, etc) from EQDSK files.')
26
+ parser.add_argument(dest='file', type=is_valid_file, help='valid path to an EQDSK file', metavar='FILE')
27
+ parser.add_argument(dest='method', type=str, default='turnbull', help='parameterization to be used for fitting the flux surfaces and Bpol', metavar='PARAM')
28
+ parser.add_argument(dest='x_fs', type=float, help='radial location to extract flux surface and Bpol shaping parameters', metavar='POSITION')
29
+ parser.add_argument('-x', '--x_label', dest='x_label', required=False, type=str, default='rho_tor', help='label of the radial location (e.g. rho_tor, rho_pol, r/a)', metavar='STR')
30
+ parser.add_argument('-r', '--refine', dest='refine', required=False, type=int, default=0, help='refine the poloidal flux map psi(R,Z) <r> times', metavar='INT')
31
+ parser.add_argument('--n_x', dest='n_x', required=False, type=int, default=9, help='number of radial points used for radial derivatives', metavar='INT')
32
+ parser.add_argument('--n_theta', dest='n_theta', required=False, type=int, default=7200, help='number of poloidal grid points', metavar='INT')
33
+ parser.add_argument('--n_harmonics', dest='n_harmonics', required=False, type=int, default=3, help='number of harmonics used in the optimization for fourier/miller_general/mxh', metavar='INT')
34
+ parser.add_argument('-p', '--printer', dest='printer', required=False, type=str, default='GENE', help='name of the code to print the geometry input values for', metavar='STR')
35
+ parser.add_argument('--printer_lref', dest='lref', required=False, type=str, default='a', help='reference length Lref used to normalized code input values', metavar='STR')
36
+ parser.add_argument('-a', '--analytic-geo', dest='analytic_geo', required=False, nargs='?', const=True, default=True, type=str2bool, help='include the analytical Miller parameters for comparison y/n', metavar='BOOL')
37
+ parser.add_argument('--opt-bpol', dest='opt_bpol', required=False, nargs='?', const=False, default=False, type=str2bool, help='optimize shape derivative parameters by minimizing the error in Bpol', metavar='BOOL')
38
+ parser.add_argument('--opt-deriv', dest='opt_deriv', required=False, nargs='?', const=False, default=False, type=str2bool, help='optimize shape derivative parameters by minimizing the error in dRdr, dZdr, dRdtheta, dZdtheta', metavar='BOOL')
39
+ args = parser.parse_args()
40
+
41
+ eq = Equilibrium()
42
+ eq.read_geqdsk(f_path=args.file)
43
+ if args.refine > 1:
44
+ eq.add_derived(refine=args.refine)
45
+ else:
46
+ eq.add_derived()
47
+ if args.x_label == 'r/a':
48
+ print('Processing Equilibrium to determine r/a(psi)...')
49
+ eq.add_fluxsurfaces()
50
+
51
+ locgeo = LocalEquilibrium(args.method,
52
+ eq,
53
+ args.x_fs,
54
+ x_label=args.x_label,
55
+ n_x=args.n_x,
56
+ n_theta=args.n_theta,
57
+ n_harmonics=args.n_harmonics,
58
+ analytic_shape=args.analytic_geo,
59
+ opt_bpol=args.opt_bpol,
60
+ opt_deriv=args.opt_deriv,
61
+ diag_lsq=0,
62
+ verbose=True)
63
+
64
+
65
+ if args.printer:
66
+ locgeo.printer(args.printer,locgeo.shape,locgeo.param_labels,locgeo.shape_deriv,locgeo.deriv_labels)
67
+ #if incl_analytic_geo:
68
+ # self.printer(printer,self.shape_analytic,self.param_labels,self.shape_deriv_analytic,self.deriv_labels)
69
+
70
+ #if not args.no_plots:
71
+ # locgeo.plot_all(incl_analytic_geo=args.analytic_geo,opt_bpol=args.opt_bpol)
72
+
73
+
74
+
75
+ str_megpy=["\n .#&%%%-.\n"
76
+ ," <===#%%%%%%%%%%.\n"
77
+ ," ?==%%( )%%%%\\\n"
78
+ ," )%%%%%%%%%%%%\\\n"
79
+ ," )%%%%%%%%%%%..%%%\n"
80
+ ," )%%%%%%%%&.. .\%.\n"
81
+ ," %%%%%%%% &\,. ...\\%.\n"
82
+ ," M%%%%%%%...&&%\%%%%%%%%%-\n"
83
+ ," %%%%%. .\%%%%%%%%%%.\n"
84
+ ," %%%.. .\%%%%%%%.\n"
85
+ ," E... .\%%%%%%%-.\n"
86
+ ," &... )%%%%(%%%.\n"
87
+ ," G.. .&). )GS\ \%%%%%%-\n"
88
+ ," \&)) \&(%^^ \&%%%%%&.\n"
89
+ ," )%% %% \%%%%%%%&.\n"
90
+ ," .&& .% \&\\%%%%\\&..\n"
91
+ ," .%< (\ % \\\n"
92
+ ," .::-P-..-& &&-Y&--.\n\n"]