In [1]:
from pythonpic.classes.species import Species
from pythonpic.classes.grid import Grid
from pythonpic.algorithms import density_profiles

import matplotlib.pyplot as plt
import numpy as np
import scipy.integrate
%matplotlib inline


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-034e7b3cd3d8> in <module>()
----> 1 from pythonpic.classes.species import Species
      2 from pythonpic.classes.grid import Grid
      3 from pythonpic.algorithms import density_profiles
      4 
      5 import matplotlib.pyplot as plt

/home/dominik/Inzynierka/pythonpic/pythonpic/__init__.py in <module>()
      2 """A work in progress particle-in-cell code written in Python, optimized for speed as well as readability."""
      3 
----> 4 from .visualization.plotting import plots
      5 from .helper_functions.helpers import plotting_parser
      6 from .algorithms import BoundaryCondition

/home/dominik/Inzynierka/pythonpic/pythonpic/visualization/__init__.py in <module>()
      1 # coding=utf-8
----> 2 from . import animation, plotting

/home/dominik/Inzynierka/pythonpic/pythonpic/visualization/plotting.py in <module>()
      6 import matplotlib.pyplot as plt
      7 
----> 8 from ..classes import simulation
      9 from ..visualization import animation
     10 from ..visualization import static_plots

/home/dominik/Inzynierka/pythonpic/pythonpic/classes/__init__.py in <module>()
      1 # coding=utf-8
----> 2 from .grid import Grid, TestGrid
      3 from .simulation import Simulation, load_simulation
      4 from .species import Species, Particle, TestSpecies

/home/dominik/Inzynierka/pythonpic/pythonpic/classes/grid.py in <module>()
      7 
      8 
----> 9 from ..helper_functions import physics
     10 from ..algorithms import charge_deposition, FieldSolver, BoundaryCondition, current_deposition, field_interpolation
     11 

/home/dominik/Inzynierka/pythonpic/pythonpic/helper_functions/physics.py in <module>()
      3 
      4 import numpy as np
----> 5 import numba
      6 
      7 

ModuleNotFoundError: No module named 'numba'

In [68]:
FDENS = density_profiles.FDENS

In [50]:



Out[50]:
0.5

In [2]:
g = Grid(1, 100, 50)
moat_left = g.L/4
ramp_length = g.L/4
plasma_length = g.L/2
N = 1000
dense_x, dense_dx = np.linspace(0, g.L, N*1000, retstep=True)
y = FDENS(dense_x, moat_left, ramp_length, plasma_length, N) * dense_dx
dense_x_indices = (dense_x // g.dx).astype(int)
print(dense_x_indices)
y_grid = np.bincount(dense_x_indices, y)
print(y_grid)
# y_grid = np.array([scipy.integrate.quad(lambda x: FDENS(x, moat_left, ramp_length, plasma_length, N), x, x+g.dx) for x in g.x])
# y_grid[1:] += y_grid[:-1] % 1
# y_grid = np.floor(y_grid)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-f187086646a8> in <module>()
----> 1 g = Grid(1, 100, 50)
      2 moat_left = g.L/4
      3 ramp_length = g.L/4
      4 plasma_length = g.L/2
      5 N = 1000

NameError: name 'Grid' is not defined

In [75]:
integrated = scipy.integrate.cumtrapz(y, dense_x).astype(int)
# plt.plot(dense_x[1:], integrated)
plt.plot(dense_x, y)
plt.plot(g.x, y_grid)
print(y_grid.sum()*g.dx - N)
print(y_grid)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-75-935629d30bed> in <module>()
      2 # plt.plot(dense_x[1:], integrated)
      3 plt.plot(dense_x, y)
----> 4 plt.plot(g.x, y_grid)
      5 print(y_grid.sum()*g.dx - N)
      6 print(y_grid)

/usr/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
   3315                       mplDeprecation)
   3316     try:
-> 3317         ret = ax.plot(*args, **kwargs)
   3318     finally:
   3319         ax._hold = washold

/usr/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1896                     warnings.warn(msg % (label_namer, func.__name__),
   1897                                   RuntimeWarning, stacklevel=2)
-> 1898             return func(ax, *args, **kwargs)
   1899         pre_doc = inner.__doc__
   1900         if pre_doc is None:

/usr/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
   1404         kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
   1405 
-> 1406         for line in self._get_lines(*args, **kwargs):
   1407             self.add_line(line)
   1408             lines.append(line)

/usr/lib/python3.6/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
    405                 return
    406             if len(remaining) <= 3:
--> 407                 for seg in self._plot_args(remaining, kwargs):
    408                     yield seg
    409                 return

/usr/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
    383             x, y = index_of(tup[-1])
    384 
--> 385         x, y = self._xy_from_xy(x, y)
    386 
    387         if self.command == 'plot':

/usr/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
    242         if x.shape[0] != y.shape[0]:
    243             raise ValueError("x and y must have same first dimension, but "
--> 244                              "have shapes {} and {}".format(x.shape, y.shape))
    245         if x.ndim > 2 or y.ndim > 2:
    246             raise ValueError("x and y can be no greater than 2-D, but have "

ValueError: x and y must have same first dimension, but have shapes (50,) and (51,)

In [5]:
indices = (integrated[1:] - integrated[:-1]) == 1
plt.plot(dense_x[:-2], indices)


Out[5]:
[<matplotlib.lines.Line2D at 0x7fb918e135c0>]

In [29]:
s = Species(1, 1, N)
s.x = dense_x[0:][indices]

plt.figure(figsize=(10,10))
plt.plot(dense_x, y, label="Distribution function")
plt.scatter(s.x, s.x, c="g", alpha=0.1, label="Particles")
plt.xlim(0, g.L)
plt.hist(s.x, g.x, label="Particle density");
plt.xticks(g.x)
# plt.grid()
plt.gca().xaxis.set_ticklabels([])
plt.legend()


/usr/lib/python3.6/site-packages/ipykernel/__main__.py:2: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 1000000 but corresponding boolean dimension is 999998
  from ipykernel import kernelapp as app
Out[29]:
<matplotlib.legend.Legend at 0x7f89c5d2d4e0>

In [30]:
plt.figure(figsize=(10,10))
quadratic_distribution_function = density_profiles.FDENS(dense_x, moat_left, ramp_length, plasma_length, N, 'quadratic')
plt.plot(dense_x, quadratic_distribution_function, label="Distribution function")
s.distribute_nonuniformly(g.L, moat_left, ramp_length, plasma_length, profile='quadratic')
plt.scatter(s.x, s.x, c="g", alpha=0.1, label="Particles")
plt.xlim(0, g.L)
plt.hist(s.x, g.x, label="Particle density");
plt.xticks(g.x)
plt.gca().xaxis.set_ticklabels([])
plt.legend()


Out[30]:
<matplotlib.legend.Legend at 0x7f89c5a8ba20>

In [23]:
plt.figure(figsize=(10,10))
s = Species(1, 1, N)
exponential_distribution_function = density_profiles.FDENS(dense_x, moat_left, ramp_length, plasma_length, N, 'exponential')
plt.plot(dense_x, exponential_distribution_function, label="Distribution function")
s.distribute_nonuniformly(g.L, moat_left, ramp_length, plasma_length, profile='exponential')
plt.scatter(s.x, s.x, c="g", alpha=0.1, label="Particles")
plt.xlim(0, g.L)
plt.hist(s.x, g.x, label="Particle number in cell");
plt.xticks(g.x)
plt.gca().xaxis.set_ticklabels([])
plt.legend()


Out[23]:
<matplotlib.legend.Legend at 0x7f89c74c3ef0>

In [26]:
plt.figure(figsize=(10,10))
s = Species(1, 1, N * 10)
exponential2_distribution_function = density_profiles.FDENS(dense_x, moat_left, ramp_length, plasma_length, N*10, 'exponential')
plt.plot(dense_x, exponential2_distribution_function, label="Distribution function")
s.distribute_nonuniformly(g.L, moat_left, ramp_length, plasma_length, profile='exponential')
plt.xlim(0, g.L)
plt.hist(s.x, g.x, label="Particle number in cell", alpha=0.5);
plt.scatter(s.x, s.x, c="g", alpha=0.1, label="Particles")
plt.xticks(g.x)
plt.gca().xaxis.set_ticklabels([])
plt.legend()


Out[26]:
<matplotlib.legend.Legend at 0x7f89c6da7eb8>

In [10]:
plt.figure(figsize=(10,10))
N = 3757
s = Species(1, 1, N, "particles")
linear_distribution_function = density_profiles.FDENS(dense_x, moat_left, ramp_length, plasma_length, N, 'linear')
s.distribute_nonuniformly(g.L, moat_left, ramp_length, plasma_length, profile='linear')

print(s.N - s.x.size)

plt.plot(dense_x, linear_distribution_function, label="Distribution function")
plt.scatter(s.x, s.x, c="g", alpha=0.1, label="Particles")
plt.hist(s.x, g.x, label="Particle density", alpha=0.5);
plt.xlim(0, g.L)
plt.xticks(g.x)
plt.gca().xaxis.set_ticklabels([])
plt.legend()


sum of indices: 3757
0
Out[10]:
<matplotlib.legend.Legend at 0x7fb915529da0>