Time-dependent Schrodinger equation on 3d lattice in Julia

617 views Asked by At

I want to solve the matrix-form time-dependent Schrodinger equation on 3d lattice with DifferentialEquations.jl,
i.e., (∂/∂t)ψ = -iHψ ,where ψ is a vector and H is a (time-independent) matrix.
I tried to write the code like this.

#Define the underlying equation
function time_evolution(ψdot,ψ,p,t)
  ψdot.=-im.*H(Lx,Ly,Lz)*ψ
end

Lx = Ly = Lz = 10
ψ0 = [] #  Initial conditions
σ = sqrt(5/2)

for iz = 1:Lz
    for ix = 1:Lx
        for iy = 1:Ly                  
           gauss = (1/(sqrt(2*π)*σ)^3)*exp(-((ix)^2 + (iy)^2 + (iz)^2)/(2*(σ)^2))
           push!(ψ0,gauss)                           
        end
    end
end

tspan = (0.,1.0) #  Simulation time span


#Pass to Solvers
prob = ODEProblem(time_evolution,ψ0,tspan)
sol = solve(prob)

Here,H(Lx,Ly,Lz) is a N×N matrix parameterized by systemsize Lx,Ly,Lz and N = Lx×Ly×Lz.
But this code has an error.

StackOverflowError:
Stacktrace:
 [1] recursive_unitless_bottom_eltype(::Type{Any}) at 
/Users/username/.julia/packages/RecursiveArrayTools/OAIEc/src/utils.jl:86 (repeats 
80000 times)

Where is the mistake in the code?

1

There are 1 answers

3
Chris Rackauckas On BEST ANSWER
ψ0 = [] #  Initial conditions

You probably don't want your equation to be non-concretely typed, so you likely want to do

ψ0 = Float64[] #  Initial conditions