MCPcopy Create free account
hub / github.com/boutproject/BOUT-dev / generate

Function generate

tests/MMS/GBS/circle.py:22–117  ·  view source on GitHub ↗
(
    nx,
    ny,
    R=2.0,
    r=0.2,  # Major & minor radius
    dr=0.05,  # Radial width of domain
    Bt=1.0,  # Toroidal magnetic field
    q=5.0,  # Safety factor
    mxg=2,
    file="circle.nc",
)

Source from the content-addressed store, hash-verified

20
21
22def generate(
23 nx,
24 ny,
25 R=2.0,
26 r=0.2, # Major & minor radius
27 dr=0.05, # Radial width of domain
28 Bt=1.0, # Toroidal magnetic field
29 q=5.0, # Safety factor
30 mxg=2,
31 file="circle.nc",
32):
33 # q = rBt / RBp
34 Bp = r * Bt / (R * q)
35
36 # Minor radius as function of x. Choose so boundary
37 # is half-way between grid points
38
39 h = dr / (nx - 2.0 * mxg) # Grid spacing in r
40 rminor = linspace(
41 r - 0.5 * dr - (mxg - 0.5) * h, r + 0.5 * dr + (mxg - 0.5) * h, nx
42 )
43
44 # mesh spacing in x and y
45 dx = ndarray([nx, ny])
46 dx[:, :] = r * Bt * h # NOTE: dx is toroidal flux
47
48 dy = ndarray([nx, ny])
49 dy[:, :] = 2.0 * pi / ny
50
51 # LogB = log(1/(1+r/R cos(theta))) =(approx) -(r/R)*cos(theta)
52 logB = zeros([nx, ny, 3]) # (constant, n=1 real, n=1 imag)
53
54 # At y = 0, Rmaj = R + r*cos(theta)
55 logB[:, 0, 1] = -(rminor / R)
56
57 # Moving in y, phase shift by (toroidal angle) / q
58 for y in range(1, ny):
59 dtheta = y * 2.0 * pi / ny / q # Change in poloidal angle
60
61 logB[:, y, 1] = -(rminor / R) * cos(dtheta)
62 logB[:, y, 2] = -(rminor / R) * sin(dtheta)
63
64 # Shift angle from one end of y to the other
65 ShiftAngle = ndarray([nx])
66 ShiftAngle[:] = 2.0 * pi / q
67
68 Rxy = ndarray([nx, ny])
69 Rxy[:, :] = r # NOTE : opposite to standard BOUT convention
70
71 Btxy = ndarray([nx, ny])
72 Btxy[:, :] = Bp
73
74 Bpxy = ndarray([nx, ny])
75 Bpxy[:, :] = Bt
76
77 Bxy = ndarray([nx, ny])
78 Bxy[:, :] = sqrt(Bt**2 + Bp**2)
79

Callers 2

generateMethod · 0.85
createRunIDMethod · 0.85

Calls 3

openMethod · 0.80
closeMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected