def load_data(resultspath):
    # Sort the data from different simulations
    dirs = FT.get_result_dirs(resultspath)
    resultsdir = FT.sort_by(dirs, "eps")

    number_simulations = FT.get_number_simulations(resultspath)

    ekindata = []
    epotdata = []
    axisdata = []

    iom = IOManager()

    for resultdir in resultsdir:
        resultsfile = FT.get_results_file(resultdir)

        print(" Reading " + resultsfile)

        iom.open_file(filename=resultsfile)
        parameters = iom.load_parameters()
        number_components = parameters["ncomponents"]
        axisdata.append(parameters["eps"])

        ekin, epot = iom.load_energy()
        ekindata.append(ekin)
        epotdata.append(epot)

    iom.finalize()

    return (axisdata, ekindata, epotdata, number_simulations, number_components)
def load_data(resultspath):
    # Sort the data from different simulations according to the filenames
    dirs = FT.get_result_dirs(resultspath)
    resultsdir = FT.sort_by(dirs, "eps")

    number_simulations = FT.get_number_simulations(resultspath)

    normdata = []
    axisdata = []

    iom = IOManager()

    for resultdir in resultsdir:
        resultsfile = FT.get_results_file(resultdir)

        print(" Reading " + resultsfile)

        iom.open_file(filename=resultsfile)
        parameters = iom.load_parameters()
        number_components = parameters["ncomponents"]
        axisdata.append(parameters["eps"])

        norms = iom.load_norm()
        normdata.append(norms)

    iom.finalize()

    return (axisdata, normdata, number_simulations, number_components)
Example #3
0
        # Set the aspect window
        if view is not None:
            ax.set_xlim(view)
        ax.grid(True)
        ax.set_xlabel(r"$x$")
        ax.set_ylabel(r"Error on $\Psi$")
        fig.savefig("wavefunction_spawn_error_sum_group"+str(gid)+ (5-len(str(step)))*"0"+str(step) +GD.output_format)
        close(fig)

    print(" Plotting frames finished")




if __name__ == "__main__":
    iom_o = IOManager()
    iom_s = IOManager()

    # NOTE
    #
    # first cmd-line data file is spawning data
    # second cmd-line data file is reference data

    # Read file with new simulation data
    try:
        iom_s.open_file(filename=sys.argv[1])
    except IndexError:
        iom_s.open_file()

    # Read file with original reference simulation data
    try:
def load_data(resultsdir, evaluation_times, which_norm="wf"):
    """This script assumes filename specification: something_eps=..._dt=..._[h|f]_other_things.
    We group the simulations first by eps and then by dt.
    """
    iom_f = IOManager()
    iom_h = IOManager()

    # Group the data from different simulations according to epsilon
    ids = get_result_dirs(resultsdir)
    eps_groups = group_by(ids, "eps")

    # Data structures for results
    epsdata = [ None for i in xrange(len(eps_groups)) ]
    axisdata = [ [] for i in xrange(len(eps_groups)) ]
    normdata = [ [ [] for i in xrange(len(eps_groups)) ] for t in xrange(len(evaluation_times)) ]

    # Loop over all simulations, grouped by same eps value
    for index, eps_group in enumerate(eps_groups):

        # Partition into fourier and hagedorn simulations
        dirs_f = gather_all(eps_group, "algorithm=fourier")
        dirs_h = gather_all(eps_group, "algorithm=hagedorn")

        if len(dirs_f) != len(dirs_h):
            raise ValueError("Found different number of fourier and hagedorn simulations!")

        # And sort by dt value
        dirs_f = sort_by(dirs_f, "dt")
        dirs_h = sort_by(dirs_h, "dt")

        # Loop over all simulations with same eps values sorted by size of dt
        for dir_f, dir_h in zip(dirs_f, dirs_h):

            print("Comparing simulation " + dir_h + " with " + dir_f)

            resultsfile_f = get_results_file(dir_f)
            iom_f.open_file(filename=resultsfile_f)

            resultsfile_h = get_results_file(dir_h)
            iom_h.open_file(filename=resultsfile_h)

            # Read the parameters
            parameters_f = iom_f.load_parameters()
            parameters_h = iom_h.load_parameters()

            # Scalar parameter of the x axis
            axisdata[index].append(parameters_f["dt"])

            # Get the data
            grid = iom_f.load_grid(blockid="global")

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

            # Convert times to timesteps using the time manager
            tm = parameters_f.get_timemanager()

            # Loop over all times
            for i, time in enumerate(evaluation_times):
                print(" at time T: " + str(time))

                step = tm.compute_timestep(time)

                data_f = iom_f.load_wavefunction(timestep=step)
                data_h = iom_h.load_wavefunction(timestep=step)

                # Compute the norm  || u_f - u_h || for all timesteps
                data_diff = data_f - data_h

                if which_norm == "wf":
                    WF.set_values( [ data_diff[0,...] ] )
                    no = WF.get_norm(summed=True)
                elif which_norm == "2":
                    no = norm( data_diff[0,...] )
                elif which_norm == "max":
                    no = max( data_diff[0,...] )

                # Append norm values to global data structure
                normdata[i][index].append(no)

        # Scalar parameter of the different curves
        # We add this here because the simulation parameters are
        # already loaded but not overwritten yet be the next iteration
        # Remember: we need only a single epsilon out of each eps_group.
        epsdata[index] = parameters_f["eps"]

    iom_f.finalize()
    iom_h.finalize()

    # Convert lists to arrays
    epsdata = array(epsdata)
    axisdata = [ array(item) for item in axisdata ]

    return (times, epsdata, axisdata, normdata)
Example #5
0
        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)


if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    parameters = iom.load_parameters()
    potential = PotentialFactory().create_potential(parameters)
    grid = iom.load_grid(blockid="global")

    plot_potential(grid, potential, fill=False)

    iom.finalize()
        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)



if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    read_all_datablocks(iom)

    iom.finalize()
            ax.plot(timegrid, imag(Qhist[j]), "m")

            ax.plot(timegrid, data, "r")

            ax.grid(True)
            ax.ticklabel_format(style="sci", scilimits=(0,0), axis="y")
            ax.set_xlabel(r"Time $t$")
            ax.set_ylabel(r"$-\frac{\Im(\overline{r_k}-r_l)}{2}$")
            ax.set_title(r"Mixing of $Q_0$ from $\Pi_"+str(i)+r"$ and $\Pi_"+str(j)+r"$")

    fig.savefig("wavepacket_parameter_mixing_Q_block"+str(blockid)+GD.output_format)
    close(fig)


if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    # Iterate over all blocks
    for blockid in iom.get_block_ids():
        print("Plotting mixing relation of data block '"+str(blockid)+"'")

        # See if we have an inhomogeneous wavepacket in the current data block
        if iom.has_inhomogwavepacket(blockid=blockid):
            data = read_data_inhomogeneous(iom, blockid=blockid)
            plot_data(blockid, *data)
Example #8
0
def load_data(resultspath, which_norm="wf"):
    # Sort the data from different simulations
    ids = FT.get_result_dirs(resultspath)
    dirs_f = FT.gather_all(ids, "fourier")
    dirs_h = FT.gather_all(ids, "hagedorn")

    dirs_f = FT.sort_by(dirs_f, "eps")
    dirs_h = FT.sort_by(dirs_h, "eps")

    if len(dirs_f) != len(dirs_h):
        raise ValueError("Found different number of fourier and hagedorn simulations!")

    number_simulations = len(dirs_f)

    normdata = []
    axisdata = []

    iom_f = IOManager()
    iom_h = IOManager()

    # Loop over all simulations
    for dir_f, dir_h in zip(dirs_f, dirs_h):

        print("Comparing simulation " + dir_h + " with " + dir_f)

        # Load the simulation data files
        resultsfile_f = FT.get_results_file(dir_f)
        iom_f.open_file(filename=resultsfile_f)

        resultsfile_h = FT.get_results_file(dir_h)
        iom_h.open_file(filename=resultsfile_h)

        # Read the parameters
        parameters_f = iom_f.load_parameters()
        parameters_h = iom_h.load_parameters()

        number_components = parameters_f["ncomponents"]

        # Scalar parameter that discriminates the simulations
        axisdata.append(parameters_f["eps"])

        # Get the data
        grid = iom_f.load_grid(blockid="global")
        timesteps = iom_f.load_wavefunction_timegrid()
        data_f = iom_f.load_wavefunction()
        data_h = iom_h.load_wavefunction()

        # Compute the norm  || u_f - u_h ||_L2 for all timesteps
        data_diff = data_f - data_h

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

        norms = []

        for i, step in enumerate(timesteps):
            if which_norm == "wf":
                WF.set_values([ data_diff[i,0,:] ])
                no = WF.get_norm()
            elif which_norm == "2":
                no = norm(data_diff[i,0,:])
            elif which_norm == "max":
                no = max(data_diff[i,0,:])

            norms.append(no)

        # Append norm values to global data structure
        norms = array(norms)
        normdata.append(norms)

    iom_f.finalize()
    iom_h.finalize()

    return (axisdata, normdata, number_simulations, number_components)
Example #9
0
def compute_grid(iom, blockid):
    # Load the parameter from the global block
    parameters = iom.load_parameters(blockid="global")

    # Compute the position space grid points
    nodes = parameters["f"] * np.pi * np.arange(-1, 1, 2.0/parameters["ngn"], dtype=np.complexfloating)

    iom.add_grid(parameters, blockid=blockid)
    iom.save_grid(nodes, blockid=blockid)




if __name__ == "__main__":

    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()
    
    # Blocks where we store the grid, per default
    # this is only the global data block.
    blockids = ["global"]

    for blockid in blockids:
        if iom.has_grid(blockid=blockid):
            print("Datablock '"+str(blockid)+"' already contains a grid, silent skip.")
            continue
                    U.project_to_canonical(Potential)

                # Save the mother packet rest
                fout.save_wavepacket_parameters(T.get_parameters(), timestep=step, blockid=2*index)
                fout.save_wavepacket_coefficients(T.get_coefficients(), timestep=step, blockid=2*index)

                # Save the spawned packet
                fout.save_wavepacket_parameters(U.get_parameters(), timestep=step, blockid=2*index+1)
                fout.save_wavepacket_coefficients(U.get_coefficients(), timestep=step, blockid=2*index+1)




if __name__ == "__main__":
    # Input data manager
    iomin = IOManager()

    # Read file with simulation data
    try:
        iomin.open_file(filename=sys.argv[1])
    except IndexError:
        iomin.open_file()

    # Read a configuration file with the spawn parameters
    try:
        parametersspawn = ParameterLoader().load_from_file(sys.argv[2])
    except IndexError:
        raise IOError("No spawn configuration given!")

    parametersin = iomin.load_parameters()
def load_data(resultspath, which_norm="wf"):
    # Group the data from different simulations
    ids = FT.get_result_dirs(resultspath)
    ids = FT.group_by(ids, "eps")

    nsims = FT.get_number_simulations(resultspath)

    groupdata = []
    axisdata = [ [] for i in xrange(nsims) ]
    normdata = [ [] for i in xrange(nsims) ]

    iom_f = IOManager()
    iom_h = IOManager()

    for index, sims in enumerate(ids):
        # Sorting based on file names
        dirs_f = FT.gather_all(sims, "fourier")
        dirs_h = FT.gather_all(sims, "hagedorn")

        if len(dirs_f) != len(dirs_h):
            raise ValueError("Found different number of fourier and hagedorn simulations!")

        dirs_f = FT.sort_by(dirs_f, "eps", as_string=True)
        dirs_h = FT.sort_by(dirs_h, "eps", as_string=True)

        # Loop over all simulations
        for dir_f, dir_h in zip(dirs_f, dirs_h):

            print("Comparing simulation " + dir_h + " with " + dir_f)

            resultsfile_f = FT.get_results_file(dir_f)
            iom_f.open_file(filename=resultsfile_f)

            resultsfile_h = FT.get_results_file(dir_h)
            iom_h.open_file(filename=resultsfile_h)

            # Read the parameters
            parameters_f = iom_f.load_parameters()
            parameters_h = iom_h.load_parameters()

            grid = iom_f.load_grid(blockid="global")

            # Precalculate eigenvectors for efficiency
            Potential = PotentialFactory().create_potential(parameters_f)
            eigenvectors = Potential.evaluate_eigenvectors_at(grid)

            # Get the data
            # Number of time steps we saved
            timesteps = iom_f.load_wavefunction_timegrid()

            # Scalar parameter that discriminates the simulations
            axisdata[index].append((parameters_f, timesteps))

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

            norms = []

            for i, step in enumerate(timesteps):
                # Load the data that belong to the current timestep
                data_f = iom_f.load_wavefunction(timestep=step)
                data_h = iom_h.load_wavefunction(timestep=step)

                data_f = Potential.project_to_eigen(grid, data_f, eigenvectors)
                data_f = array(data_f)

                data_diff = data_f - data_h

                # Compute the norm  || u_f - u_h ||
                if which_norm == "wf":
                    # Rearrange data to fit the input of WF and handle over
                    WF.set_values([ data_diff[n,:] for n in xrange(parameters_f.ncomponents) ])
                    curnorm = WF.get_norm()

                    # More than one component? If yes, compute also the overall norm
                    if parameters_f.ncomponents > 1:
                        nosum = WF.get_norm(summed=True)
                        curnorm = list(curnorm) + [nosum]

                elif which_norm == "max":
                    curnorm = [ max( abs(data_diff[n,:]) ) for n in xrange(parameters_f.ncomponents) ]

                    # More than one component? If yes, compute also the overall norm
                    if parameters_f.ncomponents > 1:
                        nosum = max(curnorm)
                        curnorm = list(curnorm) + [nosum]

                print(" at time " + str(step*parameters_f.dt) + " the error norm is " + str(curnorm))
                norms.append(curnorm)

            # Append norm values to global data structure
            norms = array(norms)
            normdata[index].append(norms)

        # Scalar parameter of the different curves
        # We add this here because the simulation parameters are
        # already loaded but not overwritten yet be the next iteration
        # Remember: we need only a single epsilon out of each eps_group.
        groupdata.append(parameters_f.dt)

    iom_f.finalize()
    iom_h.finalize()

    return (groupdata, axisdata, normdata)
            # Set the aspect window
            if view is not None:
                ax.set_xlim(view[:2])
                #ax.set_ylim(view[2:])

        fig.suptitle(r"$\arg \Psi$ at time $"+str(step*parameters["dt"])+r"$")
        fig.savefig("wavefunction_phase_block"+str(blockid)+"_"+ (7-len(str(step)))*"0"+str(step) +GD.output_format)
        close(fig)

    print(" Plotting frames finished")



if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    # The axes rectangle that is plotted
    view = [-3.5, 3.5, -0.1, 3.5]

    # Iterate over all blocks and plot their data
    for blockid in iom.get_block_ids():
        print("Plotting frames of data block "+str(blockid))
        # See if we have wavefunction values
        if iom.has_wavefunction(blockid=blockid):
            ax3.ticklabel_format(style="sci", scilimits=(0,0), axis="y")
            stemcf(k, angle(coeffs_s), abs(coeffs_s))
            ax3.set_xlim((-1, parameters["basis_size"]))
            ax3.set_xlabel(r"$k$")
            ax3.set_ylabel(r"$|c|$")
            ax3.set_title(r"Spawned packet $| \Psi^s \rangle$")

        fig.suptitle(r"Time $"+str(step*parameters["dt"])+r"$")
        fig.savefig("wavepackets_group"+str(gid)+"_"+ (5-len(str(step)))*"0"+str(step) +GD.output_format)
        close(fig)




if __name__ == "__main__":
    iom = IOManager()

    # Read file with simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    parameters = iom.load_parameters()

    # The axes rectangle that is plotted
    view = [-3, 3, 0.0, 2.5]

    plot_frames_homogeneous(iom, view=view)

    iom.finalize()
Example #14
0
        ax.plot(time, normsum[0] - normsum)

    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\|$")
    fig.savefig("norms_sumall_drift_group"+str(gid)+GD.output_format)
    close(fig)




if __name__ == "__main__":
    iom = IOManager()

    # Read the file with the simulation data
    try:
        iom.open_file(filename=sys.argv[1])
    except IndexError:
        iom.open_file()

    gids = iom.get_group_ids()

    for gid in gids:
        params, data = read_data(iom, gid)
        plot_norms(gid, params, data)

    iom.finalize()