I have a program to solve 1D Burguer’s equation. I have the following values/dimensions, which are giving me a dimensional error. I don’t understand what is going wrong. If anyone can help me, I appreciate it.
julia> size(xs)
(50,)
julia> size(ts)
(1000,)
julia> size(u)
(50, 1001)
julia> plot(xs,ts,u[1:50,1:1000],st=:surface, title="Burguer equation", xlabel="X", ylabel="Y", zlabel="U")
Arrays have incorrect length or dimension.
More on the program itself, in case it helps
Parameters (space)
nx= 50;
delta_x = 15/(nx - 1)
x = range(0, stop=delta_x*(nx-1), length=nx) # Full range of spatial steps for wich a solution is desired
Parameters (time)
endTime = 2 # simulation end time
nt = 1000 # nt is the number of timesteps we want to calculate
delta_t = endTime/nt # Δt is the amount of time each timestep covers
t = range(0, stop=endTime, length=nt) # Full range of time steps for which a solution is desired
#+RESULTS:
: 0.0:0.002002002002002002:2.0
Initial conditions (space-time)
# Init array of ones at initial timestep
u_zero = ones(nx)
# Set u₀ = 2 in the interval 0.5 ≤ x ≤ 1 as per our I.C.s
u_zero[0.5 .<= x .<= 3] .= 2 # Note use of . (dot) broadcasting syntax
u_zero
#+RESULTS:
: [1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
Run the differential equation
# u[:,] = copy(u_zero) # Initialise arbitrary future timestep with inital condition, u_zero
u=zeros((nx,nt+1))
u[:,1]=copy(u_zero)
for n in 1:nt # loop over timesteps, n: nt times
u[:,n+1] = copy(u[:,n]) # copy the existing values of u^n into u^(n+1)
for i in 2:nx
u[i,n+1] = u[i,n] - u[i,n] * delta_t/delta_x * (u[i,n] - u[i-1,n])
end
end
using Plots
gr()
plot(xs,ts,u[1:50,1:1000],st=:surface, title="Burguer equation", xlabel="X", ylabel="Y", zlabel="U")