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

Complex Number support #101

Closed
xtalax opened this issue May 19, 2022 · 5 comments · Fixed by #342
Closed

Complex Number support #101

xtalax opened this issue May 19, 2022 · 5 comments · Fixed by #342
Labels

Comments

@xtalax
Copy link
Member

xtalax commented May 19, 2022

These are currently unsupported, see #80 for example code

@curio-sitas
Copy link

Any news on Complex numbers support ?

@xtalax
Copy link
Member Author

xtalax commented Nov 22, 2022

The more people ask for it, the higher priority it gets. I think that MTK is real based but there are tricks you can use to solve complex systems, I'd expect those would work here too but I am unfamiliar with the technique

@curio-sitas
Copy link

The more people ask for it, the higher priority it gets. I think that MTK is real based but there are tricks you can use to solve complex systems, I'd expect those would work here too but I am unfamiliar with the technique

Yes, you can eventually split up your system in real and imaginary differential system, but it can be rather tidious

@xtalax
Copy link
Member Author

xtalax commented Dec 1, 2022

I can try to do this automatically perhaps

@aplund
Copy link

aplund commented Oct 31, 2023

I'm not sure if it's helpful for this or not, but I believe this is a test case of sorts:

module Schro

using ModelingToolkit
using MethodOfLines

@variables t, x
@variables u(..)::Complex

Dx = Differential(x)
Dt = Differential(t)

equation = Dt(u(t,x)) ~ -im*(1/2)*(Dx^2)(u(t,x))

tmax = 50.0
xmax = π
xmin = -xmax

domains=[
    t ∈ (0.0, tmax),
    x ∈ (xmin,xmax)
]

# Exact solution: cos(x/2) e^{-i t/8) + cos(3x/2) e^{-i 9/8 t)

boundary_conditions = [
    u(0.0,x) ~ cos(x/2) + cos(3*x/2),
    u(t,xmin) ~ 0,
    u(t,xmax) ~ 0
]

@named system = PDESystem(
    equation,
    boundary_conditions,
    domains,
    [t, x],
    [u(t,x)]
)

dx=0.1
discretization = MOLFiniteDifference([x => dx], t; approx_order = 2)
problem = discretize(system, discretization)
sol = solve(problem, Tsit5())

end

The error I get now looks like this:

ERROR: LoadError: MethodError: no method matching operation(::Complex{Num})

Closest candidates are:
  operation(::Symbolics.ArrayOp)
   @ Symbolics ~/.julia/packages/Symbolics/gBKZv/src/arrays.jl:93
  operation(::SymbolicUtils.BasicSymbolic)
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/ssQsQ/src/types.jl:101
  operation(::PolyForm)
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/ssQsQ/src/polyform.jl:184
  ...

Stacktrace:
 [1] chain_flatten_array_variables(dvs::Vector{Complex{Num}})
   @ PDEBase ~/.julia/packages/PDEBase/aRCcl/src/make_pdesys_compatible.jl:6
 [2] make_pdesys_compatible(pdesys::PDESystem)
   @ PDEBase ~/.julia/packages/PDEBase/aRCcl/src/make_pdesys_compatible.jl:32
 [3] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})
   @ PDEBase ~/.julia/packages/PDEBase/aRCcl/src/symbolic_discretize.jl:10
 [4] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization}; analytic::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ PDEBase ~/.julia/packages/PDEBase/aRCcl/src/discretization_state.jl:58
 [5] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})
   @ PDEBase ~/.julia/packages/PDEBase/aRCcl/src/discretization_state.jl:55
 [6] top-level scope
   @ ~/Work/00Projects/AndersonLocalBohm/julia/schro.jl:41
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:478
 [8] top-level scope
   @ REPL[28]:1
in expression starting at /home/lund/Work/00Projects/AndersonLocalBohm/julia/schro.jl:1

@xtalax xtalax mentioned this issue Nov 30, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants