FourierSurface
A closed toroidal surface as a Fourier series: a stellarator’s plasma boundary, or a first
wall around it. The layout is VMEC’s and ConStellaration’s SurfaceRZFourier:
and
, with along the
first axis of the arrays, along the second and the cylindrical angle.
Membership and the search for segment hits use a triangulation of the surface (a
TriangleMesh); the hits are then moved onto the exact surface by Newton steps.
import numpy as np
from simgeometry import FourierSurface
# a circular torus: R = 3 + 0.5 cos(theta), Z = 0.5 sin(theta)r_cos = np.array([[3.0], [0.5]])z_sin = np.array([[0.0], [0.5]])torus = FourierSurface(r_cos, z_sin, n_field_periods=1)print( "volume:", round(torus.volume(), 6), "exact:", round(2 * np.pi**2 * 3.0 * 0.25, 6))print("inside at R = 3:", torus.contains((3.0, 0.0, 0.0)))print("triangulation error:", round(torus.triangulation_error, 5))assert np.isclose(torus.volume(), 2 * np.pi**2 * 3.0 * 0.25)volume: 14.804407 exact: 14.804407inside at R = 3: Truetriangulation error: 0.01745Hits and offsets
Section titled “Hits and offsets”first_hit takes segments as (..., 3) arrays and gives the hit, its distance, point,
outward normal and the surface’s angles there. offset moves the surface along its normal:
for a circular torus by exactly the distance in the minor radius.
hits = torus.first_hit([[0.0, 0.0, 0.0]], [[5.0, 0.0, 0.0]])print("distance:", hits.distance[0], "normal:", hits.normal[0])wall = torus.offset(0.2)print("modes:", wall.n_poloidal, wall.n_toroidal, "minor radius:", wall.r_cos[1, 0])print("misfit:", wall.offset_residual)assert np.isclose(hits.distance[0], 2.5) and np.isclose(wall.r_cos[1, 0], 0.7)distance: 2.4999999999999996 normal: [-1.0000000e+00 -6.4324906e-16 -3.2162453e-16]modes: 1 0 minor radius: 0.7000000000000001misfit: 1.3322676295501878e-15A stellarator boundary
Section titled “A stellarator boundary”FourierSurface.from_boundary reads ConStellaration’s boundary.json (a dict, its JSON or a
SurfaceRZFourier). simgeometry.data.w7x_boundary() is W7-X’s, from DESC’s example
equilibrium; its sections over half a field period:
import matplotlib.pyplot as plt
from simgeometry.data import w7x_boundary_data
boundary = FourierSurface.from_boundary(w7x_boundary_data())theta = np.linspace(0, 2 * np.pi, 300)fig, ax = plt.subplots(figsize=(5, 4))for fraction in (0.0, 0.125, 0.25, 0.375, 0.5): phi = fraction * 2 * np.pi / boundary.nfp ax.plot(*boundary.rz(theta, phi), label=f"{np.degrees(phi):.0f}°")ax.set_aspect("equal")ax.set_xlabel("R [m]")ax.set_ylabel("Z [m]")ax.legend(title="$\\varphi$", fontsize=8)ax.set_title("W7-X boundary (DESC example) over half a field period")plt.show()