API reference

simpthon

simpthon.body

class simpthon.body.Body(m, x, v)[source]

class representing a body/particle

get_mass()[source]

return mass of a body/particle

get_pos()[source]

return position of a body/particle

get_vel()[source]

return velocity of a body/particle

set_mass(m)[source]

set mass of a body/particle as m

set_phase_space(x, v)[source]

set phase space of a body/particle as \(\mathbf{x,v}\)

set_pos(x)[source]

set position of a body/particle as \(\mathbf{x}\)

set_vel(v)[source]

set velocity of a body/particle as \(\mathbf{v}\)


class simpthon.body.NBody[source]

class representing a bunch of bodies or particles (N-body)

add(b)[source]

append a body to bodies

member()[source]

return a list of body in bodies

number()[source]

return number of bodies


simpthon.body.mass(b)[source]

mass of a body

Parameters:

b (class Body) – body.

Returns:

mass of a body.

Return type:

float


simpthon.body.pos(b)[source]

position of a body

Parameters:

b (class Body) – body.

Returns:

position of a body.

Return type:

numpy array


simpthon.body.vel(b)[source]

velocity of a body

Parameters:

b (class Body) – body.

Returns:

velocity of a body.

Return type:

numpy array


simpthon.body.angmom(b)[source]

angular momentum per unit mass of body b

\[\mathbf{L} = \mathbf{r \times v}\]
Parameters:

b (class Body) – body.

Returns:

angular momentum per unit mass of a body.

Return type:

numpy array


simpthon.body.kinetic(b)[source]

kinetic energy per unit mass of body b

\[K = \frac{1}{2} \mathbf{v} \cdot \mathbf{v}\]
Parameters:

b (class Body) – body.

Returns:

kinetic energy per unit mass of a body.

Return type:

float


simpthon.body.radius(b)[source]

radius of position of a body b i.e. \(r=\sqrt{\mathbf{x}\cdot \mathbf{x}}\).

Args:

b (class Body): body.

Returns:

radius of position of a body.

Return type:

float


simpthon.body.vradial(b)[source]

radial velocity

Parameters:

b (class Body) – body.

Returns:

radial velocity of a body.

Return type:

numpy array


simpthon.body.vtangent(b)[source]

tangential velocity

Parameters:

b (class Body) – body.

Returns:

radial velocity of a body.

Return type:

numpy array


simpthon.body.omega(b)[source]

angular frequency of body b

\[\Omega = \frac{v_{\mathrm{tangential}}}{r}\]
Parameters:

b (class Body) – body.

Returns:

angular frequency of a body.

Return type:

float


simpthon.integrator

class simpthon.integrator.integrator[source]

integrator for solving dynamical sistem:

\[\frac{dv}{dt} = a(x)\]
\[\frac{dx}{dt} = v (t)\]
abstract integrate(v, ti, tf, dt, pot)[source]

return time, position, and velocity from ti to tf.

abstract step(v, dt)[source]

return position and velocity after 1 step


class simpthon.integrator.leapfrog(pot)[source]

Bases: integrator

a Kick-Drift-Kick version of leapfrog integrator


class simpthon.integrator.Euler(pot)[source]

Bases: integrator

Euler Method \(w(t+dt) = w(t) + dt f(w(t))\)

for \(w(t) = (x(t),v(t))\).


class simpthon.integrator.RungeKutta4(pot)[source]

Bases: integrator

a Runge-Kutta 4th Order integrator


class simpthon.integrator.Forward4OSymplectic(pot)[source]

Bases: integrator

a Forward 4th Order Symplectic Integrator (Chin & Chen, 2005)


simpthon.potential

class simpthon.potential.potential[source]
abstract acc()[source]

return vector acceleration \(a\) at given position \(x\).

abstract mass()[source]

return scalar mass \(m\) inside radius \(r\).

abstract pot()[source]

return scalar potential \(\Phi\) at given position \(x\).

abstract tid()[source]

return tensor tidal force \(T\) at given position \(x\).



class simpthon.potential.potentials(pots=[])[source]

Bases: potential

list of potential:

\[\Phi (x) = \Sigma_i \Phi_i (x).\]

class simpthon.potential.osilator(k, m)[source]

Bases: potential

Harmonik oscilator potential:

\[\Phi (x) = \frac{1}{2} k x^2.\]

class simpthon.potential.pointmass(GM)[source]

Bases: potential

Point mass potential:

\[\Phi (x) = -\frac{GM}{r}.\]

class simpthon.potential.plummer(GM, b)[source]

Bases: potential

Plummer potential :

\[\Phi (x) = -\frac{GM}{\sqrt{r^2 + b^2}},\]

with \(b\) scale factor.


class simpthon.potential.jaffe(GM, b)[source]

Bases: potential

Jaffe potential:

\[\Phi (x) = -\frac{GM}{b} \frac{\ln (1+r/b)}{(r/b)^2},\]

with \(b\) scale factor.


class simpthon.potential.cluster_potential(pot, X=array([0, 0, 0]))[source]

Bases: potential


simpthon.hplot

simpthon.hplot.plot(x, y, label=['x', 'f(x)'], label_fontsize=20, style='-', xlim=[0, 0], ylim=[0, 0], hide_tick=True, hide_tick_label=True, save_fig=' ', dpi=150, plot_xaxis=False, plot_yaxis=False, remove_axis=False, legend_label=' ', legend_loc=-1, tight_layout=True, y2=' ', style2='r-.', legend_label2=' ', y3=' ', style3='g--', legend_label3=' ', texts=[[0, 0, ' ']])[source]

plot given data x,y up to 3 graphs

Parameters:
  • x (array_like) – data x-axis

  • y (array_like) – data y-axis

  • label (list, optional) – label of axes, e.g. [‘x’,f(x)’].

  • style (str, optional) – style of plot, similar to matplotlib.pyplot.plot style.

  • xlim (list, optional) – limit of x-axis, list of lower and upper limits

  • ylim (list) – limit of y axis, list of lower and upper limits

  • hide_tick (bool, optional) – do you want to hide tick?

  • hide_tick_label (bool, optional) – do you want to hide tick label

  • save_fig (str, optional) – filename for saving figure

  • dpi (int, optional) – number of dots per inch

  • plot_xaxis (bool, optional) – do you want to plot x-axis (y=0)?

  • plot_yaxis (bool, optional) – plot y-axis (x=0)?

  • remove_axis (bool, optional) – remove_axis?

  • legend_label (str, optional) – label for legend

  • legend_loc (int, optional) – location of legend

  • tight_layout (bool, optional) – do you want to tight layout

  • y2 (array_like, optional) – second data y

  • style2 (str, optional) – style of 2nd data y

  • legend_label2 (str, optional) – label for legend 2nd function.

  • y3 (array_like, optional) – third data y.

  • style3 (str, optional) – style of 3rd data y.

  • legend_label3 (str, optional) – label for legend 3rd data y.

  • texts (list, optional) – list of [x pos text,y pos text,text].

Returns:

figure – show figure and save it if save_fig given.

Return type:

matplotlib_object



simpthon.hplot.plotf(func, label=['x', 'f(x)'], label_fontsize=20, style='-', xlim=[0, 0], ylim=[0, 0], points=100, hide_tick=True, hide_tick_label=True, save_fig=' ', dpi=150, plot_xaxis=False, plot_yaxis=False, remove_axis=False, legend_label=' ', legend_loc=-1, tight_layout=True, func2=' ', style2='r-.', legend_label2=' ', func3=' ', style3='g--', legend_label3=' ', texts=[[0, 0, ' ']])[source]

plot given function

Parameters:
  • func (function) – function

  • label (list, optional) – label of axes, e.g. [‘x’,f(x)’].

  • style (str, optional) – style of plot, similar to matplotlib.pyplot.plot style.

  • xlim (list, optional) – limit of x-axis, list of lower and upper limits

  • ylim (list) – limit of y axis, list of lower and upper limits

  • points (int) – number of datum.

  • hide_tick (bool, optional) – do you want to hide tick?

  • hide_tick_label (bool, optional) – do you want to hide tick label

  • save_fig (str, optional) – filename for saving figure

  • dpi (int, optional) – number of dots per inch

  • plot_xaxis (bool, optional) – do you want to plot x-axis (y=0)?

  • plot_yaxis (bool, optional) – plot y-axis (x=0)?

  • remove_axis (bool, optional) – remove_axis?

  • legend_label (str, optional) – label for legend

  • legend_loc (int, optional) – location of legend

  • tight_layout (bool, optional) – do you want to tight layout

  • func2 (function, optional) – second function

  • style2 (str, optional) – style of 2nd function

  • legend_label2 (str, optional) – label for legend 2nd function.

  • func3 (function, optional) – third function y.

  • style3 (str, optional) – style of 3rd function.

  • legend_label3 (str, optional) – label for legend 3rd function.

  • texts (list, optional) – list of [x pos text,y pos text,text].

Returns:

figure – show figure and save it if save_fig given.

Return type:

matplotlib_object