An open API service indexing awesome lists of open source software.

https://github.com/cchandre/gc2d

Guiding-center dynamics in plasma physics
https://github.com/cchandre/gc2d

hamiltonian numpy plasma-physics pyhamsys scipy symplectic-integrator

Last synced: 29 days ago
JSON representation

Guiding-center dynamics in plasma physics

Awesome Lists containing this project

README

          

# Guiding-center dynamics in plasma physics

___
## Simplified two-dimensional guiding-center dynamics

- [`gc2ds_classes.py`](https://github.com/cchandre/GC2D/blob/main/gc2ds_classes.py): contains the GC classes and main functions defining the GC dynamics

- [`run_gc2ds.py`](https://github.com/cchandre/GC2D/blob/main/run_gc2ds.py): example of a run file to reproduce the computations done in [[Mauger, Chandre (2026)]()]

Once [`run_gc2ds.py`](https://github.com/cchandre/GC2D/blob/main/run_gc2ds.py) has been edited with the relevant parameters, run the file as
```sh
python3 run_gc2ds.py
```
or in batch mode
```sh
nohup python3 -u run_gc2ds.py &>gc2d.out < /dev/null &
```
The list of Python packages and their version are specified in [`requirements.txt`](https://github.com/cchandre/GC2D/blob/main/requirements.txt)

### Main parameters of the class GC2Ds

- *A*: Amplitude of the electrostatic potential
- *M*: Number of modes in the electrostatic potential
- *seed*: Seed for the random phases $\phi_{nm}$ of the electrostatic potential (optional; default=27)

$$ V(x,y,t) =\sum_{n, m=1}^M \frac{A}{(n^2+m^2)^{3/2}} {\rm e}^{i(n x+my +\phi_{nm} -t) } $$

#### Example
```python
params = {"A": 1.0, "M": 16, "seed": 42}
gc = GC2Ds(params)
```

### Key methods

Since GC2Ds is s subclass of HamSys (from the python package [`pyhamsys`](https://pypi.org/project/pyhamsys/)), it inherits all its methods, including:

- `integrate`: Integrate numerically the trajectories of the system defined by the element of the class GC2Ds from the initial conditions defined by the function `initial_conditions`.

- `compute_lyapunov`: Compute the Lyapunov spectrum.

- `save_data`: Save simulation results to a `.mat` file with metadata.

In addition, GC2Ds has the following key methods:

- `initial_conditions`: Generate starting (*x*, *y*) positions—random or on a regular grid.

- `y_dot`: Time derivative of positions for integration.

- `k_dot`: Scalar diagnostic of the potential field.

- `potential`: Potential value at time t and position *z*=(*x*, *y*), and its first and second derivatives, obtained by specifying (*dx*, *dy*).

- `hamiltonian`: Total Hamiltonian (sum of the potentials for each trajectory).

- `y_dot_lyap`: Extended system (equations of motion and tangent flow) for Lyapunov-exponent calculations.

- `plot_sol`: 2-D plot of a solution obtained by the function `integrate` (for Poincaré sections).

#### `initial_conditions`

Generate initial 2-D coordinates for trajectories on a periodic domain.

#### Parameters

- **n_traj**: Number of points. For `"fixed"`, rounded to a perfect square for a square grid.
- **x**, **y**: (min, max) ranges; default `(0, 2π)`.
- **kind**: `"random"` for uniform random samples, `"fixed"` for a regular grid.
- **seed**: Random seed when `type="random"`.

#### Returns

1-D `xp.ndarray` of length `2*n_traj`: all x's followed by all y's.

#### Example

``` python
z0 = gc.initial_conditions(50, type="random", seed=123)
z0 = gc.initial_conditions(100, x=(0, np.pi), y=(0, np.pi), type="fixed")
```

### Reference

F. Mauger, C. Chandre, *Extended phase-space symplectic integration for electron dynamics*, [Physical Review E 113, 045301 (2026)](https://doi.org/10.1103/7ghc-htf8)

```bibtex
@article{GC2Ds,
title = {Extended phase-space symplectic integration for electron dynamics},
author = {François Mauger and Cristel Chandre},
journal = {Physical Review E},
volume = {113},
pages = {045301},
year = {2026},
doi = {10.1103/7ghc-htf8},
}
```
---
For more information: