spectre.field_tracer

Module Contents

class spectre.field_tracer.Field_Tracer(mvol, igeometry, nfp, mpol=None, im=None, in_=None, ate=None, aze=None, ato=None, azo=None, rbs=None, rbc=None, zbs=None, zbc=None, lrad_arr=None, num_threads=1, batch_size=1, method='RK45', rtol=1e-06, atol=1e-06, comm=None)
mvol
igeometry
mpol = None
im = None
in_ = None
nfp
ate = None
aze = None
ato = None
azo = None
rbs = None
rbc = None
zbs = None
zbc = None
lrad_arr = None
num_threads = 1
batch_size = 1
method = 'RK45'
rtol = 1e-06
atol = 1e-06
comm
trace_field(init_pts, num_phi_planes=32, num_transits=1, method='RK45', rtol=None, atol=None)

Traces the magnetic field from given initial points. Volumes can have different number of trajectories, but every trajectory will have ‘num_phi_planes * num_transits’ turns. Sets the output as self attributes.

Args:

init_pts (List[ndarray[float]]): list of ndarray[num_trajectories, 2] with initial (s, theta) points for tracing num_phi_planes (int, optional): Number of phi planes to record the poincare. Defaults to 32.

num_transits (int, optional): Number of toroidal transits to perform. Defaults to 1.

method (str, optional): Method for integrating the ode. Defaults to ‘RK45’. Options: ‘RK23’, ‘RK45’, ‘DOP853’

rtol (float, optional): Relative tolerance of the integrator. Defaults to 1.0e-6. atol (float, optional): Absolute tolerance of the integrator. Defaults to 1.0e-6.

Raises:

RuntimeError: initial s is out of range [-1, 1] for a point

trace_field_single(sth_init, ivol, num_phi_planes=32, num_transits=1, method='RK45', rtol=None, atol=None)

Traces the magnetic field for one initial point, the trajectory will have ‘num_phi_planes * num_transits’ turns. Doesn’t set anything and returns the result.

Args:

init_pts (List[ndarray[float]]): list of ndarray[num_trajectories, 2] with initial (s, theta) points for tracing. ivol (int): Index of the volume where tracing is done. num_phi_planes (int, optional): Number of phi planes to record the poincare. Defaults to 32.

num_transits (int, optional): Number of toroidal transits to perform. Defaults to 1.

method (str, optional): Method for integrating the ode. Defaults to ‘RK45’. Options: ‘RK23’, ‘RK45’, ‘DOP853’

rtol (float, optional): Relative tolerance of the integrator. Defaults to 1.0e-6. atol (float, optional): Absolute tolerance of the integrator. Defaults to 1.0e-6.

Raises:

RuntimeError: initial s is out of range [-1, 1] for a point.

Returns:

List[float]: Final (s, theta) coordinates. List[float]: Final (R, Z) coordinates. float: Final iota. bool: True if integration did not reach the end, False otherwise.

plot(ind_zetan=0, zetan=None, prange='full', ax=None, figsize=(6, 5), show=False, **kwargs)

Plot the Poincare section at given toroidal location. Allow input of both zeta index and zetan float value. Zetan (if provided) takes precedence.

Args:

ind_zetan (int, optional): Index of toroidal lcoation. Defaults to 0. zetan (_type_, optional): Normalized zeta of toroidal location. Defaults to None. prange (str, optional): Designated part to plot. Defaults to “full”. Options: ‘full’, ‘upper’, ‘lower’. ax (_type_, optional): Existing axis object. Defaults to None. figsize (tuple, optional): Figure size. Defaults to (6, 5). show (bool, optional): Whether to call plt.show(). Defaults to False. kwargs: Additional keyword arguments for ax.plot().

Raises:

ValueError

Returns:

ax: The axis object of the plot.

plot_iota(xaxis='R', ax=None, figsize=(6, 5), show=False, **kwargs)

Plots the iota profile obtained from the field line tracing. Iota is found as iota = (phi_final - phi_initial) / (theta_final - theta_initial).

Args:

xaxis (str, optional): What to plot on x-axis. Defaults to ‘R’. Options: ‘R’, ‘s’. ax (_type_, optional): Existing axis object. Defaults to None. figsize (tuple, optional): Figure size. Defaults to (6, 5). show (bool, optional): Whether to call plt.show(). Defaults to False. kwargs: Additional keyword arguments for ax.plot().

Raises:

RuntimeError

save_h5(in_file='arrays.h5')

Save the object to a .h5 file in the ‘poincare_custom’ group, including data and parameters. Does not allow for the loaded object to be re-run.

Args:

in_file (str/h5py.File): Where to store the data. If a string, it’s used as the filename. If h5py.File, the File is directly appended to. Defaults to ‘arrays.h5’.

Raises:

RuntimeError

classmethod init_from_h5(in_file='arrays.h5')

Initialize a Field_Tracer object from a data saved in a .h5 file. The loaded object can NOT be used to redo the tracing, and is only fit for analysis,

Args:

in_file (str/h5py.File): From where to load the data. If a string, it’s used as the filename. If h5py.File, the File is directly appended to. Defaults to ‘arrays.h5’.

Raises:

RuntimeError

Returns:

Field_Tracer: The generated object.