Fix directories list

This commit is contained in:
Cory Balaton 2023-10-19 13:15:12 +02:00
parent 58db1d9928
commit 555c397d76
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B

View File

@ -2,10 +2,10 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
def main(): def main():
directories = { directories = [
"output/relative_error/RK4/", "output/relative_error/RK4/",
"output/relative_error/euler/", "output/relative_error/euler/",
} ]
files = [ files = [
"4000_steps.txt", "4000_steps.txt",
"8000_steps.txt", "8000_steps.txt",
@ -22,8 +22,12 @@ def main():
"Relative error for the RK4 method", "Relative error for the RK4 method",
"Relative error for the forward Euler method" "Relative error for the forward Euler method"
] ]
methods = [
"rk4",
"euler"
]
fig1, axs1 = plt.subplots(2,1) fig1, axs1 = plt.subplots(2,1)
for i, (dir, title) in enumerate(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 in zip(labels, files):
with open(dir+file) as f: with open(dir+file) as f:
@ -34,16 +38,13 @@ def main():
axs1[i].plot(t, r, label=label) axs1[i].plot(t, r, label=label)
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.log10(max_err[i+1]/max_err[i])/np.log10(.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(conv_rate) print(f"{methods[i]}: {conv_rate}")
plt.show() fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
# fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
if __name__ == "__main__": if __name__ == "__main__":