Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of ParticleTracker, Plasma class #675

Closed
wants to merge 249 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
249 commits
Select commit Hold shift + click to select a range
f70eb5d
First refactoring pass
StanczakDominik Sep 8, 2019
1ba55df
Replace grid based plasma in ParticleTracker example with new Analyti…
StanczakDominik Sep 10, 2019
a824373
Try interfaces to keep pure numpy arrays under the hood
StanczakDominik Sep 14, 2019
d879a28
Successfully use numba for ParticleTracker
StanczakDominik Sep 15, 2019
fca1dcf
Add tqdm progressbar library
StanczakDominik Sep 15, 2019
56fd22b
Minor fixes
StanczakDominik Sep 15, 2019
58610d2
Improve particle stepper example
StanczakDominik Sep 15, 2019
024242a
Pep8 fixes
StanczakDominik Sep 15, 2019
5984575
Revert debugging change
StanczakDominik Sep 15, 2019
f7e2676
Merge remote-tracking branch 'upstream/master' into RefactorTracker
StanczakDominik Sep 16, 2019
4c9e4f0
Cleanup
StanczakDominik Sep 17, 2019
7f5d170
Remove unused test
StanczakDominik Sep 21, 2019
c584597
Remove debug changes from tox.ini
StanczakDominik Sep 21, 2019
e99d7e8
Cleanup broadcasting
StanczakDominik Sep 21, 2019
b123036
Bloody numpy array dropping units is the issuerm log.py !
StanczakDominik Oct 3, 2019
d247906
Try a few alternate approaches
StanczakDominik Oct 6, 2019
457fe96
Revert "Try a few alternate approaches"
StanczakDominik Oct 10, 2019
3a64356
Revert "Bloody numpy array dropping units is the issuerm log.py !"
StanczakDominik Oct 10, 2019
b0564cd
More tests
StanczakDominik Oct 10, 2019
1db16d3
Fixed NAN errors
StanczakDominik Oct 13, 2019
efcabfb
Add Numba requirement
StanczakDominik Oct 13, 2019
89617df
Fix requirements
StanczakDominik Oct 14, 2019
ba58812
Bugfix, hypothesis test, use correct field (doesn't broadcast)
StanczakDominik Oct 14, 2019
9dd617c
Fix hypothesis test
StanczakDominik Oct 15, 2019
d21dde2
further improvements to skippable hypothesis test
StanczakDominik Oct 15, 2019
bba6bd6
Add checks for array shape
StanczakDominik Oct 15, 2019
fa7998f
Improve and refactor docs
StanczakDominik Oct 15, 2019
c2a3054
Remove note on instability
StanczakDominik Oct 15, 2019
fb88ad6
Merge branch 'master' into RefactorTracker
StanczakDominik Oct 17, 2019
a33b1d5
Bugfixes
StanczakDominik Oct 21, 2019
c0b435d
Doc cleanup
StanczakDominik Oct 21, 2019
03ccd1e
Merge branch 'master' into RefactorTracker
StanczakDominik Oct 23, 2019
f3a41ca
Disable coverage tests for numba.njitted functions
StanczakDominik Oct 24, 2019
e15acbc
Change design up?
StanczakDominik Oct 24, 2019
1b0539e
Changelog entry!
StanczakDominik Oct 24, 2019
51b1b5d
Merge branch 'master' into RefactorTracker
Jan 14, 2020
b1f98f9
Minor bug that seems to have prevented the entire package from import…
Jan 14, 2020
9fadfd2
Fix import bugs
Jan 14, 2020
430f951
Magnetostatics example
Jan 14, 2020
f2f8ee3
Replace tqdm with tqdm.auto for notebook support
Jan 14, 2020
6276c5f
Bval contour plot
Jan 14, 2020
7fe7db4
Profiling
Jan 15, 2020
614045b
Numba version of magnetic_field
Jan 15, 2020
f0a9288
Get rid of units in simulation
Jan 15, 2020
f961111
Better plots
Jan 15, 2020
75dd65f
Cleanup
Jan 15, 2020
dfd7792
Typo fix
Jan 15, 2020
8b66abd
Cleanup tokamak ipynb example
StanczakDominik Jan 19, 2020
8c90eb2
Bring plasma3d in line with other new style source classes
StanczakDominik Jan 19, 2020
b091440
Fix up shapes for AnalyticalPlasma
StanczakDominik Jan 19, 2020
8c9eb63
Handle lists in magnetic field for circular wire
StanczakDominik Jan 19, 2020
7cd1fdb
Fix conda requirements
StanczakDominik Jan 20, 2020
acb92dc
Fix mayavi requirement for simulation
StanczakDominik Jan 20, 2020
27760c3
Mayavi, vtk
StanczakDominik Jan 20, 2020
02411a6
Try tox-conda fixes
StanczakDominik Jan 20, 2020
e858029
Use tox-conda for build_docs; add tqdm to conda
StanczakDominik Jan 20, 2020
8271d42
Update changelog
StanczakDominik Jan 20, 2020
96d6d84
Move mayavi to pip[dev], disable checking [dev] in pip-install test
StanczakDominik Jan 20, 2020
cf346b6
use tox-conda for html-docs
StanczakDominik Jan 20, 2020
0a00e21
Cleanup mayavi imports
StanczakDominik Jan 20, 2020
4f6c1ba
Bring back mayavi
StanczakDominik Jan 20, 2020
54122c7
Vtk from anaconda
StanczakDominik Jan 20, 2020
219ce91
rename env
StanczakDominik Jan 20, 2020
6b82ed9
Separate mayavi install
StanczakDominik Jan 20, 2020
830e52e
Cleanup pip install log
StanczakDominik Jan 20, 2020
50be279
Split steps for vtk, mayavi
StanczakDominik Jan 20, 2020
e54f909
Split solution into ParticleTrackerSolution
Jan 21, 2020
c2e4b46
General cleanup
Jan 21, 2020
180324e
add test files, temporarily
StanczakDominik Jan 21, 2020
d3aeb9e
Rewrite field calculation using numba, for clarity and speed
Jan 22, 2020
02032c6
Merge branch 'NumbaTracker' into RefactorTracker
Jan 22, 2020
03eb550
Add numba nojit tests
Jan 22, 2020
d73f626
Fix failing tests
Jan 22, 2020
0bee871
Fix tests for ParticleTracker
Jan 22, 2020
272d936
Todo notes
Jan 22, 2020
cf81526
Fix azure pipelines test name
Jan 22, 2020
d601f42
Fix numba bug in magnetostatics
Jan 22, 2020
2b97561
try libgl1 mesa for circleci issue
Jan 22, 2020
8d26041
More packages...?
Jan 22, 2020
e57a383
Bugfixes?
Jan 22, 2020
5652e68
Add reasonable tests for coils B field
Jan 22, 2020
fb4cfc6
Fix a particularly silly bug
Jan 22, 2020
a0101eb
Add kinetic energy relative delta to postfix
Jan 22, 2020
4beb528
Fix description
Jan 22, 2020
e07a183
Unitless kinetic energy speedup
Jan 22, 2020
8a9bce7
Speedups
Jan 22, 2020
5df7fb5
Cleanup
Jan 22, 2020
19a3419
Fix floating point bug
Jan 22, 2020
6e76337
Cleanup
Jan 22, 2020
357201e
Disable mayavi
Jan 22, 2020
70c826b
Fix kinetic energy
Jan 22, 2020
3ff3934
Fixes for tests, documentation for ParticleTrackerSolution
Jan 22, 2020
66df6f8
Fix conda tests failing
Jan 24, 2020
cf5d468
Disable no numba test from running on azure; too slow
Jan 24, 2020
51c9a77
Improve test coverage
Jan 24, 2020
6808b99
Separate dir for notebooks
Jan 24, 2020
368d9f6
test bugfix
Jan 24, 2020
020f27c
Try solution as per
Jan 24, 2020
29bd057
More binder attempts
Jan 24, 2020
42bd0ff
environment.yml cleanup
Jan 24, 2020
fcc1f57
.
Jan 24, 2020
8082386
More binder stuff
Jan 24, 2020
0c35dd7
Xarray creation
StanczakDominik Jan 25, 2020
943977e
Remove '.'
StanczakDominik Jan 25, 2020
c2af85a
Adjust code for xarray purposes
StanczakDominik Jan 25, 2020
c9b172f
xvfb_bg
StanczakDominik Jan 25, 2020
a770318
3-dim xarray style approach
StanczakDominik Jan 25, 2020
6327f19
Add xarray to deps
Jan 28, 2020
98cf5b5
Bugfixes
Jan 28, 2020
d9e3f5e
Bug in kinetic energy
Jan 28, 2020
765c675
Fix toykamak tests
Jan 28, 2020
00cbd03
Merge branch 'TrackerXarray' into RefactorTracker
Jan 28, 2020
86fbd42
Switch tqdm from for to while
Jan 28, 2020
939d5e0
Diagnostics, default timestep from gyroperiod
Jan 28, 2020
7e829d0
bugfix
Jan 28, 2020
947e311
Notebook fixed for constant timestep
Jan 28, 2020
9e82d7c
Timestep in diagnostics, warning
Jan 28, 2020
52ce294
time fix
Jan 29, 2020
1439226
Store sampled fields
Jan 29, 2020
aab4bbd
Test improvements
Jan 29, 2020
0b210a6
Test 'fixes'
Jan 29, 2020
e17c064
Merge branch 'master' into RefactorTracker
StanczakDominik Feb 1, 2020
040d36e
Fix api in plot_particle_stepper
StanczakDominik Feb 1, 2020
00c1587
Add numba, xarray, tqdm to minimal deps
StanczakDominik Feb 1, 2020
67b17e3
Fix call to velocity_history in example
StanczakDominik Feb 1, 2020
25152e5
Fix xarray mean call
StanczakDominik Feb 1, 2020
cd1c6af
Try mayavi
StanczakDominik Feb 1, 2020
27487e4
add mayavi to cc deps
StanczakDominik Feb 1, 2020
e72083a
Revert Mayavi changes to dependencies, CI
StanczakDominik Feb 1, 2020
4eb1085
Replace Mayavi with Pyvista
StanczakDominik Feb 1, 2020
4a70dad
Try pyvista for binder
StanczakDominik Feb 1, 2020
f7df341
Remove pyvista from CI
StanczakDominik Feb 2, 2020
9fbb993
remove pyvista from deps
StanczakDominik Feb 2, 2020
64e67f4
Improvements to pyvista, particle stepper example
StanczakDominik Feb 2, 2020
8227399
I see my python code and I want it painted black
StanczakDominik Feb 7, 2020
d4992e0
No more will pydocstyle complain about these two
StanczakDominik Feb 7, 2020
df1124d
I could not foresee this thing happening here, too
StanczakDominik Feb 7, 2020
d865e04
Start adding implicit integrator
Feb 11, 2020
3a06350
Parametrize tests; sympy implicit solver
Feb 11, 2020
ce651cf
Zenitani/Umeda solver
Feb 11, 2020
5d732ca
Plotting improvements
Feb 11, 2020
1c923b6
Apply `white` to magnetostatics viz
Feb 12, 2020
19b1732
Apply `black` to magnetostatics
Feb 12, 2020
5d5d441
Add matrix-based version of implicit Borish pusher (no fields)
Feb 12, 2020
c7da977
Relativistic Zenitani attempts
Feb 12, 2020
c9d4c7d
Use xarray accessor rather than subclass
Feb 13, 2020
4e881b9
save/load for quantities works
Feb 13, 2020
8691914
vector norm
Feb 13, 2020
b35167e
Experiments
Feb 21, 2020
e25f529
Incorporate changes from project branch
Feb 21, 2020
0eee89b
move create_xarray to methods
Feb 21, 2020
1166a1a
save total number of iterations
Feb 21, 2020
3e5e4e1
Animation
Feb 21, 2020
3be57fe
Notebook
Feb 21, 2020
950fa50
Fixes to visualize with passed plasma
Mar 4, 2020
f81e9cd
Fix animation display for multiple particles
Mar 4, 2020
8ce6a1d
Colors for animate
Mar 5, 2020
240a8df
optional vector plot
Mar 5, 2020
519f8c0
Merge branch 'master' into RefactorTracker
StanczakDominik Mar 7, 2020
d6b86b2
Better test for kinetic energy conservation (well, duh)
StanczakDominik Mar 7, 2020
53073e3
test cleanup
StanczakDominik Mar 7, 2020
71c8d78
Remove boris2 from integrators
StanczakDominik Mar 7, 2020
ed3d3b4
Fix to kinetic energy check
StanczakDominik Mar 7, 2020
f7603d1
replace nonsensical B test with V test
StanczakDominik Mar 7, 2020
f5a786a
Add isort
Mar 11, 2020
82628fa
Remove useless mpl import
Mar 11, 2020
a5f5bf5
Pylint fixes
Mar 11, 2020
747a130
Fix order of pre-commit hooks
Mar 11, 2020
9e92999
Further pre-commit fix
Mar 11, 2020
233441c
Further pylint fixes
Mar 11, 2020
d8ef80e
Simplify plotting
StanczakDominik Mar 29, 2020
7f7203f
Merge remote-tracking branch 'upstream/master' into RefactorTracker
StanczakDominik Mar 29, 2020
c7e7488
Test improvements
StanczakDominik Mar 29, 2020
c4b8454
Remove boris2 for now
StanczakDominik Mar 29, 2020
07af9e7
add [simulations] extra so docs build
StanczakDominik Apr 1, 2020
04e5468
Revert "add [simulations] extra so docs build"
StanczakDominik Apr 1, 2020
4b1af15
Remove pyvista scraper
StanczakDominik Apr 1, 2020
3613414
Revert "Revert "add [simulations] extra so docs build""
StanczakDominik Apr 1, 2020
9adbbee
Revert "Remove pyvista scraper"
StanczakDominik Apr 1, 2020
7ebfe37
Better error handling in example
StanczakDominik Apr 1, 2020
6accd3f
reqs.txt
StanczakDominik Apr 1, 2020
499c0bb
Revert "Revert "Remove pyvista scraper""
StanczakDominik Apr 1, 2020
76d077d
Revert "reqs.txt"
StanczakDominik Apr 1, 2020
9f7cbf8
Revert "Better error handling in example"
StanczakDominik Apr 1, 2020
87bee47
Revert "Revert "Revert "add [simulations] extra so docs build"""
StanczakDominik Apr 1, 2020
252870b
Give up on testing pyvista for now
StanczakDominik Apr 1, 2020
4d3d504
fix references
StanczakDominik Apr 1, 2020
d67bd6a
Revert irrelevant changes
StanczakDominik Apr 1, 2020
fe264c6
pyvista binder
StanczakDominik Apr 1, 2020
2383b58
Fix example
StanczakDominik Apr 1, 2020
f3039af
leftover
StanczakDominik Apr 1, 2020
a545664
Doc changes for AnalyticalFields
StanczakDominik Apr 2, 2020
a6b1a0e
Doc changes for Coils
StanczakDominik Apr 2, 2020
6678d4c
add TODO
StanczakDominik Apr 2, 2020
eff0ede
NotImplementedError on using base class magnetic_field
StanczakDominik Apr 2, 2020
49a4059
Magnetostatics doc changes
StanczakDominik Apr 2, 2020
b783f67
Remove useless implicit integrators; particle_integrator doc changes
StanczakDominik Apr 2, 2020
c5a393a
Apply suggestions from code review
StanczakDominik Apr 7, 2020
d694865
Merge branch 'master' into RefactorTracker
StanczakDominik Apr 12, 2020
4974448
Remove AnalyticalFields.is_datasource_for
StanczakDominik Apr 12, 2020
f943786
Remove reference to the Spartans
StanczakDominik Apr 12, 2020
2231266
Fix __all__ ordering
StanczakDominik Apr 12, 2020
e6b0817
Make gammas private
StanczakDominik Apr 12, 2020
59ed208
private function to simplify code in AnalyticalFields
StanczakDominik Apr 12, 2020
1e8594f
Convert sphinx_gallery .py files to .ipynb
StanczakDominik Apr 25, 2020
c2643fd
Move notebooks to docs; cleanup sphinx_gallery
StanczakDominik Apr 25, 2020
9f55489
Temporarily move example langmuir files
StanczakDominik Apr 25, 2020
dcb3561
Add sphinx copybutton extension
StanczakDominik Apr 25, 2020
248a1db
actually, move langmuir samples to notebooks
StanczakDominik Apr 25, 2020
ed0ced5
add ipykernel, nbsphinx to setup.cfg reqs
StanczakDominik Apr 25, 2020
779000f
cleanup sphinx-gallery leftovers
StanczakDominik Apr 25, 2020
b310c90
Use nbgallery directive
StanczakDominik Apr 25, 2020
1243457
Add nbsphinx-gallery tags to plot cells
StanczakDominik Apr 25, 2020
0305c7f
use nbgallery for frontpage examples
StanczakDominik Apr 25, 2020
99c43fb
Adjust langmuir metadata to select output plot
StanczakDominik Apr 25, 2020
988ed3c
Add default thumbnail image - logo
StanczakDominik Apr 25, 2020
216af9a
Add binder/nbviewer header to files
StanczakDominik Apr 25, 2020
a4896a4
Black pass
StanczakDominik Apr 25, 2020
52e0c75
Replace sphinx gallery references with nbgallery calls
StanczakDominik Apr 25, 2020
f97d747
Add changelog entry
StanczakDominik Apr 25, 2020
df89ce5
Update RTD reqs
StanczakDominik Apr 25, 2020
07d8183
Add sphinx-copybutton to reqs
StanczakDominik Apr 25, 2020
b7d238c
Add pandoc to circleci apt packages
StanczakDominik Apr 25, 2020
7b028f7
add ipywidgets
StanczakDominik Apr 25, 2020
9343521
Directly copy over httml output from rendered documentation
StanczakDominik Apr 25, 2020
5a1881c
try to fix div issue
StanczakDominik Apr 25, 2020
6b445c6
Fix link in examples.rst
StanczakDominik Apr 25, 2020
190c24a
Removed sphinx-gallery 'plot_' prefix from notebooks
StanczakDominik Apr 29, 2020
71eb54f
Add note on nbsphinx to docs
StanczakDominik Apr 29, 2020
f2239b3
Rename reference to example in braginskii code
StanczakDominik Apr 29, 2020
e4a74cb
Apply suggestions from code review
StanczakDominik Apr 30, 2020
c5b1622
Rename _gamma_from_u to _Lorentz_factor
StanczakDominik Apr 30, 2020
3fa6708
Standardize _volt_over_meter name
StanczakDominik Apr 30, 2020
6071861
Mark that positions are cartesian
StanczakDominik Apr 30, 2020
45dd588
Docstrings
StanczakDominik Apr 30, 2020
670ca50
Merge branch 'RefactorTracker' of github.com:StanczakDominik/PlasmaPy…
StanczakDominik Apr 30, 2020
4899de3
Merge branch 'master' into RefactorTracker
StanczakDominik Apr 30, 2020
71fe234
Simulation.rst instead of particle tracker linked from main doc
StanczakDominik Apr 30, 2020
3cf0e33
Incorporate @rocco8773 review suggestions
StanczakDominik May 6, 2020
b592bf6
Update docs/conf.py
StanczakDominik May 19, 2020
ee6fc2e
Apply suggestions from code review
StanczakDominik May 20, 2020
09404cf
Apply code review fixes
StanczakDominik May 20, 2020
7092782
Merge branch 'master' into nbsphinx
StanczakDominik May 20, 2020
a989328
Merge branch 'nbsphinx' into RefactorTracker
StanczakDominik May 24, 2020
2660c32
Tox command for example-less build; doc note
StanczakDominik May 24, 2020
12225fc
Merge branch 'nbsphinx' into RefactorTracker
StanczakDominik May 24, 2020
cc111b6
Move notebooks
StanczakDominik Jul 2, 2020
9690499
add notebooks to gallery
StanczakDominik Jul 2, 2020
aacb45d
Rerun notebooks
StanczakDominik Jul 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
'python': ('https://docs.python.org/3', None),
'numpy': ('https://docs.scipy.org/doc/numpy', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
'astropy': ('http://docs.astropy.org/en/stable/', None)}
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ PlasmaPy Documentation

.. raw:: html

<div style="width: 30%;" class="sphx-glr-thumbcontainer" tooltip="Let&#x27;s try to look at ITER plasma conditions using the physics subpackage. ">
<div style="width: 30%;" class="sphx-glr-thumbcontainer">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_physics_thumb.png
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_particle_stepper_thumb.png

:ref:`sphx_glr_auto_examples_plot_physics.py`
:ref:`sphx_glr_auto_examples_plot_particle_stepper.py`
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved

.. raw:: html

Expand Down
1 change: 1 addition & 0 deletions plasmapy/classes/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .plasma3d import Plasma3D
from .plasmablob import PlasmaBlob
from .analyticalplasma import AnalyticalPlasma
from .openpmd_hdf5 import HDF5Reader
43 changes: 43 additions & 0 deletions plasmapy/classes/sources/analyticalplasma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is very much so a "get something working" quick and dirty copypaste of plasmablob that I'll be cleaning up later. I'm simply wondering, though, if this kind of functionality is better plugged into plasmablob or left here, as a generic "plug in your own functions of space" thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question; maybe we should talk about how to organize. It would be very useful functionality to have a class that we can use to represent plasma configurations analytically.

Defines the core Plasma class used by PlasmaPy to represent plasma properties.
"""
import warnings

import astropy.units as u

from plasmapy.physics.parameters import _grab_charge
from plasmapy.physics.dimensionless import (quantum_theta,
)
from plasmapy.transport import (coupling_parameter,
)
from plasmapy.atomic import particle_mass

from plasmapy.utils import CouplingWarning
from plasmapy.utils.pytest_helpers import call_string

from plasmapy.classes import GenericPlasma

__all__ = [
"PlasmaBlob"
]


class AnalyticalPlasma(GenericPlasma):
"""
Class for describing and calculating plasma parameters without
spatial/temporal description.
"""

def __init__(self, magnetic_field, electric_field):
"""
Initialize plasma paramters.
The most basic description is composition (ion), temperature,
density, and ionization.
"""
self.interpolate_B = magnetic_field
self.interpolate_E = electric_field
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved

# @classmethod
# def is_datasource_for(cls, **kwargs):
# match = 'E' in kwargs.keys() and 'n_e' in kwargs.keys()
# return match
26 changes: 26 additions & 0 deletions plasmapy/classes/sources/plasma3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import itertools

from plasmapy.physics.magnetostatics import MagnetoStatics
import scipy.interpolate as interp
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved

from astropy.constants import (m_p,
m_e,
Expand Down Expand Up @@ -87,6 +88,30 @@ def __init__(self, domain_x, domain_y, domain_z):
self.magnetic_field = np.zeros((3, *self.domain_shape)) * u.T
self.electric_field = np.zeros((3, *self.domain_shape)) * u.V / u.m

# create intermediate array of dimension (nx,ny,nz,3) in order to allow
# interpolation on non-equal spatial domain dimensions
self._B_interpolator = interp.RegularGridInterpolator(
(self.x.si.value,
self.y.si.value,
self.z.si.value),
self.magnetic_field.si.value.reshape((*self.domain_shape, 3)),
method="linear",
bounds_error=True)

self._E_interpolator = interp.RegularGridInterpolator(
(self.x.si.value,
self.y.si.value,
self.z.si.value),
self.electric_field.si.value.reshape((*self.domain_shape, 3)),
method="linear",
bounds_error=True)
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved

def interpolate_E(self, x):
return self._E_interpolator(x.si.value) * u.V / u.m

def interpolate_B(self, x):
return self._B_interpolator(x.si.value) * u.T

@property
def velocity(self):
return self.momentum / self.density
Expand Down Expand Up @@ -115,6 +140,7 @@ def is_datasource_for(cls, **kwargs):
match = False
return match

# TODO this needs more numba and less for loop
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved
def add_magnetostatic(self, *mstats: MagnetoStatics):
# for each MagnetoStatic argument
for mstat in mstats:
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
except ImportError:
pass
else:
matplotlib.use('Agg')
matplotlib.use("Agg")
52 changes: 34 additions & 18 deletions plasmapy/examples/plot_particle_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,50 @@
Particle stepper
================

An example of PlasmaPy's particle stepper class, currently in need of a rewrite
for speed.
An example of using PlasmaPy's particle stepper class.
"""


import numpy as np
from astropy import units as u
from plasmapy.classes import Plasma
from plasmapy.classes.sources.analyticalplasma import AnalyticalPlasma
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be cleaned up!

from plasmapy.simulation import ParticleTracker
from plasmapy.physics.parameters import gyrofrequency

############################################################
# Initialize a plasma. This will be a source of electric and magnetic
# fields for our particles to move in.

plasma = Plasma(domain_x=np.linspace(-1, 1, 10) * u.m,
domain_y=np.linspace(-1, 1, 10) * u.m,
domain_z=np.linspace(-1, 1, 10) * u.m)

############################################################
# Initialize the fields. We'll take B in the x direction
# We'll take B in the x direction
# and E in the y direction, which gets us an E cross B drift
# in the z direction.

B0 = 4 * u.T
plasma.magnetic_field[0, :, :, :] = np.ones((10, 10, 10)) * B0

E0 = 2 * u.V / u.m
plasma.electric_field[1, :, :, :] = np.ones((10, 10, 10)) * E0
def magnetic_field(r):
return u.Quantity([[4, 0, 0]]*len(r), u.T)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think *len(r) may be unnecessary if this is to broadcast to multiple particle positions via numpy...



E_unit = u.V / u.m


def electric_field(r):
return u.Quantity([[0, 2, 0]]*len(r), E_unit)


plasma = AnalyticalPlasma(magnetic_field, electric_field)

############################################################
# Calculate the timestep. We'll take one proton `p`, take its gyrofrequency, invert that
# to get to the gyroperiod, and resolve that into 10 steps for higher accuracy.

freq = gyrofrequency(B0, 'p').to(u.Hz, equivalencies=u.dimensionless_angles())
freq = gyrofrequency(4 * u.T, 'p').to(u.Hz, equivalencies=u.dimensionless_angles())
gyroperiod = (1/freq).to(u.s)
steps_to_gyroperiod = 10
timestep = gyroperiod / steps_to_gyroperiod

############################################################
# Initialize the trajectory calculation.

number_steps = steps_to_gyroperiod * int(2 * np.pi)
number_steps = 5 * steps_to_gyroperiod * int(2 * np.pi)
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved
trajectory = ParticleTracker(plasma, 'p', 1, 1, timestep, number_steps)

############################################################
Expand All @@ -58,7 +59,7 @@
# Run the pusher and plot the trajectory versus time.

trajectory.run()
trajectory.plot_time_trajectories()
trajectory.plot_time_trajectories('yz')
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved

############################################################
# Plot the shape of the trajectory in 3D.
Expand All @@ -71,9 +72,24 @@

vmean = trajectory.velocity_history[:, :, 2].mean()
print(f"The calculated drift velocity is {vmean:.4f} to compare with the"
f"theoretical E0/B0 = {E0/B0:.4f}")
f"theoretical E0/B0 = {0.5 * u.m / u.s}")

############################################################
# and from position:
Vdrift = trajectory.position_history[-1, 0, 2] / (trajectory.NT * trajectory.dt)
print(f"The calculated drift velocity from position is {Vdrift:.4f}")

############################################################
# Supposing we wanted to examine the effect of the initial velocity in the x-y plane on the trajectory:
N = 20
np.random.seed(0)
trajectory = ParticleTracker(plasma, 'p', N, 1, timestep/10, number_steps*10)
trajectory._v[:, :2] = np.random.normal(size=(N, 2))
# we choose this as our example's thumbnail:
# sphinx_gallery_thumbnail_number = 3
trajectory.run()
trajectory.plot_trajectories(alpha=0.8)

############################################################
# Note how while each trajectory fans out in a different way,
# each one traverses the z direction in about the same time!