# Error in PDE Example

I’m trying to follow the example for solving the heat equation PDE from the DiffEqOperators page, but I am running into an error in the discretization step. The code is

``````using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators

# Parameters, variables, and derivatives
@parameters t x
@variables u(..)
# Warning: `@derivatives D'''~x` is deprecated. Use `Differential(x)^3` instead.
#@derivatives Dt'~t
#@derivatives Dxx''~x
Dt = Differential(t)
Dxx = Differential(x)^2
# 1D PDE and boundary conditions

eq  = Dt(u(t,x)) ~ Dxx(u(t,x))
bcs = [u(0,x) ~ cos(x),
u(t,0) ~ exp(-t),
u(t,Float64(pi)) ~ -exp(-t)]

# Space and time domains
domains = [t ∈ IntervalDomain(0.0, 1.0),
x ∈ IntervalDomain(0.0, Float64(pi))]

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

# Method of lines discretization
dx = 0.1
order = 2
discretization = MOLFiniteDifference(dx,order)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys,discretization)  # <--- Error occurs here

# Solve ODE problem
sol = solve(prob,Tsit5(),saveat=0.1)
``````

Side note, using `@derivatives` as in the example gives a deprecation warning. With this setup, the error I get is

``````julia> prob = discretize(pdesys,discretization)
ERROR: LoadError: type Int64 has no field val
``````

This is with Julia v1.6.1 and

``````(diffeq) pkg> st
Status `~/dev/learning/diffeq/Project.toml`
[9fdde737] DiffEqOperators v4.24.0
[961ee093] ModelingToolkit v5.16.0
[1dea7af3] OrdinaryDiffEq v5.52.4
[91a5bcdd] Plots v1.12.0
``````

Thank you in advance for any help.

Edit: This error seems similar to this one, however, that issue was traced to using complex numbers, which does not seem to be the case here.

1 Like

I found a similar example in the `DiffEqOperators` docs that does work, and I think I’ve found the problem. In the above example, if `Float64(pi)` in both `bcs` and `domains` is changed to any whole number (1 and 1.0, 2 and 2.0, etc), then it works. It also works for `u(t, 4.5)` and `x ∈ IntervalDomain(0.0, 4.5)`, but fails for 4.55. So, is the problem that `IntervalDomain` cannot break up 4.55 (or pi) evenly?

1 Like

I encountered something similar. Not sure if this helps, but it appears the examples in the docs are not fully working, but the examples that can be found in the test/MOL folder of DiffEqOperators.jl are working, so those might be useful as a starting point.

Oh, looking at the tests is a good idea. I hadn’t thought of that. Thanks.

1 Like

I mean, the first line of that tutorial right now is:

Note: This uses a currently unreleased interface that is still a work in progress. Use at your own risk!

We will remove that statement when it’s all good, but right now it’s partially in development and the docs are very clear about that.

2 Likes