# MethodOfLines.jl not working

**URL:** https://discourse.julialang.org/t/methodoflines-jl-not-working/116346
**Category:** General Usage
**Tags:** package
**Created:** [June 28, 2024, 9:33am UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346 "2024-06-28T09:33:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Kaguro](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@Kaguro](https://discourse.julialang.org/u/Kaguro)
#### Post date: [June 28, 2024, 9:33am UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/1 "2024-06-28T09:33:19Z")

</div>

Hello All.  
I am to solve a PDE numerically (called Klein-Kramers-Chandrasekhar equation [KKC eqn](https://en.wikipedia.org/wiki/Klein%E2%80%93Kramers_equation) ) for some parameters. I followed the getting started instructions [intro](https://docs.sciml.ai/MethodOfLines/dev/tutorials/brusselator/) and after writing the step for

> prob = discretize(pdesys, discretization)

for my system, I got this error message:

> Discretization:  
> ERROR: LoadError: MethodError: no method matching real(::Equation)  
> The function `real` exists, but no method is defined for this combination of argument types.

I have imported the following packages: Plots,ModelingToolkit, MethodOfLines, OrdinaryDiffEq, DomainSets using the using keyword.

What did I do wrong? Any help will be very appreciated.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 28, 2024, 1:52pm UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/2 "2024-06-28T13:52:24Z")

</div>

What’s your code?

---

<div class="post-metadata">

### Author: ![Kaguro](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@Kaguro](https://discourse.julialang.org/u/Kaguro)
#### Post date: [June 29, 2024, 7:31am UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/3 "2024-06-29T07:31:54Z")

</div>

```julia
using Plots
using ModelingToolkit, MethodOfLines, OrdinaryDiffEq, DomainSets

function main()
@parameters x v t
@variables P(..)

Dt = Differential(t);Dx = Differential(x)
Dv = Differential(v);Dvv = Differential(v)^2

k=0.5;T=2;g=1;m=1/g

domains = [x in Interval(-5.0, 5.0), v in Interval(-5.0, 5.0),t in Interval(0.0,4.0)]

eq = [Dt(P(x, v, t)) ~ -v*Dx(P(x,v,t)) +g*P(x,v,t) + (g*v+k*x/m)*Dv(P(x,v,t)) +(g*T/m)*Dvv(P(x,v,t))]

bcs= [P(x,v,0)~ (m/(2*pi*T))*exp((-0.5*k*x*x -0.5*m*v*v)/T), Dx(P(x,v,0)) ~ -(m*k/(2*pi*T*T))*x*exp( (-0.5*k*x*x -0.5*m*v*v)/T),Dv(P(x,v,0)) ~ -(m^2/(2*pi*T*T))*v*exp( (-0.5*k*x*x -0.5*m*v*v)/T), Dv(Dv(P(x,v,0))) ~ -(m*m/(2*pi*T*T))*exp( (-0.5*k*x*x -0.5*m*v*v)/T)*(1-(m*(v^2)/T))]

@named pdesys = PDESystem(eq, bcs, domains, [x, v, t], [P(x,v,t)])
discretization = MOLFiniteDifference([x => 0.01, v => 0.01,t=>0.01], approx_order = 2)
@time prob = discretize(pdesys, discretization)

end

@time main()

```

This is my code.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 29, 2024, 9:08am UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/4 "2024-06-29T09:08:14Z")

</div>

During pre-compilation I get:

```julia
        Info Packages marked with ⌃ and ⌅ have new versions available. Those with ⌃ may be upgradable, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated -m`
Precompiling project...
  6 dependencies successfully precompiled in 54 seconds. 352 already precompiled.
  2 dependencies had output during precompilation:
┌ Interpolations
│ WARNING: method definition for checkbounds at /home/ufechner/.julia/packages/Interpolations/USkTk/src/Interpolations.jl:454 declares type variable N but does not use it.
│ WARNING: method definition for checkbounds at /home/ufechner/.julia/packages/Interpolations/USkTk/src/Interpolations.jl:457 declares type variable N but does not use it.
│ WARNING: method definition for GriddedInterpolation at /home/ufechner/.julia/packages/Interpolations/USkTk/src/gridded/gridded.jl:37 declares type variable pad but does not use it.
│ WARNING: method definition for GriddedInterpolation at /home/ufechner/.julia/packages/Interpolations/USkTk/src/gridded/gridded.jl:60 declares type variable pad but does not use it.
│ WARNING: method definition for interpolate! at /home/ufechner/.julia/packages/Interpolations/USkTk/src/deprecations.jl:30 declares type variable TWeights but does not use it.
└  
┌ MethodOfLines
│ ┌ Warning: The system contains interface boundaries, which are not compatible with system transformation. The system will not be transformed. Please post an issue if you need this feature.
│ └ @ MethodOfLines ~/.julia/packages/MethodOfLines/iIYN1/src/system_parsing/pde_system_transformation.jl:43
└  

```

when adding MethodOfLines.

And executing it results in:

```julia
julia> include("method.jl")
ERROR: LoadError: MethodError: no method matching real(::Equation)

Closest candidates are:
  real(::Type{Union{}}, Any...)
   @ Base complex.jl:123
  real(::ChainRulesCore.ZeroTangent)
   @ ChainRulesCore ~/.julia/packages/ChainRulesCore/I1EbV/src/tangent_arithmetic.jl:111
  real(::Symbolics.SemiMonomial)
   @ Symbolics ~/.julia/packages/Symbolics/Nk48t/src/semipoly.jl:123
  ...

Stacktrace:
  [1] _broadcast_getindex_evalf
    @ ./broadcast.jl:709 [inlined]
  [2] _broadcast_getindex
    @ ./broadcast.jl:682 [inlined]
  [3] getindex
    @ ./broadcast.jl:636 [inlined]
  [4] copy
    @ ./broadcast.jl:942 [inlined]
  [5] materialize
    @ ./broadcast.jl:903 [inlined]
  [6] broadcast_preserving_zero_d
    @ ./broadcast.jl:892 [inlined]
  [7] real(A::Matrix{Any})
    @ Base ./abstractarraymath.jl:170
  [8] hascomplex(term::Matrix{Any})
    @ PDEBase ~/.julia/packages/PDEBase/nzap9/src/symbolic_utils.jl:292
  [9] #127
    @ ~/.julia/packages/PDEBase/nzap9/src/make_pdesys_compatible.jl:86 [inlined]
 [10] _any(f::PDEBase.var"#127#135", itr::Vector{Matrix{Any}}, ::Colon)
    @ Base ./reduce.jl:1220
 [11] any(f::Function, a::Vector{Matrix{Any}}; dims::Function)
    @ Base ./reducedim.jl:1020
 [12] handle_complex(pdesys::PDESystem)
    @ PDEBase ~/.julia/packages/PDEBase/nzap9/src/make_pdesys_compatible.jl:86
 [13] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization})
    @ PDEBase ~/.julia/packages/PDEBase/nzap9/src/symbolic_discretize.jl:9
 [14] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid, MethodOfLines.ScalarizedDiscretization}; analytic::Nothing, kwargs::@Kwargs{})
    @ PDEBase ~/.julia/packages/PDEBase/nzap9/src/discretization_state.jl:58
 [15] discretize
    @ ~/.julia/packages/PDEBase/nzap9/src/discretization_state.jl:55 [inlined]
 [16] macro expansion
    @ ./timing.jl:279 [inlined]
 [17] main()
    @ Main ~/repos/tmp/method.jl:22
 [18] macro expansion
    @ ./timing.jl:279 [inlined]
 [19] top-level scope
    @ ~/repos/tmp/method.jl:269
 [20] include(fname::String)
    @ Base.MainInclude ./client.jl:489
 [21] top-level scope
    @ REPL[1]:1
in expression starting at /home/ufechner/repos/tmp/method.jl:26

```

The line that causes the error is the last line, the call of `main()`.

---

<div class="post-metadata">

### Author: ![Kaguro](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@Kaguro](https://discourse.julialang.org/u/Kaguro)
#### Post date: [June 29, 2024, 10:49am UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/5 "2024-06-29T10:49:26Z")

</div>

So… what is the actual issue here?  
That I need different kind of boundary conditions or initial conditions?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 29, 2024, 12:57pm UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/6 "2024-06-29T12:57:49Z")

</div>

@ChrisRackauckas Can you have a look?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [July 5, 2024, 6:25pm UTC](https://discourse.julialang.org/t/methodoflines-jl-not-working/116346/7 "2024-07-05T18:25:58Z")

</div>

Can you open an issue with the MWE? This is going to get lost in the pre-JuliaCon madness
