A Particle-in-Cell framework with dynamic behavior modification through callbacks
Project description
Introduction
Features
- Callback-centric simulation loop
- Diagnostics & outputs
- Modifying simulation at runtime
- Patch-based domain decomposition
- Load balancing via METIS
- Fast particle deletion with
is_deadflag - Providing particle-in-cell library via
lambdapic.core- High-level via Python
- Low-level kernels in C/Numba
- Common functionalities
- MPI + OpenMP
- PML boundary
- Photon emission & pair production
- Collision
- Nuclear physics
- GPU acceleration
Installation
-
install prebuilt packages from conda like mpi4py, h5py (which are not easy to build).
conda create -n lambdapic mpi4py h5py numpy scipy conda activate lambdapic
-
install lambdapic via pip
pip install lambdapic
or from source
git clone https://github.com/xsgeng/lambdapic.git cd lambdapic pip install .
building from source requires GCC >= 9.3 (from numpy)
Callback System
Simulation loop stages:
start: Beginning of each timestepmaxwell first: First half of Maxwell solverpush position first: First particle position updateinterpolator: Field interpolationpush momentum: Particle momentum updatepush position second: Second particle position updatecurrent deposition: Current depositionmaxwell second: Second half of Maxwell solver
Each callback can be attached to any of these stages using the @callback decorator.
# laser injector is pre-defined callback
laser = SimpleLaser(
a0=10,
w0=5e-6,
ctau=5e-6
)
# Custom callbacks
@callback()
def energy_sum(sim):
if sim.itime % 100 != 0:
return
total_energy = 0
for patch in sim.patches:
# Calculate electromagnetic energy
ex = patch.fields.ex
ey = patch.fields.ey
bz = patch.fields.bz
energy = 0.5 * (ex**2 + ey**2 + bz**2).sum()
total_energy += energy
print(f"Total EM energy: {total_energy}")
@callback(stage="maxwell first")
def mod_ex(sim):
# Modify fields during the Maxwell solver stage
for patch in sim.patches:
patch.fields.ex *= 1.1 # Amplify Ex field by 10%
# Run simulation with callback
sim.run(
nsteps=1000,
callbacks=[
laser,
energy_sum,
mod_ex,
callback(stage="start")(lambda sim: print(f"timestep @ {sim.itime} starts")),
lambda sim: print(f"timestep @ {sim.itime} ends")
]
)
Core Classes
classDiagram
Patches --> Patch : contains
Patch --> ParticlesBase : contains
Patch --> Fields : contains
Patch --> PML : contains
Patch <|-- Patch2D~Patch~
Patch <|-- Patch3D~Patch~
RadiationBase --> Patches : contains
PairProductionBase --> Patches : contains
CurrentDeposition --> Patches : contains
PusherBase --> Patches : contains
FieldInterpolation --> Patches : contains
MaxwellSolver --> Patches : contains
MPIManager --> Patches : contains
Pydantic.BaseModel <|-- Species
Species <|-- XXX~Species~
Species <|-- Electron~Species~
Species --> ParticlesBase : creates
class Patch {
index: int
*_neighbor_index: int
}
class Patches {
sync_particles()
sync_guard_fields()
sync_currents()
}
class ParticlesBase {
x,y,z ...: NDArray[float]
is_dead: NDArray[bool]
}
class Fields {
ex, ey, ...: NDArray[float]
}
class Species {
name, q, m, ...
density: Callable
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Status
λPIC is currently in active development. The API may change without notice.
License
This project is licensed under the GPL-3.0 License.
Acknowledgments
This work was supported by the National Natural Science Foundation of China (NSFC) under Grant No. 12304384.
This project was inspired by and adapted elements from the EPOCH and the Smilei projects.
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 lambdapic-0.5.5.tar.gz.
File metadata
- Download URL: lambdapic-0.5.5.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d03b912fa12be21a6a91ddfde39e854c51576d76ddd1eda1b6072dd5010397d
|
|
| MD5 |
7ffd6a28214c9924ae3a1890a90519c2
|
|
| BLAKE2b-256 |
dec1f7f8131c0e56d0902927e96a69a9aa3bc8f48a45cd8f2712b694630f26eb
|
Provenance
The following attestation bundles were made for lambdapic-0.5.5.tar.gz:
Publisher:
python-publish.yml on xsgeng/lambdapic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lambdapic-0.5.5.tar.gz -
Subject digest:
7d03b912fa12be21a6a91ddfde39e854c51576d76ddd1eda1b6072dd5010397d - Sigstore transparency entry: 248353838
- Sigstore integration time:
-
Permalink:
xsgeng/lambdapic@8ca45e790c6f288cc2757d863057fe344c2ff1db -
Branch / Tag:
refs/tags/v0.5.5 - Owner: https://github.com/xsgeng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8ca45e790c6f288cc2757d863057fe344c2ff1db -
Trigger Event:
release
-
Statement type: