From: Nils Forssén Date: Thu, 19 May 2022 22:10:31 +0000 (+0200) Subject: first push X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=ffc678e256eb4fc3d5b7ef5eb42e5cc004280319;p=TFYA84.git first push --- ffc678e256eb4fc3d5b7ef5eb42e5cc004280319 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/dispersion_calc.py b/dispersion_calc.py new file mode 100644 index 0000000..7e7c10f --- /dev/null +++ b/dispersion_calc.py @@ -0,0 +1,71 @@ +import numpy as np +import matplotlib.pyplot as plt +import matplotlib +from math import sin + +materials = { + "AL203": np.array([1.7690, 0.0557]), + "Borsilikat, pyrex": np.array([1.4740, 0.00379]), + "Borsilikatglas": np.array([1.5035, 0.00434]), + "Flintglas 1": np.array([1.2, 0.00710]), + "Flintglas 2 ": np.array([1.5961, 0.00880]), + "Flintglas 3": np.array([1.6221, 0.00970]), + "Flintglas 4": np.array([1.8332, 0.001972]), + "Kronglas 1": np.array([1.5646, 0.00649]), + "Kronglas 2": np.array([1.5593, 0.00572]), + "Kronglas 3": np.array([1.5969, 0.00572]), + "Kronglas 4": np.array([1.5043, 0.00455]), + "Kvartsglas": np.array([1.4580, 0.00354]), +} +print( + "\n Hoppas alla jag skickar detta till hade ett trevligt disco igÃ¥r/idag. Inputs skrivs med '.' som kommatecken och ' ' (mellanslag) som separator mellan värden.\n " +) +wave_blue, wave_red, B_mat, Y_b, Y_red = [ + float(elm) + for elm in input( + "wavelength_blue, wavelength_red, B_angle, Y_outangle_b, Y_outangle_red: " + ) + .strip() + .split() +] +n_1 = sin(np.radians(90 - (B_mat - Y_b))) / sin(np.radians(90 - B_mat)) +n_2 = sin(np.radians(90 - (B_mat - Y_red))) / sin(np.radians(90 - B_mat)) + +A, B = np.linalg.solve( + np.array([[1, 1 / ((wave_blue * 1e-9) ** 2)], [1, 1 / ((wave_red * 1e-9) ** 2)]]), + np.array([n_1, n_2]), +) + + +def cachys(wave, _A=A, _B=B): + return _A + _B / (wave**2) + + +def cachys_der(wave, _B=B): + return (-2 * _B) / (wave**3) + + +font = {"size": 8} + +matplotlib.rc("font", **font) +fig, axs = plt.subplots(3, 4, figsize=(15, 6)) +for i in range(3): + for j in range(4): + material = list(materials.keys())[i * 4 + j] + _a, _b = materials.get(material) + _b = _b * 1e-12 + x = range(300, 801, 10) + y = [cachys(wave * 1e-9, _a, _b) for wave in x] + axs[i, j].plot(x, y) + axs[i, j].set_ylim(min(y), max(y)) + axs[i, j].set_title(material) + +for ax in axs.flat: + ax.set(xlabel="wavelength (nm)", ylabel="n") + +print( + f"A: {A},\nB: (um)^2 {B * 1e12},\nn_green: {cachys(550 * 1e-9)},\nderivqtive_n_green: (n/m) - {cachys_der(550 * 1e-9)},\nderivativen_green: (n/nm) {cachys_der(550 * 1e-9)* 1e-9}" +) + +plt.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.25, hspace=0.45) +plt.show() diff --git a/lens_calc.py b/lens_calc.py new file mode 100644 index 0000000..6378a46 --- /dev/null +++ b/lens_calc.py @@ -0,0 +1,28 @@ +import numpy as np + +f1, f2, L, a = map(float, input("f1, f2, L, a: ").strip().split(", ")) + +# Systemmatris, brytning -> translation -> brytning +T_sys = np.array( + ((1 - (L / f1), L), ((L / (f1 * f2) - (1 / f1) - (1 / f2)), 1 - (L / f2))), + dtype=np.float64, +) + +# Effektiv fokallängd +f_eff = -1 / (((L / (f1 * f2)) - (1 / f1) - (1 / f2))) + +# b kan fÃ¥s dÃ¥ B = 0 i systemmatrisen +b = (-1 * ((a * (1 - (L / f1))) + L)) / (1 - (a / f_eff) - (L / f2)) + +# första translation +T_tr1 = np.array(((1, a), (0, 1)), dtype=np.float64) + +# Andra translation +T_tr2 = np.array(((1, b), (0, 1)), dtype=np.float64) + +# Denna ordning i matrismultiplikation används för att fÃ¥ brytningarna/translationer i rätt ordning +print("\nT_sys:\n", T_sys, "\n") +print("Tx_sys:\n", np.dot(T_tr2, np.dot(T_sys, T_tr1)), "\n") +print("f_eff: ", f_eff) +print("b: ", b) +print("M: ", np.dot(T_tr2, np.dot(T_sys, T_tr1))[0, 0]) diff --git a/polarization_calc.py b/polarization_calc.py new file mode 100644 index 0000000..3666bb3 --- /dev/null +++ b/polarization_calc.py @@ -0,0 +1,51 @@ +import numpy as np +import time +from math import cos + + +t_min, N, tot_d = None, None, None + +N, t_min, tot_d = ( + string.strip() + for string in input("input N, t_min, tot_d (? means unknown): ").strip().split(",") +) + + +def generate_degrees(total): + if not total: + return + div = 0 + while True: + div += 1 + interval = total / div + if interval >= 90: + continue + + yield (div, interval) + + +if N == "?": + for div, interval in generate_degrees(float(tot_d)): + I_t = cos(np.radians(interval)) ** (2 * div) + print(I_t) + if I_t >= float(t_min): + N = div + break + +elif t_min == "?": + for div, internal in generate_degrees(float(tot_d)): + if div == int(N): + t_min = cos(np.radians(internal)) ** (2 * div) + break + +elif tot_d == "?": + for degrees in range(int(N) * 90 * 1000): + + interval = degrees / (int(N) * 1000) + I_t = cos(np.radians(interval)) ** (2 * int(N)) + if I_t <= float(t_min): + tot_d = (degrees - 1) / 1000 + break + + +print(f"N = {N}, t_min = {t_min}, tot_d = {tot_d}") diff --git a/reflective_film_calc.py b/reflective_film_calc.py new file mode 100644 index 0000000..819e6a7 --- /dev/null +++ b/reflective_film_calc.py @@ -0,0 +1,59 @@ +from math import sqrt, cos + +N, T_min, wave_len_min, n = map(float, input("N, T_min, wave_len_min, n: ").split()) + +nf_optimalt = sqrt(float(n)) + +wave_len_list = [759.4, 656.3, 589.6, 486.1, 396.8] + +MgF2_list = [1.3754, 1.3766, 1.3777, 1.3802, 1.3841] +LiF_list = [1.3894, 1.3909, 1.3921, 1.3949, 1.3991] +CaF2_list = [1.4310, 1.4325, 1.4338, 1.4370, 1.4421] +SiO_list = [1.9354, 1.9501, 1.9686, 2.0081, 2.1556] +KCl_list = [1.4839, 1.4871, 1.4903, 1.4982, 1.5111] + +closest_wave_len = min(wave_len_list, key=lambda x: abs(x - wave_len_min)) +index = wave_len_list.index(closest_wave_len) +nf_final = 0 +minR = 1e20 + +for nf in [ + MgF2_list[index], + LiF_list[index], + CaF2_list[index], + SiO_list[index], + KCl_list[index], +]: + R_af = ((nf - 1) / (1 + nf)) ** 2 + R_fs = ((n - nf) / (n + nf)) ** 2 + + R = (R_af + R_fs + (2 * sqrt(R_af * R_fs) * -1)) / ( + 1 + (R_af * R_fs) + (2 * sqrt(R_af * R_fs) * -1) + ) + + if R < minR: + minR = R + nf_final = nf + +T = 1 - minR + +d = wave_len_min / (4 * nf_final) +d_opt = wave_len_min / (4 * nf_optimalt) + +N_AR = 0 +R_normal = ((n - 1) / (1 + n)) ** 2 + +for i in range(int(N), 0, -1): + T_tot = ((1 - R_normal) ** i) * ((1 - minR) ** (N - i)) + if T_tot >= T_min: + N_AR = int(N) - i + 1 + break + + +print("nf_opt: ", nf_optimalt) +print("d_opt: ", d_opt) +print("nf@wave_len_min: ", nf_final) +print("d: ", d) +print("R:", minR) +print("T: ", T) +print("N_AR: ", N_AR)