scotty.hamiltonian module
scotty.hamiltonian module#
- class scotty.hamiltonian.DielectricTensor(electron_density, angular_frequency, B_total, temperature=None)#
Bases:
object
Calculates 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
, andP
variables in Stix, respectively. The notation used in this code is chosen to be consistent with Hall-Chen, Parra, Hillesheim, PPCF 2022.- Parameters
electron_density (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) – Electron number density
angular_frequency (float) – Angular frequency of the beam
B_total (Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) – Magnitude of the magnetic field
temperature (Optional[Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]]) – 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:
object
Functor to evaluate derivatives of the Hamiltonian, \(H\), at a given set of points.
Scotty
calculates 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
dict
with atuple
of offsets as keys andfloat
weights 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 (scotty.geometry.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[[Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]], Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]]) – Function or
Callable
parameterising the densitydelta_R (float) – Finite difference spacing in the
R
directiondelta_Z (float) – Finite difference spacing in the
Z
directiondelta_K_R (float) – Finite difference spacing in the
K_R
directiondelta_K_zeta (float) – Finite difference spacing in the
K_zeta
directiondelta_K_Z (float) – Finite difference spacing in the
K_Z
directiontemperature_fit (Optional[Callable[[Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]], Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]]]) –
- 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
- Parameters
q_R (ArrayLike) –
q_Z (ArrayLike) –
K_R (ArrayLike) –
K_zeta (ArrayLike) –
K_Z (ArrayLike) – Coordinates to evaluate the derivatives at
second_order (bool) – If
True
, also evaluate the second derivatives
- Return type
Dict[str, Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]]]
- 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
dict
containing the second derivatives of the Hamiltonian (as returned fromHamiltonian.derivatives
withsecond_order=True
)- Parameters
dH (dict) –