Skip to content

Commit

Permalink
Proper recasting in mcwf
Browse files Browse the repository at this point in the history
  • Loading branch information
david-pl committed Nov 12, 2018
1 parent 793b276 commit 088d144
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/mcwf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,18 @@ function integrate_mcwf(dmcwf::Function, jumpfun::Function, tspan,
kwargs...) where {B<:Basis,D<:Vector{ComplexF64},T<:Ket{B,D}}

tmp = copy(psi0)
as_ket(x::D) = T(psi0.basis, x)
psi_tmp = copy(psi0)
as_vector(psi::T) = psi.data
rng = MersenneTwister(convert(UInt, seed))
jumpnorm = Ref(rand(rng))
djumpnorm(x::D, t::Float64, integrator) = norm(as_ket(x))^2 - (1-jumpnorm[])
djumpnorm(x::D, t::Float64, integrator) = norm(x)^2 - (1-jumpnorm[])

if !display_beforeevent && !display_afterevent
function dojump(integrator)
x = integrator.u
recast!(x, psi_tmp)
t = integrator.t
jumpfun(rng, t, as_ket(x), tmp)
jumpfun(rng, t, psi_tmp, tmp)
x .= tmp.data
jumpnorm[] = rand(rng)
end
Expand Down Expand Up @@ -307,7 +308,8 @@ function integrate_mcwf(dmcwf::Function, jumpfun::Function, tspan,
affect!.save_func(integrator.u, integrator.t, integrator),Val{false})
end

jumpfun(rng, t, as_ket(x), tmp)
recast!(x, psi_tmp)
jumpfun(rng, t, psi_tmp, tmp)

if display_afterevent
affect!.saveiter += 1
Expand Down

0 comments on commit 088d144

Please sign in to comment.