def generate_squeeze_factors(D): r"""Generate squeezing factors in the Fock basis. This function generates the squeezing prefactors, .. math:: prefac_{N,n,k} = \frac{\sigma_{N,k}\sqrt{n!N!}} {k!\left(\frac{n-k}{2}\right)!\left(\frac{N-k}{2}\right)!} where :math:`\sigma_{N,k}` is the parity, given by :func:`~.squeeze_parity`. Args: D (int): generate prefactors for :math:`D` dimensions. """ dim_array = np.arange(D) N = dim_array.reshape((-1, 1, 1)) n = dim_array.reshape((1, -1, 1)) k = dim_array.reshape((1, 1, -1)) # we only perform the sum when n+N is divisible by 2 # in which case we sum 0 <= k <= min(N,n) mask = np.logical_and((n+N)%2 == 0, k <= np.minimum(N, n)) # need to use np.power to avoid taking the root of a negative # in the numerator (these are discarded by the mask anyway) signs = squeeze_parity(D).reshape([D, 1, D]) logfac = np.where(mask, 0.5*(lg(n+1) + lg(N+1)) - lg(k+1) - lg((n-k)/2+1) - lg((N-k)/2+1), 0) if D <= 600: prefactor = np.exp(logfac, dtype=np.float64)*signs*mask else: prefactor = np.exp(logfac, dtype=np.float128)*signs*mask return prefactor
def free(self): """ Free energy of a polymer in solution :math:`\\frac{F \\upsilon}{V k_B T}=\\frac{f}{k_B T}` (per unit volume in :math:`k_B T` units) :return: value of free energy (float) """ x = self.x p = self.y f_ref_1 = lg(self.f_v * self.phi / self.n, self.phi / (self.n * np.exp(1))) f_ref_2 = lg((1 - self.phi), (1 - self.phi) / np.exp(1)) f_int = self.chi * self.phi * (1 - self.phi) f_as_1 = 2 * self.phi * self.f_v * (lg(x, x) + lg(1 - x, 1 - x) - x * self.df_p) f_as_2 = 2 * (1 - self.phi) * (lg(p, p) + lg(1 - p, 1 - p) - p * self.df_w) z_val = 1 - p - x * self.phi * self.f_v / (1 - self.phi) f_as_3 = 2 * (1 - self.phi) * lg(z_val, z_val) f_as_4 = -2 * (1 - self.phi) * lg(1 - z_val, (2 * (1 - self.phi) / np.exp(1))) return f_ref_1 + f_ref_2 + f_int + f_as_1 + f_as_2 + f_as_3 + f_as_4
def matrix_elem(n,r,m): eps = 1e-10 if n % 2 != m % 2: return 0.0 elif r == 0.: return np.complex(n==m) # delta function else: k = np.arange(m % 2, min([m, n]) + 1, 2) res = np.sum( (-1)**((n-k)/2) * np.exp((lg(m+1) + lg(n+1))/2 - lg(k+1) - lg((m-k)/2+1) - lg((n-k)/2+1)) * (np.sinh(r)/2+eps)**((n+m-2*k)/2) / (np.cosh(r)**((n+m+1)/2)) ) return res
def chem_potential_w(self): """ Reduced chemical potential \ of water :math:`\\frac{\\mu_w}{k_B T}=\\frac{1}{k_B T} (f- \\phi_p \\frac{\\partial f}{\\partial \\phi_p}- \ \\phi_s \\frac{\\partial f}{\\partial \\phi_s})` :return: value of chemical potential (float) """ mu_0 = (- self.u_p * self.phi_p / self.n - self.nu * self.conc_l / self.D_w) # mu_1_1 = np.log(self.phi_w) - self.phi_w mu_1_2 = self.chi_p * self.phi_p * (self.phi_p + self.phi_s)# mu_1 = mu_1_1 + mu_1_2 mu_2 = 2 * (lg(1 - self.f_a - self.p, 1 - self.f_a - self.p) + lg(self.p, self.p) - self.p * self.df_w) z_val = (1 - self.f_b - self.p - self.x * self.u_p * self.phi_p / self.phi_w) mu_3 = (2 * (1 - self.f_b - self.p) * np.log(z_val) - 2 * self.p * np.log(2 * self.phi_w / np.exp(1)) - 2 * self.p * (1 - self.phi_w) + 2 * self.x * self.u_p * self.phi_p) mu_4 = - self.df_a * self.f_a - self.df_b * self.f_b # mu_5 = (lg(1 - self.f_a - self.f_b, 1 - self.f_a - self.f_b) - lg(1 - self.f_a, 1 - self.f_a) - lg(1 - self.f_b, 1 - self.f_b)) mu_6 = - (self.f_a + self.f_b) * (np.log(self.phi_w) - self.phi_w) mu_11_1 = (- self.f_a * np.log(1 - self.f_a / self.A_a) + self.f_a * np.log(self.f_a / self.A_a)) mu_11_2 = (- self.f_b * np.log(1 - self.f_b / self.B_b) + self.f_b * np.log(self.f_b / self.B_b)) mu_11 = mu_11_1 + mu_11_2 mu_12 = self.nu * self.conc_l / self.D_w * (1 - self.osm ) mu_chi = - self.chi_e * self.phi_p * self.phi_s return (mu_0 + mu_1 + mu_2 + mu_3 + mu_4 + mu_5 + mu_6 + mu_11 + mu_12 + mu_chi)
def matrix_elem(n, r, m): """Matrix element corresponding to squeezed density matrix[n, m]""" eps = 1e-10 if n % 2 != m % 2: return 0.0 if r == 0.: return np.complex(n == m) # delta function k = np.arange(m % 2, min([m, n]) + 1, 2) res = np.sum( (-1)**((n-k)/2) * np.exp((lg(m+1) + lg(n+1))/2 - lg(k+1) - lg((m-k)/2+1) - lg((n-k)/2+1)) * (np.sinh(r)/2+eps)**((n+m-2*k)/2) / (np.cosh(r)**((n+m+1)/2)) ) return res
def chem_potential_p(self): """ Reduced chemical potential of polymer\ :math:`\\frac{\\mu_p}{k_B T} = \\frac{N \\upsilon_p}{ \\upsilon_w}\ \\frac{ \\mu_w}{k_B T} + \ \\frac{N \\upsilon_p}{ \\upsilon_w} \\frac{1}{k_B T}\ \\frac{ \\partial f}{ \\partial \\phi_p}` :return: value of chemical potential (float) """ z_val = (1 - self.f_b - self.p - self.x * self.u_p * self.phi_p / self.phi_w) mu_1_1_0 = - self.n / self.u_p * self.phi_w mu_1_1 = np.log(self.phi_p / self.n) - self.phi_p + mu_1_1_0# mu_1_2_0 = self.chi_p * self.phi_w mu_1_2 = self.n / self.u_p * (1 - self.phi_p) * (mu_1_2_0) mu_1 = mu_1_1 + mu_1_2 mu_2_0 = (lg(1 - self.x, 1 - self.x) + lg(self.x, self.x) - self.x * self.df_p) mu_2 = 2 * self.n * (mu_2_0) mu_3 = - 2 * self.n * self.x * (np.log(z_val) + 1) mu_4 = self.n / self.u_p * (self.f_a + self.f_b) * self.phi_w mu_5_0 = self.u_p * (np.log(2 * self.phi_w / np.exp(1)) - self.phi_p) mu_5 = -2 * self.n / self.u_p * (self.x * mu_5_0 - self.p * self.phi_w) mu_chi = self.chi_e * (1 - self.phi_p) * self.phi_s * self.n / self.u_p return (mu_1 + mu_2 + mu_3 + mu_4 + mu_5 + mu_chi)
def f_ideal(self, u, phi): """ Ideal free energy: .. math:: :label: free_ideal f_{id}(u, \\phi)=\\frac{\\upsilon_p}{\\upsilon}\\hat{\\xi}_S^2 Q(u)\\left[(1-\\phi(u)) \\log\\left(\\frac{1-\\phi(u)}{e}\\right)+1\\right] :param u: variable :math:`u\\equiv\\frac{z}{b}`, where z is the perpendicular direction :param phi: polymer volume fraction :math:`\\phi(u)` :return: value of the free energy (float) """ # id_1 = lg(phi / (self.r_vol * self.n_p), phi / (self.n_p * np.exp(1))) id_2 = lg(1 - phi, (1 - phi) / np.exp(1)) + 1 return self.f_norm * self.intg(u) * id_2
def day_refl(x): leg = 0 for i in range(1, 5): leg = leg + i*(r1/R)**(i-1)*lg(i)(x) return (L/(np.pi*R**2))*leg
def e26(l, ad): a = (np.power(np.pi * (2.0 * l + 1.0), (1.0 / 2.0))) / float(l) b = np.cos(ad) * lg(int(l), np.cos(ad)) c = lg(int(l + 1), np.cos(ad)) return a * (b - c)
def sum_Cl(wl, angles, nd, ad, l): tot = 0 for i in range(nd): for j in range(nd): tot += (np.abs(wl)**2) * lg(l, np.cos(angles[i][j])) return tot
def lagurrelGussian(self,rho,phi,w,l,p): rho2w = rho/w return self.N_PL(p,l)*np.power(np.sqrt(2)*rho2w,abs(l))*lg(2*np.power(rho2w,2),p,abs(l))*np.exp(-1*np.power(rho2w,2))*np.exp(complex(0,-1)*l*phi)
def free(self): """ Free energy of a polymer in solution \ :math:`\\frac{F \\upsilon}{V k_B T}=\ \\frac{f}{k_B T}` (per unit volume in :math:`k_B T` units)\ :return: value of free energy (float) """ f_ref_11 = (lg(self.u_p * self.phi_p / self.n, self.phi_p / (self.n * np.exp(1)))) f_ref_12 = self.nu * self.u_s * self.phi_s * \ (np.log(self.conc_l) - 1) f_ref_2 = lg(self.phi_w, self.phi_w / np.exp(1)) f_int_1 = self.chi_p * self.phi_p * self.phi_w f_int_2 = self.chi_e * self.phi_p * self.phi_s f_as_1_1 = (lg(self.x, self.x) + lg(1 - self.x, 1 - self.x) - self.x * self.df_p) f_as_1 = 2 * self.u_p * self.phi_p * f_as_1_1 f_as_2_1 = (lg(self.p, self.p) + lg(1 - self.f_a - self.p, 1 - self.f_a - self.p) - self.p * self.df_w) f_as_2 = 2 * self.phi_w * f_as_2_1 z_val = (1 - self.f_b - self.p - self.x * self.u_p * self.phi_p / self.phi_w) f_as_3 = 2 * self.phi_w * lg(z_val, z_val) f_as_4_1 = self.x * self.u_p * self.phi_p / self.phi_w + self.p f_as_4 = (-2 * self.phi_w * lg(f_as_4_1, 2 * self.phi_w / np.exp(1))) f_as_5_1 = - self.df_a * self.f_a f_as_5_2 = - self.df_b * self.f_b f_as_5 = self.phi_w * (f_as_5_1 + f_as_5_2) f_as_6_1 = lg(1 - self.f_a - self.f_b, 1 - self.f_a - self.f_b) f_as_6_2 = (lg(1 - self.f_a, 1 - self.f_a) + lg(1 - self.f_b, 1 - self.f_b)) f_as_6 = self.phi_w * (f_as_6_1 - f_as_6_2) f_as_7_0 = np.log(self.phi_w / np.exp(1)) f_as_7 = - self.phi_w * (self.f_a + self.f_b) * f_as_7_0 f_as_0_1 = ((self.A_a - self.f_a) * np.log(1 - self.f_a / self.A_a) + self.f_a * np.log(self.f_a / self.A_a)) f_as_0_2 = ((self.B_b - self.f_b) * np.log(1 - self.f_b / self.B_b) + self.f_b * np.log(self.f_b / self.B_b)) f_as_0 = self.phi_w * (f_as_0_1 + f_as_0_2) f_ref_all = f_ref_11 + f_ref_12 + f_ref_2 f_int_all = f_int_1 + f_int_2 f_as_all = (f_as_1 + f_as_2 + f_as_3 + f_as_4 + f_as_5 + f_as_6 + f_as_7 + f_as_0) f_exc_0 = self.nu * self.phi_w * self.conc_l / self.D_w f_exc_1 = 1 - self.osm + self.gamma f_exc = f_exc_0 * f_exc_1 return f_ref_all + f_int_all + f_as_all + f_exc # f_exc #