|
| 1 | +using ModelingToolkit, SymbolicIndexingInterface, SciMLBase |
| 2 | + |
| 3 | +@parameters t a b |
| 4 | +@variables x(t) y(t) |
| 5 | +D = Differential(t) |
| 6 | +eqs = [D(x) ~ a * y + t, D(y) ~ b * t] |
| 7 | +@named odesys = ODESystem(eqs, t, [x, y], [a, b]) |
| 8 | + |
| 9 | +@test all(is_variable.((odesys,), [x, y, 1, 2, :x, :y])) |
| 10 | +@test all(.!is_variable.((odesys,), [a, b, t, 3, 0, :a, :b])) |
| 11 | +@test variable_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == [1, 2, nothing, nothing, nothing, 1, 2, 1, 2, nothing, nothing] |
| 12 | +@test isequal(variable_symbols(odesys), [x, y]) |
| 13 | +@test all(is_parameter.((odesys,), [a, b, 1, 2, :a, :b])) |
| 14 | +@test all(.!is_parameter.((odesys,), [x, y, t, 3, 0, :x, :y])) |
| 15 | +@test parameter_index.((odesys,), [x, y, a, b, t, 1, 2, :x, :y, :a, :b]) == [nothing, nothing, 1, 2, nothing, 1, 2, nothing, nothing, 1, 2] |
| 16 | +@test isequal(parameter_symbols(odesys), [a, b]) |
| 17 | +@test all(is_independent_variable.((odesys,), [t, :t])) |
| 18 | +@test all(.!is_independent_variable.((odesys,), [x, y, a, :x, :y, :a])) |
| 19 | +@test isequal(independent_variable_symbols(odesys), [t]) |
| 20 | +@test is_time_dependent(odesys) |
| 21 | +@test constant_structure(odesys) |
| 22 | + |
| 23 | +@variables x y z |
| 24 | +@parameters σ ρ β |
| 25 | + |
| 26 | +eqs = [0 ~ σ*(y-x), |
| 27 | + 0 ~ x*(ρ-z)-y, |
| 28 | + 0 ~ x*y - β*z] |
| 29 | +@named ns = NonlinearSystem(eqs, [x,y,z],[σ,ρ,β]) |
| 30 | + |
| 31 | +@test !is_time_dependent(ns) |
| 32 | + |
| 33 | +@parameters x |
| 34 | +@variables t u(..) |
| 35 | +Dxx = Differential(x)^2 |
| 36 | +Dtt = Differential(t)^2 |
| 37 | +Dt = Differential(t) |
| 38 | + |
| 39 | +#2D PDE |
| 40 | +C=1 |
| 41 | +eq = Dtt(u(t,x)) ~ C^2*Dxx(u(t,x)) |
| 42 | + |
| 43 | +# Initial and boundary conditions |
| 44 | +bcs = [u(t,0) ~ 0.,# for all t > 0 |
| 45 | + u(t,1) ~ 0.,# for all t > 0 |
| 46 | + u(0,x) ~ x*(1. - x), #for all 0 < x < 1 |
| 47 | + Dt(u(0,x)) ~ 0. ] #for all 0 < x < 1] |
| 48 | + |
| 49 | +# Space and time domains |
| 50 | +domains = [t ∈ (0.0,1.0), |
| 51 | + x ∈ (0.0,1.0)] |
| 52 | + |
| 53 | +@named pde_system = PDESystem(eq,bcs,domains,[t,x],[u]) |
| 54 | + |
| 55 | +@test pde_system.ps == SciMLBase.NullParameters() |
| 56 | +@test parameter_symbols(pde_system) == [] |
| 57 | + |
| 58 | +@parameters t x |
| 59 | +@constants h = 1 |
| 60 | +@variables u(..) |
| 61 | +Dt = Differential(t) |
| 62 | +Dxx = Differential(x)^2 |
| 63 | +eq = Dt(u(t, x)) ~ h * Dxx(u(t, x)) |
| 64 | +bcs = [u(0, x) ~ -h * x * (x - 1) * sin(x), |
| 65 | + u(t, 0) ~ 0, u(t, 1) ~ 0] |
| 66 | + |
| 67 | +domains = [t ∈ (0.0, 1.0), |
| 68 | + x ∈ (0.0, 1.0)] |
| 69 | + |
| 70 | +analytic = [u(t, x) ~ -h * x * (x - 1) * sin(x) * exp(-2 * h * t)] |
| 71 | +analytic_function = (ps, t, x) -> -ps[1] * x * (x - 1) * sin(x) * exp(-2 * ps[1] * t) |
| 72 | + |
| 73 | +@named pdesys = PDESystem(eq, bcs, domains, [t, x], [u], [h => 1], analytic = analytic) |
| 74 | + |
| 75 | +@test isequal(pdesys.ps, [h => 1]) |
| 76 | +@test isequal(parameter_symbols(pdesys), [h]) |
| 77 | +@test isequal(parameters(pdesys), [h]) |
0 commit comments