scotty.hamiltonian module#
- class scotty.hamiltonian.DielectricTensor(electron_density, angular_frequency, B_total, temperature=None)#
Bases:
objectCalculates the components of the cold plasma dielectric tensor for a wave with angular frequency \(\Omega\):
\[\begin{split}\epsilon = \begin{pmatrix} \epsilon_{11} & -i\epsilon_{12} & 0 \\ i\epsilon_{12} & \epsilon_{11} & 0 \\ 0 & 0 & \epsilon_{bb} \\ \end{pmatrix}\end{split}\]where:
\[\begin{split}\begin{align} \epsilon_{11} &= 1 - \frac{\Omega_{pe}^2}{\Omega^2 - \Omega_{ce}^2} \\ \epsilon_{12} &= 1 - \frac{\Omega_{pe}^2\Omega_{ce}}{\Omega(\Omega^2 - \Omega_{ce}^2)} \\ \epsilon_{bb} &= 1 - \frac{\Omega_{pe}^2}{\Omega^2} \\ \end{align}\end{split}\]The components of the dielectric tensor are calculated in the \((\hat{\mathbf{u}}_1, \hat{\mathbf{u}}_2, \hat{\mathbf{b}})\) basis. Hence, \(\epsilon_{11}\), \(\epsilon_{12}\), and \(\epsilon_{bb}\) correspond to the
S,D, andPvariables in Stix, respectively. The notation used in this code is chosen to be consistent with Hall-Chen, Parra, Hillesheim, PPCF 2022.- Parameters:
electron_density (float | ndarray[tuple[int, ...], dtype[float64]]) – Electron number density
angular_frequency (float) – Angular frequency of the beam
B_total (float | ndarray[tuple[int, ...], dtype[float64]]) – Magnitude of the magnetic field
temperature (float | ndarray[tuple[int, ...], dtype[float64]] | None) – Temperature profile [optional]. Used to calculate relativistic corrections to electron mass, which affects \(\Omega_{pe}\) and :math:
Omega_{ce}.
- property e_11#
The \(\epsilon_{11}\) component
- property e_12#
The \(\epsilon_{12}\) component
- property e_bb#
The \(\epsilon_{bb}\) component
- class scotty.hamiltonian.Hamiltonian(field, launch_angular_frequency, mode_flag, density_fit, delta_R, delta_Z, delta_K_R, delta_K_zeta, delta_K_Z, temperature_fit=None)#
Bases:
objectFunctor to evaluate derivatives of the Hamiltonian, \(H\), at a given set of points.
Scottycalculates derivatives using a grid-free finite difference approach. The Hamiltonian is evaluated at, essentially, an arbitrary set of points around the location we wish to get the derivatives at. In practice we define stencils as relative offsets from a central point, and the evaluation points are the product of the spacing in a given direction with the stencil offsets. By carefully choosing our stencils and evaluating all of the derivatives at once, we can reuse evaluations of \(H\) between derivatives, saving a lot of computation.The stencils are defined as a
dictwith atupleof offsets as keys andfloatweights as values. For example, theCFD1_stencil:{(1,): 0.5, (-1,): -0.5}
defines the second-order first central-difference:
\[f' = \frac{f(x + \delta_x) - f(x - \delta_x)}{2\delta_x}\]The keys are tuples so that we can iterate over the offsets for the mixed second derivatives.
The stencils have been chosen to maximise the reuse of Hamiltonian evaluations without sacrificing accuracy.
- Parameters:
field (MagneticField) – An object describing the magnetic field of the plasma
launch_angular_frequency (float) – Angular frequency of the beam
mode_flag (int) – Either
+/-1, used to determine which mode branch to usedensity_fit (Callable[[float | ndarray[tuple[int, ...], dtype[float64]]], float | ndarray[tuple[int, ...], dtype[float64]]]) – Function or
Callableparameterising the densitydelta_R (float) – Finite difference spacing in the
Rdirectiondelta_Z (float) – Finite difference spacing in the
Zdirectiondelta_K_R (float) – Finite difference spacing in the
K_Rdirectiondelta_K_zeta (float) – Finite difference spacing in the
K_zetadirectiondelta_K_Z (float) – Finite difference spacing in the
K_Zdirectiontemperature_fit (Callable[[float | ndarray[tuple[int, ...], dtype[float64]]], float | ndarray[tuple[int, ...], dtype[float64]]] | None)
- derivatives(q_R, q_Z, K_R, K_zeta, K_Z, second_order=False)#
Evaluate the first-order derivative in all directions at the given point(s), and optionally the second-order ones too
- scotty.hamiltonian.hessians(dH)#
Compute the elements of the Hessian of the Hamiltonian:
\[\begin{split}\begin{gather} \nabla \nabla H \\ \nabla_K \nabla H \\ \nabla_K \nabla_K H \\ \end{gather}\end{split}\]given a
dictcontaining the second derivatives of the Hamiltonian (as returned fromHamiltonian.derivativeswithsecond_order=True)- Parameters:
dH (dict)