Non-Uniform Rectilinear Grids

For more information on how to use a non-uniform rectilinear grid, see the docs for MOLFiniteDifference.

MethodOfLines exports the function chebyspace, which can be used to conveniently construct a Chebyshev grid, which may prove more accurate in certain cases, especially with higher approximation order (benchmarking to come, watch this space). It takes the arguments chebyspace(N, dom) where N is the number of points, and dom is the domain set for the variable you want to discretize in this way.

using OrdinaryDiffEq, ModelingToolkit, MethodOfLines, DomainSets

# Parameters, variables, and derivatives
@parameters t x
@variables u(..)
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, 1) ~ exp(-t) * cos(1)]

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

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

# Method of lines discretization
discx = chebyspace(100, domains[2]) # 100 point Chebyshev space, pair `x => points`
discretization = MOLFiniteDifference([discx], t)

prob = discretize(pdesys, discretization)
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 1.0)
u0: 98-element Vector{Float64}:
 0.999999845952804
 0.999998812146321
 0.999995441246087
 0.9999875591001265
 0.9999722836070885
 0.9999460390354972
 0.9999045738553763
 0.999842982035982
 0.999755727752892
 0.9996366734365695
 ⋮
 0.558768258228662
 0.5551286402077258
 0.5518753322715672
 0.5490146944009753
 0.5465523077481396
 0.544492967897768
 0.5428406792820797
 0.5415986506642236
 0.5407692916166064