From 36aa52abeff34e7f211a1174f9c315fc2aea2d81 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 18 Jan 2024 17:19:55 +0000 Subject: [PATCH] Apply black to examples --- examples/example-straight-stellarator.py | 20 ++++++------ examples/field_line.py | 18 +++++++---- examples/poincare.py | 18 +++++++---- examples/straight-stellarator-curvilinear.py | 34 ++++++++++++-------- examples/straight-stellarator-poincare.py | 10 +++--- examples/tokamak.py | 21 ++++++------ 6 files changed, 71 insertions(+), 50 deletions(-) diff --git a/examples/example-straight-stellarator.py b/examples/example-straight-stellarator.py index 52c7946..98a10aa 100755 --- a/examples/example-straight-stellarator.py +++ b/examples/example-straight-stellarator.py @@ -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 @@ -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() - - diff --git a/examples/field_line.py b/examples/field_line.py index 359c115..675b061 100755 --- a/examples/field_line.py +++ b/examples/field_line.py @@ -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, +) diff --git a/examples/poincare.py b/examples/poincare.py index f82a8f8..c00e360 100755 --- a/examples/poincare.py +++ b/examples/poincare.py @@ -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 diff --git a/examples/straight-stellarator-curvilinear.py b/examples/straight-stellarator-curvilinear.py index 6b96c2f..68a9019 100755 --- a/examples/straight-stellarator-curvilinear.py +++ b/examples/straight-stellarator-curvilinear.py @@ -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 @@ -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) ############################################################################# @@ -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) @@ -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 diff --git a/examples/straight-stellarator-poincare.py b/examples/straight-stellarator-poincare.py index 4677265..8fca3a1 100755 --- a/examples/straight-stellarator-poincare.py +++ b/examples/straight-stellarator-poincare.py @@ -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 @@ -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) diff --git a/examples/tokamak.py b/examples/tokamak.py index 09ecb2f..efd9107 100755 --- a/examples/tokamak.py +++ b/examples/tokamak.py @@ -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) @@ -22,4 +26,3 @@ # Plot maps zoidberg.plot.plot_forward_map(grid, maps) -