To apply fft plan to an array A, we use a preallocated output array  by calling mul!(Â, plan, A)
. The input array A must be a complex floating-point array like the output Â. The inverse-transform is computed inplace by applying inv(P)
with ldiv!(A, P, Â)
.
function with_fft_plans_inplace(tf, nt, mesh::Mesh)
= tf/nt
dt
= zeros(Complex{Float64},(mesh.nx,mesh.ny))
f = exact(0.0, mesh)
f .= similar(f)
f̂
= exp.( 1im*tan(dt/2) .* mesh.x .* mesh.ky')
exky = exp.(-1im*sin(dt) .* mesh.y' .* mesh.kx )
ekxy
= plan_fft(f, 1)
Px = plan_fft(f, 2)
Py
for n = 1:nt
!(f̂, Py, f)
mul= f̂ .* exky
f̂ .!(f, Py, f̂)
ldiv
!(f̂, Px, f)
mul= f̂ .* ekxy
f̂ .!(f, Px, f̂)
ldiv
!(f̂, Py, f)
mul= f̂ .* exky
f̂ .!(f, Py, f̂)
ldiv
end
real(f)end
= with_fft_plans_inplace(0.1, 1, mesh) # trigger build
f @time norm(with_fft_plans_inplace(tf, nt, mesh) .- exact(tf, mesh))