ModelingToolKit and the number pi

I am likely misunderstanding the issue below.

The issues, however, of ModelingToolkit not liking pi reported previously at Discretization of semi-coupled wave and diffusion equations fails for step size of pi/(25n) using MethodOfLines.jl seems to persist.

A MWE is below. The code as given does not work well. The same code with u(x,0) ~ sin(pi*x) replaced by u(x,0) ~ sin(mypi*x) works fine.

Thx for any insight.

# Parameters, variables, and derivatives
@parameters x t
@variables u(..)
Dxx = Differential(x)^2
Dtt = Differential(t)^2
Dt = Differential(t)
Dx = Differential(x)

#2D PDE
c=1 # wave velocity 
eq  = [ Dt(u(x,t)) ~ c^2*Dxx(u(x,t)) ] 

mypi = 3.1415

# Initial and boundary conditions
# Initial velocity is still missing 
bcs = [ u(0.,t) ~ 0.,# for all t > 0
        u(1.,t) ~ 0.,
        u(x,0) ~ sin(pi*x)]

# Space and time domains
maxt = .5 
domains = [x ∈ (0.0,1.0), 
           t ∈ (0.0,maxt)]

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

#  Define discretization 
N = 32
order = 2 
discretization = MOLFiniteDifference([x=>N], t, approx_order=order)

# Convert the PDE problem into an ODE problem
println("Discretization:")
@time prob = discretize(pdesys,discretization)

println("Solve:")
@time sol = solve(prob, TRBDF2(),saveat=maxt/10)

# Plot results
surface(sol[t], sol[x], sol[u(x,t)]) 

Does it work on a desktop computer? If it does, but not on a pi, perhaps you do not have enough RAM?

Can you share the output of:

julia> versioninfo()

?
And, inthe terminal (not in Julia), the output of

free -h

?

Thx @ufechner7

pi here is the number pi. pi here is not a hardware device.

I updated the title of your post for clarity.

1 Like

Did you ever figure this out? Your code works for me. I had to add the imports back but otherwise it runs unaltered

# crazypi.jl
using ModelingToolkit
using MethodOfLines
using DifferentialEquations
using Plots

# Parameters, variables, and derivatives
@parameters x t
@variables u(..)
Dxx = Differential(x)^2
Dtt = Differential(t)^2
Dt = Differential(t)
Dx = Differential(x)

#2D PDE
c=1 # wave velocity 
eq  = [ Dt(u(x,t)) ~ c^2*Dxx(u(x,t)) ] 

mypi = 3.1415

# Initial and boundary conditions
# Initial velocity is still missing 
bcs = [ u(0.,t) ~ 0.,# for all t > 0
        u(1.,t) ~ 0.,
        u(x,0) ~ sin(pi*x)]

# Space and time domains
maxt = .5 
domains = [x ∈ (0.0,1.0), 
           t ∈ (0.0,maxt)]

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

#  Define discretization 
N = 32
order = 2 
discretization = MOLFiniteDifference([x=>N], t, approx_order=order)

# Convert the PDE problem into an ODE problem
println("Discretization:")
@time prob = discretize(pdesys,discretization)

println("Solve:")
@time sol = solve(prob, TRBDF2(),saveat=maxt/10)

# Plot results
surface(sol[t], sol[x], sol[u(x,t)])
julia> include("crazypi.jl")
Discretization:
 91.253485 seconds (101.89 M allocations: 5.144 GiB, 2.25% gc time, 99.09% compilation time: 100% of which was recompilation)
Solve:
  4.446597 seconds (4.89 M allocations: 259.379 MiB, 99.04% compilation time: 100% of which was recompilation)

julia> versioninfo()
Julia Version 1.12.0
Commit b907bd0600 (2025-10-07 15:42 UTC)
Build Info:

    Note: This is an unofficial build, please report bugs to the project
    responsible for this build and not to the Julia project unless you can
    reproduce the issue using official builds available at https://julialang.org

Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, haswell)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 4 virtual cores)
1 Like

@kousu Many thanks. The error I reported earlier indeed seems to disappear when switching to Julia 1.12.