-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
85 lines (56 loc) · 1.69 KB
/
plot.py
File metadata and controls
85 lines (56 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
import matplotlib.pyplot as plt
"""
Create Your Own Plasma PIC Simulation (With Python)
Philip Mocz (2020) Princeton Univeristy, @PMocz
Simulate the 1D Two-Stream Instability
Code calculates the motions of electron under the Poisson-Maxwell equation
using the Particle-In-Cell (PIC) method
"""
def main():
""" Plasma PIC simulation """
# Simulation parameters
# N = 100 # Number of particles
# tEnd = 50 # time at which simulation ends
# dt = 1 # timestep
boxsize = 50
# plotRealTime = False
# # number of timesteps
# Nt = int(np.ceil(tEnd/dt))
f = open('PICresult.txt', 'r')
pos, vel = [], []
N = 0
for line in f.readlines():
fields = line.split('\t')
pos.append(np.double(fields[0]))
vel.append(np.double(fields[1]))
N += 1
Nh = int(N/2)
# with open('PICresult.txt','r') as f:
# for i in range(N):
# lines = f.readlines(1)
# # pos[i], vel[i] = lines
# print(i, lines)
# prep figure
fig = plt.figure(figsize=(5,4), dpi=80)
# Simulation Main Loop
# for i in range(Nt):
# # plot in real time - color 1/2 particles blue, other half red
# if plotRealTime or (i == Nt-1):
# plt.cla()
# plt.scatter(pos[0:Nh],vel[0:Nh],s=.4,color='blue', alpha=0.5)
# plt.scatter(pos[Nh:], vel[Nh:], s=.4,color='red', alpha=0.5)
# plt.axis([0,boxsize,-6,6])
# plt.pause(0.001)
plt.cla()
plt.scatter(pos[0:Nh],vel[0:Nh],s=.4,color='blue', alpha=0.5)
plt.scatter(pos[Nh:], vel[Nh:], s=.4,color='red', alpha=0.5)
plt.axis([0,boxsize,-6,6])
# Save figure
plt.xlabel('x')
plt.ylabel('v')
plt.savefig('pic_output_t50.png',dpi=240)
plt.show()
return 0
if __name__== "__main__":
main()