forked from freegs-plasma/freegs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-xpoints.py
64 lines (46 loc) · 1.51 KB
/
06-xpoints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
#
# Example demonstrating functions for creating and finding X-points
import freegs
# Plotting routines
from freegs.plotting import plotEquilibrium, plotCoils, plotConstraints
import matplotlib.pyplot as plt
tokamak = freegs.machine.TestTokamak()
eq = freegs.Equilibrium(tokamak=tokamak, nx=256,ny=256)
##########################################################
# Calculate currents in coils to create X-points
# in specified locations
#
xpoints = [(1.1, -0.8), # (R,Z) locations of X-points
(1.1, 0.8)]
control = freegs.control.constrain(xpoints=xpoints)
control(eq) # Apply control to Equilibrium eq
psi = eq.psi()
print("=> Solved coil currents, created X-points")
ax = plotEquilibrium(eq, show=False)
plotCoils(tokamak.coils, axis=ax)
plotConstraints(control, axis=ax)
plt.show()
##########################################################
# Find critical points (O- and X-points)
#
#
import freegs.critical as critical
opt, xpt = critical.find_critical(eq.R, eq.Z, psi)
print("=> Found O- and X-points")
ax = plotEquilibrium(eq, show=False, oxpoints=False)
for r,z,_ in xpt:
ax.plot(r,z,'ro')
for r,z,_ in opt:
ax.plot(r,z,'go')
psi_bndry = xpt[0][2]
sep_contour=ax.contour(eq.R, eq.Z,psi, levels=[psi_bndry], colors='r')
plt.show()
##########################################################
# Create a mask array, 1 in the core and 0 outside
#
#
mask = critical.core_mask(eq.R, eq.Z, psi, opt, xpt)
print("=> Created X-point mask")
plt.contourf(eq.R, eq.Z, mask)
plt.show()