Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: type Array has no field lhs for Schrodinger equation #294

Closed
BearBearCodes opened this issue Jul 26, 2023 · 2 comments
Closed

ERROR: type Array has no field lhs for Schrodinger equation #294

BearBearCodes opened this issue Jul 26, 2023 · 2 comments

Comments

@BearBearCodes
Copy link

BearBearCodes commented Jul 26, 2023

Hi, I'm following the heat equation tutorial as a starting point for solving the Schrodinger equation, but I'm getting the following error (in WSL2 running Ubuntu 20.04.5 LTS):

type Array has no field lhs

Stacktrace:
  [1] getproperty
    @ [./Base.jl:37](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/Base.jl:37) [inlined]
  [2] (::PDEBase.var"#118#119"{typeof(identity)})(eq::Vector{Equation})
    @ PDEBase [~/.julia/packages/PDEBase/2OwkC/src/make_pdesys_compatible.jl:20](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/~/.julia/packages/PDEBase/2OwkC/src/make_pdesys_compatible.jl:20)
  [3] iterate
    @ [./generator.jl:47](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/generator.jl:47) [inlined]
  [4] collect_to!(dest::Vector{Equation}, itr::Base.Generator{Vector{Any}, PDEBase.var"#118#119"{typeof(identity)}}, offs::Int64, st::Int64)
    @ Base [./array.jl:840](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/array.jl:840)
  [5] collect_to_with_first!(dest::Vector{Equation}, v1::Equation, itr::Base.Generator{Vector{Any}, PDEBase.var"#118#119"{typeof(identity)}}, st::Int64)
    @ Base [./array.jl:818](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/array.jl:818)
  [6] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, PDEBase.var"#118#119"{typeof(identity)}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base [./array.jl:812](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/array.jl:812)
  [7] collect_similar
    @ [./array.jl:711](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/array.jl:711) [inlined]
  [8] map
    @ [./abstractarray.jl:3261](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/abstractarray.jl:3261) [inlined]
  [9] apply_lhs_rhs(f::typeof(identity), eqs::Vector{Any})
    @ PDEBase [~/.julia/packages/PDEBase/2OwkC/src/make_pdesys_compatible.jl:19](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/~/.julia/packages/PDEBase/2OwkC/src/make_pdesys_compatible.jl:19)
 [10] make_pdesys_compatible(pdesys::PDESystem)
    @ PDEBase [~/.julia/packages/PDEBase/2OwkC/src/make_pdesys_compatible.jl:41](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/~/.julia/packages/PDEBase/2OwkC/src/make_pdesys_compatible.jl:41)
 [11] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})
    @ PDEBase [~/.julia/packages/PDEBase/2OwkC/src/symbolic_discretize.jl:10](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/~/.julia/packages/PDEBase/2OwkC/src/symbolic_discretize.jl:10)
 [12] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization}; analytic::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ PDEBase [~/.julia/packages/PDEBase/2OwkC/src/discretization_state.jl:58](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/~/.julia/packages/PDEBase/2OwkC/src/discretization_state.jl:58)
 [13] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})
    @ PDEBase [~/.julia/packages/PDEBase/2OwkC/src/discretization_state.jl:55](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/~/.julia/packages/PDEBase/2OwkC/src/discretization_state.jl:55)
 [14] top-level scope
    @ /mnt/c/Users/ichen/OneDrive/Documents/Jobs/WaterlooWorks/3B_Jobs/S2023/CnuB-mirror/notebooks/julia_warmup.ipynb:27

I've looked at #117, but that fix doesn't apply in my case. I suspect there is a simple fix (see MWE below), but I'm not quite sure what is happening.


MWE (most of the code is directly copy-pasted from the heat equation tutorial):

using OrdinaryDiffEq, ModelingToolkit, MethodOfLines, DomainSets
# Parameters, variables, and derivatives
@parameters t x
@variables u(..)
Dt = Differential(t)
Dxx = Differential(x)^2

# 1D PDE and boundary conditions
eq = Dt(u(t, x)) ~ Dxx(u(t, x)) * (1im / 2)
bcs = [u(0, x) ~ exp(1im * x),
    u(t, 0) ~ exp(-1im * t),
    u(t, 1) ~ exp(1im * (1 - t))]

# Space and time domains
domains = [t  Interval(0.0, 1.0),
    x  Interval(0.0, 1.0)]

# PDE system
@named pdesys = PDESystem(eq, bcs, domains, [t, x], [u(t, x)])

# Method of lines discretization
dx = 0.1
order = 2
discretization = MOLFiniteDifference([x => dx], t)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys, discretization)

# Solve ODE problem
using OrdinaryDiffEq
sol = solve(prob, Tsit5(), saveat=0.5)

# Plot results
discrete_x = sol[x]
discrete_t = sol[t]
solu = sol[u(t, x)]

using Plots
plt = plot()

for i in 1:length(discrete_t)
    plot!(discrete_x, solu[i, :], label="Numerical, t=$(discrete_t[i])")
end
display(plt)
@xtalax
Copy link
Member

xtalax commented Jul 26, 2023

I'm afraid complex numbers are still unsupported, There is an open PR but we are waiting for stuff to be merged upstream.

@BearBearCodes
Copy link
Author

Oh I see. Thanks for the quick reply! I'll keep an eye out for updates to #58 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants