Skip to content

More split op updates #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 28, 2018
18 changes: 9 additions & 9 deletions contents/split-operator_method/code/julia/split_op.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ end

mutable struct Operators
V::Vector{Complex{Float64}}
PE::Vector{Complex{Float64}}
KE::Vector{Complex{Float64}}
R::Vector{Complex{Float64}}
K::Vector{Complex{Float64}}
wfc::Vector{Complex{Float64}}

Operators(res) = new(Vector{Complex{Float64}}(res),
Expand All @@ -49,11 +49,11 @@ function init(par::Param, voffset::Float64, wfcoffset::Float64)
opr.V = 0.5 * (par.x - voffset).^2
opr.wfc = exp.(-(par.x - wfcoffset).^2/2)
if (par.im_time)
opr. = exp.(-0.5*par.k.^2*par.dt)
opr.PE = exp.(-0.5*opr.V*par.dt)
opr.K = exp.(-0.5*par.k.^2*par.dt)
opr.R = exp.(-0.5*opr.V*par.dt)
else
opr. = exp.(-im*0.5*par.k.^2*par.dt)
opr.PE = exp.(-im*0.5*opr.V*par.dt)
opr.K = exp.(-im*0.5*par.k.^2*par.dt)
opr.R = exp.(-im*0.5*opr.V*par.dt)
end

return opr
Expand All @@ -64,19 +64,19 @@ function split_op(par::Param, opr::Operators)

for i = 1:par.timesteps
# Half-step in real space
opr.wfc = opr.wfc .* opr.PE
opr.wfc = opr.wfc .* opr.R

# fft to momentum space
opr.wfc = fft(opr.wfc)

# Full step in momentum space
opr.wfc = opr.wfc .* opr.
opr.wfc = opr.wfc .* opr.K

# ifft back
opr.wfc = ifft(opr.wfc)

# final half-step in real space
opr.wfc = opr.wfc .* opr.PE
opr.wfc = opr.wfc .* opr.R

# density for plotting and potential
density = abs2.(opr.wfc)
Expand Down
2 changes: 1 addition & 1 deletion contents/split-operator_method/split-operator_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Regardless, we first need to set all the initial parameters, including the initi

As a note, when we generate our grid in momentum space `k`, we need to split the grid into two lines, one that is going from `0` to `-kmax` and is then discontinuous and goes from `kmax` to `0`.
This is simply because the FFT will naturally assume that the `0` in our grid is at the left side of the simulation, so we shift k-space to match this expectation.
Also, for this code we will be using the notation from above: `opr.R` will be the real space operators and `opr.M` will be the momentum space operators.
Also, for this code we will be using notation to what we used above: `opr.R` will be the real space operators and `opr.K` will be the momentum space operators.
There is another boolean value here called `im_time`, which is for imaginary time evolution.

Afterwards, we turn them into operators:
Expand Down