예제 #1
0
def compute_evaluate_wavepackets(iom, basis="eigen", blockid=0):
    """Evaluate a homogeneous Hagdorn wavepacket on a given grid for each timestep.
    :param iom: An ``IOManager`` instance providing the simulation data.
    :param basis: The basis where the evaluation is done. Can be 'eigen' or 'canonical'.
    :param blockid: The data block from which the values are read.
    """
    parameters = iom.load_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 = PotentialFactory().create_potential(parameters)

    # Retrieve simulation data
    if iom.has_grid(blockid=blockid):
        grid = iom.load_grid(blockid=blockid)
    else:
        grid = iom.load_grid(blockid="global")

    params = iom.load_wavepacket_parameters(blockid=blockid)
    coeffs = iom.load_wavepacket_coefficients(blockid=blockid)

    # A data transformation needed by API specification
    coeffs = [ [ coeffs[i,j,:] for j in xrange(parameters["ncomponents"]) ] for i in xrange(nrtimesteps)]

    # We want to save wavefunctions, thus add a data slot to the data file
    iom.add_wavefunction(parameters, timeslots=nrtimesteps, blockid=blockid)

    # Hack for allowing data blocks with different basis size than the global one
    # todo: remove when we got local parameter sets
    parameters.update_parameters({"basis_size": coeffs[0][0].shape[0]})

    HAWP = HagedornWavepacket(parameters)
    HAWP.set_quadrature(None)

    WF = WaveFunction(parameters)
    WF.set_grid(grid)

    # Iterate over all timesteps
    for i, step in enumerate(timesteps):
        print(" Evaluating homogeneous wavepacket at timestep "+str(step))

        # Configure the wavepacket
        HAWP.set_parameters(params[i])
        HAWP.set_coefficients(coeffs[i])

        # Project to the eigenbasis if desired
        if basis == "eigen":
            HAWP.project_to_eigen(Potential)

        # 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)
예제 #2
0
def plot_frames_homogeneous(iom, blockid=0, view=None):
    """
    :param iom: An ``IOManager`` instance providing the simulation data.
    """
    parameters = iom.load_parameters()

    # Number of time steps we saved
    timesteps = iom.load_wavepacket_timegrid(blockid=blockid)
    nrtimesteps = timesteps.shape[0]

    # Initialize a Hagedorn wavepacket with the data
    Potential = PotentialFactory().create_potential(parameters)

    # Retrieve simulation data
    grid = iom.load_grid(blockid="global")
    params = iom.load_wavepacket_parameters(blockid=blockid)
    coeffs = iom.load_wavepacket_coefficients(blockid=blockid)

    # A data transformation needed by API specification
    coeffs = [ [ coeffs[i,j,:] for j in xrange(parameters["ncomponents"]) ] for i in xrange(nrtimesteps)]

    # Hack for allowing data blocks with different basis size than the global one
    # todo: remove when we got local parameter sets
    parameters.update_parameters({"basis_size": coeffs[0][0].shape[0]})

    HAWP = HagedornWavepacket(parameters)
    HAWP.set_quadrature(None)

    # Iterate over all timesteps
    for i, step in enumerate(timesteps):
        print(" Plotting frame of timestep "+str(step))

        # Configure the wavepacket and project to the eigenbasis.
        HAWP.set_parameters(params[i])
        HAWP.set_coefficients(coeffs[i])
        HAWP.project_to_eigen(Potential)

        values = HAWP.evaluate_at(grid, prefactor=True)
        coeffi = HAWP.get_coefficients()

        plot_frame(step, parameters, grid, values, coeffi, index=blockid, view=view)

    print(" Plotting frames finished")
예제 #3
0
    # Transform the nodes
    nodes1 = squeeze(HQ1.transform_nodes(WP1.get_parameters(), WP1.eps))
    nodes2 = squeeze(HQ2.transform_nodes(WP2.get_parameters(), WP2.eps))
    nodes12 = squeeze(IHQ.transform_nodes(Pibra, WP2.get_parameters(), WP1.eps))

    # Compute inner products
    Q1 = IHQ.quadrature(WP1, WP1, summed=True)
    Q2 = IHQ.quadrature(WP2, WP2, summed=True)
    Q12 = IHQ.quadrature(WP1, WP2, summed=True)

    quads1.append(Q1)
    quads2.append(Q2)
    quads12.append(Q12)

    # Evaluate the packets
    y = WP1.evaluate_at(x, prefactor=True, component=0)
    z = WP2.evaluate_at(x, prefactor=True, component=0)

    figure()
    plot(x, conj(y) * y, "b")
    plot(x, conj(z) * z, "g")
    plot(x, conj(y) * z, "r")
    plot(nodes1, zeros(nodes1.shape), "ob")
    plot(nodes2, zeros(nodes2.shape), "og")
    plot(nodes12, zeros(nodes12.shape), "or")
    ylim([-0.2, 3])
    title(r"$\langle \Psi_1 | \Psi_2 \rangle$ = " + str(Q12))
    savefig("mixed_quadrature_" + (5 - len(str(index))) * "0" + str(index) + ".png")
    close()

omega_2 = arange(0, params["ngn"]/2.0)
omega = hstack([omega_1, omega_2])

k = omega / (2*params["f"] * pi)
#k = omega / params["ngn"]


# A HAWP
HAWP = HagedornWavepacket(params)
HAWP.set_quadrature(None)

HAWP.set_parameters((1j, 1, 0, 3, -2))
HAWP.set_coefficient(0,2,1)

# Evaluate in real space
y = HAWP.evaluate_at(x)[0]

# Transform to Fourier space
HAWP.to_fourier_space()
# Evaluate in Fourier space
w = HAWP.evaluate_at(k)[0]

HAWP.to_real_space()
# Evaluate in real space again
z = HAWP.evaluate_at(x)[0]


figure()
plotcf(x, angle(y), abs(y))

figure()
예제 #5
0
@copyright: Copyright (C) 2010, 2011 R. Bourquin
@license: Modified BSD License
"""

from numpy import *
from matplotlib.pyplot import *

from WaveBlocks import HagedornWavepacket
from WaveBlocks.Plot import plotcf

nmax = 10
amp0 = 0.5

params = {}
params["eps"] = 0.2
params["basis_size"] = nmax
params["ncomponents"] = 1

HAWP = HagedornWavepacket(params)
HAWP.set_parameters((1.0j, 1.0, 0.0, -1.0, 0.0))

for i in range(0,nmax):
    HAWP.set_coefficient(0, i, amp0/ 2**i)

x = linspace(-4,4,4000)
y = HAWP.evaluate_at(x, prefactor=True, component=0)

figure()
plotcf(x, angle(y), conj(y)*y)
show()