Skip to content

Commit 10d29f5

Browse files
flatten fixed
1 parent ea01460 commit 10d29f5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
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.1.0"
4+
version = "2.1.1"
55

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

src/cellml.jl

+11-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ function find_state_names(xml)
1717
# nodes = findall("//x:math//x:eq/following-sibling::x:apply[1]/x:ci", root(xml), ["x"=>mathml_ns])
1818
# vars = nodecontent.(nodes)
1919
nodes = findall("//x:math//x:apply/x:diff", root(xml), ["x"=>mathml_ns])
20-
vars = [nodecontent(lastelement(parentnode(n))) for n in nodes]
20+
vars = [strip(nodecontent(lastelement(parentnode(n)))) for n in nodes]
2121
return unique(vars)
2222
end
2323

2424
# find the unique independent variable
2525
function find_iv(xml)
2626
nodes = findall("//x:math//x:bvar/x:ci", root(xml), ["x"=>mathml_ns])
27-
ivs = unique(nodecontent.(nodes))
27+
ivs = unique(strip.(nodecontent.(nodes)))
2828
if length(ivs) > 1
2929
error("Only one independent variable (iv) is acceptable")
3030
end
@@ -116,10 +116,15 @@ function flatten_equations(xml, eqs)
116116
s = Dict(eq.lhs => eq.rhs for eq in alg)
117117

118118
# alg = [eq.lhs ~ substitute(eq.rhs, s) for eq in alg]
119-
for (i,eq) in enumerate(alg)
120-
eq = eq.lhs ~ substitute(eq.rhs, s)
121-
s[eq.lhs] = eq.rhs
122-
alg[i] = eq
119+
b = true
120+
while b
121+
b = false
122+
for (i,eq) in enumerate(alg)
123+
eq = (eq.lhs ~ substitute(eq.rhs, s))
124+
b = b || !isequal(eq, alg[i])
125+
s[eq.lhs] = eq.rhs
126+
alg[i] = eq
127+
end
123128
end
124129

125130
# s = Dict(a.lhs => a.rhs for a in alg)

0 commit comments

Comments
 (0)