Develop #14
@ -63,8 +63,7 @@ def animate():
|
|||||||
fig, update, N, fargs=(lines, arr), interval=1, blit=False
|
fig, update, N, fargs=(lines, arr), interval=1, blit=False
|
||||||
)
|
)
|
||||||
|
|
||||||
# ani.save("../images/100_particles.gif", writer=animation.FFMpegFileWriter(fps=50))
|
ani.save("../images/100_particles.gif", writer=animation.FFMpegFileWriter(fps=50))
|
||||||
plt.show()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -16,11 +16,17 @@ params = {
|
|||||||
plt.rcParams.update(params)
|
plt.rcParams.update(params)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
directories = {
|
||||||
|
"output/simulate_2_particles/no_interaction/",
|
||||||
|
"output/simulate_2_particles/with_interaction/",
|
||||||
|
}
|
||||||
files = [
|
files = [
|
||||||
"output/simulate_2_particles/no_interaction/particle_0_r.txt",
|
"particle_0_r.txt",
|
||||||
"output/simulate_2_particles/no_interaction/particle_1_r.txt",
|
"particle_1_r.txt",
|
||||||
"output/simulate_2_particles/with_interaction/particle_0_r.txt",
|
]
|
||||||
"output/simulate_2_particles/with_interaction/particle_1_r.txt"
|
outputs = [
|
||||||
|
"../latex/images/simulate_2_particles_no_interaction_xy.pdf",
|
||||||
|
"../latex/images/simulate_2_particles_interaction_xy.pdf",
|
||||||
]
|
]
|
||||||
labels = [
|
labels = [
|
||||||
r"$p_1$",
|
r"$p_1$",
|
||||||
@ -29,28 +35,28 @@ def main():
|
|||||||
r"$\hat{p}_2$",
|
r"$\hat{p}_2$",
|
||||||
]
|
]
|
||||||
colors = [
|
colors = [
|
||||||
"mediumaquamarine",
|
|
||||||
"salmon",
|
|
||||||
"seagreen",
|
"seagreen",
|
||||||
"darkred"
|
"darkred"
|
||||||
]
|
]
|
||||||
start_pos = set()
|
start_pos = set()
|
||||||
for label, color, file in zip(labels, colors, files):
|
for dir, output in zip(directories, outputs):
|
||||||
with open(file) as f:
|
fig, ax = plt.subplots()
|
||||||
lines = f.readlines()
|
for label, color, file in zip(labels, colors, files):
|
||||||
t = np.linspace(0, 50, len(lines))
|
with open(dir+file) as f:
|
||||||
r = np.array([list(map(float, line.strip().split(","))) for line in lines])
|
lines = f.readlines()
|
||||||
plt.plot(r[:,0], r[:,1], label=label, color=color)
|
t = np.linspace(0, 50, len(lines))
|
||||||
start_pos.add((r[0,0],r[0,1]))
|
r = np.array([list(map(float, line.strip().split(","))) for line in lines])
|
||||||
|
ax.plot(r[:,0], r[:,1], label=label, color=color)
|
||||||
|
start_pos.add((r[0,0],r[0,1]))
|
||||||
|
|
||||||
for pos in start_pos:
|
for pos in start_pos:
|
||||||
plt.plot(*pos, "o", color="black")
|
ax.plot(*pos, "o", color="black")
|
||||||
|
|
||||||
plt.xlabel(r"x $(\mu m)$")
|
ax.set_xlabel(r"x $(\mu m)$")
|
||||||
plt.ylabel(r"y $(\mu m)$")
|
ax.set_ylabel(r"y $(\mu m)$")
|
||||||
plt.legend(loc="upper right")
|
ax.legend(loc="upper right")
|
||||||
plt.axis("equal")
|
ax.axis("equal")
|
||||||
plt.savefig("../latex/images/plot_2_particles_xy.pdf", bbox_inches="tight")
|
fig.savefig(output, bbox_inches="tight")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -48,7 +48,6 @@ def main():
|
|||||||
ax.set_zlabel(r"z $(\mu m)$")
|
ax.set_zlabel(r"z $(\mu m)$")
|
||||||
ax.view_init(10,-35)
|
ax.view_init(10,-35)
|
||||||
|
|
||||||
plt.title(r"2 particles with and without interactions.")
|
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.savefig("../latex/images/3d_plot.pdf")
|
plt.savefig("../latex/images/3d_plot.pdf")
|
||||||
|
|
||||||
|
|||||||
@ -16,12 +16,9 @@ plt.rcParams.update(params)
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
colors = [
|
colors = [
|
||||||
"lightskyblue",
|
"mediumseagreen",
|
||||||
"deepskyblue",
|
"darkred",
|
||||||
"salmon",
|
"darkgoldenrod"
|
||||||
"tomato",
|
|
||||||
"mediumaquamarine",
|
|
||||||
"mediumseagreen"
|
|
||||||
]
|
]
|
||||||
files = [
|
files = [
|
||||||
"output/time_dependent_potential/wide_sweep.txt",
|
"output/time_dependent_potential/wide_sweep.txt",
|
||||||
@ -49,10 +46,10 @@ def main():
|
|||||||
|
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
ax.plot(x, y1, label=r"$f_{1} = 0.1$", color=colors[0])
|
ax.plot(x, y1, label=r"$f_{1} = 0.1$", color=colors[0])
|
||||||
ax.plot(x, y2, label=r"$f_{2} = 0.4$", color=colors[2])
|
ax.plot(x, y2, label=r"$f_{2} = 0.4$", color=colors[1])
|
||||||
ax.plot(x, y3, label=r"$f_{3} = 0.7$", color=colors[4])
|
ax.plot(x, y3, label=r"$f_{3} = 0.7$", color=colors[2])
|
||||||
|
|
||||||
ax.set_xlabel(r"Frequency $\omega_V$ (MHz)")
|
ax.set_xlabel(r"Angular frequency $\omega_V$ (MHz)")
|
||||||
# ax.set_xlim((0, 2.8))
|
# ax.set_xlim((0, 2.8))
|
||||||
ax.set_ylabel(r"Fraction of particles left")
|
ax.set_ylabel(r"Fraction of particles left")
|
||||||
# ax.set_ylim((-0.1, 1.1))
|
# ax.set_ylim((-0.1, 1.1))
|
||||||
|
|||||||
@ -11,64 +11,62 @@ params = {
|
|||||||
"axes.labelsize": "large",
|
"axes.labelsize": "large",
|
||||||
"xtick.labelsize": "large",
|
"xtick.labelsize": "large",
|
||||||
"ytick.labelsize": "large",
|
"ytick.labelsize": "large",
|
||||||
"legend.fontsize": "medium"
|
"legend.fontsize": "medium",
|
||||||
}
|
}
|
||||||
plt.rcParams.update(params)
|
plt.rcParams.update(params)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
directories = {
|
directories = [
|
||||||
"output/simulate_2_particles/no_interaction/",
|
"output/simulate_2_particles/no_interaction/",
|
||||||
"output/simulate_2_particles/with_interaction/",
|
"output/simulate_2_particles/with_interaction/",
|
||||||
}
|
]
|
||||||
files = [
|
files = [
|
||||||
"particle_0",
|
"particle_0",
|
||||||
"particle_1",
|
"particle_1",
|
||||||
]
|
]
|
||||||
labels = [
|
labels = [r"$p_1$", r"$p_2$"]
|
||||||
[r"$p_1$", r"$\hat{p}_1$"],
|
output = [
|
||||||
[r"$p_2$", r"$\hat{p}_2$"]
|
"../latex/images/phase_space_no_interaction",
|
||||||
|
"../latex/images/phase_space_interaction",
|
||||||
]
|
]
|
||||||
colors = [
|
colors = [
|
||||||
"lightskyblue",
|
"seagreen",
|
||||||
"deepskyblue",
|
"darkred",
|
||||||
"salmon",
|
|
||||||
"tomato",
|
|
||||||
]
|
]
|
||||||
linestyles = [
|
|
||||||
"solid",
|
for i, dir in enumerate(directories):
|
||||||
"dotted"
|
fig1, axs1 = plt.subplots(sharex=True)
|
||||||
]
|
fig2, axs2 = plt.subplots(sharex=True)
|
||||||
fig1, axs1 = plt.subplots(2,1,sharex=True)
|
for j, (file, label, color) in enumerate(zip(files, labels, colors)):
|
||||||
fig2, axs2 = plt.subplots(2,1,sharex=True)
|
|
||||||
for i, (file, label) in enumerate(zip(files, labels)):
|
|
||||||
for j, (dir, linestyle) in enumerate(zip(directories, linestyles)):
|
|
||||||
r = []
|
r = []
|
||||||
v = []
|
v = []
|
||||||
with open(dir+file+"_r.txt") as f:
|
with open(dir + file + "_r.txt") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
r = np.array([list(map(float, line.strip().split(","))) for line in lines])
|
r = np.array(
|
||||||
|
[list(map(float, line.strip().split(","))) for line in lines]
|
||||||
|
)
|
||||||
|
|
||||||
with open(dir+file+"_v.txt") as f:
|
with open(dir + file + "_v.txt") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
v = np.array([list(map(float, line.strip().split(","))) for line in lines])
|
v = np.array(
|
||||||
axs1[i].plot(r[:,0], v[:,0], label=label[j])
|
[list(map(float, line.strip().split(","))) for line in lines]
|
||||||
axs2[i].plot(r[:,2], v[:,2], label=label[j])
|
)
|
||||||
axs1[i].axis("equal")
|
axs1.plot(r[:, 0], v[:, 0], label=label, color=color)
|
||||||
axs2[i].axis("equal")
|
axs1.plot(r[0,0], v[0,0], "ko")
|
||||||
|
axs2.plot(r[:, 2], v[:, 2], label=label, color=color)
|
||||||
|
axs2.plot(r[0,2], v[0,2], "ko")
|
||||||
|
axs1.axis("equal")
|
||||||
|
axs2.axis("equal")
|
||||||
|
|
||||||
|
axs1.set(xlabel=r"$x (\mu m)$", ylabel=r"$v_x (\mu m / \mu s)$")
|
||||||
|
axs2.set(xlabel=r"$z (\mu m)$", ylabel=r"$v_z (\mu m / \mu s)$")
|
||||||
|
|
||||||
axs1[1].set(xlabel=r"t $(\mu s)$", ylabel = r"x $(\mu m)$")
|
axs1.legend(loc="upper right")
|
||||||
axs1[0].set(ylabel = r"x $(\mu m)$")
|
axs2.legend(loc="upper right")
|
||||||
axs2[1].set(xlabel=r"t $(\mu s)$", ylabel = r"z $(\mu m)$")
|
|
||||||
axs2[0].set(ylabel = r"z $(\mu m)$")
|
|
||||||
|
|
||||||
axs1[i].legend(loc="upper right")
|
fig1.savefig(f"{output[i]}_x.pdf", bbox_inches="tight")
|
||||||
# axs1[i].set_title(title)
|
fig2.savefig(f"{output[i]}_z.pdf", bbox_inches="tight")
|
||||||
axs2[i].legend(loc="upper right")
|
|
||||||
# axs2[i].set_title(title)
|
|
||||||
|
|
||||||
fig1.savefig("../latex/images/phase_space_2_particles_x.pdf", bbox_inches="tight")
|
|
||||||
fig2.savefig("../latex/images/phase_space_2_particles_z.pdf", bbox_inches="tight")
|
|
||||||
# plt.show()
|
# plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,32 +33,39 @@ def main():
|
|||||||
r"$n_4$",
|
r"$n_4$",
|
||||||
]
|
]
|
||||||
titles = [
|
titles = [
|
||||||
"Relative error for the RK4 method",
|
"(a)",
|
||||||
"Relative error for the forward Euler method"
|
"(b)"
|
||||||
]
|
]
|
||||||
methods = [
|
methods = [
|
||||||
"rk4",
|
"rk4",
|
||||||
"euler"
|
"euler"
|
||||||
]
|
]
|
||||||
|
colors = [
|
||||||
|
"seagreen",
|
||||||
|
"darkred",
|
||||||
|
"darkgoldenrod",
|
||||||
|
"steelblue"
|
||||||
|
]
|
||||||
fig1, axs1 = plt.subplots(2,1)
|
fig1, axs1 = plt.subplots(2,1)
|
||||||
for i, (dir, title) in enumerate(list(zip(directories, titles))):
|
for i, (dir, title) in enumerate(list(zip(directories, titles))):
|
||||||
max_err = []
|
max_err = []
|
||||||
for label, file in zip(labels, files):
|
for label, file, color in zip(labels, files, colors):
|
||||||
with open(dir+file) as f:
|
with open(dir+file) as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
t = np.linspace(0, 50, len(lines))
|
t = np.linspace(0, 50, len(lines))
|
||||||
r = np.array([float(line.strip()) for line in lines])
|
r = np.array([float(line.strip()) for line in lines])
|
||||||
max_err.append(max(r))
|
max_err.append(max(r))
|
||||||
axs1[i].plot(t, r, label=label)
|
axs1[i].plot(t, r, label=label, color=color)
|
||||||
|
|
||||||
axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"relative_error $(\mu m)$")
|
axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"relative error $(\mu m)$")
|
||||||
axs1[i].legend()
|
axs1[i].legend()
|
||||||
axs1[i].set_title(title)
|
axs1[i].set_title(title)
|
||||||
|
|
||||||
conv_rate = 1/3 * sum([np.log2(max_err[i+1]/max_err[i])/np.log2(.5) for i in range(3)])
|
conv_rate = 1/3 * sum([np.log2(max_err[i+1]/max_err[i])/np.log2(.5) for i in range(3)])
|
||||||
print(f"{methods[i]}: {conv_rate}")
|
print(f"{methods[i]}: {conv_rate}")
|
||||||
|
|
||||||
fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
|
plt.tight_layout()
|
||||||
|
fig1.savefig("../latex/images/relative_error.pdf", bbox_inches="tight")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user