Fixed python calculations, added gitignore

This commit is contained in:
2023-03-22 15:07:19 +04:00
parent bd8cd9e635
commit 95fa3c4f3f
11 changed files with 77 additions and 46 deletions

View File

@@ -8,7 +8,7 @@ n2 = 1.4607 # index of refraction of the fused silica at wavelength 523 nm
NA = 1.25 # numerical aperture
f = 2.0e-3 # objective lens focus or WD
Rsp = 1.03e-6 # sphere radius
P = 4.4e-3 # power of the laser
P = 51.7e-3 # power of the laser
ratio = 1.0 # the ratio of the beam radius to the aperture radius
th_max = np.arcsin(NA / n1) # maximum angle of incidence
@@ -106,23 +106,37 @@ def q_s_y(beta, r, y):
# Intensity distributions
def gauss_peak():
A = (1 - np.exp(-2*r_max ** 2 / w0 ** 2))
return 2*A / (np.pi * w0 ** 2)
def gauss(r):
return np.exp(-2 * r ** 2 / w0 ** 2)
# the fraction of power that falls on the pupil of the micro lens
A = (1 - np.exp(-2*r_max ** 2 / w0 ** 2))
return 2 * A * np.exp(-2 * r ** 2 / w0 ** 2)
def bessel(r):
return special.jv(0, 2.405 / w0 * r) ** 2
def bessel_peak():
return 4.81 / (w0 * r_max * np.exp(0.5)) * 2 * np.pi * integrate.quad(lambda r: r * special.jv(0, 2.405 / w0 * r) ** 2,
0, r_max, epsabs=1e-12, epsrel=1e-6)[0]
ring_radius = 2.405; # radius of the first ring of the besselj_0
# the fraction of power that falls on the pupil of the micro lens
A = ring_radius / (w0 * r_max * np.exp(0.5)) * 2 * np.pi * \
integrate.quad(lambda r: r * special.jv(0, ring_radius / w0 * r) ** 2,
0, r_max, epsabs=1e-12, epsrel=1e-6)[0]
return 2 * A* special.jv(0, ring_radius / w0 * r) ** 2
def uniform(r):
return P / (np.pi * r_max ** 2) * np.ones(r.shape)
return np.ones(r.shape)
def test():
print("q_s = ", q_s(np.pi / 4, np.pi / 4))
print("q_g = ", q_g(np.pi / 4, np.pi / 4))
print("q_mag = ", q_mag(np.pi / 4, np.pi / 4))
print("q_s_avg = ", q_s_avg(np.pi / 4))
print("q_g_avg = ", q_g_avg(np.pi / 4))
print("q_mag_avg = ", q_mag_avg(np.pi / 4))
print("phi_i = ", phi_i(Rsp))
print("gamma = ", gamma(np.pi / 4, Rsp))
print("th_i_z = ", th_i_z(Rsp, Rsp))
print("th_i_y = ", th_i_y(np.pi / 4, Rsp, Rsp))
print("q_g_z = ", q_g_z(Rsp, Rsp))
print("q_s_z = ", q_s_z(Rsp, Rsp))
print("q_g_y = ", q_g_y(np.pi / 4, Rsp, Rsp))
print("q_s_y = ", q_s_y(np.pi / 4, Rsp, Rsp))

View File

@@ -24,36 +24,33 @@ plt.ylabel('I(r)', fontsize=18)
# Integration
def q_res_g(z, func):
ans = integrate.quad(lambda x: x * func(x) * q_g_z(x, z) * (~np.iscomplex(q_g_z(x, z))).astype(float),
ans = integrate.quad(lambda dr: dr * func(dr) * q_g_z(dr, z) * (~np.iscomplex(q_g_z(dr, z))).astype(float),
0, r_max, epsabs=1e-12, epsrel=1e-6)
return ans[0]
return 2 * np.pi * ans[0] / (np.pi * w0 ** 2)
def q_res_s(z, func):
ans = integrate.quad(lambda x: x * func(x) * q_s_z(x, z) * (~np.iscomplex(q_s_z(x, z))).astype(float),
ans = integrate.quad(lambda dr: dr * func(dr) * q_s_z(dr, z) * (~np.iscomplex(q_s_z(dr, z))).astype(float),
0, r_max, epsabs=1e-12, epsrel=1e-6)
return ans[0]
return 2 * np.pi * ans[0] / (np.pi * w0 ** 2)
# Calculation
n = 200
z = np.linspace(-2 * Rsp, 2 * Rsp, n)
axial_g = gauss_peak() * [q_res_g(x, gauss) for x in z]
axial_s = gauss_peak() * [q_res_s(x, gauss) for x in z]
axial_g = [q_res_g(dz, gauss) for dz in z]
axial_s = [q_res_s(dz, gauss) for dz in z]
f_0 = n1 * P / constants.c # net force
axial_g = np.array(axial_g[::-1])
axial_s = np.array(axial_s[::-1])
axial_g = F0 * np.array(axial_g[::-1])
axial_s = F0 * np.array(axial_s[::-1])
axial = axial_g + axial_s
z = -z[::-1]
# Graphics
fig2 = plt.figure(2, figsize=(10, 6))
plt.plot(z, f_0*axial_g, '-.', lw=1, label='$F_{g}$')
plt.plot(z, f_0*axial_s, '--', lw=1, label='$F_{s}$')
plt.plot(z, f_0*axial, lw=1, label='$F_{t}$')
plt.plot(z, axial_g, '-.', lw=1, label='$F_{g}$')
plt.plot(z, axial_s, '--', lw=1, label='$F_{s}$')
plt.plot(z, axial, lw=1, label='$F_{t}$')
plt.xlabel('r, m', fontsize=18)
plt.ylabel('F, N', fontsize=18)
plt.legend(fontsize=18)

View File

@@ -26,23 +26,22 @@ plt.ylabel('I(r)', fontsize=18)
def q_res_g(dy, func):
ans = integrate.dblquad(lambda dr, db, dy: dr * func(dr) * q_g_y(db, dr, dy) * (~np.iscomplex(q_g_y(db, dr, dy))).astype(float),
0, 2 * np.pi, 0, r_max, args=(dy, ),
epsabs=1e-8, epsrel=1e-6)
return ans[0]
epsabs=1e-6, epsrel=1e-6)
return ans[0] / (np.pi * w0 ** 2)
def q_res_s(dy, func):
ans = integrate.dblquad(lambda dr, db: dr * func(dr) * q_s_y(db, dr, dy) * (~np.iscomplex(q_g_y(db, dr, dy))).astype(float),
0, 2 * np.pi, 0, r_max,
epsabs=1e-8, epsrel=1e-6)
return ans[0]
epsabs=1e-6, epsrel=1e-6)
return ans[0] / (np.pi * w0 ** 2)
# Calculation
n = 150
y = np.linspace(-2 * Rsp, 2 * Rsp, n)
transverse_g = gauss_peak() * F0 * np.abs(np.array([q_res_g(x, gauss) for x in y]))
transverse_s = gauss_peak() * F0 * np.array([q_res_s(x, gauss) for x in y])
transverse_g = F0 * np.abs(np.array([q_res_g(dy, gauss) for dy in y]))
transverse_s = F0 * np.array([q_res_s(dy, gauss) for dy in y])
transverse = transverse_g + transverse_s