如何在Julia中绘制3D高斯的时间演化图?

问题描述

我想用Makie.jl绘制3D高斯的时间演化。 Here是sin(r)/ r的表面版本代码。
所以我写了一个引用它的代码。

using Makie  
using FileIO  
using LinearAlgebra  
using AbstractPlotting

scene = Scene(backgroundcolor = :black);  
f(x,y,z) = exp(-((x)^2 + (y)^2 + (z)^2))  
r = LinRange(-5,5,50)  
vol_func(t) = [Float64(f(x - cos(t),y - sin(t),z - t)) for x = r,y = r,z = r]  
vol = volume!(scene,r,vol_func(20),algorithm = :mip)[end]  
scene[Axis].names.textcolor = :gray  
N = 20  
scene 
record(scene,"voloutput.mp4",range(0,stop = 5,length = N)) do t  
    vol[3] = vol_func(t)  
end  

但是此代码不起作用。

MethodError: Cannot `convert` an object of type Array{Float64,3} to an object of type LinRange{Float64}

我应该如何修复代码?

P.S。
初始时的快照就是这样。(reference

using Makie
using FileIO
using LinearAlgebra
using AbstractPlotting

r = LinRange(-20,20,500);  # our value range

ρ(x,z) = exp(-((x-1)^2 + (y)^2 + (z)^2)) # function (charge density)

# create a Scene with the attribute `backgroundcolor = :black`,# can be any compatible color.  Useful for better contrast and not killing your eyes with a white background.
scene = Scene(backgroundcolor = :black)

volume!(
    scene,# coordinates to plot on
    ρ,# charge density (functions as colorant)
    algorithm = :mip  # maximum-intensity-projection
)

scene[Axis].names.textcolor = :gray # let axis labels be seen on dark 
background

save("sp.png",scene)

我想看到黄色区域呈螺旋状移动。 (2020/08/28)

我只是意识到不是vol [3]而是vol [4] 。然后,它起作用了。 但是我还有一个问题。 (2020/08/31)
我尝试对the matrix-form time-dependent Schrodinger equation with its initial condition being Gaussian做同样的事情。

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

Lx = Ly = Lz = 10
ψ0 = [] #  Initial conditions


for iz = 1:Lz
    for ix = 1:Lx
        for iy = 1:Ly                  
           gauss = exp(-((ix)^2 + (iy)^2 + (iz)^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)
在此,H(Lx,Ly,Lz)是一个N×N矩阵,由系统大小Lx,Ly,Lz和N = Lx×Ly×Lz来参数化。 H(Lx,Ly,Lz)的示例代码为here。 然后,
using Makie
using FileIO 
using LinearAlgebra
using AbstractPlotting
using ColorSchemes

x = 1: Lx  # our value range
y = 1: Ly
z = 1: Lz

ρ(ix,iy,iz,nt) = abs2.((sol[nt][(iz-1)*Lx*Ly + (ix-1)*Ly + (iy-1)])./norm(sol[nt][(iz-1)*Lx*Ly + (ix-1)*Ly + (iy-1)]))
ψ(nt) = Float64[ρ(ix,nt) for ix in x,iy in y,iz in z]
scene = Scene(backgroundcolor = :white)

c = ψ(length(sol.t))

vol = volume!(
scene,x,z,# coordinates to plot on
c,# charge density (functions as colorant)
algorithm = :mip,# maximum-intensity-projection
colorrange = (0,0.01),transparency = true,)[end]

update_cam!(scene,Vec3f0(1,0.5,0.1),Vec3f0(0))
scene[Axis].names.textcolor = :gray # let axis labels be seen on darkbackground

record(scene,"output.mp4",stop = length(sol.t)-1,length = 1)) do nt
    vol[4] = ψ(nt)
end

但是此代码有错误。

ArgumentError: range(0.0,stop=5.0,length=1): endpoints differ

哪里出了错?

我发现了错误。(2020/09/02)

sol[nt]→sol(nt)
range(0,length = 1)→range(0,stop = 1.0,length = 20)

然后,传递了代码,并获得了mp4动画。
但是在mp4文件中看不到该情节。为什么...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...