def plot_data(groupdata, axisdata, normdata, which_norm="L2"): nona = "L^2" if which_norm == "L2" else "\infty" for groupd, axisd, normd in zip(groupdata, axisdata, normdata): # Plot the error time series for each simulation fig = figure() ax = fig.gca() for cur_axisd, cur_norm in zip(axisd, normd): # One single component in |\Psi> if cur_norm.shape[1] == 1: ax.plot(cur_axisd[1]*cur_axisd[0].dt, cur_norm, label=r"$\varepsilon = $" + str(cur_axisd[0].eps)) # More than one component in |\Psi> else: # Plot all the error norms for all components individually for i in xrange(cur_norm.shape[1]-1): ax.semilogy(cur_axisd[1]*cur_axisd[0].dt, cur_norm[:,i], label=r"$\varepsilon = $" + str(cur_axisd[0].eps) + r", $c_"+str(i)+r"$") # Plot the overall summed error norm ax.semilogy(cur_axisd[1]*cur_axisd[0].dt, cur_norm[:,-1], label=r"$\varepsilon = $" + str(cur_axisd[0].eps) +r", $\sum_i c_i$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"$t$") ax.set_ylabel(r"$\| \phi^F - \phi^H \|_{"+nona+r"}$") ax.set_title(r"Timeseries of $\| \phi_f - \phi_h \|_{"+nona+r"}$ ") legend() fig.savefig("error_timevolution_"+which_norm+"_all"+GD.output_format) close(fig)
def plot_energies(data, index=0): print("Plotting the energies of data block '"+str(index)+"'") timegrid, 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(timegrid, 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(timegrid, 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(timegrid, 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(timegrid, ekin[-1], label=r"$\sum_i E^{kin}_i$") ax.plot(timegrid, epot[-1], label=r"$\sum_i E^{pot}_i$") # Plot the overall energy of all wave packets ax.plot(timegrid, 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(timegrid, 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)+GD.output_format) close(fig)
def plot_data(axisdata, ekindata, epotdata, number_simulations, number_components): colormap = ["b", "g", "r", "c", "m", "y", "b"] # Plot the time series for each simulation fig = figure() ax = fig.gca() for index in xrange(number_simulations): for jndex in xrange(number_components): ax.plot( ekindata[index][:, jndex], label=r"$" + str(index) + r": E^{kin}_" + str(jndex) + r"$", color=colormap[2 * jndex % len(colormap)], ) ax.plot( epotdata[index][:, jndex], label=r"$" + str(index) + r": E^{pot}_" + str(jndex) + r"$", color=colormap[(2 * jndex + 1) % len(colormap)], ) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"Timestep") ax.set_ylabel(r"$E$") ax.set_title(r"Energies timeseries comparison") legend(loc="outer right") fig.savefig("energies_all" + GD.output_format) close(fig) endkindata = [array([ekindata[j][-1, i] for j in xrange(number_simulations)]) for i in xrange(number_components)] endpotdata = [array([epotdata[j][-1, i] for j in xrange(number_simulations)]) for i in xrange(number_components)] # Plot the comparison over versus axisdata fig = figure() ax = fig.gca() # Kinetic and potential energies per component for index in xrange(number_components): ax.plot(axisdata, endkindata[index], label=r"$E^{kin}_" + str(index) + r"$", marker="o") ax.plot(axisdata, endpotdata[index], label=r"$E^{pot}_" + str(index) + r"$", marker="o") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"$\varepsilon$") ax.set_ylabel(r"$E$") ax.set_title(r"Energies end of time comparison") legend(loc="outer right") fig.savefig("energies_comparison" + GD.output_format) close(fig)
def plot_data(axisdata, normdata, number_simulations, number_components): colormap = ["b", "g", "r", "c", "m", "y", "b"] # Plot the time series for each simulation fig = figure() ax = fig.gca() for index in xrange(number_simulations): for jndex in xrange(number_components): ax.plot( normdata[index][:, jndex], label=r"$" + str(index) + r":\| \psi_" + str(jndex) + r"\|$", color=colormap[jndex % len(colormap)], ) ax.set_ylim(0, 1.1) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"Timestep") ax.set_ylabel(r"$\|\cdot\|$") ax.set_title(r"Norms timeseries comparison") legend(loc="outer right") fig.savefig("norms_comparison_all" + GD.output_format) close(fig) enddata = [array([normdata[j][-1, i] for j in xrange(number_simulations)]) for i in xrange(number_components)] # Plot the comparison over versus axisdata fig = figure() ax = fig.gca() for jndex in xrange(number_components): plot( axisdata, enddata[jndex], label=r"$\| \psi_" + str(jndex) + r"\|$", marker="o", color=colormap[jndex % len(colormap)], ) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"$\varepsilon$") ax.set_ylabel(r"$\|\cdot\|$") ax.set_title(r"Norms end of time comparison") legend(loc="outer right") fig.savefig("norms_comparison" + GD.output_format) close(fig)
def plot_data(times, epsdata, axisdata, normdata, which_norm="wf"): if which_norm == "wf": nona = "wf" elif which_norm == "2": nona = "L^2" elif which_norm == "max": nona = "max" def guessor(x, y): u = log(diff(x)) v = log(diff(y)) return v / u for t, time in enumerate(times): # Plot the convergence for all epsilon and fixed times fig = figure() ax = fig.gca() for eps, ad, nd in zip(epsdata, axisdata, normdata[t]): ax.loglog(ad, nd, "-o", label=r"$\varepsilon = "+str(eps)+"$") # Plot a convergence indicator ax.loglog(axisdata[0], axisdata[0]**2, "-k", label=r"$y = x^2$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Timestep size $dt$") ax.set_ylabel(r"$$\| \phi_f - \phi_h \|_{"+nona+r"}$$") ax.set_title(r"Error norm $\| \phi_f - \phi_h \|_{"+nona+r"}$ for time $T=" + str(time) + r"$") legend(loc="outer right") fig.savefig("convergence_FvP_time="+str(time)+"_"+nona+GD.output_format) close(fig) fig = figure() ax = fig.gca() for eps, ad, nd in zip(epsdata, axisdata, normdata[t]): values = guessor(ad, nd) ax.plot(values, "-o", label=r"$\varepsilon = "+str(eps)+"$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_title(r"guessor at time $T=" + str(time) + r"$") legend(loc="outer right") fig.savefig("guessor_FvP_time="+str(time)+"_"+nona+GD.output_format) close(fig)
def plot_data(axisdata, normdata, number_simulations, number_components, timeindices=None, which_norm="wf"): if which_norm == "wf": nona = "L^2" elif which_norm == "2": nona = "L^2" elif which_norm == "max": nona = "max" # Plot the time series for each simulation fig = figure() ax = fig.gca() for index in xrange(number_simulations): ax.plot(normdata[index], label=r"$\varepsilon = $" + str(axisdata[index])) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Timestep $t$") ax.set_ylabel(r"$\| \phi_f - \phi_h \|_{"+nona+r"}$") ax.set_title(r"Timeseries of $\| \phi_f - \phi_h \|_{"+nona+r"}$") legend(loc="outer right") fig.savefig("convergence_"+nona+"_all"+GD.output_format) close(fig) # Plot the comparison over versus axisdata for t in timeindices: # This version works too for array of different lengths tmp = [] for nd in normdata: tmp.append(nd[t]) tmp = array(tmp) fig = figure() ax = gca() ax.plot(axisdata, tmp, "-o", label=r"$t = " + str(t) + r"$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"$\varepsilon$") ax.set_ylabel(r"$\| \phi_f - \phi_h \|_{"+nona+r"}$") ax.set_title(r"$\| \phi_f - \phi_h \|_{"+nona+r"}$ for different $\varepsilon$ ") legend(loc="outer right") fig.savefig("convergence"+str(t)+"_"+nona+"_comparison"+GD.output_format) close(fig)
def plot_potential(grid, potential, fill=True, imgsize=(8,6)): # Create potential and evaluate eigenvalues potew = potential.evaluate_eigenvalues_at(grid) # Plot the energy surfaces of the potential fig = figure() ax = fig.gca() for index, ew in enumerate(potew): if fill: ax.fill(grid, ew, facecolor="blue", alpha=0.25) ax.plot(grid, ew, label=r"$\lambda_"+str(index)+r"$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.grid(True) 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_operators(parameters, omega, grid, opT, opV, index=0): """Plot the propagation operators T and V """ # Plot the kinetic operator T fig = figure() ax = fig.gca() ax.plot(omega, real(opT), label=r"$\Re T$") ax.plot(omega, imag(opT), label=r"$\Im T$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.grid(True) ax.set_xlabel(r"$\omega$") ax.set_ylabel(r"$T\left(\omega\right)$") legend(loc="outer right") ax.set_title(r"The kinetic operator T") fig.savefig("kinetic_operator_block"+str(index)+GD.output_format) close(fig) # Plot the potential operator V fig = figure() N = parameters["ncomponents"] k = 1 for i in xrange(N): for j in xrange(N): ax = fig.add_subplot(N, N, k) ax.plot(grid, real(opV[i*N+j]), label=r"$\Re V_{"+str(i)+","+str(j)+r"}$") ax.plot(grid, imag(opV[i*N+j]), label=r"$\Im V_{"+str(i)+","+str(j)+r"}$") ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.grid(True) #ax.set_xlim([0, parameters["ngn"]]) ax.set_xlabel(r"$x$") ax.set_ylabel(r"$V_{"+str(i)+","+str(j)+r"}\left(x\right)$") k += 1 fig.savefig("potential_operator_block"+str(index)+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)
def plot_energies(gid, parameters, data): print("Plotting the energies of group '" + str(gid) + "'") N = parameters["ncomponents"] for datum in data: time = datum[0] energies_m = datum[1] energies_c = datum[2] ekin_m = reduce(lambda x, y: x + y, [energies_m[0][i] for i in xrange(N)]) epot_m = reduce(lambda x, y: x + y, [energies_m[1][i] for i in xrange(N)]) ekin_c = reduce(lambda x, y: x + y, [energies_c[0][i] for i in xrange(N)]) epot_c = reduce(lambda x, y: x + y, [energies_c[1][i] for i in xrange(N)]) esum = ekin_m + epot_m + ekin_c + epot_c # Plot the energies for all components fig = figure() for c in xrange(N): ax = subplot(N, 1, c + 1) # Plot the energies of the individual wavepackets ax.plot(time, energies_m[0][c], color="darkgreen", label=r"$E^M_{kin}$") ax.plot(time, energies_c[0][c], color="lightgreen", label=r"$E^C_{kin}$") ax.plot(time, energies_m[1][c], color="blue", label=r"$E^M_{pot}$") ax.plot(time, energies_c[1][c], color="cyan", label=r"$E^C_{pot}$") # Overall energy on component c ax.plot( time, energies_m[0][c] + energies_c[0][c] + energies_m[1][c] + energies_c[1][c], color="black", label=r"$\sum E$", ) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Phi_" + str(c) + r"$") ax.legend(loc="upper left") fig.suptitle("Per-component energies of $\Psi^M$ and $\Psi^C$") fig.savefig("energies_spawn_components_group" + str(gid) + GD.output_format) close(fig) # Plot the sum of the energies of mother and child fig = figure() ax = subplot(2, 1, 1) ax.plot(time, ekin_m, color="green", label=r"$E_{kin}^M$") ax.plot(time, epot_m, color="blue", label=r"$E_{pot}^M$") ax.plot(time, ekin_m + epot_m, color="black", label=r"$E_{kin}^M + E_{pot}^M$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Psi^M$") ax.legend(loc="upper left") ax = subplot(2, 1, 2) ax.plot(time, ekin_c, color="green", label=r"$E_{kin}^C$") ax.plot(time, epot_c, color="blue", label=r"$E_{pot}^C$") ax.plot(time, ekin_c + epot_c, color="black", label=r"$E_{kin}^C + E_{pot}^C$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Psi^C$") ax.legend(loc="upper left") fig.suptitle(r"Energies of $\Psi^M$ (top) and $\Psi^C$ (bottom)") fig.savefig("energies_spawn_packetsum_group" + str(gid) + GD.output_format) close(fig) # Plot the overall sum of energies of mother and child fig = figure() ax = fig.gca() ax.plot(time, ekin_m + epot_m, color="blue", label=r"$E_{kin}^M + E_{pot}^M$") ax.plot(time, ekin_c + epot_c, color="cyan", label=r"$E_{kin}^C + E_{pot}^C$") ax.plot(time, ekin_m + epot_m + ekin_c + epot_c, label=r"$E^M + E^C$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_title(r"Energies of $\Psi^M$ and $\Psi^C$ and $\Psi^M + \Psi^C$") fig.savefig("energies_spawn_sumall_group" + str(gid) + GD.output_format) close(fig) # Plot the drift of the sum of all energies fig = figure() ax = fig.gca() ax.plot(time, esum[0] - esum) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$E(t=0) - E(t)$") ax.set_title(r"Drift of the total energy $E = E^M + E^C$") fig.savefig("energies_spawn_sumall_drift_group" + str(gid) + GD.output_format) close(fig)
def plot_energy(times, ekin, epot, etot): print("Plotting the energies") # 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(times, 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(times, 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(times, 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(times, ekin[-1], label=r"$\sum_i E^{kin}_i$") ax.plot(times, epot[-1], label=r"$\sum_i E^{pot}_i$") # Plot the overall energy of all wave packets ax.plot(times, etot, label=r"$\sum_i E^{kin}_i + \sum_i E^{pot}_i$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_title(r"Energies of the wavepacket $\Psi$") legend(loc="outer right") fig.savefig("energies_etot_canonical"+GD.output_format) close(fig) # Plot the difference between the computation of the overall energy # done in the eigenbasis and the canonical basis. etot_eig = ekin[-1] + epot[-1] fig = figure() ax = fig.gca() ax.plot(times, squeeze(etot) - etot_eig, label=r"$E_{tot}^{eig} - E_{tot}^{can}$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") fig.savefig("etot_canonical_diff"+GD.output_format) close(fig) # Plot the energy drift over time e_orig = etot[0] fig = figure() ax = fig.gca() ax.plot(times, abs(e_orig-(ekin[-1]+epot[-1])), label=r"$|E_O^0 - \left( E_k^0 + E_p^0 \right) |$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") 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 wave packet $\Psi$") fig.savefig("energies_etot_canonical_drift"+GD.output_format) close(fig)
def plot_norms(gid, parameters, data): print("Plotting the norms of group '"+str(gid)+"'") N = parameters["ncomponents"] for datum in data: time = datum[0] norms_m = datum[1] norms_c = datum[2] overall_norm = sqrt(norms_m[-1]**2 + norms_c[-1]**2) # Plot the norms for all components fig = figure() for c in xrange(N): ax = subplot(N,1,c+1) # Plot the norms of the individual wavepackets ax.plot(time, overall_norm, color="black", label=r"$\sqrt{\| \Psi^M \|^2 + \| \Psi^C \|^2}$") ax.plot(time, sqrt(norms_m[c]**2 + norms_c[c]**2), color="gray", label=r"$\sqrt{\| \Phi_"+str(c)+r"^M \|^2 + \| \Phi_"+str(c)+r"^C \|^2}$") ax.plot(time, norms_m[c], color="blue", label=r"$\| \Phi_"+str(c)+r"^M \|$") ax.plot(time, norms_c[c], color="cyan", label=r"$\| \Phi_"+str(c)+r"^C \|$") ax.grid(True) ax.set_ylim(0, 1.1*overall_norm.max()) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Phi_"+str(c)+r"$") ax.legend(loc="upper left") fig.suptitle("Per-component norms of $\Psi^M$ and $\Psi^C$") fig.savefig("norms_spawn_components_group"+str(gid)+GD.output_format) close(fig) # Plot the sum of the norms of mother and child fig = figure() ax = subplot(2,1,1) ax.plot(time, overall_norm, color="black", label=r"$\sqrt{\| \Psi^M \|^2 + \| \Psi^C \|^2}$") ax.plot(time, norms_m[-1], color="blue", label=r"$\| \Psi^M \|$") ax.grid(True) ax.set_ylim(0, 1.1*overall_norm.max()) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Psi^M$") ax.legend(loc="upper left") ax = subplot(2,1,2) ax.plot(time, overall_norm, color="black", label=r"$\sqrt{\| \Psi^M \|^2 + \| \Psi^C \|^2}$") ax.plot(time, norms_c[-1], color="cyan", label=r"$\| \Psi^C \|$") ax.grid(True) ax.set_ylim(0, 1.1*overall_norm.max()) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Psi^C$") ax.legend(loc="upper left") fig.suptitle(r"Norms of $\Psi^M$ (top) and $\Psi^C$ (bottom)") fig.savefig("norms_spawn_sumpacket_group"+str(gid)+GD.output_format) close(fig) # Plot the overall sum of norms of mother and child fig = figure() ax = fig.gca() ax.plot(time, overall_norm, color="black", label=r"$\sqrt{\| \Psi^M \|^2 + \| \Psi^C \|^2}$") ax.plot(time, norms_m[-1], color="blue", label=r"$\| \Psi^M \|$") ax.plot(time, norms_c[-1], color="cyan", label=r"$\| \Psi^C \|$") ax.grid(True) ax.set_ylim(0, 1.1*overall_norm.max()) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_title(r"Norm of $\Psi^M$ and $\Psi^C$ and $\Psi^M + \Psi^C$") fig.savefig("norms_spawn_sumall_group"+str(gid)+GD.output_format) close(fig) # Plot the drift of the sum of all norms fig = figure() ax = fig.gca() ax.plot(time, overall_norm[0] - overall_norm) ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\|\Psi(t=0)\| - \|\Psi(t)\|$") ax.set_title(r"Drift of the total norm $\|\Psi\| = \sqrt{\| \Psi^M \|^2 + \| \Psi^C \|^2}$") fig.savefig("norms_spawn_sumall_drift_group"+str(gid)+GD.output_format) close(fig)
def plot_energies(gid, parameters_o, parameters_s, data_ref, data): print("Plotting the energies of group '"+str(gid)+"'") N = parameters_o["ncomponents"] timegrido = data_ref[0] timeo = data_ref[1] energies_o = data_ref[2] ekin_o = reduce(lambda x,y: x+y, [ energies_o[0][i] for i in xrange(N) ]) epot_o = reduce(lambda x,y: x+y, [ energies_o[1][i] for i in xrange(N) ]) esum_o = ekin_o + epot_o for datum in data: timegrid = datum[0] time = datum[1] energies_m = datum[2] energies_c = datum[3] ekin_m = reduce(lambda x,y: x+y, [ energies_m[0][i] for i in xrange(N) ]) epot_m = reduce(lambda x,y: x+y, [ energies_m[1][i] for i in xrange(N) ]) ekin_c = reduce(lambda x,y: x+y, [ energies_c[0][i] for i in xrange(N) ]) epot_c = reduce(lambda x,y: x+y, [ energies_c[1][i] for i in xrange(N) ]) esum = ekin_m + epot_m + ekin_c + epot_c indo, inds = common_timesteps(timegrido, timegrid) # Plot the energies for all components fig = figure() for c in xrange(N): ax = subplot(N,1,c+1) # Plot the original energies ax.plot(timeo, energies_o[0][c], color="red", label=r"$E^O_{kin}$") ax.plot(timeo, energies_o[1][c], color="orange", label=r"$E^O_{pot}$") ax.plot(timeo, energies_o[0][c] + energies_o[1][c], color="gray", label=r"$E^O$") # Plot the energies of the individual wavepackets ax.plot(time, energies_m[0][c], color="darkgreen", label=r"$E^M_{kin}$") ax.plot(time, energies_c[0][c], color="lightgreen", label=r"$E^C_{kin}$") ax.plot(time, energies_m[1][c], color="blue", label=r"$E^M_{pot}$") ax.plot(time, energies_c[1][c], color="cyan", label=r"$E^C_{pot}$") # Overall energy on component c ax.plot(time, energies_m[0][c] + energies_c[0][c] + energies_m[1][c] + energies_c[1][c], color="black", label=r"$\sum E$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Phi_"+str(c)+r"$") ax.legend(loc="upper left") fig.suptitle("Per-component energies of $\Psi^M$ and $\Psi^C$") fig.savefig("energies_compare_components_group"+str(gid)+GD.output_format) close(fig) # Plot the sum of the energies of mother and child fig = figure() ax = subplot(2,1,1) ax.plot(timeo, ekin_o, color="red", label=r"$E_{kin}^O$") ax.plot(timeo, epot_o, color="orange", label=r"$E_{pot}^O$") ax.plot(timeo, ekin_o + epot_o, color="magenta", label=r"$E^O$") ax.plot(time, ekin_m, color="green", label=r"$E_{kin}^M$") ax.plot(time, epot_m, color="blue", label=r"$E_{pot}^M$") ax.plot(time, ekin_m + epot_m, color="black", label=r"$E_{kin}^M + E_{pot}^M$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Psi^M$") ax.legend(loc="upper left") ax = subplot(2,1,2) ax.plot(timeo, ekin_o, color="red", label=r"$E_{kin}^O$") ax.plot(timeo, epot_o, color="orange", label=r"$E_{pot}^O$") ax.plot(timeo, ekin_o + epot_o, color="magenta", label=r"$E^O$") ax.plot(time, ekin_c, color="green", label=r"$E_{kin}^C$") ax.plot(time, epot_c, color="blue", label=r"$E_{pot}^C$") ax.plot(time, ekin_c + epot_c, color="black", label=r"$E_{kin}^C + E_{pot}^C$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Psi^C$") ax.legend(loc="upper left") fig.suptitle(r"Energies of $\Psi^M$ (top) and $\Psi^C$ (bottom)") fig.savefig("energies_compare_packetsum_group"+str(gid)+GD.output_format) close(fig) # Plot the overall sum of energies of mother and child fig = figure() ax = fig.gca() ax.plot(timeo, ekin_o + epot_o, color="orange", label=r"$E_{kin}^O + E_{pot}^O$") ax.plot(time, ekin_m + epot_m, color="blue", label=r"$E_{kin}^M + E_{pot}^M$") ax.plot(time, ekin_c + epot_c, color="cyan", label=r"$E_{kin}^C + E_{pot}^C$") ax.plot(time, ekin_m + epot_m + ekin_c + epot_c, color="black", label=r"$E^M + E^C$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_title(r"Energies of $\Psi^M$ and $\Psi^C$ and $\Psi^M + \Psi^C$") fig.savefig("energies_compare_sumall_group"+str(gid)+GD.output_format) close(fig) # Plot the drift of the sum of all energies fig = figure() ax = fig.gca() ax.plot(timeo, esum_o[0] - esum_o, color="orange") ax.plot(time, esum[0] - esum, color="blue") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$E(t=0) - E(t)$") ax.set_title(r"Drift of the total energy $E = E^M + E^C$") fig.savefig("energies_compare_sumall_drift_group"+str(gid)+GD.output_format) close(fig) # Plot difference of energies between original and spawned # Plot the energies for all components fig = figure() for c in xrange(N): ax = subplot(N,1,c+1) # Plot the original energies ax.plot(timeo[indo], energies_o[0][c][indo] - (energies_m[0][c][inds] + energies_c[0][c][inds]), color="green", label=r"$E^O_{kin} - E^S_{kin}$") ax.plot(timeo[indo], energies_o[1][c][indo] - (energies_m[1][c][inds] + energies_c[1][c][inds]), color="blue", label=r"$E^O_{pot} - E^S_{pot}$") ax.plot(timeo[indo], energies_o[0][c][indo] + energies_o[1][c][indo] - (energies_m[0][c][inds] + energies_c[0][c][inds] + energies_m[1][c][inds] + energies_c[1][c][inds]), color="red", label=r"$E^O - E^S$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") ax.set_xlabel(r"Time $t$") ax.set_ylabel(r"$\Phi_"+str(c)+r"$") ax.legend(loc="upper left") fig.suptitle("Per-component energy difference $E^O - E^S$") fig.savefig("energies_compare_components_diff_group"+str(gid)+GD.output_format) close(fig) # Plot the overall sum of energies of mother and child fig = figure() ax = fig.gca() ax.plot(timeo[indo], ekin_o[indo] - (ekin_m[inds] + ekin_c[inds]), color="green", label=r"$E_{kin}^O + E_{kin}^S$") ax.plot(timeo[indo], epot_o[indo] - (epot_m[inds] + epot_c[inds]), color="blue", label=r"$E_{pot}^O + E_{pot}^S$") ax.plot(timeo[indo], ekin_o[indo] + epot_o[indo] - (ekin_m[inds] + epot_m[inds] + ekin_c[inds] + epot_c[inds]), color="red", label=r"$E^O + E^S$") ax.grid(True) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") legend(loc="outer right") ax.set_xlabel(r"Time $t$") ax.set_title(r"Energy difference $E^O - E^S$") fig.savefig("energies_compare_sumall_diff_group"+str(gid)+GD.output_format) close(fig)