def onePacketArrNoise(self, kick, init, noise): # One packet motion giving only the heller values firstnoise = noise[:int(self.n / 2)] secondnoise = noise[int(self.n / 2) - 1:] # Index may be changed later init = np.copy(init) Nhalf = int(self.n / 2) init[1] += kick tempHel = hl.Heller(Nhalf, self.dt, init, self.derivs) tl, xl, vl, al, gl = tempHel.rk4dt(self.args, noise=firstnoise) init2 = [xl[-1], vl[-1] - 2 * kick, al[-1], gl[-1]] tempHel2 = hl.Heller(Nhalf + 1, self.dt, init2, self.derivs) tl2, xl2, vl2, al2, gl2 = tempHel2.rk4dt(self.args, noise=secondnoise) tlcomb = np.concatenate((tl, np.asarray(tl2[1:]) + tl[-1]), axis=None) xlcomb = np.concatenate((xl, xl2[1:]), axis=None) vlcomb = np.concatenate((vl, vl2[1:]), axis=None) alcomb = np.concatenate((al, al2[1:]), axis=None) glcomb = np.concatenate((gl, gl2[1:]), axis=None) hel_dat = np.zeros((self.n, len(init)), dtype=complex) # Unsure about this -1 for i in range(self.n): # Unsure about this -1 hel_dat[i] = [xlcomb[i], vlcomb[i], alcomb[i], glcomb[i]] return hel_dat
def machZender(self, kick, w, phi): Nhalf = int(self.n / 2) ####### psi1 init11 = np.copy(self.initarray[0]) tempHel1 = hl.Heller(Nhalf, self.dt, init11, self.derivs) tl, xl, vl, al, gl = tempHel1.rk4dt(self.args) add_phase = -self.m * kick * xl[-1] / self.hbar - self.hbar * w * tl[ -1] - self.hbar * phi[1] init12 = [xl[-1], vl[-1] + kick, al[-1], gl[-1] + add_phase] tempHel12 = hl.Heller(Nhalf + 1, self.dt, init12, self.derivs) tl2, xl2, vl2, al2, gl2 = tempHel12.rk4dt(self.args) tlcomb = np.concatenate((tl, np.asarray(tl2[1:]) + tl[-1]), axis=None) xlcomb = np.concatenate((xl, xl2[1:]), axis=None) vlcomb = np.concatenate((vl, vl2[1:]), axis=None) alcomb = np.concatenate((al, al2[1:]), axis=None) glcomb = np.concatenate((gl, gl2[1:]), axis=None) hel_dat1 = np.zeros((self.n, len(init11)), dtype=complex) for i in range(self.n): hel_dat1[i] = [xlcomb[i], vlcomb[i], alcomb[i], glcomb[i]] ######### psi2 init21 = np.copy(self.initarray[1]) add_phase = -self.m * kick * init21[0] / self.hbar - self.hbar * phi[0] init21 = [ init21[0], init21[1] + kick, init21[2], init21[3] + add_phase ] tempHel2 = hl.Heller(Nhalf, self.dt, init21, self.derivs) tl, xl, vl, al, gl = tempHel2.rk4dt(self.args) add_phase = self.m * kick * xl[-1] / self.hbar + self.hbar * w * tl[ -1] + self.hbar * phi[1] init22 = [xl[-1], vl[-1] - kick, al[-1], gl[-1] + add_phase] tempHel22 = hl.Heller(Nhalf + 1, self.dt, init22, self.derivs) tl2, xl2, vl2, al2, gl2 = tempHel22.rk4dt(self.args) vl2[-1] += kick gl2[-1] += -self.m * kick * xl2[-1] / self.hbar - self.hbar * w * ( tl2[-1] + tl[-1]) - self.hbar * phi[2] tlcomb = np.concatenate((tl, np.asarray(tl2[1:]) + tl[-1]), axis=None) xlcomb = np.concatenate((xl, xl2[1:]), axis=None) vlcomb = np.concatenate((vl, vl2[1:]), axis=None) alcomb = np.concatenate((al, al2[1:]), axis=None) glcomb = np.concatenate((gl, gl2[1:]), axis=None) hel_dat2 = np.zeros((self.n, len(init21)), dtype=complex) # Unsure about this -1 for i in range(self.n): # Unsure about this -1 hel_dat2[i] = [xlcomb[i], vlcomb[i], alcomb[i], glcomb[i]] return tlcomb, hel_dat1, hel_dat2
def onePacket(self, kick, init, plot=False, final=False, dat=False): Nhalf = int(self.n / 2) tempHel = hl.Heller(Nhalf, self.dt, init, self.derivs) tl, xl, vl, al, gl = tempHel.rk4dt(self.args) psi_arr = np.zeros((self.n, len(self.x)), dtype=complex) for i in range(Nhalf): xi, vi, ai, gi = tempHel.getState(i) psi_i = self.hellerPacket(xi, vi, ai, gi) psi_arr[i] = psi_i init2 = [xl[-1], vl[-1] + kick, al[-1], gl[-1]] tempHel2 = hl.Heller(Nhalf, self.dt, init2, self.derivs) tl2, xl2, vl2, al2, gl2 = tempHel2.rk4dt(self.args) for i in range(Nhalf): xi, vi, ai, gi = tempHel2.getState(i) psi_i = self.hellerPacket(xi, vi, ai, gi) psi_arr[i + Nhalf] = psi_i if plot: tlcomb = np.concatenate((tl, np.asarray(tl2[1:]) + tl[-1]), axis=None) xlcomb = np.concatenate((xl, xl2[1:]), axis=None) vlcomb = np.concatenate((vl, vl2[1:]), axis=None) alcomb = np.concatenate((al, al2[1:]), axis=None) glcomb = np.concatenate((gl, gl2[1:]), axis=None) tempHel.tl = tlcomb tempHel.xl = xlcomb tempHel.vl = vlcomb tempHel.al = alcomb tempHel.gl = glcomb tempHel.plotBasic() if final: psi_f = self.hellerPacket(xl2[-1], vl2[-1] - kick / 2, al2[-1], gl2[-1]) return psi_arr, psi_f elif dat: return psi_arr, tlcomb, xlcomb, vlcomb, alcomb, glcomb else: return psi_arr
def runAll(self): psi_comb = np.zeros((self.n, len(self.x)), dtype=complex) for initi in self.initarray: tempHel = hl.Heller(self.n, self.dt, initi, self.derivs) tempHel.rk4dt(self.args) psi_arr = np.zeros((self.n, len(self.x)), dtype=complex) for i in range(self.n): xi, vi, ai, gi = tempHel.getState(i) psi_i = self.hellerPacket(xi, vi, ai, gi) psi_comb[i] += psi_i / np.sqrt(self.N_packet) # psi_comb += psi_arr / np.sqrt(self.N_packet) # psi_comb += psi_arr / self.N_packet self.psi_comb = psi_comb return self.psi_comb
w = 10 sig = 1 m = 1 hbar = 1 args = (w, m, hbar, sig) temp = 0.5 * m * w ** 2 a0 = 1j * m * w / 2 init = [0, 0, a0, 0] ############################### Gamma Calculation n_runs = 5000 title = "Gamma_full" Heller = hel.Heller(n, dt, init, derivsStocdt) Heller.averageRuns(n_runs,args,dtver=True,save=title) plt.plot(Heller.tl,Heller.g_av,label="Numeric") plt.plot(Heller.tl,expected(Heller.tl,args,init),label="Analytic") plt.title(f"Stochastic Harmonic Oscillator Phase, n={n_runs}") plt.xlabel("Time") plt.ylabel("Gamma") plt.legend() plt.savefig(f"Gamma_n_{n_runs}") plt.show() # loaded = np.load(f"{title}_{n_runs}.npz") # tl = loaded["tl"] # g_av = loaded["g_av"]
p0 = k_initial * hbar a0 = 1j * hbar / (4 * d**2) g0 = (1j * hbar / 4) * np.log(2 * np.pi * d**2) init = [x0, p0 / m, a0, g0] t = 0 dt = 0.01 step = 10 Ns = 100 Ntot = Ns * step Nhalf = int(Ntot / 2) init = [x0, p0, a0, g0] Solver = hl.Heller(Nhalf, dt, init, derivs) tl, xl, vl, al, gl = Solver.rk4(args) init2 = [xl[-1], vl[-1] - 2 * p0, al[-1], gl[-1]] Solver2 = hl.Heller(Nhalf, dt, init2, derivs) tl2, xl2, vl2, al2, gl2 = Solver2.rk4(args) tlcomb = np.concatenate((tl, np.asarray(tl2[1:]) + tl[-1]), axis=None) xlcomb = np.concatenate((xl, xl2[1:]), axis=None) vlcomb = np.concatenate((vl, vl2[1:]), axis=None) alcomb = np.concatenate((al, al2[1:]), axis=None) glcomb = np.concatenate((gl, gl2[1:]), axis=None) Solver.tl = tlcomb Solver.xl = xlcomb Solver.vl = vlcomb
sigma_noise = 0.5 * sig sigma_noise = 10**(-8) print(sigma_noise / 10**(-6)) args_stoc = (m, hbar, w, sigma_noise) T = 4 * np.pi / w Ns = 30000 dt = T / Ns x0 = 20 * sig v0 = 0 a0 = 1j * m * w / 2 g0 = (1j * hbar / 4) * np.log(2 * np.pi * sig**2) init = [x0, v0, a0, g0] solver = hel.Heller(Ns, dt, init, derivsStocdt) tl, xl, vl, al, gl = solver.rk4dt(args_stoc) tl = np.asarray(tl) xl = np.asarray(xl) vl = np.asarray(vl) al = np.asarray(al) gl = np.asarray(gl) fig, axs = plt.subplots(2, 2, sharex=True, figsize=(11, 8)) axs[0, 0].plot(tl, xl / 10**-6) axs[0, 1].plot(tl, vl / 10**-3) axs[1, 0].plot(tl, np.imag(al) / np.imag(a0)) axs[1, 1].plot(tl, gl / hbar) axs[0, 0].set_ylabel(r"$x(\mu m)$") axs[0, 1].set_ylabel(r"$v(mms^{-1})$") axs[1, 0].set_ylabel(r"$\alpha/\alpha_0$") axs[1, 0].set_xlabel(r"$t(s)$")