coilpy.surface#

class coilpy.surface.FourSurf(xm=[], xn=[], rbc=[], zbs=[], rbs=[], zbc=[])[source]#

Bases: object

toroidal surface in Fourier representation R = sum RBC cos(mu-nv) + RBS sin(mu-nv) Z = sum ZBC cos(mu-nv) + ZBS sin(mu-nv)

change_poloidal_angle()[source]#
get_area()[source]#

Get the surface area and saved in self.area More comprehensive options can be found in self._areaVolume()

Parameters:

None

Returns:

area

get_volume()[source]#

Get the surface volume and saved in self.volume More comprehensive options can be found in self._areaVolume()

Parameters:

None

Returns:

volume

grid_box(ntor=64, npol=64)[source]#

Return the max R & Z values of the surface

Parameters:
  • ntor (int, optional) – Toroidal resolution. Defaults to 64.

  • npol (int, optional) – Poloidal resolution. Defaults to 64.

Returns:

the max R & Z values

Return type:

(Rmin, Rmax, Zmin, Zmax)

plot(zeta=0.0, npoints=360, **kwargs)[source]#

plot the cross-section at zeta using matplotlib.pyplot

Parameters:
  • float (zeta --) –

  • value (toroidal angle) –

  • integer (npoints --) –

  • (default (number of discretization points) –

  • pyplot (kwargs -- optional keyword arguments for) –

Returns:

line class in matplotlib.pyplot

plot3d(engine='pyplot', theta0=0.0, theta1=6.283185307179586, zeta0=0.0, zeta1=6.283185307179586, npol=360, ntor=360, normal=False, fig=None, ax=None, show=True, **kwargs)[source]#

plot 3D shape of the surface

Parameters:
  • string (engine --) –

  • {'pyplot' (plotting engine) –

  • float (zeta1 --) – 0.0)

  • (default (if show the plotly figure immediately) – 0.0)

  • float – 2*np.pi)

  • (default – 2*np.pi)

  • float – 0.0)

  • (default – 0.0)

  • float – 2*np.pi)

  • (default – 2*np.pi)

  • integer (ntor --) –

  • (default

  • integer

  • (default

  • bool (show --) – False)

  • (default – False)

  • -- (ax) – None)

  • (default – None)

  • -- – None)

  • (default – None)

  • bool – True)

  • (default – True)

  • plotting (kwargs -- optional keyword arguments for) –

Returns:

xsurf, ysurf, zsurf – arrays of x,y,z coordinates on the surface

classmethod read_focus_input(filename, mpol=9999, ntor=9999)[source]#

initialize surface from the FOCUS format input file ‘plasma.boundary’

Parameters:
  • string (filename --) –

  • file (path + name to the FOCUS input boundary) –

  • (default (ntor -- maximum truncated toroidal mode number) –

  • (default

Returns:

fourier_surface class

classmethod read_spec_input(filename, tol=1e-08)[source]#

initialize surface from the SPEC input file ‘*.sp’

Parameters:
  • string (filename --) –

  • file (path + name to the FOCUS input boundary) –

  • (default (ntor -- maximum truncated toroidal mode number) –

  • (default

Returns:

fourier_surface class

classmethod read_spec_output(spec_out, ns=-1)[source]#

initialize surface from the ns-th interface SPEC output

Parameters:
  • class (spec_out -- SPEC) –

  • results (SPEC hdf5) –

  • integer (ns --) – -1)

  • (default (the index of SPEC interface) – -1)

Returns:

fourier_surface class

classmethod read_vmec_input(filename, tol=1e-08)[source]#

initialize surface from the ns-th interface SPEC output

Parameters:
  • string (woutfile --) –

  • output (path + name to the wout file from VMEC) –

  • integer (ns --) – -1)

  • (default (the index of VMEC nested flux surfaces) – -1)

Returns:

fourier_surface class

classmethod read_vmec_output(woutfile, ns=-1)[source]#

initialize surface from the ns-th interface SPEC output

Parameters:
  • string (woutfile --) –

  • output (path + name to the wout file from VMEC) –

  • integer (ns --) – -1)

  • (default (the index of VMEC nested flux surfaces) – -1)

Returns:

fourier_surface class

classmethod read_winding_surfce(filename, mpol=9999, ntor=9999)[source]#

initialize surface from the NESCOIL format input file ‘nescin.xxx’

Parameters:
  • string (filename --) –

  • file (path + name to the NESCOIL input boundary) –

  • (default (ntor -- maximum truncated toroidal mode number) –

  • (default

Returns:

fourier_surface class

rz(theta, zeta, normal=False)[source]#

get r,z position of list of (theta, zeta)

Parameters:
  • array_like (zeta -- float) –

  • angle (poloidal) –

  • array_like

  • value (toroidal angle) –

  • logical (normal --) – False)

  • (default (calculate the normal vector or not) – False)

Returns:

r, z – float array_like r, z, [rt, zt], [rz, zz] – if normal

toSTL(stlname, **kwargs)[source]#

save surface shape a stl file using meshio

Parameters:
  • string (stlname --) –

  • save (the filename you want to) –

  • 'stlname.vts' (final name is) –

  • self.plot3d. (kwargs -- optional keyword arguments used for) –

Returns:

Mesh object in meshio

Return type:

mesh

toVTK(vtkname, npol=360, ntor=360, **kwargs)[source]#

save surface shape a vtk grid file

Parameters:
  • string (vtkname --) –

  • save (the filename you want to) –

  • 'vtkname.vts' (final name is) –

  • integer (ntor --) –

  • (default (number of toroidal discretization points) –

  • integer

  • (default

  • pointdata (kwargs -- optional keyword arguments for saving as) –

Returns:

write_focus_input(filename, nfp=1, bn=None)[source]#

Write the Fourier harmonics down in FOCUS format

Parameters:
  • filename ([type]) – Output file name.

  • nfp (int, optional) – Number of toroidal periodicity Defaults to 1.

  • bn (dict, optional) – Bn dict, containing ‘xm’, ‘xn’, ‘bnc’, ‘bns’. Defaults to None.

write_vmec_input(filename, template=None, nfp=1, **kwargs)[source]#
xyz(theta, zeta, normal=False)[source]#

get x,y,z position of list of (theta, zeta)

Parameters:
  • array_like (zeta -- float) –

  • angle (poloidal) –

  • array_like

  • value (toroidal angle) –

  • logical (normal --) – False)

  • (default (calculate the normal vector or not) – False)

Returns:

x, y, z – float array_like x, y, z, [nx, ny, nz] – if normal