Skip to content
Projects

Torus

Download notebookView on GitHubRun when the site was built.

A solid torus: the points within minor_radius of a circle of major_radius, the shape of a tokamak or stellarator vessel, or of a ring-shaped wire.

Torus(midpoint, major_radius, minor_radius, axis=...) puts the circle in the plane normal to axis. The level set is the exact signed distance.

import numpy as np
from simgeometry import Torus
vessel = Torus(midpoint=(0.0, 0.0, 0.0), major_radius=1.0, minor_radius=0.3)
print("volume:", round(vessel.volume(), 4))
print("hole empty:", not vessel.contains((0.0, 0.0, 0.0)))
print("distance from the centre:", vessel.signed_distance((0.0, 0.0, 0.0)))
assert np.isclose(vessel.volume(), 2 * np.pi**2 * 1.0 * 0.3**2)
volume: 1.7765
hole empty: True
distance from the centre: 0.7

show(y=0) draws the section through the axis: the two discs of the tube.

import matplotlib.pyplot as plt
ax = vessel.show(y=0.0, resolution=200, display=False)
ax.set_title("The section y = 0 of a Torus")
plt.show()
Notebook output
import plasma_plots
import pyvista as pv
pv.OFF_SCREEN = True # render without a window, e.g. on a docs server
tilted = Torus(
midpoint=(0.0, 0.0, 0.0), major_radius=1.0, minor_radius=0.3, axis=(1.0, 0.0, 1.0)
)
plotter = tilted.show_3d(
backend="pyvista", display=False, resolution=64, show_bounds=False
)
plasma_plots.scene(plotter, alt="A torus with its axis tilted by 45 degrees")
A torus with its axis tilted by 45 degrees
Open in a new tab