plasmacoll 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plasmacoll-0.1.0/LICENSE.txt +21 -0
- plasmacoll-0.1.0/PKG-INFO +193 -0
- plasmacoll-0.1.0/README.md +133 -0
- plasmacoll-0.1.0/pyproject.toml +100 -0
- plasmacoll-0.1.0/setup.cfg +4 -0
- plasmacoll-0.1.0/src/plasmacoll/__init__.py +70 -0
- plasmacoll-0.1.0/src/plasmacoll/_types.py +11 -0
- plasmacoll-0.1.0/src/plasmacoll/background.py +114 -0
- plasmacoll-0.1.0/src/plasmacoll/constants.py +28 -0
- plasmacoll-0.1.0/src/plasmacoll/cross_sections.py +431 -0
- plasmacoll-0.1.0/src/plasmacoll/hydrogen.py +145 -0
- plasmacoll-0.1.0/src/plasmacoll/markers.py +168 -0
- plasmacoll-0.1.0/src/plasmacoll/mcc.py +643 -0
- plasmacoll-0.1.0/src/plasmacoll/process.py +118 -0
- plasmacoll-0.1.0/src/plasmacoll/py.typed +0 -0
- plasmacoll-0.1.0/src/plasmacoll/reactor.py +203 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/__init__.py +0 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/__init__.py +0 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/_helpers.py +62 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_background_and_process.py +109 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_constants.py +14 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_cross_sections.py +216 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_hydrogen.py +75 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_markers.py +84 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_mcc.py +723 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_reactor.py +168 -0
- plasmacoll-0.1.0/src/plasmacoll/tests/unit/test_vibrational.py +294 -0
- plasmacoll-0.1.0/src/plasmacoll/vibrational.py +195 -0
- plasmacoll-0.1.0/src/plasmacoll.egg-info/PKG-INFO +193 -0
- plasmacoll-0.1.0/src/plasmacoll.egg-info/SOURCES.txt +31 -0
- plasmacoll-0.1.0/src/plasmacoll.egg-info/dependency_links.txt +1 -0
- plasmacoll-0.1.0/src/plasmacoll.egg-info/requires.txt +22 -0
- plasmacoll-0.1.0/src/plasmacoll.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Max Lindqvist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plasmacoll
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Null-collision Monte Carlo collisions of charged particles with neutral gases, on NumPy or CuPy arrays.
|
|
5
|
+
Author: Max
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Max Lindqvist
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Source, https://github.com/max-models/plasmacoll
|
|
29
|
+
Keywords: cross sections,cupy,lxcat,monte carlo collisions,negative ions,null collision,particle-in-cell,plasma
|
|
30
|
+
Classifier: Development Status :: 3 - Alpha
|
|
31
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
36
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE.txt
|
|
40
|
+
Requires-Dist: cunumpy>=0.5
|
|
41
|
+
Requires-Dist: numpy
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: jupyterlab; extra == "dev"
|
|
44
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
45
|
+
Requires-Dist: pyproject-fmt; extra == "dev"
|
|
46
|
+
Requires-Dist: pyright; extra == "dev"
|
|
47
|
+
Requires-Dist: ruff; extra == "dev"
|
|
48
|
+
Requires-Dist: ty; extra == "dev"
|
|
49
|
+
Requires-Dist: plasmacoll[docs,test]; extra == "dev"
|
|
50
|
+
Provides-Extra: docs
|
|
51
|
+
Requires-Dist: griffe; extra == "docs"
|
|
52
|
+
Requires-Dist: ipykernel; extra == "docs"
|
|
53
|
+
Requires-Dist: matplotlib; extra == "docs"
|
|
54
|
+
Requires-Dist: nbclient>=0.11.0; extra == "docs"
|
|
55
|
+
Requires-Dist: nbformat>=5.11.1; extra == "docs"
|
|
56
|
+
Provides-Extra: test
|
|
57
|
+
Requires-Dist: pytest; extra == "test"
|
|
58
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
59
|
+
Dynamic: license-file
|
|
60
|
+
|
|
61
|
+
# plasmacoll
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
<!-- README.md is generated from README.qmd: edit the .qmd and run `make readme`. -->
|
|
65
|
+
|
|
66
|
+
[](https://github.com/max-models/plasmacoll/actions/workflows/test_pytest.yml)
|
|
67
|
+
[](https://github.com/max-models/plasmacoll/actions/workflows/static_analysis.yml)
|
|
69
|
+
[](https://max-models.github.io/plasmacoll/)
|
|
70
|
+
[](https://codecov.io/gh/max-models/plasmacoll)
|
|
71
|
+
[](https://pypi.org/project/plasmacoll/)
|
|
72
|
+
[](https://pypi.org/project/plasmacoll/)
|
|
73
|
+
|
|
74
|
+
Null-collision Monte Carlo collisions (MCC) of charged particles with
|
|
75
|
+
neutral gases, on NumPy or CuPy arrays. It is the collision step of a
|
|
76
|
+
particle-in-cell code, or with `ZeroDReactor` a homogeneous reactor for
|
|
77
|
+
testing cross-section sets.
|
|
78
|
+
|
|
79
|
+
- **Processes:** elastic, backscatter (resonant charge exchange),
|
|
80
|
+
excitation, ionization, attachment, detachment and charge transfer,
|
|
81
|
+
against Maxwellian neutral gases that are uniform or have a density
|
|
82
|
+
profile.
|
|
83
|
+
- **Cross sections:** from text tables, LXCat files or functions. Also
|
|
84
|
+
Maxwell molecules for benchmarks, and population-weighted mixtures of
|
|
85
|
+
level-resolved tables, e.g. H₂(v) dissociative attachment.
|
|
86
|
+
- **Plain arrays:** markers are positions, velocities and weights. Any
|
|
87
|
+
particle container with those plugs in, and
|
|
88
|
+
[cunumpy](https://pypi.org/project/cunumpy/) runs the same code on CPU
|
|
89
|
+
(NumPy) or GPU (CuPy).
|
|
90
|
+
- **Validated:** a 0D reactor reproduces the closed-form relaxation,
|
|
91
|
+
growth and decay rates of Maxwell-molecule gases. The tests run on
|
|
92
|
+
NumPy and on a CuPy stand-in, with 100 % combined coverage.
|
|
93
|
+
|
|
94
|
+
Documentation: <https://max-models.github.io/plasmacoll/>
|
|
95
|
+
|
|
96
|
+

|
|
99
|
+
|
|
100
|
+
## Install
|
|
101
|
+
|
|
102
|
+
``` bash
|
|
103
|
+
pip install plasmacoll
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Example
|
|
107
|
+
|
|
108
|
+
``` python
|
|
109
|
+
import plasmacoll
|
|
110
|
+
from plasmacoll.constants import ATOMIC_MASS, ELECTRON_MASS, ev_to_kelvin
|
|
111
|
+
|
|
112
|
+
argon_mass = 39.95 * ATOMIC_MASS
|
|
113
|
+
argon_gas = plasmacoll.NeutralBackground(
|
|
114
|
+
"Ar", density=1e21, temperature=300.0, mass=argon_mass
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
elastic_xs = plasmacoll.CrossSection.constant(1e-19)
|
|
118
|
+
ionization_xs = plasmacoll.CrossSection.constant(3e-20, threshold=15.76)
|
|
119
|
+
elastic = plasmacoll.CollisionProcess("elastic", "Ar", elastic_xs, energy_frame="lab")
|
|
120
|
+
ionization = plasmacoll.CollisionProcess(
|
|
121
|
+
"ionization",
|
|
122
|
+
"Ar",
|
|
123
|
+
ionization_xs,
|
|
124
|
+
energy_frame="lab",
|
|
125
|
+
products={"electron": "e", "ion": "Ar+"},
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
mcc = plasmacoll.MonteCarloCollisions(
|
|
129
|
+
species_masses={"e": ELECTRON_MASS, "Ar+": argon_mass},
|
|
130
|
+
backgrounds=[argon_gas],
|
|
131
|
+
processes={"e": [elastic, ionization]},
|
|
132
|
+
seed=1,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
temperature = ev_to_kelvin(10.0)
|
|
136
|
+
electrons = plasmacoll.ParticleArrays.maxwellian(
|
|
137
|
+
100_000, ELECTRON_MASS, temperature, seed=2
|
|
138
|
+
)
|
|
139
|
+
reactor = plasmacoll.ZeroDReactor(mcc, {"e": electrons}, volume=1e-6)
|
|
140
|
+
history = reactor.run(dt=1e-11, num_steps=500, every=10)
|
|
141
|
+
print(history.density["Ar+"][-1], history.collisions["ionization:Ar"][-1])
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
In a particle-in-cell code, call
|
|
145
|
+
`mcc.collide(species, positions, velocities, weights, dt)` on arrays, or
|
|
146
|
+
`mcc.collide_species({...}, dt)` on your own particle containers. See
|
|
147
|
+
[Use in a particle-in-cell
|
|
148
|
+
code](https://max-models.github.io/plasmacoll/guides/particle-in-cell/).
|
|
149
|
+
|
|
150
|
+
plasmacoll does not ship cross-section data. Load tables from
|
|
151
|
+
[LXCat](https://lxcat.net) or the literature with
|
|
152
|
+
`plasmacoll.read_lxcat` and `CrossSection.from_table`.
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
157
|
+
|
|
158
|
+
``` bash
|
|
159
|
+
make install # uv sync --extra dev, plus the pre-commit hooks
|
|
160
|
+
make test # pytest with coverage on NumPy
|
|
161
|
+
make test-cupy # the same tests on cunumpy's stand-in for CuPy (no GPU needed)
|
|
162
|
+
make coverage # both runs combined, must be 100 %
|
|
163
|
+
make lint # ruff check, ruff format --check, pyright, ty
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Commit messages follow [Conventional
|
|
167
|
+
Commits](https://www.conventionalcommits.org/).
|
|
168
|
+
|
|
169
|
+
## Build docs
|
|
170
|
+
|
|
171
|
+
The documentation in `docs/` is an [Astro](https://astro.build/) +
|
|
172
|
+
[Starlight](https://starlight.astro.build/) site: hand-written guides,
|
|
173
|
+
the notebooks in `tutorials/` executed and published as pages, and the
|
|
174
|
+
API reference generated from the docstrings. It needs Node 22 or newer.
|
|
175
|
+
|
|
176
|
+
``` bash
|
|
177
|
+
make docs-install # npm packages and the Python docs extra
|
|
178
|
+
make docs-notebooks # execute tutorials/*.ipynb and convert them to pages
|
|
179
|
+
make docs-dev # live preview at http://localhost:4321/plasmacoll/
|
|
180
|
+
make docs-build # the static site in docs/dist
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`README.md` is rendered from `README.qmd` with
|
|
184
|
+
[Quarto](https://quarto.org/): `make readme`.
|
|
185
|
+
|
|
186
|
+
## Releases
|
|
187
|
+
|
|
188
|
+
Before merging a release to `main`, update the version in
|
|
189
|
+
`pyproject.toml` and `src/plasmacoll/__init__.py`, and add the release
|
|
190
|
+
notes to `CHANGELOG.md`. The push to `main` creates a GitHub release
|
|
191
|
+
with a `vX.Y.Z` tag and publishes the package to PyPI with trusted
|
|
192
|
+
publishing (OIDC). See the [publishing
|
|
193
|
+
guide](https://max-models.github.io/plasmacoll/development/publishing/).
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# plasmacoll
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<!-- README.md is generated from README.qmd: edit the .qmd and run `make readme`. -->
|
|
5
|
+
|
|
6
|
+
[](https://github.com/max-models/plasmacoll/actions/workflows/test_pytest.yml)
|
|
7
|
+
[](https://github.com/max-models/plasmacoll/actions/workflows/static_analysis.yml)
|
|
9
|
+
[](https://max-models.github.io/plasmacoll/)
|
|
10
|
+
[](https://codecov.io/gh/max-models/plasmacoll)
|
|
11
|
+
[](https://pypi.org/project/plasmacoll/)
|
|
12
|
+
[](https://pypi.org/project/plasmacoll/)
|
|
13
|
+
|
|
14
|
+
Null-collision Monte Carlo collisions (MCC) of charged particles with
|
|
15
|
+
neutral gases, on NumPy or CuPy arrays. It is the collision step of a
|
|
16
|
+
particle-in-cell code, or with `ZeroDReactor` a homogeneous reactor for
|
|
17
|
+
testing cross-section sets.
|
|
18
|
+
|
|
19
|
+
- **Processes:** elastic, backscatter (resonant charge exchange),
|
|
20
|
+
excitation, ionization, attachment, detachment and charge transfer,
|
|
21
|
+
against Maxwellian neutral gases that are uniform or have a density
|
|
22
|
+
profile.
|
|
23
|
+
- **Cross sections:** from text tables, LXCat files or functions. Also
|
|
24
|
+
Maxwell molecules for benchmarks, and population-weighted mixtures of
|
|
25
|
+
level-resolved tables, e.g. H₂(v) dissociative attachment.
|
|
26
|
+
- **Plain arrays:** markers are positions, velocities and weights. Any
|
|
27
|
+
particle container with those plugs in, and
|
|
28
|
+
[cunumpy](https://pypi.org/project/cunumpy/) runs the same code on CPU
|
|
29
|
+
(NumPy) or GPU (CuPy).
|
|
30
|
+
- **Validated:** a 0D reactor reproduces the closed-form relaxation,
|
|
31
|
+
growth and decay rates of Maxwell-molecule gases. The tests run on
|
|
32
|
+
NumPy and on a CuPy stand-in, with 100 % combined coverage.
|
|
33
|
+
|
|
34
|
+
Documentation: <https://max-models.github.io/plasmacoll/>
|
|
35
|
+
|
|
36
|
+

|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
``` bash
|
|
43
|
+
pip install plasmacoll
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Example
|
|
47
|
+
|
|
48
|
+
``` python
|
|
49
|
+
import plasmacoll
|
|
50
|
+
from plasmacoll.constants import ATOMIC_MASS, ELECTRON_MASS, ev_to_kelvin
|
|
51
|
+
|
|
52
|
+
argon_mass = 39.95 * ATOMIC_MASS
|
|
53
|
+
argon_gas = plasmacoll.NeutralBackground(
|
|
54
|
+
"Ar", density=1e21, temperature=300.0, mass=argon_mass
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
elastic_xs = plasmacoll.CrossSection.constant(1e-19)
|
|
58
|
+
ionization_xs = plasmacoll.CrossSection.constant(3e-20, threshold=15.76)
|
|
59
|
+
elastic = plasmacoll.CollisionProcess("elastic", "Ar", elastic_xs, energy_frame="lab")
|
|
60
|
+
ionization = plasmacoll.CollisionProcess(
|
|
61
|
+
"ionization",
|
|
62
|
+
"Ar",
|
|
63
|
+
ionization_xs,
|
|
64
|
+
energy_frame="lab",
|
|
65
|
+
products={"electron": "e", "ion": "Ar+"},
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
mcc = plasmacoll.MonteCarloCollisions(
|
|
69
|
+
species_masses={"e": ELECTRON_MASS, "Ar+": argon_mass},
|
|
70
|
+
backgrounds=[argon_gas],
|
|
71
|
+
processes={"e": [elastic, ionization]},
|
|
72
|
+
seed=1,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
temperature = ev_to_kelvin(10.0)
|
|
76
|
+
electrons = plasmacoll.ParticleArrays.maxwellian(
|
|
77
|
+
100_000, ELECTRON_MASS, temperature, seed=2
|
|
78
|
+
)
|
|
79
|
+
reactor = plasmacoll.ZeroDReactor(mcc, {"e": electrons}, volume=1e-6)
|
|
80
|
+
history = reactor.run(dt=1e-11, num_steps=500, every=10)
|
|
81
|
+
print(history.density["Ar+"][-1], history.collisions["ionization:Ar"][-1])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
In a particle-in-cell code, call
|
|
85
|
+
`mcc.collide(species, positions, velocities, weights, dt)` on arrays, or
|
|
86
|
+
`mcc.collide_species({...}, dt)` on your own particle containers. See
|
|
87
|
+
[Use in a particle-in-cell
|
|
88
|
+
code](https://max-models.github.io/plasmacoll/guides/particle-in-cell/).
|
|
89
|
+
|
|
90
|
+
plasmacoll does not ship cross-section data. Load tables from
|
|
91
|
+
[LXCat](https://lxcat.net) or the literature with
|
|
92
|
+
`plasmacoll.read_lxcat` and `CrossSection.from_table`.
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
97
|
+
|
|
98
|
+
``` bash
|
|
99
|
+
make install # uv sync --extra dev, plus the pre-commit hooks
|
|
100
|
+
make test # pytest with coverage on NumPy
|
|
101
|
+
make test-cupy # the same tests on cunumpy's stand-in for CuPy (no GPU needed)
|
|
102
|
+
make coverage # both runs combined, must be 100 %
|
|
103
|
+
make lint # ruff check, ruff format --check, pyright, ty
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Commit messages follow [Conventional
|
|
107
|
+
Commits](https://www.conventionalcommits.org/).
|
|
108
|
+
|
|
109
|
+
## Build docs
|
|
110
|
+
|
|
111
|
+
The documentation in `docs/` is an [Astro](https://astro.build/) +
|
|
112
|
+
[Starlight](https://starlight.astro.build/) site: hand-written guides,
|
|
113
|
+
the notebooks in `tutorials/` executed and published as pages, and the
|
|
114
|
+
API reference generated from the docstrings. It needs Node 22 or newer.
|
|
115
|
+
|
|
116
|
+
``` bash
|
|
117
|
+
make docs-install # npm packages and the Python docs extra
|
|
118
|
+
make docs-notebooks # execute tutorials/*.ipynb and convert them to pages
|
|
119
|
+
make docs-dev # live preview at http://localhost:4321/plasmacoll/
|
|
120
|
+
make docs-build # the static site in docs/dist
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`README.md` is rendered from `README.qmd` with
|
|
124
|
+
[Quarto](https://quarto.org/): `make readme`.
|
|
125
|
+
|
|
126
|
+
## Releases
|
|
127
|
+
|
|
128
|
+
Before merging a release to `main`, update the version in
|
|
129
|
+
`pyproject.toml` and `src/plasmacoll/__init__.py`, and add the release
|
|
130
|
+
notes to `CHANGELOG.md`. The push to `main` creates a GitHub release
|
|
131
|
+
with a `vX.Y.Z` tag and publishes the package to PyPI with trusted
|
|
132
|
+
publishing (OIDC). See the [publishing
|
|
133
|
+
guide](https://max-models.github.io/plasmacoll/development/publishing/).
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
|
|
4
|
+
requires = [ "setuptools", "wheel" ]
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "plasmacoll"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
description = "Null-collision Monte Carlo collisions of charged particles with neutral gases, on NumPy or CuPy arrays."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
keywords = [ "cross sections", "cupy", "lxcat", "monte carlo collisions", "negative ions", "null collision", "particle-in-cell", "plasma" ]
|
|
12
|
+
license = { file = "LICENSE.txt" }
|
|
13
|
+
authors = [ { name = "Max" } ]
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"cunumpy>=0.5",
|
|
26
|
+
"numpy",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
optional-dependencies.dev = [
|
|
30
|
+
"jupyterlab",
|
|
31
|
+
"pre-commit",
|
|
32
|
+
"pyproject-fmt",
|
|
33
|
+
"pyright",
|
|
34
|
+
"ruff",
|
|
35
|
+
"ty",
|
|
36
|
+
"plasmacoll[test,docs]",
|
|
37
|
+
]
|
|
38
|
+
optional-dependencies.docs = [
|
|
39
|
+
"griffe",
|
|
40
|
+
"ipykernel",
|
|
41
|
+
"matplotlib",
|
|
42
|
+
"nbclient>=0.11.0",
|
|
43
|
+
"nbformat>=5.11.1",
|
|
44
|
+
]
|
|
45
|
+
optional-dependencies.test = [ "pytest", "pytest-cov" ]
|
|
46
|
+
urls."Source" = "https://github.com/max-models/plasmacoll"
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.packages.find]
|
|
49
|
+
where = [ "src" ]
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.package-data]
|
|
52
|
+
"*" = [ "py.typed" ]
|
|
53
|
+
|
|
54
|
+
[tool.ruff]
|
|
55
|
+
target-version = "py310"
|
|
56
|
+
line-length = 88
|
|
57
|
+
extend-include = [ "*.ipynb" ]
|
|
58
|
+
# scratch scripts kept for re-checking results; README.md is rendered from README.qmd, so
|
|
59
|
+
# `make readme-check` checks its example explicitly instead of letting `ruff format .` edit it
|
|
60
|
+
extend-exclude = [ ".claude", "README.md" ]
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
# pycodestyle, pyflakes, isort, pyupgrade, bugbear and pydocstyle
|
|
64
|
+
select = [ "B", "D", "E", "F", "I", "UP", "W" ]
|
|
65
|
+
ignore = [ "E501" ] # line length is handled by the formatter
|
|
66
|
+
pydocstyle.convention = "google"
|
|
67
|
+
per-file-ignores."**/tests/**" = [ "D" ]
|
|
68
|
+
per-file-ignores."*.ipynb" = [ "D" ]
|
|
69
|
+
per-file-ignores."docs/tools/*" = [ "D" ]
|
|
70
|
+
|
|
71
|
+
[tool.pyright]
|
|
72
|
+
include = [ "src" ]
|
|
73
|
+
venvPath = "."
|
|
74
|
+
venv = ".venv"
|
|
75
|
+
exclude = [ "**/tests" ]
|
|
76
|
+
pythonVersion = "3.10"
|
|
77
|
+
typeCheckingMode = "standard"
|
|
78
|
+
|
|
79
|
+
[tool.pytest.ini_options]
|
|
80
|
+
pythonpath = [ "src" ]
|
|
81
|
+
testpaths = [ "src" ]
|
|
82
|
+
addopts = "-ra"
|
|
83
|
+
|
|
84
|
+
[tool.coverage.run]
|
|
85
|
+
source = [ "plasmacoll" ]
|
|
86
|
+
omit = [ "*/tests/*" ]
|
|
87
|
+
|
|
88
|
+
[tool.coverage.report]
|
|
89
|
+
show_missing = true
|
|
90
|
+
|
|
91
|
+
[tool.ty.environment]
|
|
92
|
+
python = ".venv"
|
|
93
|
+
python-version = "3.10"
|
|
94
|
+
|
|
95
|
+
[tool.ty.src]
|
|
96
|
+
include = [ "src" ]
|
|
97
|
+
|
|
98
|
+
[tool.ty.analysis]
|
|
99
|
+
# CuPy is optional and not installed in CI
|
|
100
|
+
allowed-unresolved-imports = [ "cupy" ]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Null-collision Monte Carlo collisions of charged particles with neutral gases.
|
|
2
|
+
|
|
3
|
+
plasmacoll collides markers (positions, velocities and weights in NumPy or CuPy
|
|
4
|
+
arrays, through :mod:`cunumpy`) with prescribed Maxwellian neutral backgrounds:
|
|
5
|
+
elastic and backscatter collisions, excitation, ionization, attachment,
|
|
6
|
+
detachment and charge transfer, with cross sections from tables, LXCat files
|
|
7
|
+
or functions. It is the collision step of a particle-in-cell code, or with
|
|
8
|
+
:class:`ZeroDReactor` a homogeneous reactor for testing cross-section sets.
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
>>> import plasmacoll
|
|
12
|
+
>>> from plasmacoll.constants import ELECTRON_MASS, ATOMIC_MASS
|
|
13
|
+
>>> mcc = plasmacoll.MonteCarloCollisions(
|
|
14
|
+
... species_masses={"e": ELECTRON_MASS},
|
|
15
|
+
... backgrounds=[plasmacoll.NeutralBackground("Ar", 1e21, 300.0, 39.95 * ATOMIC_MASS)],
|
|
16
|
+
... processes={"e": [plasmacoll.CollisionProcess(
|
|
17
|
+
... "elastic", "Ar", plasmacoll.CrossSection.constant(1e-19))]},
|
|
18
|
+
... seed=1,
|
|
19
|
+
... )
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from plasmacoll.background import DensityProfile, NeutralBackground
|
|
23
|
+
from plasmacoll.cross_sections import (
|
|
24
|
+
CrossSection,
|
|
25
|
+
LXCatProcess,
|
|
26
|
+
find_lxcat_process,
|
|
27
|
+
read_lxcat,
|
|
28
|
+
)
|
|
29
|
+
from plasmacoll.hydrogen import proton_hydrogen_processes
|
|
30
|
+
from plasmacoll.markers import MarkerSet, ParticleArrays
|
|
31
|
+
from plasmacoll.mcc import (
|
|
32
|
+
MCCDiagnostics,
|
|
33
|
+
MCCResult,
|
|
34
|
+
MonteCarloCollisions,
|
|
35
|
+
NewMarkers,
|
|
36
|
+
make_rng,
|
|
37
|
+
)
|
|
38
|
+
from plasmacoll.process import CollisionProcess
|
|
39
|
+
from plasmacoll.reactor import ReactorHistory, ReactorState, ZeroDReactor
|
|
40
|
+
from plasmacoll.vibrational import (
|
|
41
|
+
VibrationalDistribution,
|
|
42
|
+
boltzmann_level_populations,
|
|
43
|
+
estimate_electronegativity,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
__version__ = "0.1.0"
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"CollisionProcess",
|
|
50
|
+
"CrossSection",
|
|
51
|
+
"DensityProfile",
|
|
52
|
+
"LXCatProcess",
|
|
53
|
+
"MCCDiagnostics",
|
|
54
|
+
"MCCResult",
|
|
55
|
+
"MarkerSet",
|
|
56
|
+
"MonteCarloCollisions",
|
|
57
|
+
"NeutralBackground",
|
|
58
|
+
"NewMarkers",
|
|
59
|
+
"ParticleArrays",
|
|
60
|
+
"ReactorHistory",
|
|
61
|
+
"ReactorState",
|
|
62
|
+
"VibrationalDistribution",
|
|
63
|
+
"ZeroDReactor",
|
|
64
|
+
"boltzmann_level_populations",
|
|
65
|
+
"estimate_electronegativity",
|
|
66
|
+
"find_lxcat_process",
|
|
67
|
+
"make_rng",
|
|
68
|
+
"proton_hydrogen_processes",
|
|
69
|
+
"read_lxcat",
|
|
70
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Typing aliases shared by the modules of plasmacoll."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from os import PathLike
|
|
6
|
+
from typing import Any, TypeAlias
|
|
7
|
+
|
|
8
|
+
#: A NumPy or CuPy array, as returned by :mod:`cunumpy` for the active backend.
|
|
9
|
+
Array: TypeAlias = Any
|
|
10
|
+
#: A file path given as a string or a path object.
|
|
11
|
+
PathLikeStr: TypeAlias = str | PathLike[str]
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Neutral gas backgrounds: a Maxwellian at rest, uniform or with a density profile."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import cunumpy as xp
|
|
10
|
+
|
|
11
|
+
from plasmacoll._types import Array
|
|
12
|
+
from plasmacoll.constants import BOLTZMANN
|
|
13
|
+
|
|
14
|
+
__all__ = ["DensityProfile", "NeutralBackground"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class DensityProfile:
|
|
19
|
+
"""A piecewise-linear relative neutral density along one coordinate axis.
|
|
20
|
+
|
|
21
|
+
``factors`` (dimensionless, >= 0) scale the background's reference density
|
|
22
|
+
at the tabulated ``positions`` (m, strictly increasing) of coordinate
|
|
23
|
+
``axis``. Outside the table the end values are used.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
axis: The column of the marker positions the profile depends on.
|
|
27
|
+
positions: Table positions in m.
|
|
28
|
+
factors: Density factors at ``positions``.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
axis: int
|
|
32
|
+
positions: Array
|
|
33
|
+
factors: Array
|
|
34
|
+
|
|
35
|
+
def __post_init__(self) -> None:
|
|
36
|
+
"""Validate and normalize the table."""
|
|
37
|
+
positions = xp.asarray(self.positions, dtype=float)
|
|
38
|
+
factors = xp.asarray(self.factors, dtype=float)
|
|
39
|
+
if positions.ndim != 1 or positions.shape != factors.shape:
|
|
40
|
+
raise ValueError("positions and factors must be 1D arrays of equal length")
|
|
41
|
+
if positions.size < 2:
|
|
42
|
+
raise ValueError("a density profile needs at least two points")
|
|
43
|
+
if bool(xp.any(xp.diff(positions) <= 0.0)):
|
|
44
|
+
raise ValueError("profile positions must be strictly increasing")
|
|
45
|
+
if bool(xp.any(factors < 0.0)):
|
|
46
|
+
raise ValueError("profile factors must be >= 0")
|
|
47
|
+
if self.axis < 0:
|
|
48
|
+
raise ValueError("profile axis must be >= 0")
|
|
49
|
+
object.__setattr__(self, "positions", positions)
|
|
50
|
+
object.__setattr__(self, "factors", factors)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def max_factor(self) -> float:
|
|
54
|
+
"""Return the largest factor, which bounds the density."""
|
|
55
|
+
return float(xp.max(self.factors))
|
|
56
|
+
|
|
57
|
+
def __call__(self, positions: Array) -> Array:
|
|
58
|
+
"""Return the density factor at marker ``positions`` (shape ``(N, ndim)``)."""
|
|
59
|
+
return xp.interp(positions[:, self.axis], self.positions, self.factors)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class NeutralBackground:
|
|
64
|
+
"""A stationary Maxwellian neutral gas.
|
|
65
|
+
|
|
66
|
+
The density is ``density`` everywhere, or ``density * profile(x)`` with a
|
|
67
|
+
:class:`DensityProfile`; ``density`` is then the reference density the
|
|
68
|
+
profile's factors scale.
|
|
69
|
+
|
|
70
|
+
Attributes:
|
|
71
|
+
name: The name processes refer to the background by.
|
|
72
|
+
density: Number density in m^-3.
|
|
73
|
+
temperature: Temperature in K.
|
|
74
|
+
mass: Mass of one neutral particle in kg.
|
|
75
|
+
profile: Optional spatial variation of the density.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
name: str
|
|
79
|
+
density: float
|
|
80
|
+
temperature: float
|
|
81
|
+
mass: float
|
|
82
|
+
profile: DensityProfile | None = None
|
|
83
|
+
|
|
84
|
+
def __post_init__(self) -> None:
|
|
85
|
+
"""Validate the background parameters."""
|
|
86
|
+
if self.density < 0.0:
|
|
87
|
+
raise ValueError("background density must be >= 0")
|
|
88
|
+
if self.temperature < 0.0:
|
|
89
|
+
raise ValueError("background temperature must be >= 0")
|
|
90
|
+
if self.mass <= 0.0:
|
|
91
|
+
raise ValueError("background mass must be > 0")
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def max_density_factor(self) -> float:
|
|
95
|
+
"""Return the largest factor ``density`` is scaled by (1 if uniform)."""
|
|
96
|
+
return 1.0 if self.profile is None else self.profile.max_factor
|
|
97
|
+
|
|
98
|
+
def density_factor(self, positions: Array) -> Array | float:
|
|
99
|
+
"""Return the factor ``density`` is scaled by at ``positions``."""
|
|
100
|
+
return 1.0 if self.profile is None else self.profile(positions)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def thermal_speed(self) -> float:
|
|
104
|
+
"""Return the 1D thermal speed ``sqrt(k T / M)`` in m/s."""
|
|
105
|
+
return math.sqrt(BOLTZMANN * self.temperature / self.mass)
|
|
106
|
+
|
|
107
|
+
def sample_velocities(self, rng: Any, num: int) -> Array:
|
|
108
|
+
"""Sample ``num`` neutral velocities (3 components) from the Maxwellian.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
rng: A NumPy or CuPy ``Generator``.
|
|
112
|
+
num: The number of velocities.
|
|
113
|
+
"""
|
|
114
|
+
return rng.standard_normal((num, 3)) * self.thermal_speed
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Physical constants in SI units (CODATA 2018).
|
|
2
|
+
|
|
3
|
+
The elementary charge and the Boltzmann constant are exact since the 2019
|
|
4
|
+
redefinition of the SI; the masses are the CODATA 2018 recommended values.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
#: Elementary charge in C, also the number of J in one eV (exact).
|
|
10
|
+
ELEMENTARY_CHARGE = 1.602176634e-19
|
|
11
|
+
#: Boltzmann constant in J/K (exact).
|
|
12
|
+
BOLTZMANN = 1.380649e-23
|
|
13
|
+
#: Electron mass in kg.
|
|
14
|
+
ELECTRON_MASS = 9.1093837015e-31
|
|
15
|
+
#: Proton mass in kg.
|
|
16
|
+
PROTON_MASS = 1.67262192369e-27
|
|
17
|
+
#: Atomic mass constant (1 u, 1/12 of the mass of carbon-12) in kg.
|
|
18
|
+
ATOMIC_MASS = 1.66053906660e-27
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def kelvin_to_ev(temperature: float) -> float:
|
|
22
|
+
"""Return the thermal energy ``k T`` of ``temperature`` (K) in eV."""
|
|
23
|
+
return BOLTZMANN * temperature / ELEMENTARY_CHARGE
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def ev_to_kelvin(energy: float) -> float:
|
|
27
|
+
"""Return the temperature (K) whose thermal energy ``k T`` is ``energy`` (eV)."""
|
|
28
|
+
return energy * ELEMENTARY_CHARGE / BOLTZMANN
|