Skip to content

Commit

Permalink
Apply black to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Jan 18, 2024
1 parent fdd33bf commit 36aa52a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 50 deletions.
20 changes: 10 additions & 10 deletions examples/example-straight-stellarator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
nz = 7

# Create magnetic field
magnetic_field = zoidberg.field.StraightStellarator(radius = 1.0)
magnetic_field = zoidberg.field.StraightStellarator(radius=1.0)

# Create a rectangular grid in (x,y,z)
rectangle = zoidberg.grid.rectangular_grid(nx,ny,nz,
Lx = 1.0, Lz = 1.0, Ly = 10.0,
yperiodic = True)
rectangle = zoidberg.grid.rectangular_grid(
nx, ny, nz, Lx=1.0, Lz=1.0, Ly=10.0, yperiodic=True
)

# Here both the field and and grid are centred at (x,z) = (0,0)
# and the rectangular grid here fits entirely within the coils
Expand All @@ -23,16 +23,16 @@
# Pick a poloidal slice and the next slice
yslice = 0
pol, ycoord = rectangle.getPoloidalGrid(yslice)
pol_next, ycoord_next = rectangle.getPoloidalGrid(yslice+1)
pol_next, ycoord_next = rectangle.getPoloidalGrid(yslice + 1)

# Plot the grid points at this poloidal slice
plt.plot(pol.R, pol.Z, 'x')
plt.plot(pol.R, pol.Z, "x")

# Get the coordinates which the forward map corresponds to
R_next, Z_next = pol_next.getCoordinate( maps['forward_xt_prime'][:,yslice,:], maps['forward_zt_prime'][:,yslice,:] )
R_next, Z_next = pol_next.getCoordinate(
maps["forward_xt_prime"][:, yslice, :], maps["forward_zt_prime"][:, yslice, :]
)

plt.plot(R_next, Z_next, 'o')
plt.plot(R_next, Z_next, "o")

plt.show()


18 changes: 11 additions & 7 deletions examples/field_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import zoidberg

# Size of the domain in y (periodic)
yperiod = 10.
yperiod = 10.0

# Define magnetic field
magnetic_field = zoidberg.field.StraightStellarator(I_coil=0.4, radius = 1.0, yperiod = yperiod)
magnetic_field = zoidberg.field.StraightStellarator(
I_coil=0.4, radius=1.0, yperiod=yperiod
)

# Make 3D plot
zoidberg.plot.plot_3d_field_line(magnetic_field,
0.3, # x starting position
0.0, # z starting position
yperiod, # Periodicity of y domain
cycles = 20)
zoidberg.plot.plot_3d_field_line(
magnetic_field,
0.3, # x starting position
0.0, # z starting position
yperiod, # Periodicity of y domain
cycles=20,
)
18 changes: 11 additions & 7 deletions examples/poincare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
import numpy as np

# Size of the domain in y (periodic)
yperiod = 10.
yperiod = 10.0

# Define magnetic field
magnetic_field = zoidberg.field.StraightStellarator(I_coil=0.4, radius = 1.0, yperiod = yperiod)
magnetic_field = zoidberg.field.StraightStellarator(
I_coil=0.4, radius=1.0, yperiod=yperiod
)

# Make Poincare plot
zoidberg.plot.plot_poincare(magnetic_field,
np.linspace(0,0.5,5), # x starting positions
0.0, # z starting positions
yperiod, # Periodicity of y domain
interactive=True) # Click on plot to add points
zoidberg.plot.plot_poincare(
magnetic_field,
np.linspace(0, 0.5, 5), # x starting positions
0.0, # z starting positions
yperiod, # Periodicity of y domain
interactive=True,
) # Click on plot to add points
34 changes: 21 additions & 13 deletions examples/straight-stellarator-curvilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

#############################################################################
# Define the magnetic field

# Length in y after which the coils return to their starting (R,Z) locations
yperiod = 10.
yperiod = 10.0

magnetic_field = zoidberg.field.StraightStellarator(I_coil=0.3, radius = 1.0, yperiod = yperiod)
magnetic_field = zoidberg.field.StraightStellarator(
I_coil=0.3, radius=1.0, yperiod=yperiod
)

#############################################################################
# Create the inner flux surface, starting at a point at phi=0
Expand All @@ -27,19 +29,20 @@
ycoords = np.linspace(0, yperiod, nslices)
npoints = 20 # Points per poloidal slice

rzcoord, ycoords = zoidberg.fieldtracer.trace_poincare(magnetic_field, start_r, start_z, yperiod,
y_slices=ycoords, revs=npoints)

rzcoord, ycoords = zoidberg.fieldtracer.trace_poincare(
magnetic_field, start_r, start_z, yperiod, y_slices=ycoords, revs=npoints
)

inner_lines = []
for i in range(nslices):
r = rzcoord[:,i,0]
z = rzcoord[:,i,1]
line = zoidberg.rzline.line_from_points(r,z)
r = rzcoord[:, i, 0]
z = rzcoord[:, i, 1]
line = zoidberg.rzline.line_from_points(r, z)
# Re-map the points so they're approximately uniform in distance along the surface
# Note that this results in some motion of the line
line = line.equallySpaced()
inner_lines.append(line)

# Now have a list of y coordinates (ycoords) and inner lines (inner_lines)

#############################################################################
Expand All @@ -54,12 +57,15 @@
nx = 20
ny = 20

pol_grids = [ zoidberg.poloidal_grid.grid_elliptic(inner_line, outer_line, nx,ny) for inner_line in inner_lines ]
pol_grids = [
zoidberg.poloidal_grid.grid_elliptic(inner_line, outer_line, nx, ny)
for inner_line in inner_lines
]

#############################################################################
# Create a grid, then calculate forward and backward maps

grid = zoidberg.grid.Grid( pol_grids, ycoords, yperiod, yperiodic=True)
grid = zoidberg.grid.Grid(pol_grids, ycoords, yperiod, yperiodic=True)

maps = zoidberg.make_maps(grid, magnetic_field)

Expand All @@ -69,7 +75,9 @@
filename = "stellarator.fci.nc"

print("Writing to grid file '{0}'".format(filename))
zoidberg.write_maps(grid, magnetic_field, maps, gridfile=filename, new_names=False, metric2d=True)
zoidberg.write_maps(
grid, magnetic_field, maps, gridfile=filename, new_names=False, metric2d=True
)

#############################################################################
# Plot maps
Expand Down
10 changes: 6 additions & 4 deletions examples/straight-stellarator-poincare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Create grids for a straight stellarator, based on
# Create grids for a straight stellarator, based on
# curvilinear grids

import numpy as np
Expand All @@ -10,10 +10,12 @@

#############################################################################
# Define the magnetic field

# Length in y after which the coils return to their starting (R,Z) locations
yperiod = 10.
yperiod = 10.0

magnetic_field = zoidberg.field.StraightStellarator(I_coil=0.4, radius = 1.0, yperiod = yperiod)
magnetic_field = zoidberg.field.StraightStellarator(
I_coil=0.4, radius=1.0, yperiod=yperiod
)

zoidberg.plot.plot_poincare(magnetic_field, 0.3, 0.0, yperiod)
21 changes: 12 additions & 9 deletions examples/tokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import numpy as np
import zoidberg

field = zoidberg.field.GEQDSK("test_1.geqdsk") # Read magnetic field

grid = zoidberg.grid.rectangular_grid(100, 10, 100,
1.5-0.1, # Range in R (max - min)
2*np.pi, # Toroidal angle
3., # Range in Z
xcentre=(1.5+0.1)/2, # Middle of grid in R
yperiodic=True) # Periodic in toroidal angle
field = zoidberg.field.GEQDSK("test_1.geqdsk") # Read magnetic field

grid = zoidberg.grid.rectangular_grid(
100,
10,
100,
1.5 - 0.1, # Range in R (max - min)
2 * np.pi, # Toroidal angle
3.0, # Range in Z
xcentre=(1.5 + 0.1) / 2, # Middle of grid in R
yperiodic=True,
) # Periodic in toroidal angle

# Create the forward and backward maps
maps = zoidberg.make_maps(grid, field)
Expand All @@ -22,4 +26,3 @@
# Plot maps

zoidberg.plot.plot_forward_map(grid, maps)

0 comments on commit 36aa52a

Please sign in to comment.