def plot_frames( iom, blockid=0 ): #, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, imgsize=(12,9)): parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return G = BlockFactory().create_grid(parameters) V = BlockFactory().create_potential(parameters) print(G.get_extensions()) WF = WaveFunction(parameters) WF.set_grid(G) BT = BasisTransformationWF(V) BT.set_grid(G) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) u, v = G.get_nodes(split=True, flat=False) u = real(u) v = real(v) N = WF.get_number_components() for step in timegrid: print(" Plotting frame of timestep # " + str(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in xrange(parameters["ncomponents"])] WF.set_values(values) # Transform the values to the eigenbasis # TODO: improve this: if parameters["algorithm"] == "fourier": BT.transform_to_eigen(WF) else: pass Psi = WF.get_values() fig = figure() for level in xrange(N): z = Psi[level] subplot(N, 1, level + 1) plotcm(z, darken=0.3) savefig("wavefunction_level_" + str(level) + "_timestep_" + (5 - len(str(step))) * "0" + str(step) + ".png") close(fig) print(" Plotting frames finished")
def plot_frames(iom, blockid=0): parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return G = BlockFactory().create_grid(parameters) V = BlockFactory().create_potential(parameters) WF = WaveFunction(parameters) WF.set_grid(G) BT = BasisTransformationWF(V) BT.set_grid(G) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) u, v = G.get_nodes(split=True, flat=False) u = real(u) v = real(v) N = WF.get_number_components() for step in timegrid: print(" Plotting frame of timestep # " + str(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [ wave[j,...] for j in xrange(parameters["ncomponents"]) ] WF.set_values(values) # Transform the values to the eigenbasis # TODO: improve this: if parameters["algorithm"] == "fourier": BT.transform_to_eigen(WF) else: pass Psi = WF.get_values() for level in xrange(N): z = Psi[level] # Plot the probability densities projected to the eigenbasis fig = mlab.figure(size=(800,700)) surfcf(u, v, angle(z), abs(z)) #mlab.contour_surf(u, v, abs(z)) #mlab.outline() #mlab.axes() mlab.savefig("wavefunction_level_"+str(level)+"_timestep_"+(5-len(str(step)))*"0"+str(step)+".png") mlab.close(fig) print(" Plotting frames finished")
def plot_frames(iom, blockid=0):#, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, imgsize=(12,9)): parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return G = BlockFactory().create_grid(parameters) V = BlockFactory().create_potential(parameters) print(G.get_extensions()) WF = WaveFunction(parameters) WF.set_grid(G) BT = BasisTransformationWF(V) BT.set_grid(G) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) u, v = G.get_nodes(split=True, flat=False) u = real(u) v = real(v) N = WF.get_number_components() for step in timegrid: print(" Plotting frame of timestep # " + str(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [ wave[j,...] for j in xrange(parameters["ncomponents"]) ] WF.set_values(values) # Transform the values to the eigenbasis # TODO: improve this: if parameters["algorithm"] == "fourier": BT.transform_to_eigen(WF) else: pass Psi = WF.get_values() fig = figure() for level in xrange(N): z = Psi[level] subplot(N,1,level+1) plotcm(z, darken=0.3) savefig("wavefunction_level_"+str(level)+"_timestep_"+(5-len(str(step)))*"0"+str(step)+".png") close(fig) print(" Plotting frames finished")
def plot_frames(PP, iom, blockid=0, load=False, eigentransform=False, timerange=None, sparsify=10, view=None, interactive=False, path='.'): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return if PP is None: PP = parameters if load is True: # TODO: Implement reshaping raise NotImplementedError("Loading of 2D grids is not implemented") else: G = BlockFactory().create_grid(PP) if eigentransform: V = BlockFactory().create_potential(parameters) BT = BasisTransformationWF(V) BT.set_grid(G) WF = WaveFunction(parameters) WF.set_grid(G) N = WF.get_number_components() timegrid = iom.load_wavefunction_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") u, v = G.get_nodes(split=True, flat=False) u = real(u[::sparsify, ::sparsify]) v = real(v[::sparsify, ::sparsify]) # View if view is not None: if view[0] is None: view[0] = u.min() if view[1] is None: view[1] = u.max() if view[2] is None: view[2] = v.min() if view[3] is None: view[3] = v.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) # Load the data wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in range(parameters["ncomponents"])] WF.set_values(values) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(WF) Psi = WF.get_values() for level in range(N): # Wavefunction data z = Psi[level] z = z.reshape(G.get_number_nodes())[::sparsify, ::sparsify] # View if view is not None: if view[4] is None: view[4] = 0.0 if view[5] is None: view[5] = 1.1 * abs(z).max() # Plot # if not interactive: # mlab.options.offscreen = True fig = mlab.figure(size=(800, 700)) surfcf(u, v, angle(z), abs(z), view=view) mlab.draw() if interactive: mlab.show() else: mlab.savefig(os.path.join("wavefunction_surface_block_%s_level_%d_timestep_%07d.png" % (blockid, level, step))) mlab.close(fig)
def compute_evaluate_wavepackets(pp, iom, blockid=0, eigentrafo=True): """Evaluate a homogeneous Hagedorn wavepacket on a given grid for each timestep. :param pp: An :py:class:`ParameterProvider` instance providing the grid data. :param iom: An :py:class:`IOManager` instance providing the simulation data. :param blockid: The data block from which the values are read. :param eigentrafo: Whether or not do an eigentransformation before evaluation is done. """ parameters = iom.load_parameters() if pp is None: pp = parameters # Number of time steps we saved timesteps = iom.load_wavepacket_timegrid(blockid=blockid) nrtimesteps = timesteps.shape[0] # Prepare the potential for basis transformations Potential = BlockFactory().create_potential(parameters) grid = BlockFactory().create_grid(pp) # We want to save wavefunctions, thus add a data slot to the data file d = {"ncomponents": parameters["ncomponents"], "number_nodes": pp["number_nodes"], "dimension": parameters["dimension"]} iom.add_grid(d, blockid=blockid) iom.add_wavefunction(d, timeslots=nrtimesteps, flat=True, blockid=blockid) iom.save_grid(grid.get_nodes(), blockid=blockid) # Initialize a Hagedorn wavepacket with the data descr = iom.load_wavepacket_description(blockid=blockid) HAWP = BlockFactory().create_wavepacket(descr) # Basis transformator if eigentrafo is True: BT = BasisTransformationHAWP(Potential) BT.set_matrix_builder(HAWP.get_innerproduct()) # Basis shapes BS_descr = iom.load_wavepacket_basisshapes(blockid=blockid) BS = {} for ahash, descr in BS_descr.items(): BS[ahash] = BlockFactory().create_basis_shape(descr) WF = WaveFunction(parameters) WF.set_grid(grid) # Iterate over all timesteps for i, step in enumerate(timesteps): print(" Evaluating homogeneous wavepacket at timestep %d" % step) # Retrieve simulation data params = iom.load_wavepacket_parameters(timestep=step, blockid=blockid, key=("q", "p", "Q", "P", "S", "adQ")) hashes, coeffs = iom.load_wavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid) # Configure the wavepacket HAWP.set_parameters(params, key=("q", "p", "Q", "P", "S", "adQ")) HAWP.set_basis_shapes([BS[int(ha)] for ha in hashes]) HAWP.set_coefficients(coeffs) # Transform to the eigenbasis. if eigentrafo is True: BT.transform_to_eigen(HAWP) # Evaluate the wavepacket values = HAWP.evaluate_at(grid, prefactor=True) WF.set_values(values) # Save the wave function iom.save_wavefunction(WF.get_values(), timestep=step, blockid=blockid)
def plot_frames(PP, iom, blockid=0, timerange=None, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=True, gridblockid=None, imgsize=(12, 9), path='.'): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. :param view: The aspect ratio. :param plotphase: Whether to plot the complex phase. (slow) :param plotcomponents: Whether to plot the real/imaginary parts.. :param plotabssqr: Whether to plot the absolute value squared. """ parameters = iom.load_parameters() if not parameters["dimension"] == 1: print("No two-dimensional wavefunction, silent return!") return if PP is None: PP = parameters if load is True: if gridblockid is None: gridblockid = blockid print("Loading grid data from datablock '%s'" % gridblockid) G = iom.load_grid(blockid=gridblockid) grid = real(G.reshape(-1)) else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = real(G.get_nodes(flat=True).reshape(-1)) # View if view[0] is None: view[0] = grid.min() if view[1] is None: view[1] = grid.max() timegrid = iom.load_wavefunction_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in range(parameters["ncomponents"])] # Plot fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"], 1, index + 1) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") if plotcomponents is True: ax.plot(grid, real(component)) ax.plot(grid, imag(component)) ax.set_ylabel(r"$\Re \varphi_{%d}, \Im \varphi_{%d}$" % (index, index)) if plotabssqr is True: ax.plot(grid, real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) if plotphase is True: plotcf(grid, angle(component), real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) ax.set_xlabel(r"$x$") # Set the aspect window ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if "dt" in parameters: fig.suptitle(r"$\Psi$ at time $%f$" % (step * parameters["dt"])) else: fig.suptitle(r"$\Psi$") fig.savefig( os.path.join( path, "wavefunction_block_%s_timestep_%07d.png" % (blockid, step))) close(fig)
def plot_frames(PP, iom, blockid=0, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=True, gridblockid=None, imgsize=(12,9)): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. :param view: The aspect ratio. :param plotphase: Whether to plot the complex phase. (slow) :param plotcomponents: Whether to plot the real/imaginary parts.. :param plotabssqr: Whether to plot the absolute value squared. """ parameters = iom.load_parameters() if not parameters["dimension"] == 1: print("No wavefunction of one space dimensions, silent return!") return if PP is None: PP = parameters if load is True: print("Loading grid data from datablock 'global'") if gridblockid is None: gridblockid = blockid G = iom.load_grid(blockid=gridblockid) G = G.reshape((1, -1)) grid = G else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = G.get_nodes(flat=True) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) for step in timegrid: print(" Plotting frame of timestep # " + str(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [ wave[j,...] for j in xrange(parameters["ncomponents"]) ] # Plot the probability densities projected to the eigenbasis fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"],1,index+1) ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y") if plotcomponents is True: ax.plot(squeeze(grid), real(component)) ax.plot(squeeze(grid), imag(component)) ax.set_ylabel(r"$\Re \varphi_"+str(index)+r", \Im \varphi_"+str(index)+r"$") if plotabssqr is True: ax.plot(squeeze(grid), component*conj(component)) ax.set_ylabel(r"$\langle \varphi_"+str(index)+r"| \varphi_"+str(index)+r"\rangle$") if plotphase is True: plotcf(squeeze(grid), angle(component), component*conj(component)) ax.set_ylabel(r"$\langle \varphi_"+str(index)+r"| \varphi_"+str(index)+r"\rangle$") ax.set_xlabel(r"$x$") # Set the aspect window if view is not None: ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if parameters.has_key("dt"): fig.suptitle(r"$\Psi$ at time $"+str(step*parameters["dt"])+r"$") else: fig.suptitle(r"$\Psi$") fig.savefig("wavefunction_block"+str(blockid)+"_"+ (7-len(str(step)))*"0"+str(step) +GD.output_format) close(fig) print(" Plotting frames finished")
def plot_frames(PP, iom, blockid=0, eigentransform=False, timerange=None, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=False, gridblockid=None, imgsize=(12, 9), path='.'): """Plot the wavepacket for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() BF = BlockFactory() if not parameters["dimension"] == 1: print("No one-dimensional wavepacket, silent return!") return if PP is None: PP = parameters if load is True: if gridblockid is None: gridblockid = blockid print("Loading grid data from datablock '{}'".format(gridblockid)) G = iom.load_grid(blockid=gridblockid) grid = real(G.reshape(-1)) else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = real(G.get_nodes(flat=True).reshape(-1)) if eigentransform: V = BF.create_potential(parameters) BT = BasisTransformationHAWP(V) timegrid = iom.load_wavepacket_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") # View if view is not None: if view[0] is None: view[0] = grid.min() if view[1] is None: view[1] = grid.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) HAWP = iom.load_wavepacket(step, blockid=blockid) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(HAWP) values = HAWP.evaluate_at(G.get_nodes(), prefactor=True, component=0) # Plot fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"], 1, index + 1) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") if plotcomponents is True: ax.plot(grid, real(component)) ax.plot(grid, imag(component)) ax.set_ylabel(r"$\Re \varphi_{%d}, \Im \varphi_{%d}$" % (index, index)) if plotabssqr is True: ax.plot(grid, real(component * conj(component))) ax.set_ylabel(r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) if plotphase is True: plotcf(grid, angle(component), real(component * conj(component))) ax.set_ylabel(r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) ax.set_xlabel(r"$x$") # Set the aspect window ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if "dt" in parameters: fig.suptitle(r"$\Psi$ at time $%f$" % (step * parameters["dt"])) else: fig.suptitle(r"$\Psi$") fig.savefig(os.path.join(path, "wavepacket_block_%s_timestep_%07d.png" % (blockid, step))) close(fig)
def plot_frames(PP, iom, blockid=0, load=False, eigentransform=False, timerange=None, sparsify=10, view=None, interactive=False, path='.'): """Plot the wave function for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return if PP is None: PP = parameters if load is True: # TODO: Implement reshaping raise NotImplementedError("Loading of 2D grids is not implemented") else: G = BlockFactory().create_grid(PP) if eigentransform: V = BlockFactory().create_potential(parameters) BT = BasisTransformationWF(V) BT.set_grid(G) WF = WaveFunction(parameters) WF.set_grid(G) N = WF.get_number_components() timegrid = iom.load_wavefunction_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") u, v = G.get_nodes(split=True, flat=False) u = real(u[::sparsify, ::sparsify]) v = real(v[::sparsify, ::sparsify]) # View if view is not None: if view[0] is None: view[0] = u.min() if view[1] is None: view[1] = u.max() if view[2] is None: view[2] = v.min() if view[3] is None: view[3] = v.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) # Load the data wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [wave[j, ...] for j in range(parameters["ncomponents"])] WF.set_values(values) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(WF) Psi = WF.get_values() for level in range(N): # Wavefunction data z = Psi[level] z = z.reshape(G.get_number_nodes())[::sparsify, ::sparsify] # View if view is not None: if view[4] is None: view[4] = 0.0 if view[5] is None: view[5] = 1.1 * abs(z).max() # Plot # if not interactive: # mlab.options.offscreen = True fig = mlab.figure(size=(800, 700)) surfcf(u, v, angle(z), abs(z), view=view) mlab.draw() if interactive: mlab.show() else: mlab.savefig( os.path.join( "wavefunction_surface_block_%s_level_%d_timestep_%07d.png" % (blockid, level, step))) mlab.close(fig)
def plot_frames(PP, iom, blockid=0, load=False): r""" """ parameters = iom.load_parameters() if not parameters["dimension"] == 2: print("No wavefunction of two space dimensions, silent return!") return if PP is None: PP = parameters if load is True: # TODO: Implement reshaping raise NotImplementedError("Loading of 2D grids is not implemented") #G = iom.load_grid(blockid=blockid) #G = grid.reshape((1, -1)) else: G = BlockFactory().create_grid(PP) V = BlockFactory().create_potential(parameters) WF = WaveFunction(parameters) WF.set_grid(G) BT = BasisTransformationWF(V) BT.set_grid(G) timegrid = iom.load_wavefunction_timegrid(blockid=blockid) u, v = G.get_nodes(split=True, flat=False) u = real(u) v = real(v) N = WF.get_number_components() for step in timegrid: print(" Plotting frame of timestep # " + str(step)) wave = iom.load_wavefunction(blockid=blockid, timestep=step) values = [ wave[j,...] for j in xrange(parameters["ncomponents"]) ] WF.set_values(values) # Transform the values to the eigenbasis # TODO: improve this: if parameters["algorithm"] == "fourier": BT.transform_to_eigen(WF) else: pass Psi = WF.get_values() for level in xrange(N): z = Psi[level] z = z.reshape(G.get_number_nodes()) # Plot the probability densities projected to the eigenbasis fig = mlab.figure(size=(800,700)) surfcf(u, v, angle(z), abs(z)) #mlab.contour_surf(u, v, abs(z)) #mlab.outline() #mlab.axes() mlab.savefig("wavefunction_level_"+str(level)+"_timestep_"+(5-len(str(step)))*"0"+str(step)+".png") mlab.close(fig) print(" Plotting frames finished")
def plot_frames(PP, iom, blockid=0, eigentransform=False, timerange=None, view=None, plotphase=True, plotcomponents=False, plotabssqr=False, load=False, gridblockid=None, imgsize=(12, 9), path='.'): """Plot the wavepacket for a series of timesteps. :param iom: An :py:class:`IOManager` instance providing the simulation data. """ parameters = iom.load_parameters() BF = BlockFactory() if not parameters["dimension"] == 1: print("No one-dimensional wavepacket, silent return!") return if PP is None: PP = parameters if load is True: if gridblockid is None: gridblockid = blockid print("Loading grid data from datablock '{}'".format(gridblockid)) G = iom.load_grid(blockid=gridblockid) grid = real(G.reshape(-1)) else: print("Creating new grid") G = BlockFactory().create_grid(PP) grid = real(G.get_nodes(flat=True).reshape(-1)) if eigentransform: V = BF.create_potential(parameters) BT = BasisTransformationHAWP(V) timegrid = iom.load_wavepacket_timegrid(blockid=blockid) if timerange is not None: if len(timerange) == 1: I = (timegrid == timerange) else: I = ((timegrid >= timerange[0]) & (timegrid <= timerange[1])) if any(I): timegrid = timegrid[I] else: raise ValueError("No valid timestep remains!") # View if view is not None: if view[0] is None: view[0] = grid.min() if view[1] is None: view[1] = grid.max() for step in timegrid: print(" Plotting frame of timestep # {}".format(step)) HAWP = iom.load_wavepacket(step, blockid=blockid) # Transform the values to the eigenbasis if eigentransform: BT.transform_to_eigen(HAWP) values = HAWP.evaluate_at(G.get_nodes(), prefactor=True, component=0) # Plot fig = figure(figsize=imgsize) for index, component in enumerate(values): ax = fig.add_subplot(parameters["ncomponents"], 1, index + 1) ax.ticklabel_format(style="sci", scilimits=(0, 0), axis="y") if plotcomponents is True: ax.plot(grid, real(component)) ax.plot(grid, imag(component)) ax.set_ylabel(r"$\Re \varphi_{%d}, \Im \varphi_{%d}$" % (index, index)) if plotabssqr is True: ax.plot(grid, real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) if plotphase is True: plotcf(grid, angle(component), real(component * conj(component))) ax.set_ylabel( r"$\langle \varphi_{%d} | \varphi_{%d} \rangle$" % (index, index)) ax.set_xlabel(r"$x$") # Set the aspect window ax.set_xlim(view[:2]) ax.set_ylim(view[2:]) if "dt" in parameters: fig.suptitle(r"$\Psi$ at time $%f$" % (step * parameters["dt"])) else: fig.suptitle(r"$\Psi$") fig.savefig( os.path.join( path, "wavepacket_block_%s_timestep_%07d.png" % (blockid, step))) close(fig)