Coryab/code #10

Merged
coryab merged 37 commits from coryab/code into develop 2023-10-24 10:45:33 +00:00
6 changed files with 85 additions and 79 deletions
Showing only changes of commit f7eee8dc61 - Show all commits

View File

@ -63,8 +63,7 @@ def animate():
fig, update, N, fargs=(lines, arr), interval=1, blit=False
)
# ani.save("../images/100_particles.gif", writer=animation.FFMpegFileWriter(fps=50))
plt.show()
ani.save("../images/100_particles.gif", writer=animation.FFMpegFileWriter(fps=50))
if __name__ == "__main__":

View File

@ -16,11 +16,17 @@ params = {
plt.rcParams.update(params)
def main():
directories = {
"output/simulate_2_particles/no_interaction/",
"output/simulate_2_particles/with_interaction/",
}
files = [
"output/simulate_2_particles/no_interaction/particle_0_r.txt",
"output/simulate_2_particles/no_interaction/particle_1_r.txt",
"output/simulate_2_particles/with_interaction/particle_0_r.txt",
"output/simulate_2_particles/with_interaction/particle_1_r.txt"
"particle_0_r.txt",
"particle_1_r.txt",
]
outputs = [
"../latex/images/simulate_2_particles_no_interaction_xy.pdf",
"../latex/images/simulate_2_particles_interaction_xy.pdf",
]
labels = [
r"$p_1$",
@ -29,28 +35,28 @@ def main():
r"$\hat{p}_2$",
]
colors = [
"mediumaquamarine",
"salmon",
"seagreen",
"darkred"
]
start_pos = set()
for label, color, file in zip(labels, colors, files):
with open(file) as f:
lines = f.readlines()
t = np.linspace(0, 50, len(lines))
r = np.array([list(map(float, line.strip().split(","))) for line in lines])
plt.plot(r[:,0], r[:,1], label=label, color=color)
start_pos.add((r[0,0],r[0,1]))
for pos in start_pos:
plt.plot(*pos, "o", color="black")
for dir, output in zip(directories, outputs):
fig, ax = plt.subplots()
for label, color, file in zip(labels, colors, files):
with open(dir+file) as f:
lines = f.readlines()
t = np.linspace(0, 50, len(lines))
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:
ax.plot(*pos, "o", color="black")
plt.xlabel(r"x $(\mu m)$")
plt.ylabel(r"y $(\mu m)$")
plt.legend(loc="upper right")
plt.axis("equal")
plt.savefig("../latex/images/plot_2_particles_xy.pdf", bbox_inches="tight")
ax.set_xlabel(r"x $(\mu m)$")
ax.set_ylabel(r"y $(\mu m)$")
ax.legend(loc="upper right")
ax.axis("equal")
fig.savefig(output, bbox_inches="tight")
if __name__ == "__main__":

View File

@ -48,7 +48,6 @@ def main():
ax.set_zlabel(r"z $(\mu m)$")
ax.view_init(10,-35)
plt.title(r"2 particles with and without interactions.")
plt.legend()
plt.savefig("../latex/images/3d_plot.pdf")

View File

@ -16,12 +16,9 @@ plt.rcParams.update(params)
def main():
colors = [
"lightskyblue",
"deepskyblue",
"salmon",
"tomato",
"mediumaquamarine",
"mediumseagreen"
"mediumseagreen",
"darkred",
"darkgoldenrod"
]
files = [
"output/time_dependent_potential/wide_sweep.txt",
@ -49,10 +46,10 @@ def main():
fig, ax = plt.subplots()
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, y3, label=r"$f_{3} = 0.7$", color=colors[4])
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[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_ylabel(r"Fraction of particles left")
# ax.set_ylim((-0.1, 1.1))

View File

@ -5,70 +5,68 @@ import seaborn as sns
sns.set_theme()
params = {
"font.family": "Serif",
"font.serif": "Roman",
"font.serif": "Roman",
"text.usetex": True,
"axes.titlesize": "large",
"axes.labelsize": "large",
"xtick.labelsize": "large",
"ytick.labelsize": "large",
"legend.fontsize": "medium"
"legend.fontsize": "medium",
}
plt.rcParams.update(params)
def main():
directories = {
directories = [
"output/simulate_2_particles/no_interaction/",
"output/simulate_2_particles/with_interaction/",
}
]
files = [
"particle_0",
"particle_1",
]
labels = [
[r"$p_1$", r"$\hat{p}_1$"],
[r"$p_2$", r"$\hat{p}_2$"]
]
labels = [r"$p_1$", r"$p_2$"]
output = [
"../latex/images/phase_space_no_interaction",
"../latex/images/phase_space_interaction",
]
colors = [
"lightskyblue",
"deepskyblue",
"salmon",
"tomato",
"seagreen",
"darkred",
]
linestyles = [
"solid",
"dotted"
]
fig1, axs1 = plt.subplots(2,1,sharex=True)
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)):
for i, dir in enumerate(directories):
fig1, axs1 = plt.subplots(sharex=True)
fig2, axs2 = plt.subplots(sharex=True)
for j, (file, label, color) in enumerate(zip(files, labels, colors)):
r = []
v = []
with open(dir+file+"_r.txt") as f:
with open(dir + file + "_r.txt") as f:
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()
v = np.array([list(map(float, line.strip().split(","))) for line in lines])
axs1[i].plot(r[:,0], v[:,0], label=label[j])
axs2[i].plot(r[:,2], v[:,2], label=label[j])
axs1[i].axis("equal")
axs2[i].axis("equal")
axs1[1].set(xlabel=r"t $(\mu s)$", ylabel = r"x $(\mu m)$")
axs1[0].set(ylabel = r"x $(\mu m)$")
axs2[1].set(xlabel=r"t $(\mu s)$", ylabel = r"z $(\mu m)$")
axs2[0].set(ylabel = r"z $(\mu m)$")
v = np.array(
[list(map(float, line.strip().split(","))) for line in lines]
)
axs1.plot(r[:, 0], v[:, 0], label=label, color=color)
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[i].legend(loc="upper right")
# axs1[i].set_title(title)
axs2[i].legend(loc="upper right")
# axs2[i].set_title(title)
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)$")
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")
axs1.legend(loc="upper right")
axs2.legend(loc="upper right")
fig1.savefig(f"{output[i]}_x.pdf", bbox_inches="tight")
fig2.savefig(f"{output[i]}_z.pdf", bbox_inches="tight")
# plt.show()

View File

@ -33,32 +33,39 @@ def main():
r"$n_4$",
]
titles = [
"Relative error for the RK4 method",
"Relative error for the forward Euler method"
"(a)",
"(b)"
]
methods = [
"rk4",
"euler"
]
colors = [
"seagreen",
"darkred",
"darkgoldenrod",
"steelblue"
]
fig1, axs1 = plt.subplots(2,1)
for i, (dir, title) in enumerate(list(zip(directories, titles))):
max_err = []
for label, file in zip(labels, files):
for label, file, color in zip(labels, files, colors):
with open(dir+file) as f:
lines = f.readlines()
t = np.linspace(0, 50, len(lines))
r = np.array([float(line.strip()) for line in lines])
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].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)])
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__":