Available fluid equilibria#

Available fluid backgrounds:

class struphy.fields_background.equils.HomogenSlab(B0x: float = 0.0, B0y: float = 0.0, B0z: float = 1.0, beta: float = 0.1, n0: float = 1.0)[source]#

Bases: CartesianMHDequilibrium

Homogeneous MHD equilibrium:

\[ \begin{align}\begin{aligned}\mathbf B &= B_{0x}\,\mathbf e_x + B_{0y}\,\mathbf e_y + B_{0z}\,\mathbf e_z = const.\,,\\p &= \beta \frac{|\mathbf B|^2}{2}=const.\,,\\n &= n_0 = const.\,.\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • B0x (float) – x-component of magnetic field (default: 0.).

  • B0y (float) – y-component of magnetic field (default: 0.).

  • B0z (float) – z-component of magnetic field (default: 1.).

  • beta (float) – Plasma beta (ratio of kinematic pressure to B^2/(2*mu0), default: 0.1).

  • n0 (float) – Ion number density (default: 1.).

Note

In the parameter .yml, use the following in the section fluid_background:

HomogenSlab :
    B0x  : 0. # magnetic field in x
    B0y  : 0. # magnetic field in y
    B0z  : 1. # magnetic field in z
    beta : .1 # plasma beta = p*(2*mu_0)/B^2
    n0   : 1. # number density
b_xyz(x, y, z)[source]#

Magnetic field.

a_xyz(x, y, z)[source]#

Vector potential.

j_xyz(x, y, z)[source]#

Current density.

p_xyz(x, y, z)[source]#

Plasma pressure.

n_xyz(x, y, z)[source]#

Number density.

gradB_xyz(x, y, z)[source]#

Current density.

class struphy.fields_background.equils.ShearedSlab(a: float = 1.0, R0: float = 3.0, B0: float = 1.0, q0: float = 1.05, q1: float = 1.8, n1: float = 0.0, n2: float = 0.0, na: float = 1.0, beta: float = 0.1, q_kind: int = 0)[source]#

Bases: CartesianMHDequilibrium

Sheared slab MHD equilibrium in a cube with side lengths \(L_x=a,\,L_y=2\pi a,\,L_z=2\pi R_0\). Profiles depend on \(x\) solely:

\[ \begin{align}\begin{aligned}\mathbf B(x) &= B_{0} \left( \mathbf e_z + \frac{a}{q(x)R_0}\mathbf e_y\right)\,,\qquad q(x) = q_0 + ( q_1 - q_0 )\frac{x^2}{a^2}\,,\\p(x) &= \beta\frac{B_{0}^2}{2} \left( 1 + \frac{a^2}{q(x)^2 R_0^2} \right) + B_{0}^2 \frac{a^2}{R_0^2} \left( \frac{1}{q_0^2} - \frac{1}{q(x)^2} \right)\,,\\n(x) &= n_a + ( 1 - n_a ) \left( 1 - \left(\frac{x}{a}\right)^{n_1} \right)^{n_2} \,.\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • a (float) – “Minor” radius (must be compatible with \(L_x=a\) and \(L_y=2\pi a\), default: 1.).

  • R0 (float) – “Major” radius (must be compatible with \(L_z=2\pi R_0\), default: 3.).

  • B0 (float) – z-component of magnetic field (constant) (default: 1.).

  • q0 (float) – Safety factor at x=0 (default: 1.05).

  • q1 (float) – Safety factor at x=a (default: 1.80).

  • n1 (float) – 1st shape factor for ion number density profile (default: 0.).

  • n2 (float) – 2nd shape factor for ion number density profile (default: 0.).

  • na (float) – Ion number density at x=a (default: 1.).

  • beta (float) – Plasma beta (ratio of kinematic pressure to B^2/2, default: 0.1).

  • q_kind (int) – Kind of safety factor profile, (0 or 1, default: 0).

Note

In the parameter .yml, use the following in the section fluid_background:

ShearedSlab :
    a    : 1.   # minor radius (Lx=a, Ly=2*pi*a)
    R0   : 3.   # major radius (Lz=2*pi*R0)
    B0   : 1.   # magnetic field in z-direction
    q0   : 1.05 # safety factor at x = 0
    q1   : 1.80 # safety factor at x = a
    n1   : 0.   # 1st shape factor for ion number density profile
    n2   : 0.   # 2nd shape factor for ion number density profile
    na   : 1.   # number density at r=a
    beta : .1   # plasma beta = p*2/B^2
    q_kind : 0. # kind of safety factor profile
q_x(x, der=0)[source]#

Safety factor profile q = q(x) (or its first derivative if der=1).

p_x(x)[source]#

Pressure profile p = p(x).

n_x(x)[source]#

Ion number density profile n = n(x).

plot_profiles(n_pts=501)[source]#

Plots radial profiles.

b_xyz(x, y, z)[source]#

Magnetic field.

j_xyz(x, y, z)[source]#

Current density.

p_xyz(x, y, z)[source]#

Pressure.

n_xyz(x, y, z)[source]#

Number density.

gradB_xyz(x, y, z)[source]#

Gradient of magnetic field.

class struphy.fields_background.equils.ShearFluid(a: float = 1.0, b: float = 1.0, c: float = 1.0, z1: float = 0.25, z2: float = 0.75, delta: float = 0.06666666, na: float = 1.0, nb: float = 0.25, pa: float = 1.0, pb: float = 0.0, B0x: float = 1.0, B0y: float = 0.0, B0z: float = 0.0)[source]#

Bases: CartesianMHDequilibrium

Sheared fluid equilibrium in a cube with side lengths \(L_x=a,\,L_y=b,\,L_z=c\). Profiles depend on \(z\) solely:

\[ \begin{align}\begin{aligned}p(z) &= p_a + T(z)p_b \,,\\n(z) &= n_a + T(z)n_b \,.\\T(z) &= (\tanh(z - z_1)/\delta)-\tanh(z - z_2)/\delta)) \,.\\\mathbf B &= B_{0x}\,\mathbf e_x + B_{0y}\,\mathbf e_y + B_{0z}\,\mathbf e_z = const.\,,\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • a (float) – Dimension of the slab in x (default: 1.).

  • b (float) – Dimension of the slab in y (default: 1.).

  • c (float) – Dimension of the slab in z (default: 1.).

  • z1 (float) – Location of the first swap in density (default 0.25).

  • z2 (float) – Location of the second swap in density (default 0.75).

  • delta (float) – Characteristic size of the swap region (default 1/15).

  • na (float) – Exterior value for the density (default: 1.).

  • nb (float) – Deviation of the density (default 0.25).

  • pa (float) – Exterior value for the pressure (default: 1.).

  • pb (float) – Deviation of the pressure (default 0.).

  • B0x (float) – x-component of magnetic field (default: 0.).

  • B0y (float) – y-component of magnetic field (default: 0.).

  • B0z (float) – z-component of magnetic field (default: 1.).

Note

In the parameter .yml, use the following in the section fluid_background:

ShearFluid :
    a    : 1.   # dimension in x
    b    : 1.   # dimension in y
    c    : 2.   # dimension in z
    z1   : 0.5  # first swap location
    z2   : 1.5  # second swap location
    delta: 0.06666666   # characteristic size of the swap
    na   : 1.25 # exterior density
    nb   : 0.75 # deviation from the average
    pa   : 1.   # constant pressure
    pb   : 0.   # deviation pressure
    B0x  : 1. # magnetic field in x
    B0y  : 0. # magnetic field in y
    B0z  : 0. # magnetic field in z
T_z(z)[source]#

Swap function T(z) = tanh(z - z_1)/delta) - tanh(z - z_2)/delta)

p_z(z)[source]#

Pressure profile p = p(z).

n_z(z)[source]#

Ion number density profile n = n(z).

plot_profiles(n_pts=501)[source]#

Plots radial profiles.

b_xyz(x, y, z)[source]#

Magnetic field.

a_xyz(x, y, z)[source]#

Vector potential.

j_xyz(x, y, z)[source]#

Current density.

p_xyz(x, y, z)[source]#

Pressure.

n_xyz(x, y, z)[source]#

Number density.

gradB_xyz(x, y, z)[source]#

Gradient of magnetic field.

class struphy.fields_background.equils.ScrewPinch(a: float = 1.0, R0: float = 5.0, B0: float = 1.0, q0: float = 1.05, q1: float = 1.8, n1: float = 0.0, n2: float = 0.0, na: float = 1.0, p0: float = 1e-08, beta: float = 0.1)[source]#

Bases: CartesianMHDequilibrium

Straight tokamak (screw pinch) MHD equilibrium for a cylindrical geometry of radius \(a\) and length \(L_z=2\pi R_0\).

The profiles in cylindrical coordinates \((r, \theta, z)\) with transformation formulae

\[ \begin{align}\begin{aligned}x &= r\cos\theta\,,\\y &= r\sin\theta\,,\\z &= z\,,\end{aligned}\end{align} \]

are:

\[ \begin{align}\begin{aligned}\mathbf B(r) &= B_{0}\left( \mathbf e_z + \frac{r}{q(r) R_0}\mathbf e_\theta \right)\,,\qquad q(r) = q_0 + ( q_1 - q_0 )\frac{r^2}{a^2}\,,\\p(r) &= p0 + \left\{\begin{aligned} &\frac{B_{0}^2 a^2 q_0}{ 2 R_0^2(q_1 - q_0) } \left( \frac{1}{q(r)^2} - \frac{1}{q_1^2} \right) \quad &&\textnormal{if}\quad q_1\neq q_0\neq\infty\,,\\&\frac{B_{0}^2 a^2}{R_0^2q_0^2} \left(1 - \frac{r^2}{a^2} \right) \quad &&\textnormal{if}\quad q_1= q_0\neq\infty\,,\\&\beta\frac{B_{0}^2}{2} \quad &&\textnormal{if}\quad q_0= q_1=\infty\,, \end{aligned}\right.\\n(r) &= n_a + ( 1 - n_a )\left( 1 - \left(\frac{r}{a}\right)^{n_1} \right)^{n_2}\,.\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • a (float) – “Minor” radius (radius of cylinder, default: 1.).

  • R0 (float) – “Major” radius (must be compatible with \(L_z=2\pi R_0\), default: 5.).

  • B0 (float) – z-component of magnetic field (constant) (default: 1.).

  • q0 (float, str) – Safety factor at r=0 (use the string “inf” for infinity, default: 1.05).

  • q1 (float, str) – Safety factor at r=a (use the string “inf” for infinity, default: 1.80).

  • n1 (float) – 1st shape factor for ion number density profile (default: 0.).

  • n2 (float) – 2nd shape factor for ion number density profile (default: 0.).

  • na (float) – Ion nnumber density at r=a (default: 1.).

  • p0 (float) – Pressure offset to avoid numerical issues (default: 1e-8)

  • beta (float) – Plasma beta for \(q_0=q_1=\infty\) (ratio of kinematic pressure to B^2/2, default: 0.1).

Note

In the parameter .yml, use the following in the section fluid_background:

ScrewPinch :
    a    : 1.   # minor radius (radius of cylinder)
    R0   : 3.   # major radius (length of pinch Lz=2*pi*R0)
    B0   : 1.   # magnetic field in z-direction
    q0   : 1.05 # safety factor at r=0
    q1   : 1.80 # safety factor at r=a
    n1   : 0.   # 1st shape factor for ion number density profile
    n2   : 0.   # 2nd shape factor for ion number density profile
    na   : 1.   # ion number density at r=a
    p0   : 1.   # pressure offset
    beta : 0.1  # plasma beta = p*2/B^2 for q0=q1=inf (pure axial field).
q_r(r, der=0)[source]#

Radial safety factor profile q = q(r) (and first derivative).

p_r(r)[source]#

Radial pressure profile p = p(r).

n_r(r)[source]#

Radial ion number density profile n = n(r).

plot_profiles(n_pts=501)[source]#

Plots radial profiles.

b_xyz(x, y, z)[source]#

Magnetic field.

j_xyz(x, y, z)[source]#

Current density.

p_xyz(x, y, z)[source]#

Pressure.

n_xyz(x, y, z)[source]#

Number density.

gradB_xyz(x, y, z)[source]#

Gradient of magnetic field.

class struphy.fields_background.equils.AdhocTorus(a: float = 1.0, R0: float = 3.0, B0: float = 2.0, q_kind: int = 0, q0: float = 1.71, q1: float = 1.87, n1: float = 2.0, n2: float = 1.0, na: float = 0.2, p_kind: int = 1, p0: float = 1.0, p1: float = 0.1, p2: float = 0.1, beta: float = 0.179, psi_k: int = 3, psi_nel: int = 50)[source]#

Bases: AxisymmMHDequilibrium

Ad hoc tokamak MHD equilibrium with circular concentric flux surfaces.

For a cylindrical coordinate system \((R, \phi, Z)\) with transformation formulae

\[ \begin{align}\begin{aligned}x &= R\cos(\phi)\,, &&R = \sqrt{x^2 + y^2}\,,\\y &= R\sin(\phi)\,, &&\phi = \arctan(y/x)\,,\\z &= Z\,, &&Z = z\,,\end{aligned}\end{align} \]

the magnetic field is given by

\[\mathbf B = \nabla\psi\times\nabla\phi+g\nabla\phi\,,\]

where \(g=g(R, Z)=-B_0R_0=const.\) is the toroidal field function, \(R_0\) the major radius of the torus and \(B_0\) the on-axis magnetic field. The ad hoc poloidal flux function \(\psi=\psi(r)\) is the solution of

\[\frac{\textnormal{d}\psi}{\textnormal{d}r}=\frac{B_0r}{q(r)\sqrt{1 - r^2/R_0^2}}\,,\qquad r=\sqrt{Z^2+(R-R_0)^2}\,,\]

for some given safety factor profile. Two profiles in terms of the on-axis \(q_0\equiv q(r=0)\) and edge \(q_1\equiv q(r=a)\) safety factor values are available (\(a\) is the minor radius of the torus):

\[ \begin{align}\begin{aligned}q(r) &= \left\{\begin{aligned} &q_0 + ( q_1 - q_0 )\frac{r^2}{a^2} \quad &&\textnormal{if} \quad q_\textnormal{kind}=0\,,\\&\frac{q_0}{1-\left(1-\frac{r^2}{a^2}\right)^{\frac{q_1}{q_0}}}\frac{r^2}{a^2} \quad &&\textnormal{if} \quad q_\textnormal{kind}=1\,. \end{aligned}\right.\end{aligned}\end{align} \]

The pressure profile

\[ \begin{align}\begin{aligned}p^\prime(r) &= -\frac{B_0^2}{R_0^2}\frac{r\left[2q(r)-rq^\prime(r)\right]}{q(r)^3} \quad &&\textnormal{if} \quad p_\textnormal{kind}=0\,,\\p(r) &= \beta \frac{B_{0}^2}{2} \left( p_0 - p_1 \frac{r^2}{a^2} - p_2 \frac{r^4}{a^4} \right) \quad &&\textnormal{if} \quad p_\textnormal{kind}=1\,,\end{aligned}\end{align} \]

is either the exact solution of the MHD equilibrium condition in the cylindrical limit (\(p_\textnormal{kind}=0\)) or an monotonically decreasing adhoc profile for some given on-axis plasma beta (\(p_\textnormal{kind}=1\)). Finally, the number density profile is chosen as

\[n(r) = n_a + ( 1 - n_a ) \left( 1 - \left(\frac{r}{a}\right)^{n_1} \right)^{n_2}\,.\]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • a (float) – Minor radius of torus (default: 1.).

  • R0 (float) – Major radius of torus (default: 3.).

  • B0 (float) – On-axis (r=0) toroidal magnetic field (default: 2.).

  • q_kind (int) – Which safety factor profile, see docstring (0 or 1, default: 0).

  • q0 (float) – Safety factor at r=0 (default: 1.71).

  • q1 (float) – Safety factor at r=a (default: 1.87).

  • n1 (float) – 1st shape factor for ion number density profile (default: 0.).

  • n2 (float) – 2nd shape factor for ion number density profile (default: 0.).

  • na (float) – Ion number density at r=a (default: 1.).

  • p_kind (int) – Kind of pressure profile, see docstring (0 or 1, default: 1).

  • p0 (float) – constant factor for ad hoc pressure profile (default: 1.).

  • p1 (float) – 1st shape factor for ad hoc pressure profile (default: 0.).

  • p2 (float) – 2nd shape factor for ad hoc pressure profile (default: 0.).

  • beta (float) – On-axis (r=0) plasma beta if p_kind=1 (ratio of kinematic pressure to B^2/(2*mu0), default: 0.179).

  • psi_k (int) – Spline degree to be used for interpolation of poloidal flux function (if q_kind=1, default=3).

  • psi_nel (int) – Number of cells to be used for interpolation of poloidal flux function (if q_kind=1, default=50).

Note

In the parameter .yml, use the following in the section fluid_background:

AdhocTorus :
    a       : 1.   # minor radius
    R0      : 3.   # major radius
    B0      : 2.   # on-axis toroidal magnetic field
    q_kind  : 0    # which profile (0 : parabolic, 1 : other, see documentation)
    q0      : 1.05 # safety factor at r=0
    q1      : 1.80 # safety factor at r=a
    n1      : .5   # 1st shape factor for number density profile
    n2      : 1.   # 2nd shape factor for number density profile
    na      : .2   # number density at r=a
    p_kind  : 1    # kind of pressure profile (0 : cylindrical limit, 1 : ad hoc)
    p0      : 1.   # constant factor for ad hoc pressure profile
    p1      : .1   # 1st shape factor for ad hoc pressure profile
    p2      : .1   # 2nd shape factor for ad hoc pressure profile
    beta    : .01  # plasma beta = p*(2*mu_0)/B^2 for flat safety factor
    psi_k   : 3    # spline degree to be used for interpolation of poloidal flux function (only needed if q_kind=1)
    psi_nel : 50   # number of cells to be used for interpolation of poloidal flux function (only needed if q_kind=1)
property boundary_pts_R#

R-coordinates of plasma boundary contour.

property boundary_pts_Z#

Z-coordinates of plasma boundary contour.

property psi_range#

Psi on-axis and at plasma boundary.

property psi_axis_RZ#

Location of magnetic axis in R-Z-coordinates.

psi_r(r, der=0)[source]#

Ad hoc poloidal flux function psi = psi(r).

q_r(r, der=0)[source]#

Radial safety factor profile q = q(r) (and first derivative).

p_r(r)[source]#

Radial pressure profile p = p(r).

n_r(r)[source]#

Radial number density profile n = n(r).

plot_profiles(n_pts=501)[source]#

Plots 1d profiles.

psi(R, Z, dR=0, dZ=0)[source]#

Poloidal flux function psi = psi(R, Z).

g_tor(R, Z, dR=0, dZ=0)[source]#

Toroidal field function g = g(R, Z).

p_xyz(x, y, z)[source]#

Pressure p = p(x, y, z).

n_xyz(x, y, z)[source]#

Number density n = n(x, y, z).

class struphy.fields_background.equils.AdhocTorusQPsi(a: float = 0.361925, R0: float = 1.0, B0: float = 1.0, q0: float = 0.6, q1: float = 2.5, q0p: float = 0.78, q1p: float = 5.0, n1: float = 2.0, n2: float = 1.0, na: float = 0.2, beta: float = 4.0, p1: float = 0.25, psi_k: int = 3, psi_nel: int = 50)[source]#

Bases: AxisymmMHDequilibrium

Ad hoc tokamak MHD equilibrium with circular concentric flux surfaces.

For a cylindrical coordinate system \((R, \phi, Z)\) with transformation formulae

\[ \begin{align}\begin{aligned}x &= R\cos(\phi)\,, &&R = \sqrt{x^2 + y^2}\,,\\y &= R\sin(\phi)\,, &&\phi = \arctan(y/x)\,,\\z &= Z\,, &&Z = z\,,\end{aligned}\end{align} \]

the magnetic field is given by

\[\mathbf B = \nabla\psi\times\nabla\phi+g\nabla\phi\,,\]

where \(g=g(R, Z)=-B_0R_0=const.\) is the toroidal field function, \(R_0\) the major radius of the torus and \(B_0\) the on-axis magnetic field. The ad hoc poloidal flux function \(\psi=\psi(r)\) is the solution of

\[\frac{\textnormal{d}\psi}{\textnormal{d}r}=\frac{B_0r}{q(\psi(r))\sqrt{1 - r^2/R_0^2}}\,,\qquad r=\sqrt{Z^2+(R-R_0)^2}\,,\]

for a safety factor profile

\[ \begin{align}\begin{aligned}q(\psi) &= q_0 + \psi_{\textnormal{norm}}\left[ q_1-q_0+(q_1^\prime-q_1+q_0)\frac{(1-\psi_s)(\psi_{\textnormal{norm}}-1)}{\psi_{\textnormal{norm}}-\psi_s} \right]\,,\\\psi_{\textnormal{norm}} &= \frac{\psi-\psi(0)}{\psi(a)-\psi(0)}\,,\\\psi_s &= (q_1^\prime-q_1+q_0)/(q_0^\prime+q_1^\prime-2q_1+2q_0)\,,\end{aligned}\end{align} \]

where \(a\) is the minor radius of the torus.

The pressure and number density profiles are chosen as

\[ \begin{align}\begin{aligned}p(\psi) &= \frac{\beta B_0^2}{2}\exp\left(-\frac{\psi_{\textnormal{norm}}}{p_1}\right)\,,\\n(\psi) &= n_a + ( 1 - n_a ) \left( 1 - \psi_{\textnormal{norm}}^{n_1} \right)^{n_2}\,.\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • a (float) – Minor radius of torus (default: 0.361925).

  • R0 (float) – Major radius of torus (default: 1.).

  • B0 (float) – On-axis (r=0) toroidal magnetic field (default: 1.).

  • q0 (float) – Safety factor at r=0 (default: 0.6).

  • q1 (float) – Safety factor at r=a (default: 2.5).

  • q0p (float) – Derivative of safety factor at r=0 (w.r.t. poloidal flux function, default: 0.78).

  • q1p (float) – Derivative of safety factor at r=a (w.r.t. poloidal flux function, default: 5.00).

  • n1 (float) – 1st shape factor for ion number density profile (default: 0.).

  • n2 (float) – 2nd shape factor for ion number density profile (default: 0.).

  • na (float) – Ion number density at r=a (default: 1.).

  • beta (float) – On-axis (r=0) plasma beta (ratio of kinematic pressure to B^2/(2*mu0), default: 0.1).

  • p1 (float) – Shape factor for pressure profile, see docstring (default: 0.25).

  • psi_k (int) – Spline degree to be used for interpolation of poloidal flux function (default=3).

  • psi_nel (int) – Number of cells to be used for interpolation of poloidal flux function (default=50).

Note

In the parameter .yml, use the following in the section fluid_background:

AdhocTorusQPsi :
    a       : 0.361925 # minor radius
    R0      : 1.   # major radius
    B0      : 1.   # on-axis toroidal magnetic field
    q0      : 0.6  # safety factor at r=0
    q1      : 2.5  # safety factor at r=a
    q0p     : 0.78 # derivative of safety factor at r=0 (w.r.t. to poloidal flux function)
    q1p     : 5.00 # derivative of safety factor at r=a (w.r.t. to poloidal flux function)
    n1      : .5   # shape factor for number density profile
    n2      : 1.   # shape factor for number density profile
    na      : .2   # number density at r=a
    beta    : .1   # plasma beta = p*(2*mu_0)/B^2 for flat safety factor
    p1      : 0.25 # shape factor of pressure profile
    psi_k   : 3    # spline degree to be used for interpolation of poloidal flux function
    psi_nel : 50   # number of cells to be used for interpolation of poloidal flux functionq_kind=1)
property boundary_pts_R#

R-coordinates of plasma boundary contour.

property boundary_pts_Z#

Z-coordinates of plasma boundary contour.

property psi_range#

Psi on-axis and at plasma boundary.

property psi_axis_RZ#

Location of magnetic axis in R-Z-coordinates.

psi_r(r, der=0)[source]#

Ad hoc poloidal flux function psi = psi(r).

q_psi(psi)[source]#

Safety factor profile q = q(psi).

p_psi(psi, der=0)[source]#

Pressure profile p = p(psi).

n_psi(psi, der=0)[source]#

Number density profile n = n(psi).

plot_profiles(n_pts=501)[source]#

Plots 1d profiles.

psi(R, Z, dR=0, dZ=0)[source]#

Poloidal flux function psi = psi(R, Z).

g_tor(R, Z, dR=0, dZ=0)[source]#

Toroidal field function g = g(R, Z).

p_xyz(x, y, z)[source]#

Pressure p = p(x, y, z).

n_xyz(x, y, z)[source]#

Number density n = n(x, y, z).

class struphy.fields_background.equils.EQDSKequilibrium(rel_path: bool = True, file: str | None = None, data_type: int = 0, p_for_psi: tuple = (3, 3), psi_resolution: tuple = (25.0, 6.25), p_for_flux: int = 3, flux_resolution: float = 50.0, n1: float = 2.0, n2: float = 1.0, na: float = 0.2, units: dict | None = None)[source]#

Bases: AxisymmMHDequilibrium

Interface to EQDSK file format.

Parameters:
  • rel_path (bool) – Whether file is relative to “<struphy_path>/fields_background/mhd_equil/eqdsk/data/”, or is an absolute path (default: True).

  • file (str) – Path to eqdsk file (default: “AUGNLED_g031213.00830.high”).

  • data_type (int) – 0: there is no space between data, 1: there is space between data (default: 0).

  • p_for_psi (tuple[int]) – Spline degrees in (R, Z) directions used for interpolation of psi data (default: [3, 3]).

  • psi_resolution (tuple[float]) – Resolution of psi data in (R, Z) directions in %, e.g. [50., 50.] uses every second psi data point (default: [25., 6.25]).

  • p_for_flux (int) – Spline degree in psi direction used for interpolation of 1d functions that depend on psi: f=f(psi) (default: 3).

  • flux_resolution (float) – Resolution of 1d f=f(psi) data in %, e.g. 25. uses every forth data point (default: 50.).

  • n1 (float) – 1st shape factor for ion number density profile n = n(psi) (default: 0.).

  • n2 (float) – 2nd shape factor for ion number density profile n = n(psi) (default: 0.).

  • na (float) – Ion number density at plasma boundary (default: 1.).

  • units (dict) – All Struphy units. If None, no rescaling of EQDSK output is performed.

Note

In the parameter .yml, use the following in the section fluid_background:

EQDSKequilibrium :
    rel_path        : True # whether eqdsk file path relative to "<struphy_path>/fields_background/mhd_equil/eqdsk/data/", or the absolute path
    file            : 'AUGNLED_g031213.00830.high' # path to eqdsk file
    data_type       : 0 # 0: there is no space between data, 1: there is space between data
    p_for_psi       : [3, 3]      # spline degrees used in interpolation of poloidal flux function grid data
    psi_resolution  : [25., 6.25] # resolution used in interpolation of poloidal flux function grid data in %, i.e. [100., 100.] uses all grid points
    p_for_flux      : 3   # spline degree used in interpolation of 1d functions f=f(psi) (e.g. toroidal field function)
    flux_resolution : 50. # resolution used in interpolation of of 1d functions f=f(psi) in %
    n1              : 0.  # 1st shape factor for number density profile n(psi) = (1-na)*(1 - psi_norm^n1)^n2 + na
    n2              : 0.  # 2nd shape factor for number density profile n(psi) = (1-na)*(1 - psi_norm^n1)^n2 + na
    na              : 1.  # number density at last closed flux surface
property units#

All Struphy units.

property boundary_pts_R#

R-coordinates of plasma boundary contour.

property boundary_pts_Z#

Z-coordinates of plasma boundary contour.

property limiter_pts_R#

R-coordinates of limiter contour.

property limiter_pts_Z#

Z-coordinates of limiter contour.

property range_R#

range of R of flux data.

property range_Z#

range of Z of flux data.

property psi_range#

Psi on-axis and at plasma boundary.

property psi_axis_RZ#

Location of magnetic axis in R-Z-coordinates.

q_psi(psi, der=0)[source]#

Safety factor q = q(psi).

g_psi(psi, der=0)[source]#

Toroidal field function g = g(psi).

p_psi(psi, der=0)[source]#

Pressure profile g = g(psi).

n_psi(psi, der=0)[source]#

Number density profile n = n(psi).

psi(R, Z, dR=0, dZ=0)[source]#

Poloidal flux function psi = psi(R, Z) in units Tesla*m^2.

g_tor(R, Z, dR=0, dZ=0)[source]#

Toroidal field function g = g(R, Z) in units Tesla*m.

p_xyz(x, y, z)[source]#

Pressure p = p(x, y, z) in units 1 Tesla^2/mu_0.

n_xyz(x, y, z)[source]#

Number density in physical space. Units from parameter file.

class struphy.fields_background.equils.GVECequilibrium(rel_path: bool = True, dat_file: str = 'run_03/NEO-SPITZER_State_0000_00003307.dat', param_file: str = 'run_03/parameter-fig8.ini', use_boozer: bool = False, use_nfp: bool = True, rmin: float = 0.01, Nel: tuple[int] = (16, 16, 16), p: tuple[int] = (3, 3, 3), density_profile: str = 'pressure', p0: float = 0.1, n0: float = 0.2, n1: float = 0.0, units: dict | None = None)[source]#

Bases: NumericalMHDequilibrium

Numerical equilibrium via an interface to pygvec.

Density profile can be set to

\[ \begin{align}\begin{aligned}n(r)= \left\{\begin{aligned} \ &n_0 p(r) \quad &&\textnormal{if density_profile = 'pressure'}\,,\\\ &n_1+\left(1-\left(\frac{r}{a}\right)^2\right) (n_0-n_1) \quad &&\textnormal{if density_profile = 'parabolic'}\,,\\\ &n_1+\left(1-\frac{r}{a}\right) (n_0-n_1) \quad &&\textnormal{if density_profile = 'linear'}\,, \end{aligned}\right. \,.\end{aligned}\end{align} \]
Parameters:
  • units (dict) – All Struphy units. If None, no rescaling of EQDSK output is performed.

  • rel_path (bool) – Whether dat_file (json_file) are relative to “<struphy_path>/fields_background/mhd_equil/gvec/”, or are absolute paths (default: True).

  • dat_file (str) – Path to .dat file (default: “/run_01/CIRCTOK_State_0000_00000000.dat”).

  • param_file (str) – Path to Gvec parameter.ini file (default: /run_01/parameter.ini).

  • use_boozer (bool) – Whether to use Boozer coordinates (default: False).

  • use_nfp (bool) – Whether the field periods of the stellarator should be used in the mapping, i.e. phi = 2*pi*eta3 / nfp (piece of cake) (default: True).

  • rmin (float) – Between [0, 1), radius (in logical space) of the domian hole around the magnetic axis (default: rmin=0.01).

  • Nel (tuple[int]) – Number of cells in each direction used for interpolation of the mapping (default: (16, 16, 16)).

  • p (tuple[int]) – Spline degree in each direction used for interpolation of the mapping (default: (3, 3, 3)).

  • density_profile (str) – ‘parabolic’ for a parabolic density profile, ‘linear’ for a linear density profile or ‘pressure’ for a density profile proportional to pressure

  • n0 (float) – shape factor for ion number density profile (default: 0.2).

  • n1 (float) – shape factor for ion number density profile (default: 0.).

  • p0 (float) – constant added to the pressure (default: 0.)

Note

In the parameter .yml, use the following in the section fluid_background:

GVECequilibrium :
    rel_path : True # whether file path is relative to "<struphy_path>/fields_background/mhd_equil/gvec/", or the absolute path
    dat_file : '/ellipstell_v2/newBC_E1D6_M6N6/GVEC_ELLIPSTELL_V2_State_0000_00200000.dat' # path to gvec .dat output file
    param_file : null # give directly the parsed json file, if it exists (then dat_file is not used)
    use_boozer : False # whether to use Boozer coordinates
    use_nfp : True # whether to use the field periods of the stellarator in the mapping, i.e. phi = 2*pi*eta3 / nfp (piece of cake).
    rmin : 0.0 # radius of domain hole around magnetic axis.
    Nel : [32, 32, 32] # number of cells in each direction used for interpolation of the mapping.
    p : [3, 3, 3] # spline degree in each direction used for interpolation of the mapping.
    density_profile : 'pressure'
    n0 : 0.2
    n1 : 0.
    p0 : 1.
property numerical_domain#

Domain object that characterizes the mapping from the logical to the physical domain.

property state#

Gvec state object.

property units#

All Struphy units.

bv(*etas, squeeze_out=False)[source]#

Contra-variant (vector field) magnetic field on logical cube [0, 1]^3 in Tesla / meter.

jv(*etas, squeeze_out=False)[source]#

Contra-variant (vector field) current density (=curl B) on logical cube [0, 1]^3 in Ampere / meter^3.

p0(*etas, squeeze_out=False)[source]#

0-form equilibrium pressure on logical cube [0, 1]^3.

n0(*etas, squeeze_out=False)[source]#

0-form equilibrium density on logical cube [0, 1]^3.

gradB1(*etas, squeeze_out=False)[source]#

1-form gradient of magnetic field strength on logical cube [0, 1]^3.

class struphy.fields_background.equils.DESCequilibrium(eq_name: str | None = None, rel_path: bool = False, use_pest: bool = False, use_nfp: bool = True, rmin: float = 0.01, Nel: tuple[int] = (16, 16, 50), p: tuple[int] = (3, 3, 3), T_kelvin: float = 100000.0, units: dict | None = None)[source]#

Bases: NumericalMHDequilibrium

Numerical equilibrium via an interface to the DESC code.

Parameters:
  • eq_name (str) – Name of existing DESC equilibrium object (.h5 or binary).

  • rel_path (bool) – Whether to add “<struphy_path>/fields_background/mhd_equil/desc/” before eq_name (default: False).

  • use_pest (bool) – Whether to use straigh-field line coordinates (PEST) (default: False).

  • use_nfp (bool) – Whether the field periods of the stellarator should be used in the mapping, i.e. phi = 2*pi*eta3 / nfp (piece of cake) (default: True).

  • rmin (float) – Between [0, 1), radius (in logical space) of the domian hole around the magnetic axis (default: rmin=0.01).

  • Nel (tuple[int]) – Number of cells in each direction used for interpolation of the mapping (default: (16, 16, 16)).

  • p (tuple[int]) – Spline degree in each direction used for interpolation of the mapping (default: (3, 3, 3)).

  • units (dict) – All Struphy units. If None, no rescaling of EQDSK output is performed.

  • T_kelvin (maximum of temperature in Kelvin (default: 100000).)

Note

In the parameter .yml, use the following in the section fluid_background:

DESCequilibrium :
    eq_name : null # name of DESC equilibrium; if None, the example "DSHAPE" is chosen
    rel_path : False # whether to add "<struphy_path>/fields_background/mhd_equil/desc/" before eq_name.
    use_pest : False # whether to use straight-field line coordinates (PEST)
    use_nfp : True # whether to use the field periods of the stellarator in the mapping, i.e. phi = 2*pi*eta3 / nfp (piece of cake).
    rmin : 0.0 # radius of domain hole around magnetic axis.
    Nel : [32, 32, 32] # number of cells in each direction used for interpolation of the mapping.
    p : [3, 3, 3] # spline degree in each direction used for interpolation of the mapping.
    T_kelvin : 100000 # maximum temperature in Kelvin used to set density
property numerical_domain#

Domain object that characterizes the mapping from the logical to the physical domain.

property eq#

DESC object.

property rmin#

Radius of domain hole around magnetic axis.

property use_nfp#

True (=default) if to use the field periods of the stellarator in the mapping, i.e. phi = 2*pi*eta3 / nfp (piece of cake).

property units#

All Struphy units.

bv(*etas, squeeze_out=False)[source]#

Contra-variant (vector field) magnetic field on logical cube [0, 1]^3 in Tesla / meter.

jv(*etas, squeeze_out=False)[source]#

Contra-variant (vector field) current density (=curl B) on logical cube [0, 1]^3 in Ampere / meter^3.

p0(*etas, squeeze_out=False)[source]#

0-form equilibrium pressure on logical cube [0, 1]^3 in Pascal.

n0(*etas, squeeze_out=False)[source]#

0-form equilibrium density on logical cube [0, 1]^3.

gradB1(*etas, squeeze_out=False)[source]#

1-form gradient of magnetic field strength on logical cube [0, 1]^3.

desc_eval(var: str, e1: ndarray, e2: ndarray, e3: ndarray, flat_eval: bool = False, nfp: int = 1, verbose: bool = False)[source]#

Transform the input grids to conform to desc’s .compute method and evaluate var.

Parameters:
  • var (str) – Desc equilibrium quantitiy to evaluate, from `https://desc-docs.readthedocs.io/en/latest/variables.html#list-of-variables`_.

  • e1 (xp.ndarray) – Input grids, either 1d or 3d.

  • e2 (xp.ndarray) – Input grids, either 1d or 3d.

  • e3 (xp.ndarray) – Input grids, either 1d or 3d.

  • flat_eval (bool) – Whether to do flat (marker) evaluation.

  • nfp (int) – Number of stellarator field periods to be used in the mapping (nfp=1 uses the whole stellarator).

  • verbose (bool) – Print grid check to screen.

class struphy.fields_background.equils.ConstantVelocity(ux: float = 0.0, uy: float = 0.0, uz: float = 0.0, n: float = 1.0, n1: float = 0.0, density_profile: str = 'constant', velocity_profile: str = 'constant', p0: float = 1.0)[source]#

Bases: CartesianFluidEquilibrium

Base class for a constant distribution function on the unit cube. The Background does not depend on the velocity

u_xyz(x, y, z)[source]#

Ion velocity.

p_xyz(x, y, z)[source]#

Plasma pressure.

n_xyz(x, y, z)[source]#

Number density.

class struphy.fields_background.equils.HomogenSlabITG(B0z: float = 1.0, Lx: float = 6.0, p0: float = 1.0, pmin: float = 0.1, n0: float = 1.0, eps: float = 0.1)[source]#

Bases: CartesianFluidEquilibriumWithB

Homogenous slab equilibrium with temperature gradient in x, B-field in z:

\[ \begin{align}\begin{aligned}\mathbf B &= B_{0z}\,\mathbf e_z = const.\,, \qquad n &= n_0 = const.\\p &= p_0*(1 - \frac{x}{L_x} ) + p_\textrm{min}\,,\\\mathbf u &= - \epsilon \frac{p_0}{L_x} \mathbf e_y\,.\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • B0z (float) – z-component of magnetic field (default: 1.).

  • Lx (float) – Domain length in x; 1/Lx is the temperature scale length.

  • p0 (float) – Constant pressure coefficient (default: 1.).

  • pmin (float) – Minimum pressure at x = Lx.

  • n0 (float) – Ion number density (default: 1.).

  • eps (float) – The unit factor \(1/(\hat\Omega_i \hat t)\).

Note

In the parameter .yml, use the following in the section fluid_background:

HomogenSlabITG :
    B0z  : 1.
    Lx   : 1.
    p0   : 1.
    pmin : .1
    n0   : 1.
    eps  : .1
b_xyz(x, y, z)[source]#

Magnetic field.

u_xyz(x, y, z)[source]#

Ion velocity.

p_xyz(x, y, z)[source]#

Plasma pressure.

n_xyz(x, y, z)[source]#

Number density.

gradB_xyz(x, y, z)[source]#

Field strength gradient.

class struphy.fields_background.equils.CircularTokamak(a: float = 1.0, R0: float = 2.0, B0: float = 10.0, Bp: float = 12.5)[source]#

Bases: AxisymmMHDequilibrium

Tokamak MHD equilibrium with circular concentric flux surfaces.

For a cylindrical coordinate system \((R, \phi, Z)\) with transformation formulae

\[ \begin{align}\begin{aligned}x &= R\cos(\phi)\,, &&R = \sqrt{x^2 + y^2}\,,\\y &= R\sin(\phi)\,, &&\phi = \arctan(y/x)\,,\\z &= Z\,, &&Z = z\,,\end{aligned}\end{align} \]

the magnetic field is given by

\[\mathbf B = \nabla\psi\times\nabla\phi+g\nabla\phi\,,\]

where \(g=g(R, Z)=B_0R_0=const.\) is the toroidal field function, \(R_0\) the major radius of the torus and \(B_0\) the on-axis magnetic field. The flux \(\psi=\psi(R, Z)\) is given by

\[\psi=a R_0 B_p \frac{(R-R_0)^2+Z^2}{2 a^2}\,\]

for the given constants.

The pressure profile and the number density profile are not specified

Units are those defined in the parameter file (struphy units -h).

Parameters:
  • a (float) – Minor radius of torus (default: 1.).

  • R0 (float) – Major radius of torus (default: 2.).

  • B0 (float) – On-axis (r=0) toroidal magnetic field (default: 10.).

  • Bp (float) – Poloidal magnetic field (default: 12.5).

Note

In the parameter .yml, use the following in the section fluid_background:

CircularTokamak :
    a       : 1.   # minor radius
    R0      : 2.   # major radius
    B0      : 10.  # on-axis toroidal magnetic field
    Bp      : 12.5 # poloidal magnetic field
property psi_range#

Psi on-axis and at plasma boundary.

property psi_axis_RZ#

Location of magnetic axis in R-Z-coordinates.

psi(R, Z, dR=0, dZ=0)[source]#

Poloidal flux function psi = psi(R, Z).

g_tor(R, Z, dR=0, dZ=0)[source]#

Toroidal field function g = g(R, Z).

p_xyz(x, y, z)[source]#

Pressure p = p(x, y, z).

n_xyz(x, y, z)[source]#

Number density n = n(x, y, z).

class struphy.fields_background.equils.CurrentSheet(delta: float = 0.1, amp: float = 1.0)[source]#

Bases: CartesianMHDequilibrium

Current sheet equilibrium

\[ \begin{align}\begin{aligned}B_y &= \text{tanh}(z / \delta) \,,\\B_x &= \sqrt{(1 - B_y^2)} \,,\\p &= p_0 = 5/2\,,\\n &= n_0 = 1 \,.\end{aligned}\end{align} \]

Units are those defned in the parameter file (struphy units -h).

Parameters:
  • delta (characteristic size of the current sheet)

  • amp (amplitude of the current sheet)

Note

In the parameter .yml, use the following in the section fluid_background::
CurrentSheet :

amp : 1. delta : 0.1

plot_profiles(n_pts=501)[source]#

Plots radial profiles.

b_xyz(x, y, z)[source]#

Magnetic field.

j_xyz(x, y, z)[source]#

Current density.

p_xyz(x, y, z)[source]#

Pressure.

n_xyz(x, y, z)[source]#

Number density.

gradB_xyz(x, y, z)[source]#

Gradient of magnetic field.

Projected fluid equilibria#

These classes provide discrete representations of fluid equilibria in DeRham spaces.

class struphy.fields_background.projected_equils.ProjectedFluidEquilibrium(equil: FluidEquilibrium, derham: Derham)[source]#

Bases: object

Commuting projections of FluidEquilibrium into Derham spaces. Return coefficients.

property equil#
property derham#
property p0#
property q0#
property n0#
property t0#
property vth0#
property s0_monoatomic#
property s0_diatomic#
property absB3#
property p3: StencilVector#
property q3#
property n3#
property t3#
property vth3#
property s3_monoatomic#
property s3_diatomic#
property u1#
property u2#
property uv#
class struphy.fields_background.projected_equils.ProjectedFluidEquilibriumWithB(equil: FluidEquilibriumWithB, derham: Derham)[source]#

Bases: ProjectedFluidEquilibrium

Commuting projections of FluidEquilibriumWithB into Derham spaces. Return coefficients.

property absB0#
property u_para0#
property absB3#
property u_para3#
property b1#
property unit_b1#
property gradB1#
property a1#
property b2: BlockVector#
property unit_b2#
property gradB2#
property a2#
property bv#
property unit_bv#
property gradBv#
property av#
class struphy.fields_background.projected_equils.ProjectedMHDequilibrium(equil: MHDequilibrium, derham: Derham)[source]#

Bases: ProjectedFluidEquilibriumWithB

Commuting projections of MHDequilibrium into Derham spaces. Return coefficients.

property curl_unit_b_dot_b0#
property j1#
property curl_unit_b1#
property j2#
property curl_unit_b2#
property jv#
property curl_unit_bv#

Generic fluid equilibria#

These classes can be used to quickly pass callables to Struphy objects (for instance in Jupyter notebooks).

class struphy.fields_background.generic.GenericCartesianFluidEquilibrium(u_xyz: callable | None = None, p_xyz: callable | None = None, n_xyz: callable | None = None)[source]#

Bases: CartesianFluidEquilibrium

Allows to pass callables at init.

u_xyz(x, y, z)[source]#

Cartesian velocity in physical space. Must return the components as a tuple.

p_xyz(x, y, z)[source]#

Equilibrium pressure in physical space.

n_xyz(x, y, z)[source]#

Equilibrium number density in physical space.

class struphy.fields_background.generic.GenericCartesianFluidEquilibriumWithB(u_xyz: callable | None = None, p_xyz: callable | None = None, n_xyz: callable | None = None, b_xyz: callable | None = None, gradB_xyz: callable | None = None)[source]#

Bases: GenericCartesianFluidEquilibrium

Allows to pass callables at init.

b_xyz(x, y, z)[source]#
gradB_xyz(x, y, z)[source]#