A Generic Particle+Grid Interface
Project description
GPGI
A Generic Particle + Grid data Interface
This small Python library implements fundamental grid deposition algorithms to analyse (rectilinear) grid + particle datasets, with an emphasize on performance. Core algorithms are implemented as Cython extensions.
Installation
pip install gpgi
Usage
The API consists in a load
function, which returns a Dataset
object.
Data can be 1D, 2D, or 3D and is validated at load time for consistency,
in particular with the chosen geometry (e.g. cartesian, polar, cylindrical, spherical).
Load data
import numpy as np
import gpgi
nx = ny = 64
nparticles = 600_000
prng = np.random.RandomState(0)
ds = gpgi.load(
geometry="cartesian",
grid={
"cell_edges": {
"x": np.linspace(-1, 1, nx),
"y": np.linspace(-1, 1, ny),
},
},
particles={
"coordinates": {
"x": 2 * (prng.normal(0.5, 0.25, nparticles) % 1 - 0.5),
"y": 2 * (prng.normal(0.5, 0.25, nparticles) % 1 - 0.5),
},
"fields": {
"mass": np.ones(nparticles),
},
},
)
The Dataset
object holds a grid
and a particle
attribute,
which both hold a fields
attribute for accessing their data.
But more importantly, the Dataset
has a deposit
method to
translate particle fields to the grid formalism.
Deposit Particle fields on the grid
particle_mass = ds.deposit("mass", method="particle_in_cell") # or "pic" for shorts
Visualize
In this example we'll use matplotlib
for rendering, but note that matplotlib
is not a dependency to gpgi
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set(aspect=1, xlabel="x", ylabel="y")
im = ax.pcolormesh(
"x",
"y",
particle_mass.T,
data=ds.grid.cell_edges,
cmap="viridis",
)
fig.colorbar(im, ax=ax)
The example script given here takes about a second (top to bottom).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file gpgi-0.1.0.tar.gz
.
File metadata
- Download URL: gpgi-0.1.0.tar.gz
- Upload date:
- Size: 268.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c790e8c56d2a6d0be10b7a993251a24711eada678a0dba665e5ae25e7af5dd0e |
|
MD5 | c5be4e555481fabb4c5a5034f382b884 |
|
BLAKE2b-256 | db76425b86b67f017da5219ec650b866fe7d1fd2c96e044a11f46bd7c646808d |