pyoculus 0.1.1
Loading...
Searching...
No Matches
pyoculus.problems.base_problem.BaseProblem Class Reference

Abstract class that used to drive calculation. More...

Inheritance diagram for pyoculus.problems.base_problem.BaseProblem:
pyoculus.problems.cylindrical_problem.CylindricalProblem pyoculus.problems.toroidal_problem.ToroidalProblem pyoculus.problems.cartesian_bfield.CartesianBfield pyoculus.problems.cylindrical_bfield.CylindricalBfield pyoculus.problems.toroidal_bfield.ToroidalBfield pyoculus.problems.simsgeo_biot_savart.SimsgeoBiotSavart pyoculus.problems.m3dc1_bfield.M3DC1Bfield pyoculus.problems.qfm_bfield.QFMBfield pyoculus.problems.spec_bfield.SPECBfield pyoculus.problems.two_waves.TwoWaves

Public Member Functions

 __init__ (self)
 
 f (self, t, y, *args)
 Returns ODE RHS.
 
 f_tangent (self, t, y, *args)
 Returns ODE RHS, with tangent.
 
 convert_coords (self, coord1)
 Converts coordinates (for example \(s,\theta,\zeta\) to \(R,Z,\varphi\))
 

Public Attributes

int problem_size = 2
 
str poincare_plot_type = "yx"
 
str poincare_plot_xlabel = "y"
 
str poincare_plot_ylabel = "x"
 

Detailed Description

Abstract class that used to drive calculation.

This is an abstract class, should never be used as an instance.

All problems should be a derived type of BaseProblem. They should contain the ODEs to solve, as specified by the Hamiltonian system of that problem.

Hamilton's equation

1.5D

If the Hamiltonian system is 1.5 dimensional, the Hamiltonian takes the form \(H=H(p,q,t)\). The Hamilton's equations are given by

\[ \frac{dq}{dt} = \frac{\partial H}{\partial p}, \quad \frac{dp}{dt} = -\frac{\partial H}{\partial q}. \quad\]

2D

If the Hamiltonian system is two-dimensional, the Hamiltonian takes the form \(H=H(p_1,q_1,p_2,q_2)\). The Hamilton's equations are given by

\[ \frac{dq_i}{dt} = \frac{\partial H}{\partial p_i}, \quad \frac{dp_i}{dt} = -\frac{\partial H}{\partial q_i}, \quad\]

in which \(i=1,2\).

The Hamiltonian \(H\) itself is a constant of motion, i.e. \(dH/dt=0\).

Given \( p_1, q_1, q_2\), we can invert \(H=H(p_1,q_1,p_2,q_2)=\mbox{const} \) to get \(p_2 = p_2(p_1, q_1, q_2)\).

If further \(q_2 \) is monotonically increasing with \(t\), one can replace \(t\) by \(q_2\) and get

\[ \frac{dq_1}{dq_2} = \left.\frac{\frac{\partial H}{\partial p_1}}{\frac{\partial H}{\partial p_2}} \right|_{p_2(p_1, q_1, q_2)}, \]

\[ \frac{dp_1}{dq_2} = \left.\frac{-\frac{\partial H}{\partial q_1} }{\frac{\partial H}{\partial p_2}}\right|_{p_2(p_1, q_1, q_2)}, \]

after computing which the value of \(p_2\) is substituted into these equations.

General ODEs with two variables

The Hamilton's equations, after converted can be combined and written as

\[ \frac{d y_1}{dt} = F_1(t, y_1, y_2),\]

\[ \frac{d y_2}{dt} = F_2(t, y_1, y_2).\]

The tangent of the above ODEs are given by

\[ \frac{d}{dt} \begin{bmatrix}\Delta y_1\\ \Delta y_2 \end{bmatrix} = \begin{bmatrix} \partial_{y_1}F_1 & \partial_{y_2}F_1 \\ \partial_{y_1}F_2 & \partial_{y_2}F_2 \end{bmatrix} \cdot \begin{bmatrix}\Delta y_1\\ \Delta y_2 \end{bmatrix}, \]

where the partial derivatives are evaluated at \(y_1(t), y_2(t)\) as the solution of the original ODEs.

Implementing a Problem class

All problem classes should inherit the BaseProblem class.

class SomeProblem(BaseProblem):
    def __init__(self, params):
        """some codes to initialize the problem"""
    def f(self, t, y, *args):
        """some codes compute the RHS (F) of the ODEs given t and y"""
    def f_tangent(self, t, y, *args):
        """some codes compute the ODEs and the tangent the ODEs given t and y, y contains two tangent vectors"""
    def convert_coords(self, coord1):
        """some codes compute the coordinate transformation"""

The member function f should be implemented in any case. The tangent and convert_coords functions are optional for some solvers.

Constructor & Destructor Documentation

◆ __init__()

Member Function Documentation

◆ convert_coords()

pyoculus.problems.base_problem.BaseProblem.convert_coords ( self,
coord1 )

Converts coordinates (for example \(s,\theta,\zeta\) to \(R,Z,\varphi\))

Parameters
coords1the coordinates to convert
Returns
the converted coordinates

Reimplemented in pyoculus.problems.qfm_bfield.QFMBfield, pyoculus.problems.spec_bfield.SPECBfield, pyoculus.problems.toroidal_problem.ToroidalProblem, and pyoculus.problems.two_waves.TwoWaves.

◆ f()

pyoculus.problems.base_problem.BaseProblem.f ( self,
t,
y,
* args )

Returns ODE RHS.

Parameters
ttime in ODE
yvariables in ODE
*argsparameter for the ODE
Returns
the RHS of the ODE

Reimplemented in pyoculus.problems.cylindrical_problem.CylindricalProblem, pyoculus.problems.toroidal_bfield.ToroidalBfield, and pyoculus.problems.toroidal_problem.ToroidalProblem.

◆ f_tangent()

pyoculus.problems.base_problem.BaseProblem.f_tangent ( self,
t,
y,
* args )

Returns ODE RHS, with tangent.

Parameters
ttime in ODE
y\(\bf y\) variables in ODE and \(\Delta \mathbf{y}_1\), \(\Delta \mathbf{y}_2\)
*argsparameter for the ODE
Returns
the RHS of the ODE, with tangent

Reimplemented in pyoculus.problems.cylindrical_problem.CylindricalProblem, pyoculus.problems.toroidal_bfield.ToroidalBfield, and pyoculus.problems.toroidal_problem.ToroidalProblem.

Member Data Documentation

◆ poincare_plot_type

str pyoculus.problems.base_problem.BaseProblem.poincare_plot_type = "yx"

◆ poincare_plot_xlabel

str pyoculus.problems.base_problem.BaseProblem.poincare_plot_xlabel = "y"

◆ poincare_plot_ylabel

str pyoculus.problems.base_problem.BaseProblem.poincare_plot_ylabel = "x"

◆ problem_size

int pyoculus.problems.base_problem.BaseProblem.problem_size = 2

The documentation for this class was generated from the following file: