-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathpde.jl
29 lines (22 loc) · 879 Bytes
/
pde.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
using ModelingToolkit: t_nounits as t, D_nounits as Dt
# Define some variables
@parameters x
@constants h = 1
@variables u(..)
Dxx = Differential(x)^2
eq = Dt(u(t, x)) ~ h * Dxx(u(t, x))
bcs = [u(0, x) ~ -h * x * (x - 1) * sin(x),
u(t, 0) ~ 0, u(t, 1) ~ 0]
domains = [t ∈ (0.0, 1.0),
x ∈ (0.0, 1.0)]
analytic = [u(t, x) ~ -h * x * (x - 1) * sin(x) * exp(-2 * h * t)]
analytic_function = (ps, t, x) -> -ps[1] * x * (x - 1) * sin(x) * exp(-2 * ps[1] * t)
@named pdesys = PDESystem(eq, bcs, domains, [t, x], [u], [h], analytic = analytic)
@show pdesys
@test all(isequal.(independent_variables(pdesys), [t, x]))
dx = 0:0.1:1
dt = 0:0.1:1
# Test generated analytic_func
@test all(pdesys.analytic_func[u(t, x)]([2], disct, discx) ≈
analytic_function([2], disct, discx) for disct in dt, discx in dx)