Skip to content

Commit 0283fcf

Browse files
Merge pull request #49 from SciML/observables
add observables test
2 parents c6d537c + 9b74a4c commit 0283fcf

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/downstream/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
2+
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
23
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"

test/downstream/observables.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using ModelingToolkit, OrdinaryDiffEq, Test
2+
3+
@parameters t σ ρ β
4+
@variables x(t) y(t) z(t)
5+
D = Differential(t)
6+
7+
eqs = [D(x) ~ σ*(y-x),
8+
D(y) ~ x*-z)-y,
9+
D(z) ~ x*y - β*z]
10+
11+
lorenz1 = ODESystem(eqs,name=:lorenz1)
12+
lorenz2 = ODESystem(eqs,name=:lorenz2)
13+
14+
@variables a, α
15+
@parameters γ
16+
connections = [0 ~ lorenz1.x + lorenz2.y + a*γ,
17+
α ~ 2lorenz1.x + a*γ]
18+
connected = structural_simplify(ODESystem(connections,t,[a,α],[γ],systems=[lorenz1,lorenz2]))
19+
20+
u0 = [lorenz1.x => 1.0,
21+
lorenz1.y => 0.0,
22+
lorenz1.z => 0.0,
23+
lorenz2.x => 0.0,
24+
lorenz2.y => 1.0,
25+
lorenz2.z => 0.0,
26+
a => 2.0]
27+
28+
p = [lorenz1.σ => 10.0,
29+
lorenz1.ρ => 28.0,
30+
lorenz1.β => 8/3,
31+
lorenz2.σ => 10.0,
32+
lorenz2.ρ => 28.0,
33+
lorenz2.β => 8/3,
34+
γ => 2.0]
35+
36+
tspan = (0.0,100.0)
37+
prob = ODEProblem(connected,u0,tspan,p)
38+
sol = solve(prob,Rodas4())
39+
40+
@test sol[lorenz1.x] isa Vector
41+
@test sol[lorenz1.x,2] isa Float64
42+
@test sol[lorenz1.x,:] isa Vector
43+
@test length(sol[lorenz1.x,1:5]) == 5
44+
@test sol[α] isa Vector
45+
@test sol[α,3] isa Float64
46+
@test length(sol[α,5:10]) == 6
47+
48+
#=
49+
using Plots
50+
plot(sol,vars=(lorenz2.x,lorenz2.z))
51+
plot(sol,vars=(α,lorenz2.z))
52+
plot(sol,vars=(lorenz2.x,α))
53+
plot(sol,vars=α)
54+
plot(sol,vars=(t,α))
55+
=#

0 commit comments

Comments
 (0)