# example_pkg.schemes

*module*

Time steps for a particle in a force field: kick, drift and their leapfrog.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L1-L1)

## example_pkg.schemes.Drift

*class*

```python
class Drift(Scheme)
```

Bases: `example_pkg.schemes.Scheme`

Move the position at the current velocity.

**Numerics**

*update*

$$
x^{n+1} = x^n + v^n\,\Delta t
$$

Assumptions:

- velocity constant over the step

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L29-L37)

### example_pkg.schemes.Drift.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance the position only.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L35-L37)

## example_pkg.schemes.Kick

*class*

```python
class Kick(Scheme)
```

Bases: `example_pkg.schemes.Scheme`

Change the velocity by the acceleration at the current position.

**Numerics**

*update*

$$
v^{n+1} = v^n + a(x^n)\,\Delta t
$$

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L19-L26)

### example_pkg.schemes.Kick.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance the velocity only.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L24-L26)

## example_pkg.schemes.Leapfrog

*class*

```python
class Leapfrog(Scheme)
```

Bases: `example_pkg.schemes.Scheme`

Half a kick, a drift and half a kick: the velocity Verlet scheme.

**Numerics**

*half kick*

$$
v^{n+1/2} = v^n + \tfrac{1}{2} a(x^n)\,\Delta t
$$

*drift*

$$
x^{n+1} = x^n + v^{n+1/2}\,\Delta t
$$

*kick*

$$
v^{n+1} = v^{n+1/2} + \tfrac{1}{2} a(x^{n+1})\,\Delta t
$$

*energy*

$$
\left|H(x^n, v^n) - H(x^0, v^0)\right| = \mathcal{O}(\Delta t^2) \quad \text{for all } n
$$

Order of accuracy: x: 2, v: 2.

Assumptions:

- the acceleration depends on the position only

References:

- Hairer, Lubich and Wanner, Geometric Numerical Integration (2006), section I.1.4

Built from:

- `example_pkg.schemes.Kick`
- `example_pkg.schemes.Drift`

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L40-L66)

### example_pkg.schemes.Leapfrog.run

*method*

```python
def run(x, v, dt: float, steps: int, acceleration: Callable) -> np.ndarray
```

Take ``steps`` steps and return the positions, ``(steps + 1,)``.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L60-L66)

### example_pkg.schemes.Leapfrog.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance ``(x, v)`` by one leapfrog step.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L54-L58)

## example_pkg.schemes.Scheme

*class*

```python
class Scheme(NumericalMethod)
```

Bases: `NumericalMethod`

A one-step scheme for ``x'' = a(x)``.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L11-L16)

### example_pkg.schemes.Scheme.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance ``(x, v)`` by ``dt``.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/schemes.py#L14-L16)
