Skip to content

Commit

Permalink
Merge pull request #100 from bauglir/set-ODESystem-defaults
Browse files Browse the repository at this point in the history
Set known defaults for a `CellModel`s `ODESystem`
  • Loading branch information
anandijain authored Dec 16, 2022
2 parents 2afeff5 + 7e1ffa8 commit ebee603
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CellMLToolkit"
uuid = "03cb29e0-1ef4-4721-aa24-cf58a006576f"
authors = ["Shahriar Iravanian <siravan@svtsim.com>"]
version = "2.9.1"
version = "2.9.2"

[deps]
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
Expand Down
5 changes: 5 additions & 0 deletions src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ function process_components(doc::Document; simplify = true)
if simplify
sys = structural_simplify(sys)
@set! sys.eqs = substitute_eqs(equations(sys), post_sub)

# Defaults need to be set after simplifying as otherwise parameters and
# states for which no defaults are available may still be present in
# the system
@set! sys.defaults = Dict(find_list_value(doc, vcat(parameters(sys), states(sys))))
end

return sys
Expand Down
9 changes: 9 additions & 0 deletions test/beeler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ V2 = map(x -> x[1], sol2.u)
err = sum(abs.(V1 .- V2)) / length(V1)
@test err < 0.1

# Ensure defaults are set and that generating an `ODEProblem` directly from the
# `ODESystem` is equivalent to doing so from a `CellModel`
@test length(ModelingToolkit.defaults(ml.sys)) > 0
sys_prob = ODEProblem(ml.sys; tspan = (0, 10000.0))
sol3 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
V3 = map(x -> x[1], sol3.u)
err2 = sum(abs.(V1 .- V3)) / length(V1)
@test err2 0

# prob = ODEProblem(ml, (0,10000.0); jac=true)
# sol3 = solve(prob, TRBDF2(), dtmax=0.5, saveat=1.0)
# V3 = map(x -> x[1], sol2.u)
Expand Down
13 changes: 11 additions & 2 deletions test/noble_1962.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ sol1 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
sol2 = solve(prob, TRBDF2(), dtmax = 0.5, saveat = 1.0)
V1 = map(x -> x[2], sol1.u)
V2 = map(x -> x[2], sol2.u)
err = sum(abs.(V1 .- V2)) / length(V1)
@test err < 1.0
err1 = sum(abs.(V1 .- V2)) / length(V1)
@test err1 < 1.0

# Ensure defaults are set and that generating an `ODEProblem` directly from the
# `ODESystem` is equivalent to doing so from a `CellModel`
@test length(ModelingToolkit.defaults(ml.sys)) > 0
sys_prob = ODEProblem(ml.sys; tspan = (0, 10000.0))
sol3 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
V3 = map(x -> x[2], sol3.u)
err2 = sum(abs.(V1 .- V3)) / length(V1)
@test err2 0

2 comments on commit ebee603

@anandijain
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/74251

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.9.2 -m "<description of version>" ebee6039b58ab1282f987da1e9bb1db378e45a4e
git push origin v2.9.2

Please sign in to comment.