-
Notifications
You must be signed in to change notification settings - Fork 54
/
08-mast-upgrade.py
146 lines (101 loc) · 3.91 KB
/
08-mast-upgrade.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
import freegs
from freegs.plotting import plotConstraints
#########################################
# Create the machine, which specifies coil locations
# and equilibrium, specifying the domain to solve over
tokamak = freegs.machine.MASTU_simple()
eq = freegs.Equilibrium(tokamak=tokamak,
Rmin=0.1, Rmax=2.0, # Radial domain
Zmin=-2.1, Zmax=2.1, # Height range
nx=65, ny=65) # Number of grid points
#########################################
# Plasma profiles
profiles = freegs.jtor.ConstrainPaxisIp(eq,
6e4, # Plasma pressure on axis [Pascals]
1e6, # Plasma current [Amps]
0.65, # vacuum f = R*Bt
alpha_m = 1.0,
alpha_n = 2.0)
#########################################
# Coil current constraints
#
# Specify locations of the X-points
# to use to constrain coil currents
Rx = 0.509
Zx = 1.291
Rmid = 1.34 # Outboard midplane
Rin = 0.3581 # Inboard midplane
xpoints = [(Rx, -Zx), # (R,Z) locations of X-points
(Rx, Zx)]
isoflux = [(Rx,-Zx, Rmid, 0.0) # Outboard midplane, lower X-point
,(Rx,Zx, Rmid, 0.0) # Outboard midplane, upper X-point
# Link inner and outer midplane locations
,(Rmid, 0.0, Rin, 0.0)
# Separatrix in the divertor chamber
,(Rx,-Zx, 0.95, -1.77)
,(Rx, Zx, 0.95, 1.77)
]
constrain = freegs.control.constrain(xpoints=xpoints, gamma=8e-6, isoflux=isoflux)
constrain(eq)
#########################################
# Nonlinear solve
freegs.solve(eq, # The equilibrium to adjust
profiles, # The plasma profiles
constrain, # Plasma control constraints
show=True) # Shows results at each nonlinear iteration
#########################################
# Now adjust the equilibrium manually
#
isoflux = [(Rx,-Zx, Rmid, 0.0) # Outboard midplane, lower X-point
,(Rx,Zx, Rmid, 0.0) # Outboard midplane, upper X-point
,(Rmid, 0.0, Rin, 0.0)
,(Rx,-Zx, 0.95, -1.77)
,(Rx, Zx, 0.95, 1.77)
,(Rx,-Zx, 0.76, -1.58)
,(Rx, Zx, 0.76, 1.58)
,(Rx,-Zx, 1.25, -1.8)
,(Rx, Zx, 1.25, 1.8)
]
constrain = freegs.control.constrain(xpoints=xpoints, gamma=1e-12, isoflux=isoflux)
# Turn off feedback control for all coils
for label, coil in tokamak.coils:
coil.control = False
# Centre column coil
tokamak["Pc"].current = -4e4
# Turn on vertical feedback control
tokamak["P6"].control = True
# Coil in the "nose" of the divertor
tokamak["Dp"].current = -1000.0
# At top of divertor chamber
tokamak["D6"].current = 500.0
tokamak["D7"].current = 500.0
# X-point location
tokamak["Px"].current = 2000.0
tokamak["D1"].current = 1000.0
# Coil in outer corner
tokamak["D5"].current = 1500.
# Coil at bottom centre
tokamak["D3"].current = 2800
freegs.solve(eq, # The equilibrium to adjust
profiles, # The plasma profiles
constrain, # Plasma control constraints
show=True) # Shows results at each nonlinear iteration
# eq now contains the solution
print("Done!")
print("Plasma current: %e Amps" % (eq.plasmaCurrent()))
print("Pressure on axis: %e Pascals" % (eq.pressure(0.0)))
print("Poloidal beta: %e" % (eq.poloidalBeta()))
print("Plasma volume: %e m^3" % (eq.plasmaVolume()))
eq.tokamak.printCurrents()
axis = eq.plot(show=False)
eq.tokamak.plot(axis=axis)
constrain.plot(axis=axis)
##############################################
# Save to geqdsk file
from freegs import geqdsk
with open("mast-upgrade.geqdsk", "w") as f:
geqdsk.write(eq, f)
# Call matplotlib show so plot pauses
import matplotlib.pyplot as plt
plt.show()