def plot_potential(grid, potential, view=None, size=(12,9), fill=False): # The Grid u = grid.get_nodes(split=True, flat=False) u = real(u[0]) # Create potential and evaluate eigenvalues potew = potential.evaluate_eigenvalues_at(grid) potew = [ level.reshape(grid.get_number_nodes(overall=False)) for level in potew ] # Plot the energy surfaces of the potential fig = figure(figsize=size) ax = fig.gca() for index, ew in enumerate(potew): if fill: ax.fill(u, ew, facecolor="blue", alpha=0.25) ax.plot(u, ew, label=r"$\lambda_"+str(index)+r"$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.grid(True) # Set the aspect window if view is not None: ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) ax.set_xlabel(r"$x$") ax.set_ylabel(r"$\lambda_i\left(x\right)$") legend(loc="outer right") ax.set_title(r"The eigenvalues $\lambda_i$ of the potential $V\left(x\right)$") fig.savefig("potential"+GD.output_format) close(fig)
def plot_potential(grid, potential, view=None, size=(12, 9), path="."): # The Grid u = grid.get_nodes(split=True) u = real(u[0]) # Create potential and evaluate eigenvalues potew = potential.evaluate_eigenvalues_at(grid) potew = [real(level).reshape(-1) for level in potew] # View if view[0] is None: view[0] = u.min() if view[1] is None: view[1] = u.max() # Plot the energy surfaces of the potential fig = figure(figsize=size) ax = fig.gca() for index, ew in enumerate(potew): ax.plot(u, ew, label=r"$\lambda_{%d}$" % index) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) ax.set_xlabel(r"$x$") ax.set_ylabel(r"$\lambda_i\left(x\right)$") legend(loc="outer right") ax.set_title(r"The eigenvalues $\lambda_i$ of the potential $V\left(x\right)$") fig.savefig(os.path.join(path, "potential" + GD.output_format)) close(fig)
def plot_autocorrelations(data, index=0): print("Plotting the autocorrelations of data block '"+str(index)+"'") timegrid, autocorrelations = data # Plot the autocorrelations fig = figure() ax = fig.gca() # Plot the autocorrelations of the individual wavepackets for i, datum in enumerate(autocorrelations[:-1]): label_i = r"$|\langle \Phi_"+str(i)+r"(0) | \Phi_"+str(i)+r"(t) \rangle|$" #ax.plot(timegrid, real(datum), label=label_i) #ax.plot(timegrid, imag(datum), label=label_i) ax.plot(timegrid, abs(datum), label=label_i) # Plot the sum of all autocorrelations ax.plot(timegrid, abs(autocorrelations[-1]), color=(1,0,0), label=r"$\sum_i {|\langle \Phi_i(0) | \Phi_i(t) \rangle|}$") ax.set_xlim(min(timegrid), max(timegrid)) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_title(r"Autocorrelations of $\Psi$") legend(loc="upper right") ax.set_xlabel(r"Time $t$") ax.set_ylim(0, 1.1) fig.savefig("autocorrelations_block"+str(index)+GD.output_format) close(fig) # Plot the autocorrelations N = len(autocorrelations) -1 fig = figure() # Plot the autocorrelations of the individual wavepackets for i, datum in enumerate(autocorrelations[:-1]): ax = fig.add_subplot(N, 1, i+1) label_ir = r"$\Re \langle \Phi_"+str(i)+r"(0) | \Phi_"+str(i)+r"(t) \rangle$" label_ii = r"$\Im \langle \Phi_"+str(i)+r"(0) | \Phi_"+str(i)+r"(t) \rangle$" label_im = r"$|\langle \Phi_"+str(i)+r"(0) | \Phi_"+str(i)+r"(t) \rangle|$" ax.plot(timegrid, real(datum), label=label_ir) ax.plot(timegrid, imag(datum), label=label_ii) ax.plot(timegrid, abs(datum), label=label_im) ax.set_xlim(min(timegrid), max(timegrid)) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") legend(loc="upper right") ax.set_ylim(0, 1.1) ax.set_title(r"Autocorrelations of $\Psi$") fig.savefig("autocorrelations_per_component_block"+str(index)+GD.output_format) close(fig)
def plot_energies(data, index=0): print("Plotting the energies of data block '"+str(index)+"'") timegridk, timegridp, ekin, epot = data # Plot the energies fig = figure() ax = fig.gca() # Plot the kinetic energy of the individual wave packets for i, kin in enumerate(ekin[:-1]): ax.plot(timegridk, kin, label=r"$E^{kin}_"+str(i)+r"$") # Plot the potential energy of the individual wave packets for i, pot in enumerate(epot[:-1]): ax.plot(timegridp, pot, label=r"$E^{pot}_"+str(i)+r"$") # Plot the sum of kinetic and potential energy for all wave packets for i, (kin, pot) in enumerate(zip(ekin, epot)[:-1]): ax.plot(timegridk, kin + pot, label=r"$E^{kin}_"+str(i)+r"+E^{pot}_"+str(i)+r"$") # Plot sum of kinetic and sum of potential energy ax.plot(timegridk, ekin[-1], label=r"$\sum_i E^{kin}_i$") ax.plot(timegridp, epot[-1], label=r"$\sum_i E^{pot}_i$") # Plot the overall energy of all wave packets ax.plot(timegridk, ekin[-1] + epot[-1], label=r"$\sum_i E^{kin}_i + \sum_i E^{pot}_i$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.grid(True) ax.set_xlabel(r"Time $t$") legend(loc="outer right") ax.set_title(r"Energies of the wavepacket $\Psi$") fig.savefig("energies_block"+str(index)+GD.output_format) close(fig) # Plot the energy drift e_orig = (ekin[-1]+epot[-1])[0] data = abs(e_orig-(ekin[-1]+epot[-1])) fig = figure() ax = fig.gca() ax.plot(timegridk, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.grid(True) ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig("energy_drift_block"+str(index)+"_lin"+GD.output_format) close(fig) fig = figure() ax = fig.gca() ax.semilogy(timegridk, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.grid(True) ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig("energy_drift_block"+str(index)+"_log"+GD.output_format) close(fig)
def plot_autocorrelations(data, blockid=0, view=None, path='.'): print("Plotting the autocorrelations of data block '%s'" % blockid) timegrid, autocorrelations, dt = data if dt is None: xlbl = r"Timesteps $n$" dt = 1.0 else: xlbl = r"Time $t$" # Filter time = timegrid * dt time = where(timegrid < 0, nan, time) # View if view[0] is None: view[0] = nanmin(time) if view[1] is None: view[1] = nanmax(time) if view[2] is None: view[2] = 0.0 if view[3] is None: view[3] = 1.1 # Plot the autocorrelations fig = figure() ax = fig.gca() # Plot the autocorrelations of the individual wavepackets for i, datum in enumerate(autocorrelations[:-1]): ax.plot(time, abs(datum), label=r"$|\langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle|$" % (i, i)) # Plot the sum of all autocorrelations ax.plot(time, abs(autocorrelations[-1]), color=(1, 0, 0), label=r"$\sum_i {|\langle \Phi_i(0) | \Phi_i(t) \rangle|}$") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Autocorrelations of $\Psi$") legend(loc="upper right") ax.set_xlabel(xlbl) fig.savefig( os.path.join( path, "autocorrelations_block" + str(blockid) + GD.output_format)) close(fig) # Plot the autocorrelations N = len(autocorrelations) - 1 fig = figure() # Plot the autocorrelations of the individual wavepackets for i, datum in enumerate(autocorrelations[:-1]): ax = fig.add_subplot(N, 1, i + 1) ax.plot(time, real(datum), label=r"$\Re \langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle$" % (i, i)) ax.plot(time, imag(datum), label=r"$\Im \langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle$" % (i, i)) ax.plot(time, abs(datum), label=r"$|\langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle|$" % (i, i)) ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(xlbl) legend(loc="upper right") ax.set_title(r"Autocorrelations of $\Psi$") fig.savefig( os.path.join( path, "autocorrelations_per_component_block" + str(blockid) + GD.output_format)) close(fig)
def plot_energies(data, blockid=0, view=None, path='.'): print("Plotting the energies of data block '{}'".format(blockid)) timegridk, timegridp, ekin, epot, dt = data if dt is None: xlbl = r"Timesteps $n$" dt = 1.0 else: xlbl = r"Time $t$" # Filter timek = timegridk * dt timep = timegridp * dt timek = where(timegridk < 0, nan, timek) timep = where(timegridp < 0, nan, timep) # View if view[0] is None: view[0] = min(nanmin(timek), nanmin(timep)) if view[1] is None: view[1] = max(nanmax(timek), nanmax(timep)) # Plot the energies fig = figure() ax = fig.gca() # Plot the kinetic energy of the individual wave packets for i, kin in enumerate(ekin[:-1]): ax.plot(timek, kin, label=r"$E^{kin}_{%d}$" % i) # Plot the potential energy of the individual wave packets for i, pot in enumerate(epot[:-1]): ax.plot(timep, pot, label=r"$E^{pot}_{%d}$" % i) # Plot the sum of kinetic and potential energy for all wave packets for i, (kin, pot) in enumerate(list(zip(ekin, epot))[:-1]): ax.plot(timek, kin + pot, label=r"$E^{kin}_{%d}+E^{pot}_{%d}$" % (i, i)) # Plot sum of kinetic and sum of potential energy ax.plot(timek, ekin[-1], label=r"$\sum_i E^{kin}_i$") ax.plot(timep, epot[-1], label=r"$\sum_i E^{pot}_i$") # Plot the overall energy of all wave packets ax.plot(timek, ekin[-1] + epot[-1], label=r"$\sum_i E^{kin}_i + \sum_i E^{pot}_i$") ax.set_xlim(view[:2]) if None not in view[2:]: ax.set_ylim(view[2:]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlabel(xlbl) legend(loc="outer right") ax.set_title(r"Energies of the wavepacket $\Psi$") fig.savefig( os.path.join(path, "energies_block" + str(blockid) + GD.output_format)) close(fig) # Plot the energy drift e_orig = (ekin[-1] + epot[-1])[0] data = abs(e_orig - (ekin[-1] + epot[-1])) fig = figure() ax = fig.gca() ax.plot(timek, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_xlim(view[:2]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlabel(xlbl) ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig( os.path.join( path, "energy_drift_block" + str(blockid) + "_lin" + GD.output_format)) close(fig) fig = figure() ax = fig.gca() ax.semilogy(timek, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_xlim(view[:2]) ax.grid(True) ax.set_xlabel(xlbl) ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig( os.path.join( path, "energy_drift_block" + str(blockid) + "_log" + GD.output_format)) close(fig)
def plot_norms(data, blockid=0, view=None, path='.'): print("Plotting the norms of data block '{}'".format(blockid)) timegrid, norms, dt = data # Filter time = timegrid * dt time = where(timegrid < 0, nan, time) if dt is None: xlbl = r"Timesteps $n$" dt = 1.0 else: xlbl = r"Time $t$" # View if view[0] is None: view[0] = nanmin(time) if view[1] is None: view[1] = nanmax(time) if view[2] is None: view[2] = 0.0 if view[3] is None: view[3] = 1.1 * max(norms[-1]) # Plot the norms fig = figure() ax = fig.gca() # Plot the norms of the individual wavepackets for i, norm in enumerate(norms[:-1]): label_i = r"$\| \Phi_{%d} \|$" % i ax.plot(time, norm, label=label_i) # Plot the sum of all norms ax.plot(time, norms[-1], color=(1, 0, 0), label=r"${\sqrt{\sum_i {\| \Phi_i \|^2}}}$") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2], view[3]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(xlbl) fig.savefig(os.path.join(path, "norms_block"+str(blockid)+GD.output_format)) close(fig) fig = figure() ax = fig.gca() # Plot the squared norms of the individual wavepackets for i, norm in enumerate(norms[:-1]): label_i = r"$\| \Phi_{%d} \|^2$" % i ax.plot(time, norm**2, label=label_i) # Plot the squared sum of all norms ax.plot(time, norms[-1]**2, color=(1, 0, 0), label=r"${\sum_i {\| \Phi_i \|^2}}$") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2], view[3]**2) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Squared norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(xlbl) fig.savefig(os.path.join(path, "norms_sqr_block"+str(blockid)+GD.output_format)) close(fig) # Plot the difference from the theoretical norm fig = figure() ax = fig.gca() ax.plot(time, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.grid(True) ax.set_xlim(view[:2]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(xlbl) ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig(os.path.join(path, "norms_drift_block"+str(blockid)+GD.output_format)) close(fig) fig = figure() ax = fig.gca() ax.semilogy(time, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.set_xlim(view[:2]) ax.grid(True) ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(xlbl) ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig(os.path.join(path, "norms_drift_block"+str(blockid)+"_log"+GD.output_format)) close(fig)
def plot_norms(data, index=0): print("Plotting the norms of data block '"+str(index)+"'") timegrid, norms = data # Plot the norms fig = figure() ax = fig.gca() # Plot the norms of the individual wavepackets for i, datum in enumerate(norms[:-1]): label_i = r"$\| \Phi_"+str(i)+r" \|$" ax.plot(timegrid, datum, label=label_i) # Plot the sum of all norms ax.plot(timegrid, norms[-1], color=(1,0,0), label=r"${\sqrt{\sum_i {\| \Phi_i \|^2}}}$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_title(r"Norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylim([0,1.1*max(norms[:-1])]) fig.savefig("norms_block"+str(index)+GD.output_format) close(fig) fig = figure() ax = fig.gca() # Plot the squared norms of the individual wavepackets for i, datum in enumerate(norms[:-1]): label_i = r"$\| \Phi_"+str(i)+r" \|^2$" ax.plot(timegrid, datum**2, label=label_i) # Plot the squared sum of all norms ax.plot(timegrid, norms[-1]**2, color=(1,0,0), label=r"${\sum_i {\| \Phi_i \|^2}}$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_title(r"Squared norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylim([0,1.1*max(norms[-1]**2)]) fig.savefig("norms_sqr_block"+str(index)+GD.output_format) close(fig) # Plot the difference from the theoretical norm fig = figure() ax = fig.gca() ax.plot(timegrid, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig("norms_drift_block"+str(index)+GD.output_format) close(fig) fig = figure() ax = fig.gca() ax.semilogy(timegrid, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.grid(True) ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig("norms_drift_block"+str(index)+"_log"+GD.output_format) close(fig)
def plot_norms(data, blockid=0, view=None, path='.'): print("Plotting the norms of data block '{}'".format(blockid)) timegrid, norms, dt = data if dt is None: xlbl = r"Timesteps $n$" dt = 1.0 else: xlbl = r"Time $t$" # Filter time = timegrid * dt time = where(timegrid < 0, nan, time) # View if view[0] is None: view[0] = nanmin(time) if view[1] is None: view[1] = nanmax(time) if view[2] is None: view[2] = 0.0 if view[3] is None: view[3] = 1.1 * max(norms[-1]) # Plot the norms fig = figure() ax = fig.gca() # Plot the norms of the individual wavepackets for i, norm in enumerate(norms[:-1]): label_i = r"$\| \Phi_{%d} \|$" % i ax.plot(time, norm, label=label_i) # Plot the sum of all norms ax.plot(time, norms[-1], color=(1, 0, 0), label=r"${\sqrt{\sum_i {\| \Phi_i \|^2}}}$") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2], view[3]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(xlbl) fig.savefig( os.path.join(path, "norms_block" + str(blockid) + GD.output_format)) close(fig) fig = figure() ax = fig.gca() # Plot the squared norms of the individual wavepackets for i, norm in enumerate(norms[:-1]): label_i = r"$\| \Phi_{%d} \|^2$" % i ax.plot(time, norm**2, label=label_i) # Plot the squared sum of all norms ax.plot(time, norms[-1]**2, color=(1, 0, 0), label=r"${\sum_i {\| \Phi_i \|^2}}$") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2], view[3]**2) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Squared norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(xlbl) fig.savefig( os.path.join(path, "norms_sqr_block" + str(blockid) + GD.output_format)) close(fig) # Plot the difference from the theoretical norm fig = figure() ax = fig.gca() ax.plot(time, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.grid(True) ax.set_xlim(view[:2]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(xlbl) ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig( os.path.join(path, "norms_drift_block" + str(blockid) + GD.output_format)) close(fig) fig = figure() ax = fig.gca() ax.semilogy(time, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.set_xlim(view[:2]) ax.grid(True) ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(xlbl) ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig( os.path.join( path, "norms_drift_block" + str(blockid) + "_log" + GD.output_format)) close(fig)
def plot_norms(data, index=0): print("Plotting the norms of data block '" + str(index) + "'") timegrid, norms = data # Plot the norms fig = figure() ax = fig.gca() # Plot the norms of the individual wavepackets for i, datum in enumerate(norms[:-1]): label_i = r"$\| \Phi_" + str(i) + r" \|$" ax.plot(timegrid, datum, label=label_i) # Plot the sum of all norms ax.plot(timegrid, norms[-1], color=(1, 0, 0), label=r"${\sqrt{\sum_i {\| \Phi_i \|^2}}}$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylim([0, 1.1 * max(norms[:-1])]) fig.savefig("norms_block" + str(index) + GD.output_format) close(fig) fig = figure() ax = fig.gca() # Plot the squared norms of the individual wavepackets for i, datum in enumerate(norms[:-1]): label_i = r"$\| \Phi_" + str(i) + r" \|^2$" ax.plot(timegrid, datum**2, label=label_i) # Plot the squared sum of all norms ax.plot(timegrid, norms[-1]**2, color=(1, 0, 0), label=r"${\sum_i {\| \Phi_i \|^2}}$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Squared norms of $\Psi$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylim([0, 1.1 * max(norms[-1]**2)]) fig.savefig("norms_sqr_block" + str(index) + GD.output_format) close(fig) # Plot the difference from the theoretical norm fig = figure() ax = fig.gca() ax.plot(timegrid, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig("norms_drift_block" + str(index) + GD.output_format) close(fig) fig = figure() ax = fig.gca() ax.semilogy(timegrid, abs(norms[-1][0] - norms[-1]), label=r"$\|\Psi\|_0 - \|\Psi\|_t$") ax.grid(True) ax.set_title(r"Drift of $\| \Psi \|$") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\|\Psi\|_0 - \|\Psi\|_t$") fig.savefig("norms_drift_block" + str(index) + "_log" + GD.output_format) close(fig)
def plot_energies(data, index=0): print("Plotting the energies of data block '" + str(index) + "'") timegridk, timegridp, ekin, epot = data # Plot the energies fig = figure() ax = fig.gca() # Plot the kinetic energy of the individual wave packets for i, kin in enumerate(ekin[:-1]): ax.plot(timegridk, kin, label=r"$E^{kin}_" + str(i) + r"$") # Plot the potential energy of the individual wave packets for i, pot in enumerate(epot[:-1]): ax.plot(timegridp, pot, label=r"$E^{pot}_" + str(i) + r"$") # Plot the sum of kinetic and potential energy for all wave packets for i, (kin, pot) in enumerate(zip(ekin, epot)[:-1]): ax.plot(timegridk, kin + pot, label=r"$E^{kin}_" + str(i) + r"+E^{pot}_" + str(i) + r"$") # Plot sum of kinetic and sum of potential energy ax.plot(timegridk, ekin[-1], label=r"$\sum_i E^{kin}_i$") ax.plot(timegridp, epot[-1], label=r"$\sum_i E^{pot}_i$") # Plot the overall energy of all wave packets ax.plot(timegridk, ekin[-1] + epot[-1], label=r"$\sum_i E^{kin}_i + \sum_i E^{pot}_i$") ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlabel(r"Time $t$") legend(loc="outer right") ax.set_title(r"Energies of the wavepacket $\Psi$") fig.savefig("energies_block" + str(index) + GD.output_format) close(fig) # Plot the energy drift e_orig = (ekin[-1] + epot[-1])[0] data = abs(e_orig - (ekin[-1] + epot[-1])) fig = figure() ax = fig.gca() ax.plot(timegridk, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig("energy_drift_block" + str(index) + "_lin" + GD.output_format) close(fig) fig = figure() ax = fig.gca() ax.semilogy(timegridk, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.grid(True) ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig("energy_drift_block" + str(index) + "_log" + GD.output_format) close(fig)
def plot_autocorrelations(data, blockid=0, view=None, path='.'): print("Plotting the autocorrelations of data block '%s'" % blockid) timegrid, autocorrelations, dt = data if dt is None: xlbl = r"Timesteps $n$" dt = 1.0 else: xlbl = r"Time $t$" # Filter time = timegrid * dt time = where(timegrid < 0, nan, time) # View if view[0] is None: view[0] = nanmin(time) if view[1] is None: view[1] = nanmax(time) if view[2] is None: view[2] = 0.0 if view[3] is None: view[3] = 1.1 # Plot the autocorrelations fig = figure() ax = fig.gca() # Plot the autocorrelations of the individual wavepackets for i, datum in enumerate(autocorrelations[:-1]): ax.plot(time, abs(datum), label=r"$|\langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle|$" % (i, i)) # Plot the sum of all autocorrelations ax.plot(time, abs(autocorrelations[-1]), color=(1, 0, 0), label=r"$\sum_i {|\langle \Phi_i(0) | \Phi_i(t) \rangle|}$") ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_title(r"Autocorrelations of $\Psi$") legend(loc="upper right") ax.set_xlabel(xlbl) fig.savefig(os.path.join(path, "autocorrelations_block" + str(blockid) + GD.output_format)) close(fig) # Plot the autocorrelations N = len(autocorrelations) - 1 fig = figure() # Plot the autocorrelations of the individual wavepackets for i, datum in enumerate(autocorrelations[:-1]): ax = fig.add_subplot(N, 1, i + 1) ax.plot(time, real(datum), label=r"$\Re \langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle$" % (i, i)) ax.plot(time, imag(datum), label=r"$\Im \langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle$" % (i, i)) ax.plot(time, abs(datum), label=r"$|\langle \Phi_{%d}(0) | \Phi_{%d}(t) \rangle|$" % (i, i)) ax.grid(True) ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(xlbl) legend(loc="upper right") ax.set_title(r"Autocorrelations of $\Psi$") fig.savefig(os.path.join(path, "autocorrelations_per_component_block" + str(blockid) + GD.output_format)) close(fig)
def plot_energies(data, blockid=0, view=None, path='.'): print("Plotting the energies of data block '{}'".format(blockid)) timegridk, timegridp, ekin, epot, dt = data if dt is None: xlbl = r"Timesteps $n$" dt = 1.0 else: xlbl = r"Time $t$" # Filter timek = timegridk * dt timep = timegridp * dt timek = where(timegridk < 0, nan, timek) timep = where(timegridp < 0, nan, timep) # View if view[0] is None: view[0] = min(nanmin(timek), nanmin(timep)) if view[1] is None: view[1] = max(nanmax(timek), nanmax(timep)) # Plot the energies fig = figure() ax = fig.gca() # Plot the kinetic energy of the individual wave packets for i, kin in enumerate(ekin[:-1]): ax.plot(timek, kin, label=r"$E^{kin}_{%d}$" % i) # Plot the potential energy of the individual wave packets for i, pot in enumerate(epot[:-1]): ax.plot(timep, pot, label=r"$E^{pot}_{%d}$" % i) # Plot the sum of kinetic and potential energy for all wave packets for i, (kin, pot) in enumerate(list(zip(ekin, epot))[:-1]): ax.plot(timek, kin + pot, label=r"$E^{kin}_{%d}+E^{pot}_{%d}$" % (i, i)) # Plot sum of kinetic and sum of potential energy ax.plot(timek, ekin[-1], label=r"$\sum_i E^{kin}_i$") ax.plot(timep, epot[-1], label=r"$\sum_i E^{pot}_i$") # Plot the overall energy of all wave packets ax.plot(timek, ekin[-1] + epot[-1], label=r"$\sum_i E^{kin}_i + \sum_i E^{pot}_i$") ax.set_xlim(view[:2]) if None not in view[2:]: ax.set_ylim(view[2:]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlabel(xlbl) legend(loc="outer right") ax.set_title(r"Energies of the wavepacket $\Psi$") fig.savefig(os.path.join(path, "energies_block" + str(blockid) + GD.output_format)) close(fig) # Plot the energy drift e_orig = (ekin[-1] + epot[-1])[0] data = abs(e_orig - (ekin[-1] + epot[-1])) fig = figure() ax = fig.gca() ax.plot(timek, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_xlim(view[:2]) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.grid(True) ax.set_xlabel(xlbl) ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig(os.path.join(path, "energy_drift_block" + str(blockid) + "_lin" + GD.output_format)) close(fig) fig = figure() ax = fig.gca() ax.semilogy(timek, data, label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_xlim(view[:2]) ax.grid(True) ax.set_xlabel(xlbl) ax.set_ylabel(r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.set_title(r"Energy drift of the wavepacket $\Psi$") fig.savefig(os.path.join(path, "energy_drift_block" + str(blockid) + "_log" + GD.output_format)) close(fig)