Skip to content

Compile time assessment with increasing grid points // ArrayDiscretization? #476

@thomvet

Description

@thomvet

I am trying to understand what the current state of compile time and grid points is and whether it is practical to have a high resolution grid in nD (n > 1):

Here is a quick test:

using ModelingToolkit, MethodOfLines, DomainSets, GLMakie

#define a simple column with flow rate 1, length 1 and just advection
@parameters t z
@variables  c(..)

Dₜ = Differential(t)
D_z = Differential(z)
pde = Dₜ(c(t, z)) + D_z(c(t, z)) ~ 0

# Boundary & initial conditions
Lval   = 1.0                      # reactor length [m] (numeric in the domain)
t_final = 3.0
domains = [t ∈ Interval(0.0, t_final), z ∈ Interval(0.0, Lval)]
bcsics     = [c(t, 0) ~ 5.0, c(0, z) ~ 0.0]   # Dirichlet inlet, initial condition column containing nothing at start
@named pdesys = PDESystem(pde, bcsics, domains, [t, z], [c(t,z)])

#now gather some time on discretization times for different number of grid points
N = 10:10:400
times = zeros(size(N))
#warm up
discr = MOLFiniteDifference([z => 1/N[1]], t)     
odesys = discretize(pdesys, discr)

#gather time taken vs. number of points
for i in eachindex(N)
    @show i
    discr = MOLFiniteDifference([z => 1/N[i]], t)     
    inter = @timed odesys = discretize(pdesys, discr)
    times[i] = inter.time
end
 
#plot
f = Figure()
ax = Axis(f[1,1], xlabel = "N [-]", ylabel = "time [s]")
scatter!(ax, N, times)

Results in:

Image

(If anyone knows why there is a drop in compilation time at N = 330, I'd be curious to know :))

Anyhow, compilation time scales roughly with N^2.

With a 40 x 40 grid in a 2D case, one would pass around 1 hr in compilation time.

This is on a reasonable CPU and newest Julia version:
versioninfo()

Julia Version 1.11.7
Commit f2b3dbda30 (2025-09-08 12:10 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 24 × 12th Gen Intel(R) Core(TM) i7-12850HX
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 20 default, 0 interactive, 10 GC (on 24 virtual cores)

and relatively new package versions (Pkg.status()):

  [5b8099bc] DomainSets v0.7.16
  [e9467ef8] GLMakie v0.13.6
  [94925ecb] MethodOfLines v0.11.9
  [961ee093] ModelingToolkit v10.23.0

So, my conclusion is that compile times currently are prohibitive even at relatively low number of grid points in, e.g., 2D.

Now, the question. I have seen that there is a fragment of an ArrayDiscretization in the source code that hints at possibly lower compile times when implemented. Is there any way of bringing this along? Any hints on getting it done?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions