Skip to content

Commit ebee603

Browse files
authored
Merge pull request #100 from bauglir/set-ODESystem-defaults
Set known defaults for a `CellModel`s `ODESystem`
2 parents 2afeff5 + 7e1ffa8 commit ebee603

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CellMLToolkit"
22
uuid = "03cb29e0-1ef4-4721-aa24-cf58a006576f"
33
authors = ["Shahriar Iravanian <[email protected]>"]
4-
version = "2.9.1"
4+
version = "2.9.2"
55

66
[deps]
77
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"

src/components.jl

+5
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ function process_components(doc::Document; simplify = true)
234234
if simplify
235235
sys = structural_simplify(sys)
236236
@set! sys.eqs = substitute_eqs(equations(sys), post_sub)
237+
238+
# Defaults need to be set after simplifying as otherwise parameters and
239+
# states for which no defaults are available may still be present in
240+
# the system
241+
@set! sys.defaults = Dict(find_list_value(doc, vcat(parameters(sys), states(sys))))
237242
end
238243

239244
return sys

test/beeler.jl

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ V2 = map(x -> x[1], sol2.u)
1717
err = sum(abs.(V1 .- V2)) / length(V1)
1818
@test err < 0.1
1919

20+
# Ensure defaults are set and that generating an `ODEProblem` directly from the
21+
# `ODESystem` is equivalent to doing so from a `CellModel`
22+
@test length(ModelingToolkit.defaults(ml.sys)) > 0
23+
sys_prob = ODEProblem(ml.sys; tspan = (0, 10000.0))
24+
sol3 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
25+
V3 = map(x -> x[1], sol3.u)
26+
err2 = sum(abs.(V1 .- V3)) / length(V1)
27+
@test err2 0
28+
2029
# prob = ODEProblem(ml, (0,10000.0); jac=true)
2130
# sol3 = solve(prob, TRBDF2(), dtmax=0.5, saveat=1.0)
2231
# V3 = map(x -> x[1], sol2.u)

test/noble_1962.jl

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,14 @@ sol1 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
66
sol2 = solve(prob, TRBDF2(), dtmax = 0.5, saveat = 1.0)
77
V1 = map(x -> x[2], sol1.u)
88
V2 = map(x -> x[2], sol2.u)
9-
err = sum(abs.(V1 .- V2)) / length(V1)
10-
@test err < 1.0
9+
err1 = sum(abs.(V1 .- V2)) / length(V1)
10+
@test err1 < 1.0
11+
12+
# Ensure defaults are set and that generating an `ODEProblem` directly from the
13+
# `ODESystem` is equivalent to doing so from a `CellModel`
14+
@test length(ModelingToolkit.defaults(ml.sys)) > 0
15+
sys_prob = ODEProblem(ml.sys; tspan = (0, 10000.0))
16+
sol3 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
17+
V3 = map(x -> x[2], sol3.u)
18+
err2 = sum(abs.(V1 .- V3)) / length(V1)
19+
@test err2 0

0 commit comments

Comments
 (0)