Skip to content

Commit

Permalink
Merge pull request #128 from termi-official/do/mtk-update
Browse files Browse the repository at this point in the history
Update to MTK 9
  • Loading branch information
ChrisRackauckas authored Jul 17, 2024
2 parents 1e4495f + 2fef2d7 commit 78cec21
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
9 changes: 3 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
MathML = "abcecc63-2b08-419c-80c4-c63dca6fa478"
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.8"
EzXML = "1.1"
MathML = "0.1.14"
Memoize = "0.4.2"
ModelingToolkit = "8.71"
ModelingToolkit = "9"
OrdinaryDiffEq = "6.56"
Random = "1.10"
SafeTestsets = "0.1"
Setfield = "0.8, 1"
SymbolicUtils = "1.2"
Setfield = "1"
SymbolicUtils = "1.2, 2"
Test = "1.10"
julia = "1.10"

Expand Down
15 changes: 9 additions & 6 deletions src/CellMLToolkit.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module CellMLToolkit

using MathML

using ModelingToolkit
using SymbolicUtils: FnType, Sym, operation, arguments
using EzXML
using Memoize
using EzXML: EzXML, elements, namespace, nodecontent, parentnode, readxml, root
using MathML: extract_mathml, parse_node
using Memoize: @memoize
using SymbolicUtils: operation
using ModelingToolkit: ModelingToolkit, @parameters, @variables, Differential,
Equation, ODEProblem, ODESystem,
Symbolics, equations, parameters, structural_simplify,
substitute, unknowns
using Setfield: @set!

include("structures.jl")
include("accessors.jl")
Expand Down
7 changes: 3 additions & 4 deletions src/components.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Setfield

const cellml_ns(xml::EzXML.Document) = namespace(root(xml))
const cellml_ns(node::EzXML.Node) = namespace(node)
const mathml_ns = "http://www.w3.org/1998/Math/MathML"
Expand Down Expand Up @@ -238,7 +236,8 @@ function process_components(doc::Document; simplify = true)
# 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))))
@set! sys.defaults = Dict(find_list_value(
doc, vcat(parameters(sys), unknowns(sys))))
end

return sys
Expand Down Expand Up @@ -310,7 +309,7 @@ function split_sym(sym)
end

find_sys_p(doc::Document, sys) = find_list_value(doc, parameters(sys))
find_sys_u0(doc::Document, sys) = find_list_value(doc, states(sys))
find_sys_u0(doc::Document, sys) = find_list_value(doc, unknowns(sys))

function find_list_value(doc::Document, names)
vars, syms = collect_initiated_values(doc)
Expand Down
4 changes: 1 addition & 3 deletions src/import.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Random

sym(x) = Symbol(x)

function populate_dependency!(doc, comp)
Expand Down Expand Up @@ -154,7 +152,7 @@ function list_top_cellml_files(dir)
imported = Set{String}()
for f in files
xml = readxml(joinpath(dir, f))
for n in CellMLToolkit.list_imports(xml)
for n in list_imports(xml)
push!(imported, n["xlink:href"])
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/noble_1962.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ml = CellModel(path * "/../models/noble_1962/Noble_1962.cellml")

prob = ODEProblem(ml, (0, 10000.0))
sol1 = solve(prob, Euler(), dt = 0.01, saveat = 1.0)
sol2 = solve(prob, TRBDF2(), dtmax = 0.5, saveat = 1.0)
sol2 = solve(prob, TRBDF2(), dtmax = 0.5, saveat = 1.0, reltol = 1e-8, abstol = 1e-8)
V1 = map(x -> x[2], sol1.u)
V2 = map(x -> x[2], sol2.u)
err1 = sum(abs.(V1 .- V2)) / length(V1)
Expand Down

0 comments on commit 78cec21

Please sign in to comment.