Utilities#
Domain-related utility functions.
- struphy.geometry.utilities.field_line_tracing(psi, psi_axis_R, psi_axis_Z, psi0, psi1, Nel, p, psi_power=1, xi_param='equal_angle', Nel_pre=(64, 256), p_pre=(3, 3), r0=0.3)[source]#
Given a poloidal flux function \(\psi(R, Z)\), constructs a flux-aligned spline mapping \((R, Z) = F(s(\psi), \xi)\).
The radial coordinate \(s \in [0, 1]\) is parametrized in terms of powers of \(\psi\):
\[s(\psi) = [ (\psi - \psi_0)/(\psi_1 - \psi_0) ]^p,\]where \(\psi_0\) is the value of the innermost flux surface of the mapping, \(\psi_1\) the value of the outermost flux surface, and \(p \in \mathbb Q\) is some power.
The angular coordinate \(\xi \in (0, 2\pi)\) can be parametrized in five different ways:
equal_angleequal_arc_lengthsfl(straight field line angle)equal_areaequal_volume
All \(\xi\)-parametrizations other than
equal_angleinvolve a two step procedure:First, a flux-aligned mapping with parameters
Nel_pre,p_preis constructed withxi=equal angle.Second, a mapping with lower resolution is constructed with the desired \(\xi\)-parametrization.
The field-line tracing algorithm for the
equal_angle-parametrization is as follows: given a callable mapping \(s(R, Z) = [ (\psi(R, Z) - \psi_0)/(\psi_1 - \psi_0) ]^p \in [0, 1]\), we want to find the spline mapping\[ \begin{align}\begin{aligned}R(s, \xi) &= \sum_{i=1}^{N_1}\sum_{j=1}^{N_2}c^R_{ij}N_1(s)N_2(\xi)\,,\\Z(s, \xi) &= \sum_{i=1}^{N_1}\sum_{j=1}^{N_2}c^Z_{ij}N_1(s)N_2(\xi).\end{aligned}\end{align} \]This will be achieved by interpolation, which means we need a set of function values \((R_{ij}, Z_{ij})\) at the interpolation point sets \((s_i, \xi_j)_{i=1,j=1}^{N_1, N_2}\). At first, we need to obtain these function values. For this we draw lines for \(\xi_j=j\Delta\xi\) for \(j\in\{0,1,\cdots,N_2-1\}\):
\[ \begin{align}\begin{aligned}R_j(r) &= R_\text{axis} + r\cos(\xi_j)\,,\\Z_j(r) &= Z_\text{axis} + r\sin(\xi_j)\,.\end{aligned}\end{align} \]For each \(j\), we calculate the intersections with certain \(s_i\)-values by computing the root of the function
\[f(r) = s(R_j(r),Z_j(r)) - s_i\,.\]This yields a \(r_{i}\) which leads to \(R_{ij}=R_j(r_i)\) and \(Z_{ij}=Z_j(r_i)\). Finally, after having found the \((R_{ij}, Z_{ij})\), we solve a spline interpolation problem to find the \((c^R_{ij}, c^Z_{ij})\).
- Parameters:
psi (callable) – The poloidal flux function psi(R, Z).
psi_axis_R (float) – R coordinate of the minimum of psi.
psi_axis_Z (float) – Z coordinate of the minimum of psi.
psi0 (float) – Value of the innermost flux surface of the mapping.
psi1 (float) – Value of the outermost flux surface of the mapping.
Nel (list[int]) – Number of elements to be used for spline inerpolation.
p (list[int]) – Spline degrees for spline interpolation.
psi_power (int, optional) – Power of normalized poloidal flux used in s parametrization.
xi_param (str) – Which angular (xi) parametrization.
Nel_pre (tuple | list, optional) – Number of elements to be used for the pre-mapping.
p_pre (tuple | list, optional) – Spline degrees to be used for the pre-mapping.
r0 (float, optional) – Initial guess for radial distance from (psi_axis_R, psi_axis_Z) used in Newton root-finding method for flux surfaces.
- Returns:
cR (xp.ndarray) – Control points (2d) of flux aligned spline mapping (R-component).
cZ (xp.ndarray) – Control points (2d) of flux aligned spline mapping (Z-component).
- class struphy.geometry.utilities.TransformedPformComponent(fun: Callable | list, given_in_basis: Literal['0', '1', '2', '3', 'v', 'physical', 'physical_at_eta', 'norm', None], out_form: str, comp: int = 0, domain: Domain | None = None)[source]#
Bases:
objectConstruct callable component of p-form on logical domain (unit cube).
- Parameters:
fun (Callable | list) – Callable function (components). Has to be length three for vector-valued funnctions,.
given_in_basis (GivenInBasis) – In which basis fun is represented: either a p-form, then ‘0’ or ‘3’ for scalar and ‘v’, ‘1’ or ‘2’ for vector-valued, ‘physical’ when defined on the physical (mapped) domain, ‘physical_at_eta’ when given the Cartesian components defined on the logical domain, and ‘norm’ when given in the normalized contra-variant basis (\(\delta_i / |\delta_i|\)).
out_form (str) – The p-form representation of the output: ‘0’, ‘1’, ‘2’ ‘3’ or ‘v’.
comp (int) – Which component of the vector-valued function to return (=0 for scalars).
domain (struphy.geometry.domains) – All things mapping. If None, the input fun is just evaluated and not transformed at __call__.