simsopt.field package

Submodules

simsopt.field.biotsavart module

class simsopt.field.biotsavart.BiotSavart(coils, coil_currents)

Bases: simsoptpp.BiotSavart, simsopt.field.magneticfield.MagneticField

Computes the MagneticField induced by a list of closed curves \(\Gamma_k\) with electric currents \(I_k\). The field is given by

\[B(\mathbf{x}) = \frac{\mu_0}{4\pi} \sum_{k=1}^{n_\mathrm{coils}} I_k \int_0^1 \frac{(\Gamma_k(\phi)-\mathbf{x})\times \Gamma_k'(\phi)}{\|\Gamma_k(\phi)-\mathbf{x}\|^3} d\phi\]

where \(\mu_0=4\pi 10^{-7}\) is the magnetic constant.

A(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_and_dB_vjp(v, vgrad)

Same as simsopt.field.biotsavart.BiotSavart.B_vjp but returns the vector Jacobian product for \(B\) and \(\nabla B\), i.e. it returns

\[\{ \sum_{i=1}^{n} \mathbf{v}_i \cdot \partial_{\mathbf{c}_k} \mathbf{B}_i \}_k, \{ \sum_{i=1}^{n} {\mathbf{v}_\mathrm{grad}}_i \cdot \partial_{\mathbf{c}_k} \nabla \mathbf{B}_i \}_k.\]
B_cyl(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

B_vjp(v)

Assume the field was evaluated at points \(\mathbf{x}_i, i\in \{1, \ldots, n\}\) and denote the value of the field at those points by \(\{\mathbf{B}_i\}_{i=1}^n\). These values depend on the shape of the coils, i.e. on the dofs \(\mathbf{c}_k\) of each coil. This function returns the vector Jacobian product of this dependency, i.e.

\[\{ \sum_{i=1}^{n} \mathbf{v}_i \cdot \partial_{\mathbf{c}_k} \mathbf{B}_i \}_k.\]
GradAbsB(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

compute(self: simsoptpp.BiotSavart, arg0: int) None
compute_A(compute_derivatives=0)

Compute the potential of a BiotSavart field

\[A(\mathbf{x}) = \frac{\mu_0}{4\pi} \sum_{k=1}^{n_\mathrm{coils}} I_k \int_0^1 \frac{\Gamma_k'(\phi)}{\|\Gamma_k(\phi)-\mathbf{x}\|} d\phi\]

as well as the derivatives of A if requested.

d2A_by_dXdX(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdcoilcurrents(compute_derivatives=1)
d3B_by_dXdXdcoilcurrents(compute_derivatives=2)
dA_by_dX(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dcoilcurrents(compute_derivatives=0)
fieldcache_get_or_create(self: simsoptpp.BiotSavart, arg0: str, arg1: List[int]) numpy.ndarray[numpy.float64]
fieldcache_get_status(self: simsoptpp.BiotSavart, arg0: str) bool
get_points_cart(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.BiotSavart) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.BiotSavart) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.BiotSavart, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.BiotSavart, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.BiotSavart, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

simsopt.field.magneticfield module

class simsopt.field.magneticfield.MagneticField

Bases: simsoptpp.MagneticField

Generic class that represents any magnetic field from which each magnetic field class inherits. The usage of MagneticField is as follows:

bfield = BiotSavart(coils, currents) # An instance of a MagneticField
points = ... # points is a (n, 3) numpy array
bfield.set_points(points)
B = bfield.B() # returns the Magnetic field at `points`
dA = bfield.dA_by_dX() # returns the gradient of the potential of the field at `points`

MagneticField has a cache to avoid repeated calculations. To clear this cache, call the clear_cached_properties() function. The cache is automatically cleard when set_points is called.

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfield.MagneticFieldMultiply(scalar, Bfield)

Bases: simsopt.field.magneticfield.MagneticField

Class used to multiply a magnetic field by a scalar. It takes as input a MagneticField class and a scalar and multiplies B, A and their derivatives by that value.

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfield.MagneticFieldSum(Bfields)

Bases: simsopt.field.magneticfield.MagneticField

Class used to sum two or more magnetic field together. It can either be called directly with a list of magnetic fields given as input and outputing another magnetic field with B, A and its derivatives added together or it can be called by summing magnetic fields classes as Bfield1 + Bfield1

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

simsopt.field.magneticfieldclasses module

class simsopt.field.magneticfieldclasses.ChebyshevInterpolationRule

Bases: simsoptpp.ChebyshevInterpolationRule

property degree

The degree of the polynomial. The number of interpolation points in degree+1.

class simsopt.field.magneticfieldclasses.CircularCoil(r0=0.1, center=[0, 0, 0], I=159154.94309189534, normal=[0, 0])

Bases: simsopt.field.magneticfield.MagneticField

Magnetic field created by a single circular coil evaluated using analytical functions, including complete elliptic integrals of the first and second kind. As inputs, it takes the radius of the coil (r0), its center, current (I) and its normal vector [either spherical angle components (normal=[theta,phi]) or (x,y,z) components of a vector (normal=[x,y,z])]).

Parameters
  • r0 – radius of the coil

  • center – point at the coil center

  • I – current of the coil in Ampere’s

  • normal – if list with two values treats it as spherical angles theta and phi of the normal vector to the plane of the coil centered at the coil center, if list with three values treats it a vector

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfieldclasses.Dommaschk(mn=[[0, 0]], coeffs=[[0, 0]])

Bases: simsopt.field.magneticfield.MagneticField

Vacuum magnetic field created by an explicit representation of the magnetic field scalar potential as proposed by W. Dommaschk (1986), Computer Physics Communications 40, 203-218. As inputs, it takes the arrays for the harmonics m, n and its corresponding coefficients.

Parameters
  • m – first harmonic array

  • n – second harmonic array

  • coeffs – coefficient for Vml for each of the ith index of the harmonics m and n

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfieldclasses.InterpolatedField(field, degree, rrange, phirange, zrange, extrapolate=True, nfp=1, stellsym=False)

Bases: simsoptpp.InterpolatedField, simsopt.field.magneticfield.MagneticField

This field takes an existing field and interpolates it on a regular grid in \(r,\phi,z\). This resulting interpolant can then be evaluated very quickly.

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__init__(field, degree, rrange, phirange, zrange, extrapolate=True, nfp=1, stellsym=False)
Parameters
  • field – the underlying simsopt.field.magneticfield.MagneticField to be interpolated.

  • degree – the degree of the piecewise polynomial interpolant.

  • rrange – a 3-tuple of the form (rmin, rmax, nr). This mean that the interval \([rmin, rmax]\) is split into nr many subintervals.

  • phirange – a 3-tuple of the form (phimin, phimax, nphi).

  • zrange – a 3-tuple of the form (zmin, zmax, nz).

  • extrapolate – whether to extrapolate the field when evaluate outside the integration domain or to throw an error.

  • nfp – Whether to exploit rotational symmetry. In this case any angle is always mapped into the interval \([0, 2\pi/\mathrm{nfp})\), hence it makes sense to use phimin=0 and phimax=2*np.pi/nfp.

  • stellsym – Whether to exploit stellarator symmetry. In this case z is always mapped to be positive, hence it makes sense to use zmin=0.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

estimate_error_B(self: simsoptpp.InterpolatedField, arg0: int) Tuple[float, float]
estimate_error_GradAbsB(self: simsoptpp.InterpolatedField, arg0: int) Tuple[float, float]
get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

property phi_range
property r_range
property rule
set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, h=0.1)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

property z_range
class simsopt.field.magneticfieldclasses.PoloidalField(R0, B0, q)

Bases: simsopt.field.magneticfield.MagneticField

Magnetic field purely in the poloidal direction, that is, in the theta direction of a poloidal-toroidal coordinate system. Its modulus is given by B = B0 * r / (R0 * q) so that, together with the toroidal field, it creates a safety factor equals to q

Parameters
  • B0 – modulus of the magnetic field at R0

  • R0 – major radius of the magnetic axis

  • q – safety factor/pitch angle of the magnetic field lines

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfieldclasses.Reiman(iota0=0.15, iota1=0.38, k=[6], epsilonk=[0.01], m0=1)

Bases: simsopt.field.magneticfield.MagneticField

Magnetic field model in section 5 of Reiman and Greenside, Computer Physics Communications 43 (1986) 157—167. This field allows for an analytical expression of the magnetic island width that can be used for island optimization. However, the field is not completely physical as it does not have nested flux surfaces.

Parameters
  • iota0 – unperturbed rotational transform

  • iota1 – unperturbed global magnetic shear

  • k – integer array specifying the Fourier modes used

  • epsilonk – coefficient of the Fourier modes

  • m0 – toroidal symmetry parameter (normally m0=1)

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfieldclasses.ScalarPotentialRZMagneticField(PhiStr)

Bases: simsopt.field.magneticfield.MagneticField

Vacuum magnetic field as a solution of B = grad(Phi) where Phi is the magnetic field scalar potential. It takes Phi as an input string, which should contain an expression involving the standard cylindrical coordinates (R, phi, Z) Example: ScalarPotentialRZMagneticField(“2*phi”) yields a magnetic field B = grad(2*phi) = (0,2/R,0). Note: this function needs sympy.

Parameters

PhiStr – string containing vacuum scalar potential expression as a function of R, Z and phi

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfieldclasses.ToroidalField(R0, B0)

Bases: simsopt.field.magneticfield.MagneticField

Magnetic field purely in the toroidal direction, that is, in the phi direction with (R,phi,Z) the standard cylindrical coordinates. Its modulus is given by B = B0*R0/R where R0 is the first input and B0 the second input to the function.

Parameters
  • B0 – modulus of the magnetic field at R0

  • R0 – radius of normalization

A(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic potential (in cartesian coordinates). Denoting the indices by i and l, the result contains A_l(x_i).

A_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As A, but returns a reference to the array (this array should be read only).

AbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 1) array containing the absolute value of the magnetic field (in cartesian coordinates).

AbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As AbsB, but returns a reference to the array (this array should be read only).

B(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the magnetic field (in cartesian coordinates). Denoting the indices by i and l, the result contains B_l(x_i).

B_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Return a (npoints, 3) array containing the magnetic field (in cylindrical coordinates) (the order is \((B_r, B_\phi, B_z)\)).

B_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B_cyl, but returns a reference to the array (this array should be read only).

B_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As B, but returns a reference to the array (this array should be read only).

GradAbsB(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3) array containing the gradient of the absolute value of the magnetic field (in cartesian coordinates).

GradAbsB_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]
GradAbsB_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As GradAbsB, but returns a reference to the array (this array should be read only).

__add__(other)

Add two magnetic fields.

__mul__(other)

Multiply a field with a scalar.

__rmul__(other)

Multiply a field with a scalar.

clear_cached_properties()

Clear the cache.

d2A_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the hessian of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j A_l(x_i).

d2A_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2A_by_dXdX, but returns a reference to the array (this array should be read only).

d2B_by_dXdX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3, 3) array containing the hessian of magnetic field (in cartesian coordinates). Denoting the indices by i, j, k and l, the result contains partial_kpartial_j B_l(x_i).

d2B_by_dXdX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As d2B_by_dXdX, but returns a reference to the array (this array should be read only).

dA_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of the magnetic potential (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j A_l(x_i).

dA_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dA_by_dX, but returns a reference to the array (this array should be read only).

dB_by_dX(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Returns a (npoints, 3, 3) array containing the gradient of magnetic field (in cartesian coordinates). Denoting the indices by i, j and l, the result contains partial_j B_l(x_i).

dB_by_dX_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As dB_by_dX, but returns a reference to the array (this array should be read only).

get_points_cart(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cartesian coordinates.

get_points_cart_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cart, but returns a reference to the array (this array should be read only).

get_points_cyl(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

Get the point where the field should be evaluated in cylindrical coordinates (the order is \((r, \phi, z)\)).

get_points_cyl_ref(self: simsoptpp.MagneticField) numpy.ndarray[numpy.float64]

As get_points_cyl, but returns a reference to the array (this array should be read only).

invalidate_cache(self: simsoptpp.MagneticField) None

Clear the cache. Called automatically after each call to set_points[…].

set_points(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Shorthand for set_points_cart.

set_points_cart(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cartesian coordinates.

set_points_cyl(self: simsoptpp.MagneticField, arg0: numpy.ndarray[numpy.float64]) simsoptpp.MagneticField

Set the points where to evaluate the magnetic fields, in cylindrical coordinates (the order is \((r, \phi, z)\)).

to_vtk(filename, nr=10, nphi=10, nz=10, rmin=1.0, rmax=2.0, zmin=- 0.5, zmax=0.5)

Export the field evaluated on a regular grid for visualisation with e.g. Paraview.

class simsopt.field.magneticfieldclasses.UniformInterpolationRule

Bases: simsoptpp.UniformInterpolationRule

property degree

The degree of the polynomial. The number of interpolation points in degree+1.

simsopt.field.tracing module

class simsopt.field.tracing.IterationStoppingCriterion

Bases: simsoptpp.IterationStoppingCriterion

Stop the iteration once the maximum number of iterations is reached.

class simsopt.field.tracing.LevelsetStoppingCriterion(classifier)

Bases: simsoptpp.LevelsetStoppingCriterion

Based on a scalar function \(f:R^3\to R\), this criterion checks whether \(f(x, y, z) < 0\) and stops the iteration once this is true.

The idea is to use this for example with signed distance functions to a surface.

simsopt.field.tracing.compute_fieldlines(field, R0, Z0, tmax=200, tol=1e-07, phis=[], stopping_criteria=[], comm=None)

Compute magnetic field lines by solving

\[[\dot x, \dot y, \dot z] = B(x, y, z)\]
Parameters
  • field – the magnetic field \(B\)

  • R0 – list of radial components of initial points

  • Z0 – list of vertical components of initial points

  • tmax – for how long to trace. will do roughly |B|*tmax/(2*pi*r0) revolutions of the device

  • tol – tolerance for the adaptive ode solver

  • phis – list of angles in [0, 2pi] for which intersection with the plane corresponding to that phi should be computed

  • stopping_criteria – list of stopping criteria, mostly used in combination with the LevelsetStoppingCriterion accessed via simsopt.field.tracing.SurfaceClassifier.

Returns: 2 element tuple containing
  • res_tys:

    A list of numpy arrays (one for each particle) describing the solution over time. The numpy array is of shape (ntimesteps, 4). Each row contains the time and the position, i.e.`[t, x, y, z]`.

  • res_phi_hits:

    A list of numpy arrays (one for each particle) containing information on each time the particle hits one of the phi planes or one of the stopping criteria. Each row of the array contains [time, idx, x, y, z], where idx tells us which of the phis or stopping_criteria was hit. If idx>=0, then phis[int(idx)] was hit. If idx<0, then stopping_criteria[int(-idx)-1] was hit.

simsopt.field.tracing.compute_gc_radius(m, vperp, q, absb)

Computes the gyro radius of a particle in a field with strenght absb`, that is r=m*vperp/(abs(q)*absb).

simsopt.field.tracing.gc_to_fullorbit_initial_guesses(field, xyz_inits, speed_pars, speed_total, m, q, eta=0)

Takes in guiding center positions xyz_inits as well as a parallel speeds speed_pars and total velocities speed_total to compute orbit positions for a full orbit calculation that matches the given guiding center. The phase angle can be controll via the eta parameter

simsopt.field.tracing.parallel_loop_bounds(comm, n)

Split up an array [0, 1, …, n-1] across an mpi communicator. Example: n = 8, comm with size=2 will return (0, 4) on core 0, (4, 8) on core 1, meaning that the array is split up as [0, 1, 2, 3] + [4, 5, 6, 7].

simsopt.field.tracing.particles_to_vtk(res_tys, filename)

Export particle tracing or field lines to a vtk file. Expects that the xyz positions can be obtained by xyz[:, 1:4].

simsopt.field.tracing.plot_poincare_data(fieldlines_phi_hits, phis, filename, mark_lost=False, aspect='equal', dpi=300)

Create a poincare plot. Usage:

phis = np.linspace(0, 2*np.pi/nfp, nphis, endpoint=False)
res_tys, res_phi_hits = compute_fieldlines(
    bsh, R0, Z0, tmax=1000, phis=phis, stopping_criteria=[])
plot_poincare_data(res_phi_hits, phis, '/tmp/fieldlines.png')

Requires matplotlib to be installed.

simsopt.field.tracing.trace_particles(field: simsopt.field.magneticfield.MagneticField, xyz_inits: nptyping.types._ndarray.NDArray[None, nptyping.types._number.Float[float, numpy.floating]], parallel_speeds: nptyping.types._ndarray.NDArray[None, nptyping.types._number.Float[float, numpy.floating]], tmax=0.0001, mass=6.69509884346e-27, charge=3.204353268e-19, Ekin=5.639661751679999e-13, tol=1e-09, comm=None, phis=[], stopping_criteria=[], mode='gc_vac', forget_exact_path=False, phase_angle=0)

Follow particles in a magnetic field.

In the case of mod='full' we solve

\[[\ddot x, \ddot y, \ddot z] = \frac{q}{m} [\dot x, \dot y, \dot z] \times B\]

in the case of mod='gc_vac' we solve the guiding center equations under the assumption \(\nabla p=0\), that is

\[\begin{split}[\dot x, \dot y, \dot z] &= v_{||}\frac{B}{|B|} + \frac{m}{q|B|^3} (0.5v_\perp^2 + v_{||}^2) B\times \nabla(|B|)\\ \dot v_{||} &= -\mu (B \cdot \nabla(|B|))\end{split}\]

where \(v_\perp = 2\mu|B|\). See equations (12) and (13) of [Guiding Center Motion, H.J. de Blank, https://doi.org/10.13182/FST04-A468].

Parameters
  • field – The magnetic field \(B\).

  • xyz_inits – A (nparticles, 3) array with the initial positions of the particles.

  • parallel_speeds – A (nparticles, ) array containing the speed in direction of the B field for each particle.

  • tmax – integration time

  • mass – particle mass in kg, defaults to the mass of an alpha particle

  • charge – charge in Coulomb, defaults to the charge of an alpha particle

  • Ekin – kinetic energy in Joule, defaults to 3.52MeV

  • tol – tolerance for the adaptive ode solver

  • comm – MPI communicator to parallelize over

  • phis – list of angles in [0, 2pi] for which intersection with the plane corresponding to that phi should be computed

  • stopping_criteria – list of stopping criteria, mostly used in combination with the LevelsetStoppingCriterion accessed via simsopt.field.tracing.SurfaceClassifier.

  • mode – how to trace the particles. options are gc: general guiding center equations, gc_vac: simplified guiding center equations for the case \(\nabla p=0\), full: full orbit calculation (slow!)

  • forget_exact_path – return only the first and last position of each particle for the res_tys. To be used when only res_phi_hits is of interest or one wants to reduce memory usage.

  • phase_angle – the phase angle to use in the case of full orbit calculations

Returns: 2 element tuple containing
  • res_tys:

    A list of numpy arrays (one for each particle) describing the solution over time. The numpy array is of shape (ntimesteps, M) with M depending on the mode. Each row contains the time and the state. So for mode=’gc’ and mode=’gc_vac’ the state consists of the xyz position and the parallel speed, hence each row contains [t, x, y, z, v_par]. For mode=’full’, the state consists of position and velocity vector, i.e. each row contains [t, x, y, z, vx, vy, vz].

  • res_phi_hits:

    A list of numpy arrays (one for each particle) containing information on each time the particle hits one of the phi planes or one of the stopping criteria. Each row of the array contains [time] + [idx] + state, where idx tells us which of the phis or stopping_criteria was hit. If idx>=0, then phis[int(idx)] was hit. If idx<0, then stopping_criteria[int(-idx)-1] was hit.

simsopt.field.tracing.trace_particles_starting_on_curve(curve, field, nparticles, tmax=0.0001, mass=6.69509884346e-27, charge=3.204353268e-19, Ekin=5.639661751679999e-13, tol=1e-09, comm=None, seed=1, umin=- 1, umax=1, phis=[], stopping_criteria=[], mode='gc_vac', forget_exact_path=False, phase_angle=0)

Follows particles spawned at random locations on the magnetic axis with random pitch angle. See simsopt.field.tracing.trace_particles for the governing equations.

Parameters
  • curve – The simsopt.geo.curve.Curve to spawn the particles on. Uses rejection sampling to sample points on the curve. Warning: assumes that the underlying quadrature points on the Curve are uniformly distributed.

  • field – The magnetic field \(B\).

  • nparticles – number of particles to follow.

  • tmax – integration time

  • mass – particle mass in kg, defaults to the mass of an alpha particle

  • charge – charge in Coulomb, defaults to the charge of an alpha particle

  • Ekin – kinetic energy in Joule, defaults to 3.52MeV

  • tol – tolerance for the adaptive ode solver

  • comm – MPI communicator to parallelize over

  • seed – random seed

  • umin – the parallel speed is defined as v_par = u * speed_total where u is drawn uniformly in [umin, umax]

  • umax – see umin

  • phis – list of angles in [0, 2pi] for which intersection with the plane corresponding to that phi should be computed

  • stopping_criteria – list of stopping criteria, mostly used in combination with the LevelsetStoppingCriterion accessed via simsopt.field.tracing.SurfaceClassifier.

  • mode – how to trace the particles. options are gc: general guiding center equations, gc_vac: simplified guiding center equations for the case \(\nabla p=0\), full: full orbit calculation (slow!)

  • forget_exact_path – return only the first and last position of each particle for the res_tys. To be used when only res_phi_hits is of interest or one wants to reduce memory usage.

  • phase_angle – the phase angle to use in the case of full orbit calculations

Returns: see simsopt.field.tracing.trace_particles

simsopt.field.tracing.trace_particles_starting_on_surface(surface, field, nparticles, tmax=0.0001, mass=6.69509884346e-27, charge=3.204353268e-19, Ekin=5.639661751679999e-13, tol=1e-09, comm=None, seed=1, umin=- 1, umax=1, phis=[], stopping_criteria=[], mode='gc_vac', forget_exact_path=False, phase_angle=0)

Follows particles spawned at random locations on the magnetic axis with random pitch angle. See simsopt.field.tracing.trace_particles for the governing equations.

Parameters
  • surface – The simsopt.geo.surface.Surface to spawn the particles on. Uses rejection sampling to sample points on the curve. Warning: assumes that the underlying quadrature points on the Curve as uniformly distributed.

  • field – The magnetic field \(B\).

  • nparticles – number of particles to follow.

  • tmax – integration time

  • mass – particle mass in kg, defaults to the mass of an alpha particle

  • charge – charge in Coulomb, defaults to the charge of an alpha particle

  • Ekin – kinetic energy in Joule, defaults to 3.52MeV

  • tol – tolerance for the adaptive ode solver

  • comm – MPI communicator to parallelize over

  • seed – random seed

  • umin – the parallel speed is defined as v_par = u * speed_total where u is drawn uniformly in [umin, umax].

  • umax – see umin

  • phis – list of angles in [0, 2pi] for which intersection with the plane corresponding to that phi should be computed

  • stopping_criteria – list of stopping criteria, mostly used in combination with the LevelsetStoppingCriterion accessed via simsopt.field.tracing.SurfaceClassifier.

  • mode – how to trace the particles. options are gc: general guiding center equations, gc_vac: simplified guiding center equations for the case \(\nabla p=0\), full: full orbit calculation (slow!)

  • forget_exact_path – return only the first and last position of each particle for the res_tys. To be used when only res_phi_hits is of interest or one wants to reduce memory usage.

  • phase_angle – the phase angle to use in the case of full orbit calculations

Returns: see simsopt.field.tracing.trace_particles

Module contents