forked from freegs-plasma/freegs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
09-metal-wall.py
84 lines (58 loc) · 2.53 KB
/
09-metal-wall.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
#!/usr/bin/env python
#
# Calculate the equilibrium for a plasma surrounded by a metal wall
# This is done by creating a ring of coils, with feedback control setting
# the poloidal flux to zero at the location of each coil.
import freegs
import numpy as np
#########################################
# Create a circular metal wall by using a ring of coils and psi constraints
R0 = 1.0 # Middle of the circle
rwall = 0.5 # Radius of the circular wall
npoints = 200 # Number of points on the wall
# Poloidal angles
thetas = np.linspace(0, 2*np.pi, npoints, endpoint=False)
# Points on the wall
Rwalls = R0 + rwall * np.cos(thetas)
Zwalls = rwall * np.sin(thetas)
#########################################
# Create the machine, which specifies coil locations
# and equilibrium, specifying the domain to solve over
coils = [ ("wall_"+str(theta), freegs.machine.Coil(R, Z))
for theta, R, Z in zip(thetas, Rwalls, Zwalls) ]
tokamak = freegs.machine.Machine(coils)
eq = freegs.Equilibrium(tokamak=tokamak,
Rmin=0.1, Rmax=2.0, # Radial domain
Zmin=-1.0, Zmax=1.0, # Height range
nx=65, ny=65, # Number of grid points
boundary=freegs.boundary.freeBoundaryHagenow) # Boundary condition
#########################################
# Plasma profiles
profiles = freegs.jtor.ConstrainPaxisIp(1e4, # Plasma pressure on axis [Pascals]
1e6, # Plasma current [Amps]
2.0) # Vacuum f=R*Bt
#########################################
# Coil current constraints
#
# Same location as the coils
psivals = [ (R, Z, 0.0) for R, Z in zip(Rwalls, Zwalls) ]
constrain = freegs.control.constrain(psivals=psivals)
#########################################
# Nonlinear solve
freegs.solve(eq, # The equilibrium to adjust
profiles, # The toroidal current profile function
constrain, # Constraint function to set coil currents
psi_bndry=0.0) # Because no X-points, specify the separatrix psi
# eq now contains the solution
print("Done!")
print("Plasma current: %e Amps" % (eq.plasmaCurrent()))
print("Plasma pressure on axis: %e Pascals" % (eq.pressure(0.0)))
##############################################
# Save to G-EQDSK file
from freegs import geqdsk
with open("metal-wall.geqdsk", "w") as f:
geqdsk.write(eq, f)
##############################################
# Final plot
axis = eq.plot(show=False)
constrain.plot(axis=axis, show=True)