MethodOfLines.jl icon indicating copy to clipboard operation
MethodOfLines.jl copied to clipboard

CallWithMetadata has no field val error for simple PDE system

Open harrybooth opened this issue 3 years ago • 1 comments

using DifferentialEquations
using ModelingToolkit, MethodOfLines

@parameters x
@variables t c(..)

Dx = Differential(x)
Dxx = Differential(x)^2
Dt = Differential(t)

L = 1.
D = 0.16
k = 1.
j0 = 0.4

eq  = Dt(c(t,x)) ~ D*Dxx(c(t,x)) - k*c(t,x)

# Initial and boundary conditions
bcs = [c(0,x) ~ 0., 
       Dx(c(t,0)) ~ -j0, Dx(c(t,L)) ~ 0.]

# Space and time domains
domains = [t ∈ (0.0,12.0),
           x ∈ (0.0,L)]

@named pde_system = PDESystem(eq,bcs,domains,[t,x],[c])

dx = 0.01
order = 2
discretization = MOLFiniteDifference([x => dx], t)

prob = discretize(pde_system,discretization)

produces the error

type CallWithMetadata has no field val

Stacktrace:
 [1] getproperty
   @ ./Base.jl:38 [inlined]
 [2] (::MethodOfLines.var"#418#435")(x::Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Real}, Base.ImmutableDict{DataType, Any}})
   @ MethodOfLines ~/.julia/packages/MethodOfLines/EqHjt/src/MOL_discretization.jl:16
 [3] iterate
   @ ./generator.jl:47 [inlined]
 [4] _collect
   @ ./array.jl:807 [inlined]
 [5] collect_similar(cont::Vector{Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Real}, Base.ImmutableDict{DataType, Any}}}, itr::Base.Generator{Vector{Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Real}, Base.ImmutableDict{DataType, Any}}}, MethodOfLines.var"#418#435"})
   @ Base ./array.jl:716
 [6] map(f::Function, A::Vector{Symbolics.CallWithMetadata{SymbolicUtils.FnType{Tuple, Real}, Base.ImmutableDict{DataType, Any}}})
   @ Base ./abstractarray.jl:2933
 [7] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid})
   @ MethodOfLines ~/.julia/packages/MethodOfLines/EqHjt/src/MOL_discretization.jl:16
 [8] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{MethodOfLines.CenterAlignedGrid})
   @ MethodOfLines ~/.julia/packages/MethodOfLines/EqHjt/src/MOL_discretization.jl:162
 [9] top-level scope
   @ ~/Documents/Hadjivasiliou_Julia_Tutorial/notebooks/Tutorial_SymbolicNumerics.ipynb:1

Project.toml:

  [6e4b80f9] BenchmarkTools v1.3.1
  [2b5f629d] DiffEqBase v6.105.1
  [ebbdde9d] DiffEqBayes v3.1.0
  [459566f4] DiffEqCallbacks v2.24.2
  [1130ab10] DiffEqParamEstim v1.27.0
  [0c46a032] DifferentialEquations v7.5.0
  [634d3b9d] DrWatson v2.11.1
  [94925ecb] MethodOfLines v0.5.1
⌃ [961ee093] ModelingToolkit v8.29.0
  [76087f3c] NLopt v0.6.5
⌃ [91a5bcdd] Plots v1.35.4
  [731186ca] RecursiveArrayTools v2.32.0
  [0c5d862f] Symbolics v4.13.0
  [fce5fe82] Turing v0.21.12
  [e88e6eb3] Zygote v0.6.49
  [37e2e46d] LinearAlgebra

harrybooth avatar Oct 21 '22 13:10 harrybooth

Please give the arguments of c in the PDESystem; try:

@named pde_system = PDESystem(eq,bcs,domains,[t,x],[c(t,x)])

xtalax avatar Oct 21 '22 17:10 xtalax

Ok done, and solved!

Might need to change the example in the Modeling toolkit documentation? : https://mtk.sciml.ai/stable/systems/PDESystem/

Currently it doesn't say to give the arguments (t,x)

harrybooth avatar Oct 24 '22 08:10 harrybooth