<commit_before>#=-------------splitstep.jl----------------------------------------------------#
#
#              split step method for macroscopic wave function generation
#
# Purpose: This file is intended to create a splitstep method for BEC systems.
#          Eventually we may incorporate real-time evolution, but we need to 
#          first generate the grounds state and go from there.
#
#   Notes: Units of hbar = c  = 1
#-----------------------------------------------------------------------------=#

global xmax = 20
global res = 2^8
global g = 500

# This initializes the potential well and also the gaussian init wavefunction
function initialize()
    gaus = zeros(res)
    pot = zeros(res)
    for ix = 1:res
        x = ix * (xmax/res) - xmax / 2
        gaus[ix] = exp(-x * x )
        pot[ix] = 0.5 * x * x
        #println(gaus[ix], '\t', pot[ix], '\t', x)
    end
    return gaus, pot
end

# This will return the kinetic and potential energies at every timestep
# Note unphysical units will be fixed in the future.
function energy(wave, pot, dt)

    KE = complex(zeros(size(wave,1)))
    PE = complex(zeros(size(wave,1)))

    dk = 2pi / xmax

    for i = 1:size(wave,1)
        if i <= size(wave,1) / 2
            k = dk * (i)
        else
            k = dk * (i - (size(wave,1) / 2))
        end
        KE[i] = exp( -0.5 * (k*k) * dt)
        PE[i] = exp( -0.5 * (pot[i] + g*wave[i]*wave[i]) *dt)
    end
    return PE, KE
end

# The whole shebang
# Psi * Uv -> fft -> Psi * Uk -> ifft -> renormalization -> cycle
function splitstep(stepnum, dt)

    output = open("out.dat", "w")
    wave, pot = initialize()

    for j = 1:stepnum

        PE, KE = energy(wave, pot, dt)
        norm_const = 0

        for i = 1:res
            wave[i] *= PE[i]
        end
 
        wave = fft(wave)

        for i = 1:res
            wave[i] *= KE[i]
        end

        wave = ifft(wave)

        norm_const = 0
        for i = 1:res
            norm_const += abs2(wave[i])
        end

        println(norm_const)

        for i = 1:res
            wave[i] *= 1/norm_const
        end

        if j % 1000 == 0 || j == 0
            for i = 1:res
                println(output, wave[i])
            end

            print(output, '\n', '\n')
        end

    end
end

# Main

splitstep(10000, 0.001)<commit_msg>generating a basic ground state with imaginary time evolution!<commit_after>#=-------------splitstep.jl----------------------------------------------------#
#
#              split step method for macroscopic wave function generation
#
# Purpose: This file is intended to create a splitstep method for BEC systems.
#          Eventually we may incorporate real-time evolution, but we need to 
#          first generate the grounds state and go from there.
#
#   Notes: Units of hbar = c  = 1
#-----------------------------------------------------------------------------=#

global xmax = 40
global res = 2^8
global g = 500

# This initializes the potential well and also the gaussian init wavefunction
function initialize()
    gaus = zeros(res)
    pot = zeros(res)
    for ix = 1:res
        x = ix * (xmax/res) - xmax / 2
        gaus[ix] = exp(-x * x )
        pot[ix] = 0.25 * x * x
        #println(gaus[ix], '\t', pot[ix], '\t', x)
    end
    return gaus, pot
end

# This will return the kinetic and potential energies at every timestep
# Note unphysical units will be fixed in the future.
function energy(wave, pot, dt)

    KE = complex(zeros(size(wave,1)))
    PE = complex(zeros(size(wave,1)))

    dk = 2pi / xmax

    for i = 1:size(wave,1)
        if i <= size(wave,1) / 2
            k = dk * (i)
        else
            k = dk * (i - (size(wave,1) / 2))
        end
        KE[i] = exp( -0.5 * (k*k) * dt)
        PE[i] = exp( -0.5 * (pot[i] + g*abs2(wave[i])) *dt)
    end
    return PE, KE
end

# The whole shebang
# Psi * Uv -> fft -> Psi * Uk -> ifft -> renormalization -> cycle
function splitstep(stepnum, dt)

    output = open("out.dat", "w")
    wave, pot = initialize()
    density = zeros(size(wave,1))

    for j = 1:stepnum

        PE, KE = energy(wave, pot, dt)
        norm_const = 0

        for i = 1:res
            wave[i] *= PE[i]
        end
 
        wave = fft(wave)

        for i = 1:res
            wave[i] *= KE[i]
        end

        wave = ifft(wave)

        norm_const = 0
        for i = 1:res
            norm_const += abs2(wave[i]) * xmax / res
        end

        println(norm_const)

        for i = 1:res
            wave[i] *= 1/norm_const
        end

        for i = 1:res
            density[i] = abs(conj(wave[i]) * wave[i])
        end

        if j % 30000 == 0 || j == 0
            for i = 1:res
                println(output, density[i])
            end

            print(output, '\n', '\n')
        end

    end
end

# Main

splitstep(300000, 0.001)
{'fraction_non_alphanumeric': 0.1749535795337322, 'fraction_numerical': 0.021869197441716524, 'mean_word_length': 1.5067218200620476, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6047542', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1525, 'n_words': 506}