simulation_api.simulation

Package contents

Submodules

simulation_api.simulation.demo_run_simulation

Test for simulations defined in simulation module

simulation_api.simulation.simulations

This module simulates mechanical systems

class simulation_api.simulation.simulations.ChenLeeAttractor(t_span: Optional[Tuple[float, float]] = [0, 400], t_eval: Optional[tuple] = None, ini_cndtn: List[float] = [10.0, 10.0, 0.0], params: dict = {'a': 3.0, 'b': - 5.0, 'c': - 1.0}, method: str = 'RK45', user_name: Optional[str] = None)[source]

Bases: simulation_api.simulation.simulations.Simulation

Simulates Chen-Lee Attractor.

a

\(\omega_x\) parameter.

Type

float

b

\(\omega_y\) parameter.

Type

float

c

\(\omega_z\) parameter.

Type

float

Notes

The Chen-Lee Attractor is a dynamical system defined by:1

\[ \begin{align}\begin{aligned}\frac{d\omega_x}{dt} &= - \omega_y \omega_z + a \, \omega_x\\\frac{d\omega_y}{dt} &= \omega_z \omega_x + b \, \omega_y\\\frac{d\omega_z}{dt} &= \frac{1}{3} \omega_x \omega_y + c \, \omega_z\end{aligned}\end{align} \]

Its origin is closely related to the motion of a rigid body in a rotating frame of reference.

References

1

https://doi.org/10.1142/S0218127403006509

__init__(t_span: Optional[Tuple[float, float]] = [0, 400], t_eval: Optional[tuple] = None, ini_cndtn: List[float] = [10.0, 10.0, 0.0], params: dict = {'a': 3.0, 'b': - 5.0, 'c': - 1.0}, method: str = 'RK45', user_name: Optional[str] = None)None[source]

Extends Simulation.__init__()

Adds attributes ChenLeeAttractor.a, ChenLeeAttractor.b and ChenLeeAttractor.c.

Parameters
  • ini_cndtn (array_like, shape (3,)) – Initial condition of 1D Harmonic Oscillator. Convention: \(\texttt{ini_cndtn} = [\omega_{x0}, \omega_{y0}, \omega_{z0}]\). Default is [10, 10, 0]. A list of initial conditions can be used, in this case a list of solutions will be returned by Simulation.simulate()

  • params (dict, optional) –

    Contains all the parameters of the simulation. Schema must match:

    {
        "a": float,     # `\omega_x` parameter.
        "b": float,     # `\omega_x` parameter.
        "c": float,     # `\omega_z` parameter.
    }
    

    Default is {"a": 3.0, "b": - 5.0, "c": - 1.0}.

dyn_sys_eqns(t: float, w: List[float])List[float][source]

Chen-Lee Dynamical system definition

Note

Overwrites Simulation.dyn_sys_eqns.

Parameters
  • w (array_like, shape (3,)) – Vector of angular velocity. Convention: \(\texttt{w} = [\omega_x, \omega_y, \omega_z]\).

  • t (float) – Time.

Returns

dwdt – Dynamical system equations of Chen Lee attractor evaluated at w.

Return type

array_like, shape (3,)

system = 'Chen-Lee-Attractor'

Name of system.

class simulation_api.simulation.simulations.HarmonicOsc1D(t_span: Optional[Tuple[float, float]] = [0, 6.283185307179586], t_eval: Optional[tuple] = None, ini_cndtn: List[float] = [0.0, 1.0], params: dict = {'k': 1.0, 'm': 1.0}, method: str = 'RK45', user_name: Optional[str] = None)[source]

Bases: simulation_api.simulation.simulations.Simulation

1-D Harmonic Oscillator simulation

m

Mass of object.

Type

float

k

Force constant of harmonic oscilltor.

Type

float

Notes

The hamiltonian describing the Harmonic Oscillator is defined dy

\[H = \frac{1}{2m}p^2 + \frac{1}{2}k q^2\]
__init__(t_span: Optional[Tuple[float, float]] = [0, 6.283185307179586], t_eval: Optional[tuple] = None, ini_cndtn: List[float] = [0.0, 1.0], params: dict = {'k': 1.0, 'm': 1.0}, method: str = 'RK45', user_name: Optional[str] = None)None[source]

Extends Simulation.__init__()

Adds attributes HarmonicOsc1D.m and HarmonicOsc1D.k.

Parameters
  • ini_cndtn (array_like, shape (2,)) – Initial condition of 1D Harmonic Oscillator. Convention: \(\texttt{ini_cndtn} = [q_0, p_0]\) where \(q_0\) is the initial generalised position and \(p_0\) is the initial generalised momentum. Default is [0., 1.]. A list of initial conditions can be used, in this case a list of solutions will be returned by Simulation.simulate().

  • params (dict, optional) –

    Contains all the parameters of the simulation. Schema must match:

    {
        "m": float,     # Mass of object.
        "k": float,     # Force constant of harmonic oscilltor.
    }
    

    Default is {"m": 1., "k": 1.}.

dyn_sys_eqns(t: float, y: List[float])List[float][source]

Hamilton’s equations for 1D-Harmonic Oscillator.

Note

Overwrites Simulation.dyn_sys_eqns.

Parameters
  • t (float) – Time of evaluation of Hamilton’s equations.

  • y (array_like, shape (2,)) – Canonical coordinates. Convention: \(\texttt{y} = [q, p]\) where \(q\) is the generalised position and \(p\) is the generalised momentum.

Returns

dydt – Hamilton’s equations for 1D Harmonic Oscillator. \(\texttt{dydt} = \left[ \frac{dq}{dt}, \frac{dp}{dt} \right] = \left[ \frac{\partial H}{\partial p}, - \frac{\partial H}{\partial q} \right]\)

Return type

array_like, shape (2,)

system = 'Harmonic-Oscillator'

Name of system.

class simulation_api.simulation.simulations.Simulation(t_span: Optional[List[float]] = None, t_eval: Optional[list] = None, ini_cndtn: Optional[list] = None, params: Optional[dict] = None, method: Optional[str] = 'RK45', user_name: Optional[str] = None)[source]

Bases: object

Simulation of a continuous dynamical system described by first order coupled differential equations.

t_span

Interval of integration (t0, tf).

Type

List[float, float] or None

t_eval

Times at which to store the computed solution, must be sorted and lie within t_span.

Type

array_like or None

ini_cndtn

Initial condition of simulation, its specification depends on the system being simulated.

Type

array_like or None

params

Contains all the parameters of the simulation (e.g. for the harmonic oscillator self.params = {"m": 1., "k": 1.})

Type

dict or None

method

Method of integration.

Type

str, optional

user_name

Username that instantiated the simulation.

Type

str or None

date

UTC date and time of instantiation of object.

Type

datetime (str)

results

Results of simulation.

Type

scipy.integrate._ivp.ivp.OdeResult or None

__init__(t_span: Optional[List[float]] = None, t_eval: Optional[list] = None, ini_cndtn: Optional[list] = None, params: Optional[dict] = None, method: Optional[str] = 'RK45', user_name: Optional[str] = None)None[source]

Initializes all self attributes except self.system

dyn_sys_eqns(t: float, y: List[float])List[float][source]

Trivial 2D dynamical system. Just for reference.

Note

The actual simulations that inherit this class will replace this method with the relevant dynamical equations.

simulate()scipy.integrate._ivp.ivp.OdeResult[source]

Simulates self.system abstracted in self.dyn_sys_eqns and using scipy.integrate.solve_ivp.

Returns

self.results

Bunch object with the following fields defined:

tndarray, shape (n_points,)

Time points.

yndarray, shape (n, n_points)

Values of the solution at t.

solOdeSolution or None

Found solution as OdeSolution instance; None if dense_output was set to False.

t_eventslist of ndarray or None

Contains for each event type a list of arrays at which an event of that type event was detected. None if events was None.

y_eventslist of ndarray or None

For each value of t_events, the corresponding value of the solution. None if events was None.

nfevint

Number of evaluations of the right-hand side.

njevint

Number of evaluations of the Jacobian.

nluint

Number of LU decompositions.

statusint

Reason for algorithm termination: -1, Integration step failed; 0, The solver successfully reached the end of tspan; 1, A termination event occurred.

messagestring

Human-readable description of the termination reason.

successbool

True if the solver reached the interval end or a termination event occurred (status >= 0).

Return type

OdeResult

system = None

Name of system.

simulation_api.simulation.simulations.Simulations = {'Chen-Lee-Attractor': <class 'simulation_api.simulation.simulations.ChenLeeAttractor'>, 'Harmonic-Oscillator': <class 'simulation_api.simulation.simulations.HarmonicOsc1D'>}

Maps the names of the available systems to their corresponding classes.

Warning

Must be updated each time a new simulation is added (add the new relevant item to the dictionary).