Inplace computation
- We remove the Float64-Complex128 conversion by allocating the distribution function
f
as a Complex array
- Note that we need to use the inplace assignement operator “.=” to initialize the
f
array.
- We use inplace computation for fft with the “bang” operator
!
function inplace(tf, nt, mesh::Mesh)
dt = tf/nt
f = zeros(Complex{Float64},(mesh.nx,mesh.ny))
f .= exact(0.0, mesh)
exky = exp.( 1im*tan(dt/2) .* mesh.x .* mesh.ky')
ekxy = exp.(-1im*sin(dt) .* mesh.y' .* mesh.kx )
for n = 1:nt
fft!(f, 2)
f .= exky .* f
ifft!(f,2)
fft!(f, 1)
f .= ekxy .* f
ifft!(f, 1)
fft!(f, 2)
f .= exky .* f
ifft!(f,2)
end
real(f)
end
f = inplace(0.1, 1, mesh) # trigger build
@time norm(inplace(tf, nt, mesh) .- exact(tf, mesh))